From 9fe2446725d272e82ed90942455d89a325fa7a23 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 10 Nov 2015 19:25:39 +0000 Subject: [PATCH 01/11] Clarify the configuration part of bootstrap --- lib/bootstrap.js | 26 +++++++++++++++++--------- package.json | 1 + 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/bootstrap.js b/lib/bootstrap.js index 41ad24e7..8b2c188d 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -25,6 +25,8 @@ 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'); function gitUrl(dir) { return new Promise(function (resolve, reject) { @@ -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; } @@ -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; }); @@ -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) { @@ -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) { @@ -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) { diff --git a/package.json b/package.json index e1c60f1c..90df52e0 100644 --- a/package.json +++ b/package.json @@ -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", From 3072a9020573fc988e4894536db7869ec8346445 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 10 Nov 2015 19:26:15 +0000 Subject: [PATCH 02/11] Improve the output of the gulp-conflict module --- lib/bootstrap.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bootstrap.js b/lib/bootstrap.js index 8b2c188d..1ba3be19 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -141,7 +141,11 @@ 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()) .pipe(sink()); // Sink is required to trigger the finish event with install. From 5138f83274badf6bf1a4e0131398669ddc15ffc7 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 10:46:48 +0000 Subject: [PATCH 03/11] Show spinner while installing npm dependencies --- lib/bootstrap.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/bootstrap.js b/lib/bootstrap.js index 1ba3be19..53d74128 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -27,6 +27,7 @@ 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) { @@ -147,7 +148,14 @@ module.exports = function(config) { }, })) .pipe(gulp.dest(rootDir)) + .on('end', function() { + console.log('\n' + chalk.green('✓ ') + 'Creating files… done!'); + cli.spinner(' Installing npm dependencies…'); + }) .pipe(install()) + .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('error', reject); From 949bb1184bc2a834fc5571d0681230f297885d6d Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 10:47:35 +0000 Subject: [PATCH 04/11] Show message at the end of the bootstrap process --- lib/bootstrap.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/bootstrap.js b/lib/bootstrap.js index 53d74128..da0b4bab 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -157,7 +157,19 @@ module.exports = function(config) { 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' + + 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); }); }); From d285f4d0352b7e1ec6c078dced4a1e30d5d2dfac Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 11:15:19 +0000 Subject: [PATCH 05/11] Use custom gulp-install that allows controlling the output of the module and the npm process --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 90df52e0..382d1656 100644 --- a/package.json +++ b/package.json @@ -45,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/0095bf1e9b41201dfebd384e6239758a49f061bf", "gulp-rename": "^1.2.2", "gulp-template": "^3.0.0", "gulp-util": "^3.0.6", From d2e4080c77d126aca2f5f42313a7f553c7617b58 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 11:23:21 +0000 Subject: [PATCH 06/11] Update gulp-install custom module --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 382d1656..6e72206f 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "gulp-conflict": "^0.4.0", "gulp-connect": "^2.2.0", "gulp-gh-pages": "^0.5.2", - "gulp-install": "https://github.com/marco-c/gulp-install/tarball/0095bf1e9b41201dfebd384e6239758a49f061bf", + "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", From 0e4e7402aa315cacda9c1c9d3dd8bd545d1f379e Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 11:24:09 +0000 Subject: [PATCH 07/11] Don't print npm output --- lib/bootstrap.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bootstrap.js b/lib/bootstrap.js index da0b4bab..9d837faa 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -152,7 +152,9 @@ module.exports = function(config) { console.log('\n' + chalk.green('✓ ') + 'Creating files… done!'); cli.spinner(' Installing npm dependencies…'); }) - .pipe(install()) + .pipe(install({ + npmStdio: ['ignore', 'ignore', 'ignore'], + })) .on('end', function() { cli.spinner(chalk.green('✓ ') + 'Installing npm dependencies… done!\n', true); }) From d977342dee29a71ac5ee8e6541c9d1ffac56c219 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 11:24:41 +0000 Subject: [PATCH 08/11] Stop spinner when there's an error installing the npm dependencies --- lib/bootstrap.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bootstrap.js b/lib/bootstrap.js index 9d837faa..3628c080 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -153,6 +153,10 @@ module.exports = function(config) { 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() { From 60e853e21e2339924e82896ab4cb3e2455354e65 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 11:29:41 +0000 Subject: [PATCH 09/11] Update bootstrap question in the live test --- test/testLiveAsTemplate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testLiveAsTemplate.js b/test/testLiveAsTemplate.js index 8d51cd6b..cec237af 100644 --- a/test/testLiveAsTemplate.js +++ b/test/testLiveAsTemplate.js @@ -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', } ])) From 6aa7db67a3d213645fb7c67ebcce17f343fe9d1b Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 11:31:56 +0000 Subject: [PATCH 10/11] Fix indentation --- lib/bootstrap.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/bootstrap.js b/lib/bootstrap.js index 3628c080..93a8d201 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -163,19 +163,21 @@ module.exports = function(config) { 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', 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' + - 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('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' + + 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); }); }); From d6b5a5bd0d9d9555017c6f26593e9c90dbfed732 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 11 Nov 2015 12:22:00 +0000 Subject: [PATCH 11/11] Don't require gutil --- lib/bootstrap.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/bootstrap.js b/lib/bootstrap.js index 93a8d201..7a49d140 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -24,7 +24,6 @@ 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');