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

Commit 338f094

Browse files
authored
Merge pull request #15 from feathersjs/slajax/15
support yarn
2 parents 02c4d14 + 8c7f3ad commit 338f094

File tree

7 files changed

+45
-16
lines changed

7 files changed

+45
-16
lines changed

src/app/generator.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Great success! Your new app "${options.name}" has been created.
6262
Change to the directory by running 'cd ${options.root} start the app with 'npm start'.
6363
`;
6464

65-
install(options).then(() => test(options).then(() => done(null, message)));
65+
install(options)
66+
.then(() => test(options)
67+
.then(() => done(null, message)));
6668
});
6769
};

src/app/middleware/package-json.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Debug from 'debug';
22
import merge from 'lodash.merge';
3+
import { spawnSync as spawn } from 'child_process';
34

45
const debug = Debug('feathers-generator'); // eslint-disable-line
56

@@ -61,8 +62,13 @@ export default function (options) {
6162
template.scripts.mocha = `NODE_ENV=testing mocha $(find {server,test} -name '*.test.js') --recursive`;
6263
}
6364

64-
const newJSON = merge(template, existing);
65+
// if not yarn, fall back to npm
66+
let yarn = spawn('yarn', ['--version']);
67+
if(yarn.error) {
68+
delete template['engines']['yarn'];
69+
}
6570

71+
const newJSON = merge(template, existing);
6672
files['package.json'].contents = JSON.stringify(newJSON, null, 2);
6773

6874
done();

src/app/templates/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"contributors": [],
1515
"bugs": {},
1616
"engines": {
17-
"node": ">=0.12.0",
18-
"npm": ">=2.0.0"
17+
"node": ">=4.4.0",
18+
"yarn": ">=0.19.1"
1919
},
2020
"semistandard": {
2121
"globals": [ "describe", "before", "after", "it" ]

src/repo/middleware/package-json.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Debug from 'debug';
22
import merge from 'lodash.merge';
3+
import { spawnSync as spawn } from 'child_process';
34

45
const debug = Debug('feathers-generator'); // eslint-disable-line
56

@@ -57,8 +58,13 @@ export default function (options) {
5758
template.scripts.mocha = `NODE_ENV=testing mocha $(find {server,test} -name '*.test.js') --recursive`;
5859
}
5960

60-
const newJSON = merge(template, existing);
61+
// if not yarn, fall back to npm
62+
let yarn = spawn('yarn', ['--version']);
63+
if(yarn.error) {
64+
delete template['engines']['yarn'];
65+
}
6166

67+
const newJSON = merge(template, existing);
6268
files['package.json'].contents = JSON.stringify(newJSON, null, 2);
6369

6470
done();

src/repo/templates/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"contributors": [],
1515
"bugs": {},
1616
"engines": {
17-
"node": ">=0.12.0",
18-
"npm": ">=2.0.0"
17+
"node": ">=4.4.0",
18+
"yarn": ">=0.19.1"
1919
},
2020
"semistandard": {
2121
"globals": [ "describe", "before", "after", "it" ]

src/utils/install.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@
22
* Run npm install to install dependencies
33
*/
44

5+
import path from 'path';
56
import Debug from 'debug';
67
import { spawn } from 'child_process';
78

89
const debug = Debug('feathers-generator:install');
910

1011
export default function (options) {
1112
return new Promise((resolve, reject) => {
13+
let packagePath = path.resolve(options.root, 'package.json');
14+
let packageJSON = require(packagePath);
15+
let engine = packageJSON.engines.yarn ? 'yarn' : 'npm';
16+
17+
// yarn fall back is in src/app/middleware/package-json.js:68
18+
// yarn fall back is in src/repo/middleware/package-json.js:60
19+
1220
console.log();
13-
console.log(`Installing dependencies...`);
21+
console.log(`Installing dependencies using ${engine}...`);
1422
console.log();
1523

16-
const npm = spawn('npm', ['install'], {stdio: 'inherit', cwd: options.root});
24+
const installer = spawn(engine, ['install'], {stdio: 'inherit', cwd: options.root});
1725

18-
npm.on('close', function (code) {
19-
debug(`'npm install' exited with code ${code}`);
26+
installer.on('close', function (code) {
27+
debug(`'${engine} install' exited with code ${code}`);
2028

2129
if (code === 0) {
2230
return resolve();

src/utils/test.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,31 @@
22
* Run npm test
33
*/
44

5+
import path from 'path';
56
import Debug from 'debug';
67
import { spawn } from 'child_process';
78

89
const debug = Debug('feathers-generator:test');
910

1011
export default function (options) {
1112
return new Promise((resolve, reject) => {
13+
let packagePath = path.resolve(options.root, 'package.json');
14+
let packageJSON = require(packagePath);
15+
let engine = packageJSON.engines.yarn ? 'yarn' : 'npm';
16+
17+
// TODO @slajax - async check that yarn is installed
18+
1219
console.log();
13-
console.log(`Running integration tests...`);
20+
console.log(`Running integration tests using ${engine}...`);
1421
console.log(options.root);
1522

16-
const npm = spawn('npm', ['test'], {stdio: 'inherit', cwd: process.cwd() });
23+
const tester = spawn(engine, ['test'], {stdio: 'inherit', cwd: process.cwd() });
1724

18-
npm.on('close', function (code) {
19-
debug(`'npm test' exited with code ${code}`);
25+
tester.on('close', function (code) {
26+
debug(`'${engine} test' exited with code ${code}`);
2027

2128
if (code === 0) {
22-
debug('npm test ran successfully');
29+
debug(`${engine} test ran successfully`);
2330
return resolve();
2431
}
2532

0 commit comments

Comments
 (0)