Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 52 additions & 13 deletions lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ var rename = require('gulp-rename');
var promptly = require('promisified-promptly');
var gitconfiglocal = require('gitconfiglocal');
var through2 = require('through2');
var gutil = require('gulp-util');
var chalk = require('chalk');
var changeCase = require('change-case');
var cli = require('cli');

function gitUrl(dir) {
return new Promise(function (resolve, reject) {
Expand All @@ -42,10 +44,10 @@ function gitUrl(dir) {
}

function templateConfigPrompt(defaultConfig) {
gutil.log('The current template configuration is:');
gutil.log(templateConfigToString(defaultConfig));
console.log('Your app\'s configuration is:\n');
console.log(templateConfigToString(defaultConfig));

return promptly.confirm('Would you like to change any of the above configuration values?').then(function(fillInConfig) {
return promptly.confirm('Would you like to change its configuration (y/N)?', { default: false }).then(function(fillInConfig) {
if (!fillInConfig) {
return defaultConfig;
}
Expand All @@ -58,10 +60,12 @@ function templateConfigPrompt(defaultConfig) {
});
}

return prompt('Project name: ', 'name')
.then(prompt.bind(null, 'Repository URL: ', 'repository'))
.then(prompt.bind(null, 'Description: ', 'description'))
.then(prompt.bind(null, 'License: ', 'license'))
console.log('\n');

return prompt(chalk.bold('Name:'), 'name')
.then(prompt.bind(null, chalk.bold('Repository:'), 'repository'))
.then(prompt.bind(null, chalk.bold('Description:'), 'description'))
.then(prompt.bind(null, chalk.bold('License:'), 'license'))
.then(function() {
return config;
});
Expand All @@ -81,9 +85,9 @@ function templateConfigOption(defaultConfig, config) {
function templateConfigToString(config) {
var out = [];
for (var key in config) {
out.push(key + ': ' + config[key]);
out.push(chalk.bold(changeCase.upperCaseFirst(key)) + ': ' + config[key]);
}
return out.join('\n');
return out.join('\n') + '\n';
}

function getDefaultTemplateConfig(dir) {
Expand Down Expand Up @@ -115,6 +119,8 @@ function sink() {
module.exports = function(config) {
config = config || {};

console.log('Bootstrapping current directory as Oghliner app…\n');

var rootDir = config.rootDir ? config.rootDir : '.';
return getDefaultTemplateConfig(rootDir)
.then(function(defaultConfig) {
Expand All @@ -124,6 +130,8 @@ module.exports = function(config) {
return templateConfigPrompt(defaultConfig);
})
.then(function(templateConfig) {
console.log('\nCreating files…');

return new Promise(function(resolve, reject) {
var stream = gulp.src([__dirname + '/../templates/**'])
.pipe(rename(function (path) {
Expand All @@ -133,11 +141,42 @@ module.exports = function(config) {
}
}))
.pipe(template(templateConfig))
.pipe(conflict(rootDir))
.pipe(conflict(rootDir, {
logger: function(message, fileName, extraText) {
console.log(chalk.green('✓ ') + message + ' ' + chalk.stripColor(fileName));
},
}))
.pipe(gulp.dest(rootDir))
.pipe(install())
.on('end', function() {
console.log('\n' + chalk.green('✓ ') + 'Creating files… done!');
cli.spinner(' Installing npm dependencies…');
})
.pipe(install({
log: function() {
cli.spinner(chalk.red('× ') + 'Installing npm dependencies… error!\n', true);
console.log(Array.prototype.slice.call(arguments).join(''));
},
npmStdio: ['ignore', 'ignore', 'ignore'],
}))
.on('end', function() {
cli.spinner(chalk.green('✓ ') + 'Installing npm dependencies… done!\n', true);
})
.pipe(sink()); // Sink is required to trigger the finish event with install.
stream.on('finish', resolve);

stream.on('finish', function() {
console.log(
'Your app has been bootstrapped! Just commit the changes and push the commit\n' +
'to the origin/master branch:\n\n' +
chalk.bold('git commit -m"initial version of Oghliner app" --all') + '\n' +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per that issue @wfwalker ran into with configure, I guess this should be git add --all && git commit -m"initial version of Oghliner app".

chalk.bold('git push origin master') + '\n\n' +
'Then you can build, offline, and deploy the app using ' + chalk.bold.italic('gulp') + ' commands.\n\n' +
chalk.bold.blue('ℹ For more information about building, offlining and deployment, see:\n' +
' https://mozilla.github.io/oghliner/')
);

resolve();
});

stream.on('error', reject);
});
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
],
"dependencies": {
"chalk": "^1.1.1",
"change-case": "^2.3.0",
"cli": "^0.11.1",
"commander": "^2.8.1",
"fs-extra": "^0.26.0",
Expand All @@ -44,7 +45,7 @@
"gulp-conflict": "^0.4.0",
"gulp-connect": "^2.2.0",
"gulp-gh-pages": "^0.5.2",
"gulp-install": "^0.6.0",
"gulp-install": "https://github.com/marco-c/gulp-install/tarball/56f8ebf87f14651f586d6377dea75c2f3d1b1691",
"gulp-rename": "^1.2.2",
"gulp-template": "^3.0.0",
"gulp-util": "^3.0.6",
Expand Down
2 changes: 1 addition & 1 deletion test/testLiveAsTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('CLI interface, oghliner as a template', function() {
.then(liveUtils.spawn.bind(null, 'npm', ['install', path.dirname(__dirname)]))
.then(liveUtils.spawn.bind(null, path.join('node_modules', '.bin', 'oghliner'), ['bootstrap', '.'], [
{
q: 'Would you like to change any of the above configuration values?',
q: 'Would you like to change its configuration (y/N)?',
r: 'n',
}
]))
Expand Down