Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

init: runtime scaffolding

  • Loading branch information...
commit 35a647c9c541dae1fbca1b115c1d5612df90c890 1 parent 1e9da0a
@tjanczuk authored
View
3  package.json
@@ -10,7 +10,8 @@
"dependencies": {
"xml2js" : ">= 0.1.11",
"commander": ">= 0.5.2",
- "colors": "0.6.0"
+ "colors": "0.6.0",
+ "async": ">= 0.1.10"
},
"devDependencies": {
},
View
14 src/cli/commands/common.js
@@ -2,10 +2,10 @@ var path = require('path')
, fs = require('fs')
, spawn = require('child_process').spawn
-exports.git = function (args, callback) {
+exports.git = function (args, dir, callback) {
if (typeof args === 'string')
args = [args];
- var git = spawn('git', args, { cwd: process.cwd() });
+ var git = spawn('git', args, { cwd: dir || process.cwd() });
var stdout = ''
var stderr = ''
git.stdout.on('data', function (data) { stdout += data.toString(); })
@@ -26,7 +26,9 @@ exports.gitAzureConfigNames = [
'serviceLocation',
'vmSize',
'instances',
- 'blobContainerName'
+ 'blobContainerName',
+ 'remote',
+ 'branch'
]
exports.getAzureConfigFromGit = function (callback) {
@@ -35,7 +37,7 @@ exports.getAzureConfigFromGit = function (callback) {
var result = {}
var getNextSetting = function (i) {
- exports.git(['config','--get','azure.' + exports.gitAzureConfigNames[i]], function (err, stdout) {
+ exports.git(['config','--get','azure.' + exports.gitAzureConfigNames[i]], null, function (err, stdout) {
if (!err && typeof stdout === 'string' && stdout.length > 0)
result[exports.gitAzureConfigNames[i]] = stdout.replace('\n','')
if (++i === exports.gitAzureConfigNames.length)
@@ -68,7 +70,9 @@ exports.getCurrentConfig = function (callback) {
var config = {
serviceLocation: 'Anywhere US',
vmSize: 'ExtraSmall',
- instances: 1
+ instances: 1,
+ remote: 'origin',
+ branch: 'master'
}
// override with configuration stored in Git
View
63 src/cli/commands/init.js
@@ -3,22 +3,75 @@ var fs = require('fs')
, xml2js = require('xml2js')
, assert = require('assert')
, common = require('./common.js')
- , pfx2pem = require('./pkcs.js').pfx2pem;
+ , pfx2pem = require('./pkcs.js').pfx2pem
+ , async = require('async');
exports.action = function (cmd) {
var gitAzureDir = '.git-azure'
+ var gitAzureRepo = 'git@github.com:tjanczuk/git-azure.git'
var config
+ function gitOrDie(args, successMessage, dieMessage, callback) {
+ common.git(args, config.projectRoot, function (err, result) {
+ if (err) {
+ console.error(dieMessage)
+ console.error(err.msg)
+ process.exit(1)
+ }
+
+ if (successMessage)
+ console.log(successMessage.green)
+
+ if (callback)
+ callback(err, result)
+ })
+ }
+
function ensureGitAzureSubmodule() {
var gitAzure = path.resolve(config.git.projectRoot, gitAzureDir)
if (fs.existsSync(gitAzure)) {
console.log(('OK: detected existing ' + gitAzure + ' directory, skipping scaffolding.').green)
}
- else {
- console.log(('OK: created scaffolding of the git-azure runtime at ' + gitAzure).green)
- }
+ else
+ async.series([
+
+ // Create scaffolding of the git-azure runtime. Issue the command:
+ // git submodule add git@github.com:tjanczuk/git-azure.git .git-azure
+ // at the project root directory.
+
+ async.apply(gitOrDie,
+ ['submodule', 'add', gitAzureRepo, gitAzureDir],
+ 'OK: created scaffolding of git-azure runtime as a submodule at ' + gitAzure,
+ 'Unable to create scaffolding of the git-azure runtime as a Git submodule at ' + gitAzure + ':'),
+
+ // Add the scaffolding to Git index
+
+ async.apply(gitOrDie,
+ ['add', '.'],
+ 'OK: added scaffolding changes to Git index.',
+ 'Unable to add git-azure scaffolding changes to Git index:'),
+
+ // Commit the scaffolding changes
+
+ async.apply(gitOrDie,
+ ['commit', '-m', 'git-azure service runtime'],
+ 'OK: commited scaffolding changes.',
+ 'Unable to commit git-azure scaffolding changes:'),
+
+ // Push the scaffolding changes
+
+ async.apply(gitOrDie,
+ ['push', '-u', config.remote, config.branch],
+ 'OK: pushed scaffolding changes to ' + config.remote + '/' + config.branch + '.',
+ 'Unable to push git-azure scaffolding changes to ' + config.remote + '/' + config.branch +'.\n'
+ + 'WARNING: changes have already been commited locally; please push them manually to your remote, '
+ + 'then re-run this command.\nError details:')
+ ],
+ function () {
+ console.log(('OK: created and pushed scaffolding of the git-azure runtime at ' + gitAzure).green)
+ });
}
function processPublishSettings() {
@@ -126,7 +179,7 @@ exports.action = function (cmd) {
missing.push('- subscriptionId must be specified when managementCertificate is specified');
['storageAccountName', 'storageAccountKey', 'serviceName', 'serviceLocation',
- 'vmSize', 'instances', 'blobContainerName'].forEach(function (item) {
+ 'vmSize', 'instances', 'blobContainerName', 'remote', 'branch'].forEach(function (item) {
if (!config[item])
missing.push('- ' + item)
});
View
2  src/cli/git-azure.js
@@ -27,6 +27,8 @@ program.command('init')
.option('-m, --vmSize <size>', 'size of the Windows Azure Worker Role VM to create [ExtraSmall|Small|Medium|Large|ExtraLarge]')
.option('-i, --instances <number>', 'number of instances of Windows Azure Worker Role to create')
.option('-b, --blobContainerName <name>', 'name of the Windows Azure Blob Storage contaniner to create or use')
+ .option('-r, --remote <name>', 'remote name to push git-azure runtime scaffolding to (defaults to origin)')
+ .option('-t, --branch <name>', 'branch name to push git-azure runtime scaffolding to (defaults to master)')
.option('-n, --no_persist', 'do not store any settings in the azure section of the Git configuration for convenience of later use')
.option('-q, --quiet', 'succeed or fail without showing prompts')
.action(require('./commands/init.js').action)
Please sign in to comment.
Something went wrong with that request. Please try again.