Skip to content

Commit

Permalink
Log files created by nwb new
Browse files Browse the repository at this point in the history
Closes #26
  • Loading branch information
insin committed Dec 21, 2015
1 parent 052a652 commit c2a8e80
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
10 changes: 7 additions & 3 deletions 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:**
Expand All @@ -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:**
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions src/bin/nwb.js
@@ -1,5 +1,7 @@
#!/usr/bin/env node

import chalk from 'chalk'

import cli from '../cli'
import {UserError} from '../errors'

Expand All @@ -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)
Expand Down
27 changes: 18 additions & 9 deletions 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'
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
})
},
Expand All @@ -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()
})
})
Expand All @@ -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)
}

0 comments on commit c2a8e80

Please sign in to comment.