diff --git a/src/app/generator.js b/src/app/generator.js index cb8b3d6..808a4cd 100644 --- a/src/app/generator.js +++ b/src/app/generator.js @@ -62,6 +62,8 @@ Great success! Your new app "${options.name}" has been created. Change to the directory by running 'cd ${options.root} start the app with 'npm start'. `; - install(options).then(() => test(options).then(() => done(null, message))); + install(options) + .then(() => test(options) + .then(() => done(null, message))); }); }; diff --git a/src/app/middleware/package-json.js b/src/app/middleware/package-json.js index 2d8ebef..0dba814 100644 --- a/src/app/middleware/package-json.js +++ b/src/app/middleware/package-json.js @@ -1,5 +1,6 @@ import Debug from 'debug'; import merge from 'lodash.merge'; +import { spawnSync as spawn } from 'child_process'; const debug = Debug('feathers-generator'); // eslint-disable-line @@ -61,8 +62,13 @@ export default function (options) { template.scripts.mocha = `NODE_ENV=testing mocha $(find {server,test} -name '*.test.js') --recursive`; } - const newJSON = merge(template, existing); + // if not yarn, fall back to npm + let yarn = spawn('yarn', ['--version']); + if(yarn.error) { + delete template['engines']['yarn']; + } + const newJSON = merge(template, existing); files['package.json'].contents = JSON.stringify(newJSON, null, 2); done(); diff --git a/src/app/templates/package.json b/src/app/templates/package.json index bc1cf09..73f108f 100644 --- a/src/app/templates/package.json +++ b/src/app/templates/package.json @@ -14,8 +14,8 @@ "contributors": [], "bugs": {}, "engines": { - "node": ">=0.12.0", - "npm": ">=2.0.0" + "node": ">=4.4.0", + "yarn": ">=0.19.1" }, "semistandard": { "globals": [ "describe", "before", "after", "it" ] diff --git a/src/repo/middleware/package-json.js b/src/repo/middleware/package-json.js index d308c1e..8fb34be 100644 --- a/src/repo/middleware/package-json.js +++ b/src/repo/middleware/package-json.js @@ -1,5 +1,6 @@ import Debug from 'debug'; import merge from 'lodash.merge'; +import { spawnSync as spawn } from 'child_process'; const debug = Debug('feathers-generator'); // eslint-disable-line @@ -57,8 +58,13 @@ export default function (options) { template.scripts.mocha = `NODE_ENV=testing mocha $(find {server,test} -name '*.test.js') --recursive`; } - const newJSON = merge(template, existing); + // if not yarn, fall back to npm + let yarn = spawn('yarn', ['--version']); + if(yarn.error) { + delete template['engines']['yarn']; + } + const newJSON = merge(template, existing); files['package.json'].contents = JSON.stringify(newJSON, null, 2); done(); diff --git a/src/repo/templates/package.json b/src/repo/templates/package.json index ddee8f8..a7c4aac 100644 --- a/src/repo/templates/package.json +++ b/src/repo/templates/package.json @@ -14,8 +14,8 @@ "contributors": [], "bugs": {}, "engines": { - "node": ">=0.12.0", - "npm": ">=2.0.0" + "node": ">=4.4.0", + "yarn": ">=0.19.1" }, "semistandard": { "globals": [ "describe", "before", "after", "it" ] diff --git a/src/utils/install.js b/src/utils/install.js index 878012f..0442305 100644 --- a/src/utils/install.js +++ b/src/utils/install.js @@ -2,6 +2,7 @@ * Run npm install to install dependencies */ +import path from 'path'; import Debug from 'debug'; import { spawn } from 'child_process'; @@ -9,14 +10,21 @@ const debug = Debug('feathers-generator:install'); export default function (options) { return new Promise((resolve, reject) => { + let packagePath = path.resolve(options.root, 'package.json'); + let packageJSON = require(packagePath); + let engine = packageJSON.engines.yarn ? 'yarn' : 'npm'; + + // yarn fall back is in src/app/middleware/package-json.js:68 + // yarn fall back is in src/repo/middleware/package-json.js:60 + console.log(); - console.log(`Installing dependencies...`); + console.log(`Installing dependencies using ${engine}...`); console.log(); - const npm = spawn('npm', ['install'], {stdio: 'inherit', cwd: options.root}); + const installer = spawn(engine, ['install'], {stdio: 'inherit', cwd: options.root}); - npm.on('close', function (code) { - debug(`'npm install' exited with code ${code}`); + installer.on('close', function (code) { + debug(`'${engine} install' exited with code ${code}`); if (code === 0) { return resolve(); diff --git a/src/utils/test.js b/src/utils/test.js index 609dee9..6e31530 100644 --- a/src/utils/test.js +++ b/src/utils/test.js @@ -2,6 +2,7 @@ * Run npm test */ +import path from 'path'; import Debug from 'debug'; import { spawn } from 'child_process'; @@ -9,17 +10,23 @@ const debug = Debug('feathers-generator:test'); export default function (options) { return new Promise((resolve, reject) => { + let packagePath = path.resolve(options.root, 'package.json'); + let packageJSON = require(packagePath); + let engine = packageJSON.engines.yarn ? 'yarn' : 'npm'; + + // TODO @slajax - async check that yarn is installed + console.log(); - console.log(`Running integration tests...`); + console.log(`Running integration tests using ${engine}...`); console.log(options.root); - const npm = spawn('npm', ['test'], {stdio: 'inherit', cwd: process.cwd() }); + const tester = spawn(engine, ['test'], {stdio: 'inherit', cwd: process.cwd() }); - npm.on('close', function (code) { - debug(`'npm test' exited with code ${code}`); + tester.on('close', function (code) { + debug(`'${engine} test' exited with code ${code}`); if (code === 0) { - debug('npm test ran successfully'); + debug(`${engine} test ran successfully`); return resolve(); }