Last active
November 5, 2015 17:04
-
-
Save grantges/dda6d1bb4098f729b435 to your computer and use it in GitHub Desktop.
Grunt File for Arrow Publishing (credit goes to Fokke for that one)
This file contains 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
var child_process = require('child_process'), | |
async = require('async'); | |
var REGEXP_VERSIONS = /versions: ((?:(?:, )?[0-9]+\.[0-9]+\.[0-9]+)+)\..+currently: ([0-9]+\.[0-9]+\.[0-9]+)/; | |
module.exports = function(grunt) { | |
grunt.initConfig({ | |
spawn: { | |
bump: { | |
command: 'npm', | |
args: ['version', 'patch', '-m', 'bump version'] | |
}, | |
publish: { | |
command: 'appc', | |
args: ['acs', 'publish'] | |
} | |
}, | |
nodemailer: { | |
options: { | |
transport: { | |
type: 'SMTP', | |
options: { | |
host: '<HOST>', | |
auth: { | |
user: '<USER>', | |
pass: '<PASS>' | |
}, | |
secure: true | |
} | |
}, | |
message: { | |
from: 'Fokke Zandbergen <[email protected]>', | |
subject: '[DEPLOY] https://community.appcelerator.com', | |
text: 'Publishing a new version to https://community.appcelerator.com', | |
}, | |
recipients: [{ | |
email: '[email protected]', | |
name: 'Deploy' | |
}] | |
}, | |
deploy: {} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-nodemailer'); | |
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 = 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); | |
}); | |
}); | |
grunt.registerTask('unpublish', 'Unpublished old versions', function() { | |
var done = this.async(); | |
child_process.exec('appc acs publish --list_versions', function(error, stdout, stderr) { | |
if (error !== null) { | |
return grunt.fail.fatal(error); | |
} | |
var matches = stdout.match(REGEXP_VERSIONS); | |
if (matches === null) { | |
return done(); | |
} | |
var all = matches[1].split(', '); | |
var deployed = matches[2]; | |
if (all.length === 1) { | |
return done(); | |
} | |
async.each(all, function(version, callback) { | |
if (version === deployed) { | |
return callback(); | |
} | |
grunt.log.writeln('Unpublishing: ' + version); | |
child_process.exec('appc acs unpublish --ver ' + version, callback); | |
}, done); | |
}); | |
}); | |
grunt.registerTask('publish', ['spawn:bump', 'unpublish', 'spawn:publish']); | |
grunt.registerTask('prod', ['spawn:bump', 'unpublish', 'spawn:publish', 'nodemailer:deploy']); | |
grunt.registerTask('default', 'publish'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment