Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-p committed Dec 28, 2013
0 parents commit 6d43481
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
.DS_Store
25 changes: 25 additions & 0 deletions package.json
@@ -0,0 +1,25 @@
{
"private": true,
"name": "grunt-gapreload",
"version": "0.1.0",
"description": "A Grunt tasks for the Cordova/PhoneGap GapReload plugin.",
"author": "fingerproof",
"license": "MIT",
"homepage": "https://github.com/fingerproof/grunt-gapreload",
"repository": {
"type": "git",
"url": "git://github.com/fingerproof/grunt-gapreload.git"
},
"bugs": {
"url": "https://github.com/fingerproof/grunt-gapreload/issues"
},
"peerDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-watch": "~0.5.3"
},
"dependencies": {
"grunt-concurrent": "~0.4.2",
"grunt-exec": "~0.4.2",
"register-grunt-sub-tasks": "fingerproof/register-grunt-sub-tasks"
}
}
69 changes: 69 additions & 0 deletions tasks/gapreload.js
@@ -0,0 +1,69 @@
/*jshint node:true */

var register = require("register-grunt-sub-tasks");
var variables = register.unpack("SERVER LIVERELOAD", "$1_HOSTNAME $1_PORT");

function cordova (command, format) {
command = "cordova " + command;
function task (config, grunt) {
function cmd () { return command + format(arguments, config, grunt); }
return { cmd: cmd, cwd: config("cwd") || "cordova" };
}
return { type: "exec", task: task };
}

function add (format, _) {
var url = "https://github.com/fingerproof/cordova-plugin-gapreload";
return cordova("plugin add " + url, function formatter (params, config, grunt) {
return format(variables, function separator (key, index) {
var value = params[index] || config(key);
if (key === variables[3] && !value) {
var port = grunt.config("watch.gapreload.options.livereload");
if (_.isPlainObject(port)) { port = port.port; }
if (_.isNumber(port)) { value = port; }
}
return value ? " --variable " + key + "='" + value + "'" : "";
});
});
}

function serve (format) {
return cordova("serve", function formatter (params, config) {
return format.shell(params[0] || config(variables[1]));
});
}

function watch () {
var task = {
tasks: ["gapreload-serve", "watch:gapreload"],
options: { logConcurrentOutput: true }
};
return { type: "concurrent", task: task };
}

function remove () {
function noop () { return ""; }
return cordova("plugin remove pro.fing.cordova.gapreload", noop);
}

function prepare (format) { return cordova("prepare", format.shell); }

function gapreload (format) {
function task (config, grunt) {
return function () {
var params = format.grunt(arguments);
var tasks = register.unpack("add watch", "gapreload-$1" + params);
grunt.task.run(tasks);
};
}
return { type: "grunt", task: task };
}

module.exports = register("gapreload", {
"add: Installs the Cordova GapReload plugin if needed.": add,
"serve: Executes `$ cordova serve <port>`.": serve,
"watch: Runs '<%= sup %>-serve' and 'watch:<%= sup %>'.": watch,
"remove: Uninstalls the Cordova GapReload plugin.": remove,
"prepare: Executes `$ cordova prepare <platforms>`.": prepare,
"<%= sup %>: Runs '<%= sup %>-add' and '<%= sup %>-watch'.": gapreload
});

0 comments on commit 6d43481

Please sign in to comment.