From 649962d9d61389599404501f4939eb713b8a2a31 Mon Sep 17 00:00:00 2001 From: Joe Lanman Date: Fri, 21 Oct 2016 18:20:31 +0100 Subject: [PATCH] check for node_modules in start.js then run gulp --- package.json | 4 ++- start.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 start.js diff --git a/package.json b/package.json index 62833fc938..c486e868ed 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "node": ">=4.0 <6.7" }, "scripts": { - "start": "if [ -d \"node_modules\" ]; then gulp; else echo 'gulp is missing - try running npm install' ; fi", + "start": "node start.js", "lint": "standard", "test": "npm run lint" }, @@ -16,6 +16,7 @@ "basic-auth-connect": "^1.0.0", "body-parser": "^1.14.1", "browser-sync": "^2.11.1", + "chalk": "^1.1.3", "consolidate": "0.x", "express": "4.13.3", "express-session": "^1.13.0", @@ -34,6 +35,7 @@ "minimist": "0.0.8", "nunjucks": "^2.4.2", "portscanner": "^1.0.0", + "pretty-hrtime": "^1.0.2", "prompt": "^0.2.14", "readdir": "0.0.6", "require-dir": "^0.3.0", diff --git a/start.js b/start.js new file mode 100644 index 0000000000..312f1fbf8b --- /dev/null +++ b/start.js @@ -0,0 +1,73 @@ +'use strict' + +const fs = require('fs') +const path = require('path') + +if (!fs.existsSync(path.join(__dirname, '/node_modules'))) { + console.log('node modules are missing, run npm install') + process.exit(0) +} + +const gulp = require('gulp') +const gutil = require('gulp-util') +const chalk = require('chalk') +const prettyTime = require('pretty-hrtime') +require(path.join(__dirname, '/gulpfile.js')) + +// we need to set up logging for gulp +// all copied from https://github.com/gulpjs/gulp/blob/master/bin/gulp.js + +// Format orchestrator errors +function formatError (e) { + if (!e.err) { + return e.message + } + + // PluginError + if (typeof e.err.showStack === 'boolean') { + return e.err.toString() + } + + // Normal error + if (e.err.stack) { + return e.err.stack + } + + // Unknown (string, number, etc.) + return new Error(String(e.err)).stack +} + +gulp.on('task_start', function (e) { + // TODO: batch these + // so when 5 tasks start at once it only logs one time with all 5 + gutil.log('Starting', '\'' + chalk.cyan(e.task) + '\'...') +}) + +gulp.on('task_stop', function (e) { + var time = prettyTime(e.hrDuration) + gutil.log( + 'Finished', '\'' + chalk.cyan(e.task) + '\'', + 'after', chalk.magenta(time) + ) +}) + +gulp.on('task_err', function (e) { + var msg = formatError(e) + var time = prettyTime(e.hrDuration) + gutil.log( + '\'' + chalk.cyan(e.task) + '\'', + chalk.red('errored after'), + chalk.magenta(time) + ) + gutil.log(msg) +}) + +gulp.on('task_not_found', function (err) { + gutil.log( + chalk.red('Task \'' + err.task + '\' is not in your gulpfile') + ) + gutil.log('Please check the documentation for proper gulpfile formatting') + process.exit(1) +}) + +gulp.start('default')