diff --git a/CHANGES.md b/CHANGES.md index 7a2d29f1..4be4bf16 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,8 +1,7 @@ **Added:** -- Added a new web app project type - this is for anyone who wants to use nwb's build/serve/test setup but isn't using React. -- Added a `--reload` option to auto-reload the page when webpack hot module replacement gets stuck. This is primarily intended for use with the new web-app - project type. +- Added a new `web-app` project type - this is for anyone who wants to use nwb's build/serve/test setup but isn't using React. +- Added a `--reload` option to auto-reload the page when webpack hot module replacement gets stuck. This is primarily intended for use with the new `web-app` project type. - Command-line arguments can now be used to configure settings for `nwb new`. **Fixed:** @@ -12,9 +11,14 @@ **Changed:** +- Commands which create files now log details of what they've created [[#26](https://github.com/insin/nwb/issues/26)] - The ES6 modules build for npm modules is now optional, controlled by a `jsNext` setting in `nwb.config.js`, defaulting to `true`. - nwb 0.6 will default `jsNext` to `true` and log a warning when it's missing from a config file - this behaviour will be removed in nwb 0.7. +**Dependencies:** + +- copy-template-dir: v1.1.0 → v1.2.0 - provide created file paths in callback + # 0.5.0 / 2015-12-15 **Added:** diff --git a/package.json b/package.json index 2254e4c0..58ee7bcb 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ }, "dependencies": { "argv-set-env": "1.0.0", - "copy-template-dir": "1.1.0", + "chalk": "1.1.1", + "copy-template-dir": "1.2.0", "debug": "2.2.0", "eventsource-polyfill": "0.9.6", "express": "4.13.3", diff --git a/src/bin/nwb.js b/src/bin/nwb.js index 56fea310..62d51778 100644 --- a/src/bin/nwb.js +++ b/src/bin/nwb.js @@ -1,5 +1,7 @@ #!/usr/bin/env node +import chalk from 'chalk' + import cli from '../cli' import {UserError} from '../errors' @@ -15,10 +17,10 @@ catch (err) { // Assumption: error will be undefined or null on success if (error != null) { if (error instanceof UserError) { - console.error(error.message) + console.error(chalk.red(error.message)) } else { - console.error('nwb: error running command:') + console.error(chalk.red('nwb: error running command:')) console.error(error.stack) } process.exit(1) diff --git a/src/commands/new.js b/src/commands/new.js index 19408f97..08158e68 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -1,6 +1,7 @@ import path from 'path' import {execSync} from 'child_process' +import chalk from 'chalk' import copyTemplateDir from 'copy-template-dir' import inquirer from 'inquirer' import glob from 'glob' @@ -68,6 +69,13 @@ function installReact(targetDir) { }) } +function logCreatedFiles(targetDir, createdFiles) { + createdFiles.sort().forEach(createdFile => { + let relativePath = path.relative(targetDir, createdFile) + console.log(` ${chalk.green('create')} ${relativePath}`) + }) +} + export function npmModuleVars(vars) { vars.jsNextMain = vars.jsNext ? '\n "jsnext:main": "es6/index.js",' : '' return vars @@ -77,9 +85,9 @@ let projectCreators = { [REACT_APP](args, name, targetDir, cb) { let templateDir = path.join(__dirname, `../../templates/${REACT_APP}`) let templateVars = {name, nwbVersion, reactVersion} - copyTemplateDir(templateDir, targetDir, templateVars, err => { + copyTemplateDir(templateDir, targetDir, templateVars, (err, createdFiles) => { if (err) return cb(err) - console.log(`nwb: created ${targetDir}`) + logCreatedFiles(targetDir, createdFiles) console.log('nwb: installing dependencies') installReact(targetDir) cb() @@ -92,9 +100,9 @@ let projectCreators = { let templateVars = npmModuleVars( {umd, globalVariable, jsNext, name, nwbVersion, reactVersion} ) - copyTemplateDir(templateDir, targetDir, templateVars, err => { + copyTemplateDir(templateDir, targetDir, templateVars, (err, createdFiles) => { if (err) return cb(err) - console.log(`nwb: created ${targetDir}`) + logCreatedFiles(targetDir, createdFiles) console.log('nwb: installing dependencies') installReact(targetDir) cb() @@ -105,9 +113,9 @@ let projectCreators = { [WEB_APP](args, name, targetDir, cb) { let templateDir = path.join(__dirname, `../../templates/${WEB_APP}`) let templateVars = {name, nwbVersion} - copyTemplateDir(templateDir, targetDir, templateVars, err => { + copyTemplateDir(templateDir, targetDir, templateVars, (err, createdFiles) => { if (err) return cb(err) - console.log(`nwb: created ${targetDir}`) + logCreatedFiles(targetDir, createdFiles) cb() }) }, @@ -118,9 +126,9 @@ let projectCreators = { let templateVars = npmModuleVars( {umd, globalVariable, jsNext, name, nwbVersion} ) - copyTemplateDir(templateDir, targetDir, templateVars, err => { + copyTemplateDir(templateDir, targetDir, templateVars, (err, createdFiles) => { if (err) return cb(err) - console.log(`nwb: created ${targetDir}`) + logCreatedFiles(targetDir, createdFiles) cb() }) }) @@ -145,9 +153,10 @@ export default function(args, cb) { return cb(new UserError(`nwb: a project name must be provided`)) } if (glob.sync(`${name}/`).length !== 0) { - return cb(new UserError(`nwb: "${name}" directory already exists`)) + return cb(new UserError(`nwb: ${name}/ directory already exists`)) } let targetDir = path.join(process.cwd(), name) + console.log(`nwb: new ${projectType}`) projectCreators[projectType](args, name, targetDir, cb) }