Skip to content

Commit fb6efea

Browse files
Merge pull request #885 from pattern-lab/dev
Dev
2 parents 8be2cc5 + 7232cd4 commit fb6efea

File tree

4 files changed

+49
-22
lines changed

4 files changed

+49
-22
lines changed

packages/cli/bin/cli-actions/init.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ const init = options =>
4545

4646
if (edition) {
4747
spinner.text = `⊙ patternlab → Installing edition: ${edition}`;
48-
const newConf = yield installEdition(edition, patternlabConfig); // 3.1
48+
const newConf = yield installEdition(
49+
edition,
50+
patternlabConfig,
51+
projectDir
52+
); // 3.1
4953
patternlabConfig = Object.assign(patternlabConfig, newConf); // 3.2
5054
spinner.succeed(`⊙ patternlab → Installed edition: ${edition}`);
5155
}

packages/cli/bin/install-edition.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,63 @@
11
'use strict';
2+
23
const path = require('path');
3-
const pkg = require(path.resolve(process.cwd(), 'package.json'));
4+
const EOL = require('os').EOL;
45
const {
56
checkAndInstallPackage,
67
copyAsync,
78
wrapAsync,
89
writeJsonAsync,
10+
getJSONKey,
911
} = require('./utils');
1012

11-
const installEdition = (edition, config) =>
12-
wrapAsync(function*() {
13+
const installEdition = (edition, config, projectDir) => {
14+
const pkg = require(path.resolve(projectDir, 'package.json'));
15+
16+
return wrapAsync(function*() {
1317
/**
1418
* 1. Trigger edition install
1519
* 2. Copy over the mandatory edition files to sourceDir
16-
* 3. Do custom post-install procedures for different core editions:
17-
* 3.1 Copy gulpfile.js for edition-node-gulp
20+
* 3. Copy dependencies defined in edition
21+
* 4. Do custom post-install procedures for different core editions:
22+
* 4.1 Copy gulpfile.js for edition-node-gulp
23+
* 4.2 Copy scripts for edition-node
1824
*/
1925
const sourceDir = config.paths.source.root;
2026
yield checkAndInstallPackage(edition); // 1
2127
yield copyAsync(
2228
path.resolve('./node_modules', edition, 'source', '_meta'),
2329
path.resolve(sourceDir, '_meta')
2430
); // 2
25-
switch (edition) { // 3
26-
// 3.1
31+
pkg.dependencies = Object.assign(
32+
{},
33+
pkg.dependencies || {},
34+
yield getJSONKey(edition, 'dependencies')
35+
); // 3
36+
switch (edition) { // 4
37+
// 4.1
2738
case '@pattern-lab/edition-node-gulp': {
2839
yield copyAsync(
2940
path.resolve('./node_modules', edition, 'gulpfile.js'),
3041
path.resolve(sourceDir, '../', 'gulpfile.js')
3142
);
3243
break;
3344
}
45+
// 4.2
3446
case '@pattern-lab/edition-node': {
35-
const scriptsJSON = {
36-
'pl:build': 'patternlab build --config ./patternlab-config.json',
37-
'pl:help': 'patternlab --help',
38-
'pl:install': 'patternlab install --config ./patternlab-config.json',
39-
'pl:serve': 'patternlab serve --config ./patternlab-config.json',
40-
'pl:version': 'patternlab --version',
41-
};
42-
pkg.scripts = Object.assign({}, pkg.scripts || {}, scriptsJSON);
43-
yield writeJsonAsync('./package.json', pkg, { spaces: 2 });
47+
pkg.scripts = Object.assign(
48+
{},
49+
pkg.scripts || {},
50+
yield getJSONKey(edition, 'scripts')
51+
);
4452
break;
4553
}
4654
}
55+
yield writeJsonAsync(path.resolve(projectDir, 'package.json'), pkg, {
56+
spaces: 2,
57+
EOL: EOL,
58+
});
4759
return config;
4860
});
61+
};
4962

5063
module.exports = installEdition;

packages/cli/bin/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ const checkAndInstallPackage = (packageName, url) =>
175175
*/
176176
const noop = () => {};
177177

178+
const getJSONKey = (packageName, key, fileName = 'package.json') =>
179+
wrapAsync(function*() {
180+
yield checkAndInstallPackage(packageName);
181+
const packageJSON = yield fs.readJson(
182+
path.resolve('node_modules', packageName, fileName)
183+
);
184+
return packageJSON[key];
185+
});
186+
178187
module.exports = {
179188
copyWithPattern,
180189
copyAsync: fs.copy,
@@ -189,4 +198,5 @@ module.exports = {
189198
wrapAsync,
190199
checkAndInstallPackage,
191200
noop,
201+
getJSONKey,
192202
};

packages/edition-node/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"bugs": "https://github.com/pattern-lab/patternlab-node/issues",
2020
"author": "Brian Muenzenmeyer",
2121
"scripts": {
22-
"build": "patternlab build --config ./patternlab-config.json",
23-
"help": "patternlab --help",
24-
"install": "patternlab install --config ./patternlab-config.json",
25-
"serve": "patternlab serve --config ./patternlab-config.json",
26-
"version": "patternlab --version"
22+
"pl:build": "patternlab build --config ./patternlab-config.json",
23+
"pl:help": "patternlab --help",
24+
"pl:install": "patternlab install --config ./patternlab-config.json",
25+
"pl:serve": "patternlab serve --config ./patternlab-config.json",
26+
"pl:version": "patternlab --version"
2727
},
2828
"license": "MIT",
2929
"engines": {

0 commit comments

Comments
 (0)