From 1ca109c0b02984a1596171d5e8708ef377c53733 Mon Sep 17 00:00:00 2001 From: Micha Mazaheri Date: Sat, 29 Nov 2014 12:30:15 -0800 Subject: [PATCH] Configured for GitHub Releases and Travis CI. --- .gitignore | 3 + .travis.yml | 19 + Cakefile | 94 ++++- ObjCNSURLConnectionCodeGenerator.js | 178 --------- README.md | 7 + URI.js => lib/URI.js | 0 mustache.js | 578 ---------------------------- package.json | 16 + 8 files changed, 132 insertions(+), 763 deletions(-) create mode 100644 .gitignore create mode 100644 .travis.yml delete mode 100644 ObjCNSURLConnectionCodeGenerator.js rename URI.js => lib/URI.js (100%) delete mode 100644 mustache.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f99b9b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +node_modules/ +build/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4de6cb5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: node_js +node_js: +- '0.10' +before_install: +- npm install coffee-script +before_script: +- ./node_modules/.bin/cake archive +script: +- ./node_modules/.bin/cake test +deploy: + provider: releases + api_key: + secure: by9x9mMPf7QcZEu1XsCCpTqM8CUgVs5+KZfmMNCE/bGuAn94pSdcKADiZFuQhRyJBiXT8V7yUOdeEtkgyhVNLfceoqStkWhFXWT1iILfiOzOrHsH2sjSfBFfvD2zAoAy7JBeqdiPbBsvuZfrdYS5QmZ654A6mHokeUnM0t42ePs= + file: build/ObjCNSURLConnectionCodeGenerator.zip + skip_cleanup: true + on: + tags: true + all_branches: true + repo: LuckyMarmot/Paw-ObjCNSURLConnectionCodeGenerator diff --git a/Cakefile b/Cakefile index 15927b9..195162f 100644 --- a/Cakefile +++ b/Cakefile @@ -1,19 +1,99 @@ -{print} = require 'sys' {spawn} = require 'child_process' +{ncp} = require 'ncp' +mkdirp = require 'mkdirp' +fs = require 'fs' file = 'ObjCNSURLConnectionCodeGenerator.coffee' +identifier = 'com.luckymarmot.PawExtensions.ObjCNSURLConnectionCodeGenerator' -task 'build', -> - coffee = spawn 'coffee', ['-c', file] +extensions_dir = "#{ process.env.HOME }/Library/Containers/com.luckymarmot.Paw/Data/Library/Application Support/com.luckymarmot.Paw/Extensions/" +build_root_dir = "build" +build_dir = "#{ build_root_dir }/#{ identifier }" + +# compile CoffeeScript +build_coffee = (callback) -> + coffee = spawn 'coffee', ['-c', '-o', build_dir, file] coffee.stderr.on 'data', (data) -> process.stderr.write data.toString() coffee.stdout.on 'data', (data) -> - print data.toString() + process.stdout.write data.toString() coffee.on 'exit', (code) -> if code is 0 - console.log '>>> Build successful' + callback?() + else + console.error "Build failed with error: #{ code }" + +# copy files to build directory +build_copy = () -> + fs.writeFileSync "#{ build_dir }/README.md", fs.readFileSync("./README.md") + fs.writeFileSync "#{ build_dir }/LICENSE", fs.readFileSync("./LICENSE") + fs.writeFileSync "#{ build_dir }/objc.mustache", fs.readFileSync("./objc.mustache") + fs.writeFileSync "#{ build_dir }/mustache.js", fs.readFileSync("./node_modules/mustache/mustache.js") + fs.writeFileSync "#{ build_dir }/URI.js", fs.readFileSync("./lib/URI.js") + +# build: build CoffeeScript and copy files to build directory +build = (callback) -> + # mkdir build dir + mkdirp build_dir, (err) -> + if err + console.error err else - console.log '!!! Build failed' + build_coffee () -> + build_copy() + callback?() + +# install: copy files to Extensions directory +install = (callback) -> + ncp build_dir, "#{ extensions_dir }/#{ identifier }", (err) -> + if err + console.error err + else + callback?() + +# archive: create a zip archive from the build +archive = (callback) -> + zip_file = "#{ identifier.split('.').pop() }.zip" + + # go to build dir + process.chdir "#{ build_root_dir }/" + + # delete any previous zip + if fs.existsSync zip_file + fs.unlinkSync zip_file + + # zip + zip = spawn 'zip', ["-r", zip_file, "#{ identifier }/"] + zip.stderr.on 'data', (data) -> + process.stderr.write data.toString() + zip.stdout.on 'data', (data) -> + process.stdout.write data.toString() + zip.on 'exit', (code) -> + if code is 0 + callback?() + else + console.error "zip returned with error code: #{ code }" + +task 'build', -> + build() + +task 'test', -> + build () -> + # no test to run + +task 'install', -> + build () -> + install() + +task 'archive', -> + build () -> + archive() task 'watch', -> - spawn 'coffee', ['--watch', '--compile', file] + # find all files in directory + for filename in fs.readdirSync '.' + # only watch non-hidden files + if not filename.match(/^\./) and fs.lstatSync("./#{ filename }").isFile() + fs.watchFile "./#{ filename }", {persistent:true, interval:500}, (_event, _filename) -> + # when a file is changed, build and install + build () -> + install() diff --git a/ObjCNSURLConnectionCodeGenerator.js b/ObjCNSURLConnectionCodeGenerator.js deleted file mode 100644 index c026b0b..0000000 --- a/ObjCNSURLConnectionCodeGenerator.js +++ /dev/null @@ -1,178 +0,0 @@ -// Generated by CoffeeScript 1.8.0 -(function() { - var ObjCNSURLConnectionCodeGenerator, addslashes; - - require("mustache.js"); - - require("URI.js"); - - addslashes = function(str) { - return ("" + str).replace(/[\\"]/g, '\\$&'); - }; - - ObjCNSURLConnectionCodeGenerator = function() { - this.url = function(request) { - var name, url_params, url_params_object, value; - url_params_object = (function() { - var _uri; - _uri = URI(request.url); - return _uri.search(true); - })(); - url_params = (function() { - var _results; - _results = []; - for (name in url_params_object) { - value = url_params_object[name]; - _results.push({ - "name": addslashes(name), - "value": addslashes(value) - }); - } - return _results; - })(); - return { - "base": addslashes((function() { - var _uri; - _uri = URI(request.url); - _uri.search(""); - return _uri; - })()), - "params": url_params, - "has_params": url_params.length > 0 - }; - }; - this.headers = function(request) { - var header_name, header_value, headers; - headers = request.headers; - return { - "has_headers": Object.keys(headers).length > 0, - "header_list": (function() { - var _results; - _results = []; - for (header_name in headers) { - header_value = headers[header_name]; - _results.push({ - "header_name": addslashes(header_name), - "header_value": addslashes(header_value) - }); - } - return _results; - })() - }; - }; - this.body = function(request) { - var json_body, name, raw_body, url_encoded_body, value; - json_body = request.jsonBody; - if (json_body) { - return { - "has_json_body": true, - "json_body_object": this.json_body_object(json_body) - }; - } - url_encoded_body = request.urlEncodedBody; - if (url_encoded_body) { - return { - "has_url_encoded_body": true, - "url_encoded_body": (function() { - var _results; - _results = []; - for (name in url_encoded_body) { - value = url_encoded_body[name]; - _results.push({ - "name": addslashes(name), - "value": addslashes(value) - }); - } - return _results; - })() - }; - } - raw_body = request.body; - if (raw_body) { - if (raw_body.length < 10000) { - return { - "has_raw_body": true, - "raw_body": addslashes(raw_body) - }; - } else { - return { - "has_long_body": true - }; - } - } - }; - this.json_body_object = function(object, indent) { - var indent_str, indent_str_children, key, s, value; - if (indent == null) { - indent = 0; - } - if (object === null) { - s = "[NSNull null]"; - } else if (typeof object === 'string') { - s = "@\"" + (addslashes(object)) + "\""; - } else if (typeof object === 'number') { - s = "@" + object; - } else if (typeof object === 'boolean') { - s = "@" + (object ? "YES" : "NO"); - } else if (typeof object === 'object') { - indent_str = Array(indent + 1).join('\t'); - indent_str_children = Array(indent + 2).join('\t'); - if (object.length != null) { - s = "@[\n" + ((function() { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = object.length; _i < _len; _i++) { - value = object[_i]; - _results.push("" + indent_str_children + (this.json_body_object(value, indent + 1))); - } - return _results; - }).call(this)).join(',\n') + ("\n" + indent_str + "]"); - } else { - s = "@{\n" + ((function() { - var _results; - _results = []; - for (key in object) { - value = object[key]; - _results.push("" + indent_str_children + "@\"" + (addslashes(key)) + "\": " + (this.json_body_object(value, indent + 1))); - } - return _results; - }).call(this)).join(',\n') + ("\n" + indent_str + "}"); - } - } - if (indent === 0) { - if (typeof object === 'object') { - if (object.length != null) { - s = "NSArray* bodyObject = " + s + ";"; - } else { - s = "NSDictionary* bodyObject = " + s + ";"; - } - } else { - s = "id bodyObject = " + s + ";"; - } - } - return s; - }; - this.generate = function(context) { - var request, template, view; - request = context.getCurrentRequest(); - view = { - "request": context.getCurrentRequest(), - "url": this.url(request), - "headers": this.headers(request), - "body": this.body(request) - }; - if (view.url.has_params || (view.body && view.body.has_url_encoded_body)) { - view["has_utils_query_string"] = true; - } - template = readFile("objc.mustache"); - return Mustache.render(template, view); - }; - }; - - ObjCNSURLConnectionCodeGenerator.identifier = "com.luckymarmot.PawExtensions.ObjCNSURLConnectionCodeGenerator"; - - ObjCNSURLConnectionCodeGenerator.title = "Objective-C (NSURLConnection)"; - - registerCodeGenerator(ObjCNSURLConnectionCodeGenerator); - -}).call(this); diff --git a/README.md b/README.md index 4cd8a92..735b873 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/LuckyMarmot/Paw-ObjCNSURLConnectionCodeGenerator.svg?branch=master)](https://travis-ci.org/LuckyMarmot/Paw-ObjCNSURLConnectionCodeGenerator) + #Objective-C + NSURLConnection Code Generator (Paw Extension) This a Paw Extension that generates code for Objective-C using the `NSURLConnection` library. @@ -8,6 +10,11 @@ This Paw Extension is released under the [MIT License](LICENSE). Feel free to fo Copyright © 2014 Paw Inc. +##Contributors + +See [Contributors](https://github.com/LuckyMarmot/Paw-ObjCNSURLConnectionCodeGenerator/graphs/contributors). + ##Credits * [Mustache.js](https://github.com/janl/mustache.js/), also released under the MIT License +* [URI.js](http://medialize.github.io/URI.js/), also released under the MIT License diff --git a/URI.js b/lib/URI.js similarity index 100% rename from URI.js rename to lib/URI.js diff --git a/mustache.js b/mustache.js deleted file mode 100644 index be3d01a..0000000 --- a/mustache.js +++ /dev/null @@ -1,578 +0,0 @@ -/*! - * mustache.js - Logic-less {{mustache}} templates with JavaScript - * http://github.com/janl/mustache.js - */ - -/*global define: false*/ - -(function (global, factory) { - if (typeof exports === "object" && exports) { - factory(exports); // CommonJS - } else if (typeof define === "function" && define.amd) { - define(['exports'], factory); // AMD - } else { - factory(global.Mustache = {}); //