Skip to content

Commit 07f38ef

Browse files
Merge pull request #898 from pattern-lab/plugin-work
Plugin work
2 parents 1f14270 + a1a9779 commit 07f38ef

File tree

36 files changed

+267
-494
lines changed

36 files changed

+267
-494
lines changed

packages/cli/CHANGELOG.md

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,102 +16,77 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
1616

1717

1818
<a name="0.0.1-alpha.22"></a>
19+
1920
## [0.0.1-alpha.22](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-07-06)
2021

2122
**Note:** Version bump only for package @pattern-lab/cli
2223

23-
24-
25-
26-
2724
<a name="0.0.1-alpha.21"></a>
28-
## [0.0.1-alpha.21](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-07-06)
2925

26+
## [0.0.1-alpha.21](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-07-06)
3027

3128
### Bug Fixes
3229

3330
* **install:** add break statements to install edition command ([3b1813c](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/3b1813c))
3431
* **install:** use process to find package.json ([200c7cb](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/200c7cb))
3532

36-
3733
### Features
3834

3935
* **package:** add npmrc file ([55f5bc2](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/55f5bc2))
4036
* **package:** pin all dependencies ([415698e](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/415698e))
4137
* **package:** remove package-lock.json files ([5ab3995](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/5ab3995))
4238

43-
44-
45-
46-
4739
<a name="0.0.1-alpha.20"></a>
48-
## [0.0.1-alpha.20](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-07-05)
4940

41+
## [0.0.1-alpha.20](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-07-05)
5042

5143
### Bug Fixes
5244

5345
* **cli:** change whitespace to spaces per standard ([4556fc7](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/4556fc7))
5446
* **tests:** change test command name similar to live-server until this passes CI ([5c39be1](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/5c39be1))
5547

56-
5748
### Features
5849

5950
* **serve:** change calling method ([3b86a0d](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/3b86a0d))
6051
* **tests:** use lerna run test at the monorepo level ([38a01b1](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/38a01b1))
6152

62-
63-
64-
6553
<a name="0.0.1-alpha.19"></a>
66-
## [0.0.1-alpha.19](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-19)
6754

55+
## [0.0.1-alpha.19](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-19)
6856

6957
### Bug Fixes
7058

7159
* **cli:** change line-endings of cli entrypoint ([3fc86c2](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/3fc86c2))
7260
* **wording:** reconcile Pattern Lab vs PatternLab ([f3d1e0d](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/f3d1e0d))
7361

74-
75-
76-
7762
<a name="0.0.1-alpha.18"></a>
78-
## [0.0.1-alpha.18](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-04)
7963

64+
## [0.0.1-alpha.18](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-04)
8065

8166
### Bug Fixes
8267

8368
* **version:** use static core method getVersion ([f9dcd4d](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/f9dcd4d))
8469

85-
86-
87-
8870
<a name="0.0.1-alpha.17"></a>
89-
## [0.0.1-alpha.17](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-04)
9071

72+
## [0.0.1-alpha.17](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-04)
9173

9274
### Bug Fixes
9375

9476
* **package:** update publish config and installation target ([27d2c8f](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/27d2c8f))
9577

96-
97-
98-
9978
<a name="0.0.1-alpha.16"></a>
100-
## [0.0.1-alpha.16](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-04)
10179

80+
## [0.0.1-alpha.16](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-04)
10281

10382
### Features
10483

10584
* **API:** standardize v() and version() into a single call ([6309e69](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/6309e69))
10685

107-
10886
### BREAKING CHANGES
10987

11088
* **API:** change `version()` to return a string representation of the version, removing `v()`
11189

112-
113-
114-
11590
<a name="0.0.1-alpha.15"></a>
11691

11792
## [0.0.1-alpha.15](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-03-21)

packages/cli/bin/install-plugin.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'use strict';
2+
3+
const path = require('path');
4+
25
const _ = require('lodash');
6+
37
const checkAndInstallPackage = require('./utils').checkAndInstallPackage;
48
const wrapAsync = require('./utils').wrapAsync;
59

@@ -8,7 +12,21 @@ const installPlugin = (plugin, config) =>
812
const name = plugin.name || plugin;
913
yield checkAndInstallPackage(name);
1014
// Put the installed plugin in the patternlab-config.json
11-
_.set(config, `plugins[${name}]['enabled']`, false);
15+
_.set(config, `plugins[${name}]['enabled']`, true);
16+
_.set(config, `plugins[${name}]['initialized']`, false);
17+
18+
// Get the options from the plugin, if any
19+
const pluginPathConfig = path.resolve(
20+
path.join(process.cwd(), 'node_modules', name, 'config.json')
21+
);
22+
try {
23+
const pluginConfigJSON = require(pluginPathConfig);
24+
if (!_.has(config.plugins[name].options)) {
25+
_.set(config, `plugins[${name}]['options]`, pluginConfigJSON);
26+
}
27+
} catch (ex) {
28+
//a config.json file is not required at this time
29+
}
1230
return name;
1331
});
1432

