From 1acef874765d21e75a65a9b6cad0a0291822f804 Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Mon, 9 Jul 2018 06:35:19 -0500 Subject: [PATCH 1/2] fix(install): copy dependencies wip --- packages/cli/bin/cli-actions/init.js | 6 +++- packages/cli/bin/install-edition.js | 45 ++++++++++++++++++---------- packages/cli/bin/utils.js | 10 +++++++ 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/packages/cli/bin/cli-actions/init.js b/packages/cli/bin/cli-actions/init.js index 6136ae193..a69d39642 100644 --- a/packages/cli/bin/cli-actions/init.js +++ b/packages/cli/bin/cli-actions/init.js @@ -45,7 +45,11 @@ const init = options => if (edition) { spinner.text = `⊙ patternlab → Installing edition: ${edition}`; - const newConf = yield installEdition(edition, patternlabConfig); // 3.1 + const newConf = yield installEdition( + edition, + patternlabConfig, + projectDir + ); // 3.1 patternlabConfig = Object.assign(patternlabConfig, newConf); // 3.2 spinner.succeed(`⊙ patternlab → Installed edition: ${edition}`); } diff --git a/packages/cli/bin/install-edition.js b/packages/cli/bin/install-edition.js index 278027dc6..dee31895c 100644 --- a/packages/cli/bin/install-edition.js +++ b/packages/cli/bin/install-edition.js @@ -1,20 +1,26 @@ 'use strict'; + const path = require('path'); -const pkg = require(path.resolve(process.cwd(), 'package.json')); +const EOL = require('os').EOL; const { checkAndInstallPackage, copyAsync, wrapAsync, writeJsonAsync, + getJSONKey, } = require('./utils'); -const installEdition = (edition, config) => - wrapAsync(function*() { +const installEdition = (edition, config, projectDir) => { + const pkg = require(path.resolve(projectDir, 'package.json')); + + return wrapAsync(function*() { /** * 1. Trigger edition install * 2. Copy over the mandatory edition files to sourceDir - * 3. Do custom post-install procedures for different core editions: - * 3.1 Copy gulpfile.js for edition-node-gulp + * 3. Copy dependencies defined in edition + * 4. Do custom post-install procedures for different core editions: + * 4.1 Copy gulpfile.js for edition-node-gulp + * 4.2 Copy scripts for edition-node */ const sourceDir = config.paths.source.root; yield checkAndInstallPackage(edition); // 1 @@ -22,8 +28,13 @@ const installEdition = (edition, config) => path.resolve('./node_modules', edition, 'source', '_meta'), path.resolve(sourceDir, '_meta') ); // 2 - switch (edition) { // 3 - // 3.1 + pkg.dependencies = Object.assign( + {}, + pkg.dependencies || {}, + yield getJSONKey(edition, 'dependencies') + ); // 3 + switch (edition) { // 4 + // 4.1 case '@pattern-lab/edition-node-gulp': { yield copyAsync( path.resolve('./node_modules', edition, 'gulpfile.js'), @@ -31,20 +42,22 @@ const installEdition = (edition, config) => ); break; } + // 4.2 case '@pattern-lab/edition-node': { - const scriptsJSON = { - 'pl:build': 'patternlab build --config ./patternlab-config.json', - 'pl:help': 'patternlab --help', - 'pl:install': 'patternlab install --config ./patternlab-config.json', - 'pl:serve': 'patternlab serve --config ./patternlab-config.json', - 'pl:version': 'patternlab --version', - }; - pkg.scripts = Object.assign({}, pkg.scripts || {}, scriptsJSON); - yield writeJsonAsync('./package.json', pkg, { spaces: 2 }); + pkg.scripts = Object.assign( + {}, + pkg.scripts || {}, + yield getJSONKey(edition, 'scripts') + ); break; } } + yield writeJsonAsync(path.resolve(projectDir, 'package.json'), pkg, { + spaces: 2, + EOL: EOL, + }); return config; }); +}; module.exports = installEdition; diff --git a/packages/cli/bin/utils.js b/packages/cli/bin/utils.js index 10048ecee..0699bff36 100644 --- a/packages/cli/bin/utils.js +++ b/packages/cli/bin/utils.js @@ -175,6 +175,15 @@ const checkAndInstallPackage = (packageName, url) => */ const noop = () => {}; +const getJSONKey = (packageName, key, fileName = 'package.json') => + wrapAsync(function*() { + yield checkAndInstallPackage(packageName); + const packageJSON = yield fs.readJson( + path.resolve('node_modules', packageName, fileName) + ); + return packageJSON[key]; + }); + module.exports = { copyWithPattern, copyAsync: fs.copy, @@ -189,4 +198,5 @@ module.exports = { wrapAsync, checkAndInstallPackage, noop, + getJSONKey, }; From 3ecbb3e9467552c13f9c9d77329b2554920a8cff Mon Sep 17 00:00:00 2001 From: bmuenzenmeyer Date: Mon, 9 Jul 2018 09:00:11 -0500 Subject: [PATCH 2/2] feat(scripts): namespace scripts --- packages/edition-node/package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/edition-node/package.json b/packages/edition-node/package.json index 78922641b..78bb0190f 100644 --- a/packages/edition-node/package.json +++ b/packages/edition-node/package.json @@ -19,11 +19,11 @@ "bugs": "https://github.com/pattern-lab/patternlab-node/issues", "author": "Brian Muenzenmeyer", "scripts": { - "build": "patternlab build --config ./patternlab-config.json", - "help": "patternlab --help", - "install": "patternlab install --config ./patternlab-config.json", - "serve": "patternlab serve --config ./patternlab-config.json", - "version": "patternlab --version" + "pl:build": "patternlab build --config ./patternlab-config.json", + "pl:help": "patternlab --help", + "pl:install": "patternlab install --config ./patternlab-config.json", + "pl:serve": "patternlab serve --config ./patternlab-config.json", + "pl:version": "patternlab --version" }, "license": "MIT", "engines": {