Skip to content

Commit

Permalink
Merge pull request #898 from pattern-lab/plugin-work
Browse files Browse the repository at this point in the history
Plugin work
  • Loading branch information
bmuenzenmeyer committed Jul 27, 2018
2 parents 1f14270 + a1a9779 commit 07f38ef
Show file tree
Hide file tree
Showing 36 changed files with 267 additions and 494 deletions.
39 changes: 7 additions & 32 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,102 +16,77 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline


<a name="0.0.1-alpha.22"></a>

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

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





<a name="0.0.1-alpha.21"></a>
## [0.0.1-alpha.21](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/cli@0.0.1-alpha.20...@pattern-lab/cli@0.0.1-alpha.21) (2018-07-06)

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

### Bug Fixes

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


### Features

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





<a name="0.0.1-alpha.20"></a>
## [0.0.1-alpha.20](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/cli@0.0.1-alpha.19...@pattern-lab/cli@0.0.1-alpha.20) (2018-07-05)

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

### Bug Fixes

* **cli:** change whitespace to spaces per standard ([4556fc7](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/commit/4556fc7))
* **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))


### Features

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




<a name="0.0.1-alpha.19"></a>
## [0.0.1-alpha.19](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/cli@0.0.1-alpha.18...@pattern-lab/cli@0.0.1-alpha.19) (2018-05-19)

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

### Bug Fixes

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




<a name="0.0.1-alpha.18"></a>
## [0.0.1-alpha.18](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/cli@0.0.1-alpha.17...@pattern-lab/cli@0.0.1-alpha.18) (2018-05-04)

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

### Bug Fixes

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




<a name="0.0.1-alpha.17"></a>
## [0.0.1-alpha.17](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/cli@0.0.1-alpha.16...@pattern-lab/cli@0.0.1-alpha.17) (2018-05-04)

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

### Bug Fixes

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




<a name="0.0.1-alpha.16"></a>
## [0.0.1-alpha.16](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/cli@0.0.1-alpha.15...@pattern-lab/cli@0.0.1-alpha.16) (2018-05-04)

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

### Features

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


### BREAKING CHANGES

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




<a name="0.0.1-alpha.15"></a>

## [0.0.1-alpha.15](https://github.com/pattern-lab/patternlab-node/tree/master/packages/cli/compare/@pattern-lab/cli@0.0.1-alpha.14...@pattern-lab/cli@0.0.1-alpha.15) (2018-03-21)
Expand Down
20 changes: 19 additions & 1 deletion packages/cli/bin/install-plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict';

const path = require('path');

const _ = require('lodash');

const checkAndInstallPackage = require('./utils').checkAndInstallPackage;
const wrapAsync = require('./utils').wrapAsync;

Expand All @@ -8,7 +12,21 @@ const installPlugin = (plugin, config) =>
const name = plugin.name || plugin;
yield checkAndInstallPackage(name);
// Put the installed plugin in the patternlab-config.json
_.set(config, `plugins[${name}]['enabled']`, false);
_.set(config, `plugins[${name}]['enabled']`, true);
_.set(config, `plugins[${name}]['initialized']`, false);

// Get the options from the plugin, if any
const pluginPathConfig = path.resolve(
path.join(process.cwd(), 'node_modules', name, 'config.json')
);
try {
const pluginConfigJSON = require(pluginPathConfig);
if (!_.has(config.plugins[name].options)) {
_.set(config, `plugins[${name}]['options]`, pluginConfigJSON);
}
} catch (ex) {
//a config.json file is not required at this time
}
return name;
});

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/bin/patternlab.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
'use strict';
const cli = require('commander');
const path = require('path');
const build = require('./cli-actions/build');
const disable = require('./cli-actions/disable');
const enable = require('./cli-actions/enable');
Expand Down Expand Up @@ -42,7 +43,7 @@ cli
'-c, --config <path>',
'Specify config file. Default looks up the project dir',
val => val.trim(),
'./patternlab-config.json'
path.resolve(process.cwd(), 'patternlab-config.json')
)
.option('-v, --verbose', 'Show verbose console logs', verboseLogs)
.option('--silent', 'Turn off console logs', silenceLogs);
Expand Down
24 changes: 21 additions & 3 deletions packages/cli/bin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,39 @@ const checkAndInstallPackage = (packageName, url) =>
*/
const noop = () => {};

/**
* @func writeJsonAsync
* Wrapper for fs.writeJsonAsync with consistent spacing
* @param {string} filePath
* @param {object} data
*/
const writeJsonAsync = (filePath, data) =>
wrapAsync(function*() {
yield fs.outputJSON(filePath, data, { spaces: 2 });
});

