Skip to content

Commit cd91786

Browse files
committed
feat(cli): if starterkit has pl config, deep merge it in
1 parent 105e91c commit cd91786

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const patternlab = require('@pattern-lab/core');
3+
const merge = require('deepmerge');
34
const ask = require('../ask');
45
const scaffold = require('../scaffold');
56
const installEdition = require('../install-edition');
@@ -50,14 +51,22 @@ const init = options =>
5051
patternlabConfig,
5152
projectDir
5253
); // 3.1
53-
patternlabConfig = Object.assign(patternlabConfig, newConf); // 3.2
54+
if (newConf) {
55+
patternlabConfig = merge(patternlabConfig, newConf); // 3.2
56+
}
5457
spinner.succeed(`⊙ patternlab → Installed edition: ${edition}`);
5558
}
5659
if (starterkit) {
5760
spinner.text = `⊙ patternlab → Installing starterkit ${starterkit}`;
5861
spinner.start();
59-
yield installStarterkit(starterkit, patternlabConfig);
62+
const starterkitConfig = yield installStarterkit(
63+
starterkit,
64+
patternlabConfig
65+
);
6066
spinner.succeed(`⊙ patternlab → Installed starterkit: ${starterkit}`);
67+
if (starterkitConfig) {
68+
patternlabConfig = merge(patternlabConfig, starterkitConfig);
69+
}
6170
} // 4
6271
yield writeJsonAsync(
6372
path.resolve(projectDir, 'patternlab-config.json'),

packages/cli/bin/install-edition.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const path = require('path');
4+
const merge = require('deepmerge');
45
const EOL = require('os').EOL;
56
const {
67
checkAndInstallPackage,
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
'use strict';
22
const path = require('path');
3-
const checkAndInstallPackage = require('./utils').checkAndInstallPackage;
4-
const copyAsync = require('./utils').copyAsync;
5-
const wrapAsync = require('./utils').wrapAsync;
3+
const fs = require('fs-extra');
4+
const {
5+
copyAsync,
6+
wrapAsync,
7+
checkAndInstallPackage,
8+
readJsonAsync,
9+
} = require('./utils');
610

711
const installStarterkit = (starterkit, config) =>
812
wrapAsync(function*() {
913
const sourceDir = config.paths.source.root;
1014
const name = starterkit.value || starterkit;
1115
const url = name.startsWith('@pattern-lab/') ? name : `pattern-lab/${name}`;
1216
yield checkAndInstallPackage(name, url);
13-
yield copyAsync(
14-
path.resolve('./node_modules', name, 'dist'),
15-
path.resolve(sourceDir)
16-
);
17-
return name;
17+
const kitPath = path.resolve('./node_modules', name);
18+
yield copyAsync(path.resolve(kitPath, 'dist'), path.resolve(sourceDir));
19+
let kitConfig;
20+
const kitConfigPath = path.resolve(kitPath, 'patternlab-config.json');
21+
if (fs.existsSync(kitConfigPath)) {
22+
kitConfig = yield readJsonAsync(kitConfigPath);
23+
}
24+
return kitConfig;
1825
});
1926

2027
module.exports = installStarterkit;

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"archiver": "2.1.1",
1515
"chalk": "2.4.1",
1616
"commander": "2.15.1",
17+
"deepmerge": "^2.1.1",
1718
"execa": "0.10.0",
1819
"fs-extra": "6.0.1",
1920
"glob": "7.1.2",

0 commit comments

Comments
 (0)