Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit e50fb06

Browse files
committed
Adding yarn support
1 parent 043a8b5 commit e50fb06

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

bin/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const glob = require('glob');
55
const path = require('path');
66
const chalk = require('chalk');
77
const EventEmitter = require('events').EventEmitter;
8+
const hasYarn = require('has-yarn');
89

910
/**
1011
* @name log
@@ -95,13 +96,16 @@ const copyWithPattern = (cwd, pattern, dest) => wrapAsync(function*() {
9596
* @param {string} [url] - A URL which will be used to fetch the package from
9697
*/
9798
const fetchPackage = (packageName, url) => wrapAsync(function*() {
99+
const useYarn = hasYarn();
100+
const pm = useYarn ? 'yarn' : 'npm';
101+
const installCmd = useYarn ? 'add' : 'install';
98102
try {
99103
if (packageName || url) {
100-
const cmd = yield spawn('npm', ['install', url || packageName]);
104+
const cmd = yield spawn(pm, [installCmd, url || packageName]);
101105
error(cmd.stderr);
102106
}
103107
} catch (err) {
104-
error(`patternlab→fetchPackage: Fetching required dependencies from NPM failed for ${packageName} with ${err}`);
108+
error(`fetchPackage: Fetching required dependencies from ${pm} failed for ${packageName} with ${err}`);
105109
throw err; // Rethrow error
106110
}
107111
});
@@ -118,7 +122,7 @@ const checkAndInstallPackage = (packageName, url) => wrapAsync(function*() {
118122
require.resolve(packageName);
119123
return true;
120124
} catch (err) {
121-
debug(`patternlab→checkAndInstallPackage: ${packageName} not installed. Fetching it now from NPM …`);
125+
debug(`checkAndInstallPackage: ${packageName} not installed. Fetching it now …`);
122126
yield fetchPackage(packageName, url);
123127
return false;
124128
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"execa": "0.6.1",
1919
"fs-promise": "2.0.0",
2020
"glob": "7.1.1",
21+
"has-yarn": "1.0.0",
2122
"inquirer": "2.0.0",
2223
"lodash": "4.17.4",
2324
"ora": "1.1.0",

0 commit comments

Comments
 (0)