packages/cli/bin/patternlab.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22
'use strict';
33
const cli = require('commander');
4+
const path = require('path');
45
const build = require('./cli-actions/build');
56
const disable = require('./cli-actions/disable');
67
const enable = require('./cli-actions/enable');
@@ -42,7 +43,7 @@ cli
4243
'-c, --config <path>',
4344
'Specify config file. Default looks up the project dir',
4445
val => val.trim(),
45-
'./patternlab-config.json'
46+
path.resolve(process.cwd(), 'patternlab-config.json')
4647
)
4748
.option('-v, --verbose', 'Show verbose console logs', verboseLogs)
4849
.option('--silent', 'Turn off console logs', silenceLogs);

packages/cli/bin/utils.js

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

178+
/**
179+
* @func writeJsonAsync
180+
* Wrapper for fs.writeJsonAsync with consistent spacing
181+
* @param {string} filePath
182+
* @param {object} data
183+
*/
184+
const writeJsonAsync = (filePath, data) =>
185+
wrapAsync(function*() {
186+
yield fs.outputJSON(filePath, data, { spaces: 2 });
187+
});
188+
189+
/**
190+
* @func getJSONKey
191+
* Installs package, then returns the value for the given JSON file's key within
192+
* @param {string} packageName - the node_module to install / load
193+
* @param {object} key - the key to find
194+
* @param {object} fileName - the filePath of the JSON
195+
*/
178196
const getJSONKey = (packageName, key, fileName = 'package.json') =>
179197
wrapAsync(function*() {
180198
yield checkAndInstallPackage(packageName);
181-
const packageJSON = yield fs.readJson(
199+
const jsonData = yield fs.readJson(
182200
path.resolve('node_modules', packageName, fileName)
183201
);
184-
return packageJSON[key];
202+
return jsonData[key];
185203
});
186204

187205
module.exports = {
188206
copyWithPattern,
189207
copyAsync: fs.copy,
190208
mkdirsAsync: fs.mkdirs,
191209
moveAsync: fs.move,
192-
writeJsonAsync: fs.outputJson,
210+
writeJsonAsync: writeJsonAsync,
193211
readJsonAsync: fs.readJson,
194212
error,
195213
info,

packages/cli/test/cli-init.test.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@ const wrapAsync = require('../bin/utils').wrapAsync;
88
const projectRoot = getUniqueProjectPath();
99

1010
tap.test('Init ->', t =>
11-
wrapAsync(function*() {
12-
yield spawnCmd([
13-
'init',
14-
'--verbose',
15-
'--project-dir',
16-
projectRoot,
17-
'--edition',
18-
'@pattern-lab/edition-node',
19-
'--starterkit',
20-
'@pattern-lab/starterkit-mustache-base',
21-
]);
22-
t.ok(
23-
exists.sync(path.resolve(projectRoot)),
24-
'should initialize a Pattern Lab project'
25-
);
26-
t.ok(exists.sync(path.resolve(projectRoot, 'source')), 'with a source dir');
27-
t.ok(exists.sync(path.resolve(projectRoot, 'public')), 'with a public dir');
28-
t.ok(
29-
exists.sync(path.resolve(projectRoot, 'pattern_exports')),
30-
'with a pattern_exports dir'
31-
);
32-
t.ok(
33-
exists.sync(path.resolve(projectRoot, 'patternlab-config.json')),
34-
'with a pattern_exports dir'
35-
);
36-
t.end();
37-
})
11+
wrapAsync(function*() {
12+
yield spawnCmd([
13+
'init',
14+
'--verbose',
15+
'--project-dir',
16+
projectRoot,
17+
'--edition',
18+
'@pattern-lab/edition-node',
19+
'--starterkit',
20+
'@pattern-lab/starterkit-mustache-base',
21+
]);
22+
t.ok(
23+
exists.sync(path.resolve(projectRoot)),
24+
'should initialize a Pattern Lab project'
25+
);
26+
t.ok(exists.sync(path.resolve(projectRoot, 'source')), 'with a source dir');
27+
t.ok(exists.sync(path.resolve(projectRoot, 'public')), 'with a public dir');
28+
t.ok(
29+
exists.sync(path.resolve(projectRoot, 'pattern_exports')),
30+
'with a pattern_exports dir'
31+
);
32+
t.ok(
33+
exists.sync(path.resolve(projectRoot, 'patternlab-config.json')),
34+
'with a pattern_exports dir'
35+
);
36+
t.end();
37+
})
3838
);

packages/core/CHANGELOG.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,24 @@ All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

66
<a name="3.0.0-alpha.16"></a>
7+
78
# [3.0.0-alpha.16](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-07-06)
89

910
**Note:** Version bump only for package @pattern-lab/core
1011

11-
12-
13-
14-
1512
<a name="3.0.0-alpha.15"></a>
16-
# [3.0.0-alpha.15](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-07-06)
1713

14+
# [3.0.0-alpha.15](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-07-06)
1815

1916
### Features
2017

2118
* **package:** add npmrc file ([55f5bc2](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/55f5bc2))
2219
* **package:** pin all dependencies ([415698e](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/415698e))
2320
* **package:** remove package-lock.json files ([5ab3995](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/5ab3995))
2421

25-
26-
27-
28-
2922
<a name="3.0.0-alpha.14"></a>
30-
# [3.0.0-alpha.14](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-07-05)
3123

24+
# [3.0.0-alpha.14](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-07-05)
3225

3326
### Bug Fixes
3427

@@ -38,7 +31,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
3831
* **viewall:** fix viewall generation ([543558a](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/543558a))
3932
* **watch:** wire up serve and watch listeners correctly ([04cd18e](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/04cd18e))
4033

41-
4234
### Features
4335

4436
* **events:** add PATTERNLAB_BUILD_END event and rename BUILD_START ([5b7bfa3](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/5b7bfa3))
@@ -47,23 +39,17 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
4739
* **server:** continue server refactor ([8f6cd91](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/8f6cd91))
4840
* **watches:** add additional assets to ignore ([18e74c2](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/18e74c2))
4941

50-
51-
52-
5342
<a name="3.0.0-alpha.13"></a>
54-
# [3.0.0-alpha.13](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-04)
5543

44+
# [3.0.0-alpha.13](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-04)
5645

5746
### Features
5847

5948
* **api:** expose getVersion statically ([4683cd0](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/4683cd0))
6049

61-
62-
63-
6450
<a name="3.0.0-alpha.12"></a>
65-
# [3.0.0-alpha.12](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-04)
6651

52+
# [3.0.0-alpha.12](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-05-04)
6753

6854
### Bug Fixes
6955

@@ -76,7 +62,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
7662
* **tests:** prevent dependency graph output file from being written ([0d9c57e](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/0d9c57e))
7763
* **uikits:** fix ui_builder_tests ([e75f434](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/e75f434))
7864

79-
8065
### Features
8166

8267
* **API:** standardize v() and version() into a single call ([6309e69](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/6309e69))
@@ -96,14 +81,10 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
9681
* **uikits:** support watched-asset copying ([4f05311](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/4f05311))
9782
* **uikits:** uikits config to default ([a393851](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/commit/a393851))
9883

99-
10084
### BREAKING CHANGES
10185

10286
* **API:** change `version()` to return a string representation of the version, removing `v()`
10387

104-
105-
106-
10788
<a name="3.0.0-alpha.11"></a>
10889

10990
# [3.0.0-alpha.11](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/[email protected]...@pattern-lab/[email protected]) (2018-03-21)

packages/core/scripts/events.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Pattern Lab emits numerous events during the [build](../docs/) process. Some uses of events:
66

77
* Core uses `patternlab-pattern-change` events when watching for changes in order to trigger another build
8-
* Plugins such as [plugin-node-tab](https://github.com/pattern-lab/plugin-node-tab) can use an event like `patternlab-pattern-write-end` to define additional code tabs to the pattern viewer / modal
8+
* Plugins such as [plugin-tab](https://github.com/pattern-lab/patternlab-node/tree/master/packages/plugin-tab) can use an event like `patternlab-pattern-write-end` to define additional code tabs to the pattern viewer / modal
99

1010
Learn more about [Creating Plugins](https://github.com/pattern-lab/patternlab-node/wiki/Creating-Plugins).
1111

packages/core/src/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010

1111
'use strict';
1212

13+
const path = require('path');
14+
1315
const updateNotifier = require('update-notifier');
1416

1517
const packageInfo = require('../package.json');
1618
const events = require('./lib/events');
1719
const pe = require('./lib/pattern_exporter');
20+
const pm = require('./lib/plugin_manager');
1821

1922
const defaultConfig = require('../patternlab-config.json');
2023

@@ -189,7 +192,11 @@ const patternlab_module = function(config) {
189192
* @returns {void}
190193
*/
191194
installplugin: function(pluginName) {
192-
patternlab.installPlugin(pluginName);
195+
//get the config
196+
const configPath = path.resolve(process.cwd(), 'patternlab-config.json');
197+
const plugin_manager = new pm(config, configPath);
198+
199+
plugin_manager.install_plugin(pluginName);
193200
},
194201

195202
/**

0 commit comments

Comments
 (0)