Last active
June 3, 2016 17:16
-
-
Save FokkeZB/01ab944f80b34d81358e to your computer and use it in GitHub Desktop.
Grunt for publishing Arrow apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (grunt) { | |
grunt.initConfig({ | |
clean: { | |
node: ['node_modules'] | |
}, | |
spawn: { | |
unpublish: { | |
command: 'appc', | |
args: ['unpublish'] | |
}, | |
bump: { | |
command: 'npm', | |
args: ['version', 'patch', '-m', 'bump version'] | |
}, | |
install: { | |
command: 'npm', | |
args: ['install'] | |
}, | |
publish: { | |
command: 'appc', | |
args: ['publish'] | |
} | |
}, | |
}); | |
// Load grunt plugins for modules | |
grunt.loadNpmTasks('grunt-contrib-clean'); | |
// Not using a Grunt-contrib for this because it must work while node_modules is gone | |
grunt.registerMultiTask('spawn', 'Spawns a child process', function () { | |
if (!this.data) { | |
return grunt.fail.fatal('Configuration is missing'); | |
} | |
if (!this.data.command) { | |
return grunt.fail.fatal('Command is missing'); | |
} | |
var done = this.async(); | |
var spawn = require('child_process').spawn, | |
child = spawn(this.data.command, this.data.args || []); | |
child.stdout.on('data', function (data) { | |
grunt.log.write(data); | |
}); | |
child.stderr.on('data', function (data) { | |
grunt.log.error(data); | |
}); | |
child.on('close', function (code) { | |
done(code === 0); | |
}); | |
}); | |
/** | |
* 1. Bumps the version using NPM, making sure we're clean and have a git-tag | |
* 2. Unpublished the last version while we wait for NODEJS-1983 | |
* 3. Clean node_modules while we wait for NODEJS-1946 | |
* 4. Publish the new version | |
* 5. Re-install dev dependencies | |
*/ | |
grunt.registerTask('publish', ['spawn:bump', 'spawn:unpublish', 'clean:node', 'spawn:publish', 'spawn:install']); | |
grunt.registerTask('default', 'publish'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment