Skip to content
This repository has been archived by the owner on Feb 15, 2018. It is now read-only.

Commit

Permalink
Merge pull request #15 from feathersjs/slajax/15
Browse files Browse the repository at this point in the history
support yarn
  • Loading branch information
kc-dot-io authored Mar 1, 2017
2 parents 02c4d14 + 8c7f3ad commit 338f094
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/app/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
});
};
8 changes: 7 additions & 1 deletion src/app/middleware/package-json.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
8 changes: 7 additions & 1 deletion src/repo/middleware/package-json.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/repo/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
16 changes: 12 additions & 4 deletions src/utils/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

// 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();
Expand Down
17 changes: 12 additions & 5 deletions src/utils/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@
* Run npm test
*/

import path from 'path';
import Debug from 'debug';
import { spawn } from 'child_process';

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();
}

Expand Down

0 comments on commit 338f094

Please sign in to comment.