/**
* @func getJSONKey
* Installs package, then returns the value for the given JSON file's key within
* @param {string} packageName - the node_module to install / load
* @param {object} key - the key to find
* @param {object} fileName - the filePath of the JSON
*/
const getJSONKey = (packageName, key, fileName = 'package.json') =>
wrapAsync(function*() {
yield checkAndInstallPackage(packageName);
const packageJSON = yield fs.readJson(
const jsonData = yield fs.readJson(
path.resolve('node_modules', packageName, fileName)
);
return packageJSON[key];
return jsonData[key];
});

module.exports = {
copyWithPattern,
copyAsync: fs.copy,
mkdirsAsync: fs.mkdirs,
moveAsync: fs.move,
writeJsonAsync: fs.outputJson,
writeJsonAsync: writeJsonAsync,
readJsonAsync: fs.readJson,
error,
info,
Expand Down
54 changes: 27 additions & 27 deletions packages/cli/test/cli-init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ const wrapAsync = require('../bin/utils').wrapAsync;
const projectRoot = getUniqueProjectPath();

tap.test('Init ->', t =>
wrapAsync(function*() {
yield spawnCmd([
'init',
'--verbose',
'--project-dir',
projectRoot,
'--edition',
'@pattern-lab/edition-node',
'--starterkit',
'@pattern-lab/starterkit-mustache-base',
]);
t.ok(
exists.sync(path.resolve(projectRoot)),
'should initialize a Pattern Lab project'
);
t.ok(exists.sync(path.resolve(projectRoot, 'source')), 'with a source dir');
t.ok(exists.sync(path.resolve(projectRoot, 'public')), 'with a public dir');
t.ok(
exists.sync(path.resolve(projectRoot, 'pattern_exports')),
'with a pattern_exports dir'
);
t.ok(
exists.sync(path.resolve(projectRoot, 'patternlab-config.json')),
'with a pattern_exports dir'
);
t.end();
})
wrapAsync(function*() {
yield spawnCmd([
'init',
'--verbose',
'--project-dir',
projectRoot,
'--edition',
'@pattern-lab/edition-node',
'--starterkit',
'@pattern-lab/starterkit-mustache-base',
]);
t.ok(
exists.sync(path.resolve(projectRoot)),
'should initialize a Pattern Lab project'
);
t.ok(exists.sync(path.resolve(projectRoot, 'source')), 'with a source dir');
t.ok(exists.sync(path.resolve(projectRoot, 'public')), 'with a public dir');
t.ok(
exists.sync(path.resolve(projectRoot, 'pattern_exports')),
'with a pattern_exports dir'
);
t.ok(
exists.sync(path.resolve(projectRoot, 'patternlab-config.json')),
'with a pattern_exports dir'
);
t.end();
})
);
29 changes: 5 additions & 24 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,24 @@ All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

<a name="3.0.0-alpha.16"></a>

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

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





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

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

### Features

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





<a name="3.0.0-alpha.14"></a>
# [3.0.0-alpha.14](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/core@3.0.0-alpha.13...@pattern-lab/core@3.0.0-alpha.14) (2018-07-05)

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

### Bug Fixes

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


### Features

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




<a name="3.0.0-alpha.13"></a>
# [3.0.0-alpha.13](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/core@3.0.0-alpha.12...@pattern-lab/core@3.0.0-alpha.13) (2018-05-04)

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

### Features

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




<a name="3.0.0-alpha.12"></a>
# [3.0.0-alpha.12](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/core@3.0.0-alpha.11...@pattern-lab/core@3.0.0-alpha.12) (2018-05-04)

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

### Bug Fixes

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


### Features

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


### BREAKING CHANGES

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




<a name="3.0.0-alpha.11"></a>

# [3.0.0-alpha.11](https://github.com/pattern-lab/patternlab-node/tree/master/packages/core/compare/@pattern-lab/core@3.0.0-alpha.10...@pattern-lab/core@3.0.0-alpha.11) (2018-03-21)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/scripts/events.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Pattern Lab emits numerous events during the [build](../docs/) process. Some uses of events:

* Core uses `patternlab-pattern-change` events when watching for changes in order to trigger another build
* 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
* 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

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

Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

'use strict';

const path = require('path');

const updateNotifier = require('update-notifier');

const packageInfo = require('../package.json');
const events = require('./lib/events');
const pe = require('./lib/pattern_exporter');
const pm = require('./lib/plugin_manager');

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

Expand Down Expand Up @@ -189,7 +192,11 @@ const patternlab_module = function(config) {
* @returns {void}
*/
installplugin: function(pluginName) {
patternlab.installPlugin(pluginName);
//get the config
const configPath = path.resolve(process.cwd(), 'patternlab-config.json');
const plugin_manager = new pm(config, configPath);

plugin_manager.install_plugin(pluginName);
},

/**
Expand Down
Loading

0 comments on commit 07f38ef

Please sign in to comment.