Skip to content

Commit

Permalink
Merge pull request #132 from calvium-forks/master
Browse files Browse the repository at this point in the history
Added variables option for plugins
  • Loading branch information
logankoester committed Aug 5, 2015
2 parents 0d693ea + 13908c7 commit 556589e
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 5 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,23 @@ grunt.initConfig({
html : 'index.html', // (Optional) You may change this to any other.html
path: 'phonegap',
cleanBeforeBuild: true // when false the build path doesn't get regenerated
plugins: ['/local/path/to/plugin', 'http://example.com/path/to/plugin.git'],
plugins: [
'/local/path/to/plugin',
'http://example.com/path/to/plugin.git',
{
id: 'git://example.com/example/repository',
variables: [
{
name: 'APP_ID',
value: 'EXAMPLE_ID'
},
{
name: 'CLIENT_KEY',
value: 'EXAMPLE_KEY'
}
]
}
],
platforms: ['android'],
maxBuffer: 200, // You may need to raise this for iOS.
verbose: false,
Expand Down
18 changes: 17 additions & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,23 @@ grunt.initConfig({
html : 'index.html', // (Optional) You may change this to any other.html
path: 'phonegap',
cleanBeforeBuild: true // when false the build path doesn't get regenerated
plugins: ['/local/path/to/plugin', 'http://example.com/path/to/plugin.git'],
plugins: [
'/local/path/to/plugin',
'http://example.com/path/to/plugin.git',
{
id: 'git://example.com/example/repository',
variables: [
{
name: 'APP_ID',
value: 'EXAMPLE_ID'
},
{
name: 'CLIENT_KEY',
value: 'EXAMPLE_KEY'
}
]
}
],
platforms: ['android'],
maxBuffer: 200, // You may need to raise this for iOS.
verbose: false,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-copy": "~0.5.0",
"grunt-bump": "git://github.com/logankoester/grunt-bump#gpg-sign",
"xml2json": "~0.4.0",
"xml2json": "~0.7.0",
"lodash": "~2.4.0",
"hash_file": "~0.1.1",
"grunt-readme-generator": "git://github.com/logankoester/grunt-readme-generator#semver-sort"
Expand Down
2 changes: 2 additions & 0 deletions src/tasks/build/after/local/ios.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ module.exports = ios = (grunt) ->
tasks =
buildIcons: require('./ios/icons')(grunt).build
buildScreens: require('./ios/screens')(grunt).build
buildResources: require('./ios/resources')(grunt).build
setStatusBar: require('./ios/plist')(grunt).setStatusBar

run: (fn) ->
fluid(tasks)
.buildIcons()
.buildScreens()
.buildResources()
.setStatusBar()
.go (err, result) ->
if err then grunt.fatal err
Expand Down
23 changes: 23 additions & 0 deletions src/tasks/build/after/local/ios/resources.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
path = require 'path'

module.exports = resources = (grunt) ->
helpers = require('../../../../helpers')(grunt)

build: (fn) ->
resources = helpers.config 'resources'
phonegapPath = helpers.config 'path'
appName = helpers.config 'name'

dest = path.join phonegapPath, 'platforms', 'ios', appName

if resources?.ios
for resource in resources?.ios
console.log 'resource from:'+resource.from+", to:"+resource.to
grunt.file.recurse resource.from, (file, root, filepath, filename) ->
console.log "copying "+file+ ","+root+","+filepath+","+filename
if filepath
grunt.file.copy file, path.join dest, resource.to, filepath, filename
else
grunt.file.copy file, path.join dest, resource.to, filename

if fn then fn()
9 changes: 9 additions & 0 deletions src/tasks/build/base/plugin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ module.exports = plugin = (grunt) ->

addPlugin = (plugin, fn) ->

if typeof plugin is 'object'
variables = plugin.variables || []
plugin = plugin.id

# If plugin is on the local filesystem, resolve it's absolute
# path from process.cwd()
uri = new URI(plugin)
if uri.protocol() == '' and (plugin.substr(0, 1) == '.' or plugin.substr(0, 1) == '/')
plugin = path.resolve(uri.path())

cmd = grunt.config.get('phonegap.config.cli') + " plugin add #{plugin} #{helpers.setVerbosity()}"

if typeof variables isnt 'undefined'
for d, i in variables
cmd += " --variable #{d.name}='#{d.value}'"

helpers.exec cmd, fn

add: (plugins, fn) ->
Expand Down
3 changes: 2 additions & 1 deletion tasks/build/after/local/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
tasks = {
buildIcons: require('./ios/icons')(grunt).build,
buildScreens: require('./ios/screens')(grunt).build,
buildResources: require('./ios/resources')(grunt).build,
setStatusBar: require('./ios/plist')(grunt).setStatusBar
};
return {
run: function(fn) {
return fluid(tasks).buildIcons().buildScreens().setStatusBar().go(function(err, result) {
return fluid(tasks).buildIcons().buildScreens().buildResources().setStatusBar().go(function(err, result) {
if (err) {
grunt.fatal(err);
}
Expand Down
38 changes: 38 additions & 0 deletions tasks/build/after/local/ios/resources.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion tasks/build/base/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@
var addPlugin, helpers;
helpers = require('../../helpers')(grunt);
addPlugin = function(plugin, fn) {
var cmd, uri;
var cmd, d, i, uri, variables, _i, _len;
if (typeof plugin === 'object') {
variables = plugin.variables || [];
plugin = plugin.id;
}
uri = new URI(plugin);
if (uri.protocol() === '' && (plugin.substr(0, 1) === '.' || plugin.substr(0, 1) === '/')) {
plugin = path.resolve(uri.path());
}
cmd = grunt.config.get('phonegap.config.cli') + (" plugin add " + plugin + " " + (helpers.setVerbosity()));
if (typeof variables !== 'undefined') {
for (i = _i = 0, _len = variables.length; _i < _len; i = ++_i) {
d = variables[i];
cmd += " --variable " + d.name + "='" + d.value + "'";
}
}
return helpers.exec(cmd, fn);
};
return {
Expand Down

0 comments on commit 556589e

Please sign in to comment.