Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Clarify the output of the 'integrate' command. Fixes #161
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Castelluccio committed Nov 10, 2015
1 parent a09d26a commit 7a2051c
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions lib/integrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,39 @@ var fs = require('fs');
var path = require('path');
var gutil = require('gulp-util');
var fse = require('fs-extra');
var cli = require('cli');
var chalk = require('chalk');

module.exports = function(config) {
var dir = config.dir || './';
var spinnerMessage;

function startSpinner(message) {
spinnerMessage = message;
cli.spinner(message);
}

function stopSpinner(error) {
var symbol = error ? chalk.bold.red('× ') : chalk.bold.green('✓ ');
var result = error ? 'error' : 'done';
cli.spinner(symbol + spinnerMessage + ' ' + result + '!\n', true);
}

module.exports = function(config) {
return new Promise(function(resolve, reject) {
var dir = config.dir || './';

console.log('Integrating Oghliner into the app in the current directory…\n');

startSpinner('Copying offline-manager.js to ' + dir + '…');

fs.stat(dir, function(err, stat) {
if (err) {
stopSpinner(err);
reject(new Error(dir + ' doesn\'t exist or is not accessible.'));
return;
}

if (!stat.isDirectory()) {
stopSpinner(err);
reject(new Error(dir + ' isn\'t a directory.'));
return;
}
Expand All @@ -40,14 +61,26 @@ module.exports = function(config) {

fse.copy(path.join(path.dirname(__dirname), 'templates', 'app', 'scripts', 'offline-manager.js'), dest, function(err) {
if (err) {
stopSpinner(err);
reject(err);
} else {
gutil.log(gutil.colors.blue.bold(
'Your app needs to load the script offline-manager.js in order to register the service\n' +
'worker that offlines your app. To load the script, add this line to your app\'s HTML\n' +
'page(s)/template(s):\n\n' +
'\t<script src="' + dest + '"></script>'
));
stopSpinner();

console.log(
'Oghliner has been integrated into the app!\n\n' +

'The app needs to load the script offline-manager.js in order to register\n' +
'the service worker that offlines the app. To load the script, add this line\n' +
'to the app\'s HTML page(s)/template(s):\n\n' +
chalk.bold('<script src="' + dest + '"></script>') + '\n\n' +
'And commit the changes and push the commit to the origin/master branch:\n\n' +
chalk.bold('git commit -m"integrate Oghliner" --all') + '\n' +
chalk.bold('git push origin master') + '\n\n' +
'Then you can offline and deploy the app using the ' + chalk.bold.italic('offline') + ' and ' + chalk.bold.italic('deploy') + ' commands.\n\n' +
chalk.bold.blue('ℹ For more information about offlining and deployment, see:\n' +
' https://mozilla.github.io/oghliner/')
);

resolve();
}
});
Expand Down

0 comments on commit 7a2051c

Please sign in to comment.