Skip to content

Commit

Permalink
described from, to options
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Dec 11, 2013
1 parent 35a90ca commit 10b889e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -21,7 +21,10 @@ grunt.initConfig({
all: {
options: {
// sync specific options
sync: ['author', 'name', 'version', 'private']
sync: ['author', 'name', 'version', 'private'],
// optional: specify source and destination filenames
from: '../package.json',
to: 'dist/bower.json'
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions tasks/sync.js
Expand Up @@ -30,24 +30,28 @@ module.exports = function (grunt) {
function sync() {
/*jshint validthis:true */
var configValues = (this.data && this.data.options) || {};
var sourceFilename = configValues.from || 'package.json';
var destinationFilename = configValues.to || 'bower.json';
var propertiesToSync = configValues.sync || [
'name',
'author',
'version',
'description',
'private'
'private',
'license'
];
grunt.verbose.writeln('syncing', propertiesToSync);
grunt.verbose.writeln('syncing', propertiesToSync, 'from', sourceFilename,
'to', destinationFilename);

var pkg = grunt.file.readJSON('package.json');
var pkg = grunt.file.readJSON(sourceFilename);
verifyPackage(pkg);

// If bower.json doesn't exist yet, add one.
if (!grunt.file.exists('bower.json')) {
grunt.file.write('bower.json', "{}");
if (!grunt.file.exists(destinationFilename)) {
grunt.file.write(destinationFilename, "{}");
}

var bower = grunt.file.readJSON('bower.json');
var bower = grunt.file.readJSON(destinationFilename);

var options = {};
propertiesToSync.forEach(function (propertyToSync) {
Expand All @@ -56,7 +60,7 @@ module.exports = function (grunt) {
grunt.verbose.writeln('options added to bower', JSON.stringify(options, null, 2));

bower = JSON.stringify(_.extend(bower, options), null, 2);
grunt.file.write('bower.json', bower);
grunt.file.write(destinationFilename, bower);
}

grunt.registerMultiTask('sync', 'Sync package.json -> bower.json', sync);
Expand Down

0 comments on commit 10b889e

Please sign in to comment.