This repository has been archived by the owner on Mar 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
External dependencies checks (only git for now).
This might also fix Travis CI.
- Loading branch information
Showing
3 changed files
with
178 additions
and
73 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* WSK dependencies check module | ||
*/ | ||
|
||
var exec = require('child_process').exec; | ||
var events = require('events'); | ||
|
||
|
||
function checkAll(reqs) { | ||
var e = new events.EventEmitter(); | ||
|
||
var checks = [checkGit]; | ||
|
||
process.nextTick(function () { | ||
var counter = 0, maybeDone = function (result, data) { | ||
counter += 1; | ||
e.emit(result, data); | ||
if (counter === checks.length) { | ||
e.emit('done'); | ||
} | ||
}; | ||
|
||
for (var i = 0; i < checks.length; i++) { | ||
checks[i](maybeDone); | ||
}; | ||
}); | ||
|
||
return e; | ||
} | ||
|
||
function checkGit(callback) { | ||
exec("git config --get-regexp 'user\..*'", function (err, stdout) { | ||
if (err) { | ||
callback('failed', {what: 'git', error: err}); | ||
return; | ||
} | ||
|
||
var user = stdout.match(/^user\.name\s+(.+)$/m); | ||
var email = stdout.match(/^user\.email\s+(.+)$/m); | ||
|
||
if (user && user[1] && email && email[1]) { | ||
callback('passed', {what: 'git'}); | ||
} else { | ||
callback('failed', {what: 'git', error: new Error('Git: not configured')}); | ||
} | ||
}); | ||
} | ||
|
||
module.exports = { | ||
checkAll: checkAll, | ||
checkGit: checkGit | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ var chalk = require('chalk'); | |
var prompt = require('./prompt'); | ||
var download = require('./download'); | ||
var hosting = require('./hosting'); | ||
var deps = require('./deps'); | ||
|
||
|
||
var MobileGenerator = module.exports = yeoman.generators.Base.extend({ | ||
|
@@ -41,6 +42,12 @@ var MobileGenerator = module.exports = yeoman.generators.Base.extend({ | |
|
||
// load package | ||
this.pkg = require('../package.json'); | ||
|
||
// info/error/warning messages during the generation process | ||
this.messages = []; | ||
|
||
// dependencies checks; | ||
this.checks = {}; | ||
}, | ||
|
||
prompting: function () { | ||
|
@@ -68,35 +75,49 @@ var MobileGenerator = module.exports = yeoman.generators.Base.extend({ | |
}, | ||
|
||
configuring: function () { | ||
var log = this.log, | ||
verbose = this.verbose, | ||
dest = this.destinationRoot(), | ||
var self = this, | ||
done = this.async(); | ||
|
||
verbose && log.write().info('Getting latest WSK release version ...'); | ||
this.verbose && this.log.write().info('Getting latest WSK release version ...'); | ||
|
||
download({extract: true, strip: 1}, function (err, downloader, url, ver) { | ||
if (err) { | ||
log.error(err); | ||
return; | ||
self.log.error(err); | ||
process.exit(1); | ||
} | ||
|
||
if (verbose) { | ||
log.info('Found release %s', ver.tag_name) | ||
if (self.verbose) { | ||
self.log.info('Found release %s', ver.tag_name) | ||
.info('Fetching %s ...', url) | ||
.info(chalk.yellow('This might take a few moments')); | ||
downloader.use(function (res) { | ||
res.on('data', function () { log.write('.') }); | ||
res.on('data', function () { self.log.write('.') }) ; | ||
}); | ||
} | ||
|
||
downloader.dest(dest).run(function (err) { | ||
downloader.dest(self.destinationRoot()).run(function (err) { | ||
if (err) { | ||
log.write().error(err).write(); | ||
} else { | ||
verbose && log.write().ok('Done').write(); | ||
self.log.write().error(err).write(); | ||
process.exit(1); | ||
} | ||
done(); | ||
|
||
if (self.verbose) { | ||
self.log.write().ok('Done').info('Checking dependencies ...'); | ||
} | ||
|
||
var checks = deps.checkAll(self.prompts); | ||
checks.on('done', done); | ||
|
||
checks.on('passed', function (res) { | ||
self.checks[res.what] = true; | ||
self.verbose && self.log.ok(res.what + ' ' + (res.result || '')); | ||
}); | ||
|
||
checks.on('failed', function (res) { | ||
self.checks[res.what] = false; | ||
self.messages.push(res.error.message); | ||
self.log.error(res.error.message); | ||
}); | ||
}); | ||
|
||
}); | ||
|
@@ -241,26 +262,22 @@ var MobileGenerator = module.exports = yeoman.generators.Base.extend({ | |
this.dest.write(path.join('app', 'CNAME'), this.prompts.siteHost); | ||
} | ||
|
||
if (!this.checks.git) | ||
return; | ||
|
||
var log = !this.quiet && this.log, | ||
done = this.async(); | ||
|
||
exec('git --version', function (err) { | ||
if (err) { | ||
// TODO: remember to notify user and describe manual steps | ||
done(); | ||
return; | ||
} | ||
var cmd = [ | ||
'git init .', | ||
'git checkout -b ' + this.prompts.githubBranch, | ||
'git commit --allow-empty -m "Initial empty commit"', | ||
'git remote add origin [email protected]:' + this.prompts.githubTarget | ||
]; | ||
exec(cmd.join(' && '), {cwd: path.join('dist')}, function (err, stdout) { | ||
log && log.write().info(stdout); | ||
done(); | ||
}); | ||
}.bind(this)); | ||
var cmd = [ | ||
'git init .', | ||
'git checkout -b ' + this.prompts.githubBranch, | ||
'git commit --allow-empty -m "Initial empty commit"', | ||
'git remote add origin [email protected]:' + this.prompts.githubTarget | ||
]; | ||
exec(cmd.join(' && '), {cwd: path.join('dist')}, function (err, stdout) { | ||
log && log.write().info(stdout); | ||
done(); | ||
}); | ||
} | ||
|
||
}, | ||
|
@@ -279,6 +296,9 @@ var MobileGenerator = module.exports = yeoman.generators.Base.extend({ | |
}, | ||
|
||
git: function () { | ||
if (!this.checks.git) | ||
return; | ||
|
||
var self = this, done = this.async(), | ||
cmd = ['git init', 'git add .'], | ||
gitignore = this.readFileAsString('.gitignore'); | ||
|
@@ -301,5 +321,18 @@ var MobileGenerator = module.exports = yeoman.generators.Base.extend({ | |
done(); | ||
}); | ||
} | ||
}, | ||
|
||
end: function () { | ||
if (this.messages.length === 0) { | ||
this.verbose && this.log.write().ok('You are all set now. Happy coding!'); | ||
return; | ||
} | ||
|
||
this.log.write().error('There were some errors during the process:').write(); | ||
|
||
for (var i = 0, m; m = this.messages[i]; i++) { | ||
this.log.write((i + 1) + ' ' + m); | ||
} | ||
} | ||
}); |
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