Skip to content

Commit

Permalink
fix(cli): allow any package to be installed as a starterkit
Browse files Browse the repository at this point in the history
Let any package be installed as a Patternlab starterkit. (#1067)
  • Loading branch information
ringods authored and bmuenzenmeyer committed Oct 11, 2019
1 parent 18f8773 commit d2aa1be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
3 changes: 1 addition & 2 deletions packages/cli/bin/install-starterkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const installStarterkit = (starterkit, config) =>
wrapAsync(function*() {
const sourceDir = config.paths.source.root;
const name = starterkit.value || starterkit;
const url = name.startsWith('@pattern-lab/') ? name : `pattern-lab/${name}`;
yield checkAndInstallPackage(name, url);
yield checkAndInstallPackage(name);
const kitPath = path.resolve('./node_modules', name);
yield copyAsync(path.resolve(kitPath, 'dist'), path.resolve(sourceDir));
let kitConfig;
Expand Down
12 changes: 5 additions & 7 deletions packages/cli/bin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,15 @@ const copyWithPattern = (cwd, pattern, dest) =>
* @func fetchPackage
* @desc Fetches and saves packages from npm into node_modules and adds a reference in the package.json under dependencies
* @param {string} packageName - The package name
* @param {string} [url] - A URL which will be used to fetch the package from
*/
const fetchPackage = (packageName, url) =>
const fetchPackage = packageName =>
wrapAsync(function*() {
const useYarn = hasYarn();
const pm = useYarn ? 'yarn' : 'npm';
const installCmd = useYarn ? 'add' : 'install';
try {
if (packageName || url) {
const cmd = yield spawn(pm, [installCmd, url || packageName]);
if (packageName) {
const cmd = yield spawn(pm, [installCmd, packageName]);
error(cmd.stderr);
}
} catch (err) {
Expand All @@ -150,10 +149,9 @@ const fetchPackage = (packageName, url) =>
* @func checkAndInstallPackage
* Checks whether a package for a given packageName is installed locally. If package cannot be found, fetch and install it
* @param {string} packageName - The package name
* @param {string} [url] - A URL which will be used to fetch the package from
* @return {boolean}
*/
const checkAndInstallPackage = (packageName, url) =>
const checkAndInstallPackage = packageName =>
wrapAsync(function*() {
try {
require.resolve(packageName);
Expand All @@ -162,7 +160,7 @@ const checkAndInstallPackage = (packageName, url) =>
debug(
`checkAndInstallPackage: ${packageName} not installed. Fetching it now …`
);
yield fetchPackage(packageName, url);
yield fetchPackage(packageName);
return false;
}
});
Expand Down

0 comments on commit d2aa1be

Please sign in to comment.