From a7bf89907bd7d9d7983ad4d4b0c70f18ca801891 Mon Sep 17 00:00:00 2001 From: Kyle Campbell Date: Tue, 14 Feb 2017 12:03:50 -0800 Subject: [PATCH 1/3] default to yarn when present in the package.json --- src/app/generator.js | 4 +++- src/app/templates/package.json | 4 ++-- src/repo/templates/package.json | 4 ++-- src/utils/install.js | 14 +++++++++++--- src/utils/test.js | 13 +++++++++---- 5 files changed, 27 insertions(+), 12 deletions(-) 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/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/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..8515e51 100644 --- a/src/utils/install.js +++ b/src/utils/install.js @@ -2,21 +2,29 @@ * Run npm install to install dependencies */ +import path from 'path'; import Debug from 'debug'; import { spawn } from 'child_process'; 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'; + 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 npm = spawn(engine, ['install'], {stdio: 'inherit', cwd: options.root}); npm.on('close', function (code) { - debug(`'npm install' exited with code ${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..596cb1d 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,21 @@ 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'; + 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 npm = spawn(engine, ['test'], {stdio: 'inherit', cwd: process.cwd() }); npm.on('close', function (code) { - debug(`'npm test' exited with code ${code}`); + debug(`'${engine} test' exited with code ${code}`); if (code === 0) { - debug('npm test ran successfully'); + debug(`${engine} test ran successfully`); return resolve(); } From 2e8ee34c23b499f5a859250202056dacc8461e8e Mon Sep 17 00:00:00 2001 From: Kyle Campbell Date: Tue, 14 Feb 2017 12:08:27 -0800 Subject: [PATCH 2/3] reminder --- src/utils/install.js | 9 ++++----- src/utils/test.js | 6 ++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/utils/install.js b/src/utils/install.js index 8515e51..2e1b13f 100644 --- a/src/utils/install.js +++ b/src/utils/install.js @@ -9,21 +9,20 @@ import { spawn } from 'child_process'; 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'; + // TODO @slajax: sync check if yarn installed + console.log(); console.log(`Installing dependencies using ${engine}...`); console.log(); - const npm = spawn(engine, ['install'], {stdio: 'inherit', cwd: options.root}); + const installer = spawn(engine, ['install'], {stdio: 'inherit', cwd: options.root}); - npm.on('close', function (code) { + installer.on('close', function (code) { debug(`'${engine} install' exited with code ${code}`); if (code === 0) { diff --git a/src/utils/test.js b/src/utils/test.js index 596cb1d..6e31530 100644 --- a/src/utils/test.js +++ b/src/utils/test.js @@ -14,13 +14,15 @@ export default function (options) { 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 using ${engine}...`); console.log(options.root); - const npm = spawn(engine, ['test'], {stdio: 'inherit', cwd: process.cwd() }); + const tester = spawn(engine, ['test'], {stdio: 'inherit', cwd: process.cwd() }); - npm.on('close', function (code) { + tester.on('close', function (code) { debug(`'${engine} test' exited with code ${code}`); if (code === 0) { From 8c7f3adfc2e3e5160273509d7575f4f5b97cbccf Mon Sep 17 00:00:00 2001 From: Kyle Campbell Date: Tue, 28 Feb 2017 20:19:15 -0800 Subject: [PATCH 3/3] check yarn is installed @daffl --- src/app/middleware/package-json.js | 8 +++++++- src/repo/middleware/package-json.js | 8 +++++++- src/utils/install.js | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) 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/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/utils/install.js b/src/utils/install.js index 2e1b13f..0442305 100644 --- a/src/utils/install.js +++ b/src/utils/install.js @@ -14,7 +14,8 @@ export default function (options) { let packageJSON = require(packagePath); let engine = packageJSON.engines.yarn ? 'yarn' : 'npm'; - // TODO @slajax: sync check if yarn installed + // 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 using ${engine}...`);