Skip to content

Commit 1acf169

Browse files
Merge branch 'dev' into update-pattern-states
2 parents 7728acc + 4a2fe28 commit 1acf169

31 files changed

+261
-171
lines changed

packages/cli/bin/install-plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const installPlugin = (plugin, config) =>
2222
try {
2323
const pluginConfigJSON = require(pluginPathConfig);
2424
if (!_.has(config.plugins[name].options)) {
25-
_.set(config, `plugins[${name}]['options]`, pluginConfigJSON);
25+
_.set(config, `plugins[${name}][options]`, pluginConfigJSON);
2626
}
2727
} catch (ex) {
2828
//a config.json file is not required at this time

packages/cli/bin/install-starterkit.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ const installStarterkit = (starterkit, config) =>
1212
wrapAsync(function*() {
1313
const sourceDir = config.paths.source.root;
1414
const name = starterkit.value || starterkit;
15-
const url = name.startsWith('@pattern-lab/') ? name : `pattern-lab/${name}`;
16-
yield checkAndInstallPackage(name, url);
15+
yield checkAndInstallPackage(name);
1716
const kitPath = path.resolve('./node_modules', name);
1817
yield copyAsync(path.resolve(kitPath, 'dist'), path.resolve(sourceDir));
1918
let kitConfig;

packages/cli/bin/utils.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,15 @@ const copyWithPattern = (cwd, pattern, dest) =>
126126
* @func fetchPackage
127127
* @desc Fetches and saves packages from npm into node_modules and adds a reference in the package.json under dependencies
128128
* @param {string} packageName - The package name
129-
* @param {string} [url] - A URL which will be used to fetch the package from
130129
*/
131-
const fetchPackage = (packageName, url) =>
130+
const fetchPackage = packageName =>
132131
wrapAsync(function*() {
133132
const useYarn = hasYarn();
134133
const pm = useYarn ? 'yarn' : 'npm';
135134
const installCmd = useYarn ? 'add' : 'install';
136135
try {
137-
if (packageName || url) {
138-
const cmd = yield spawn(pm, [installCmd, url || packageName]);
136+
if (packageName) {
137+
const cmd = yield spawn(pm, [installCmd, packageName]);
139138
error(cmd.stderr);
140139
}
141140
} catch (err) {
@@ -150,10 +149,9 @@ const fetchPackage = (packageName, url) =>
150149
* @func checkAndInstallPackage
151150
* Checks whether a package for a given packageName is installed locally. If package cannot be found, fetch and install it
152151
* @param {string} packageName - The package name
153-
* @param {string} [url] - A URL which will be used to fetch the package from
154152
* @return {boolean}
155153
*/
156-
const checkAndInstallPackage = (packageName, url) =>
154+
const checkAndInstallPackage = packageName =>
157155
wrapAsync(function*() {
158156
try {
159157
require.resolve(packageName);
@@ -162,7 +160,7 @@ const checkAndInstallPackage = (packageName, url) =>
162160
debug(
163161
`checkAndInstallPackage: ${packageName} not installed. Fetching it now …`
164162
);
165-
yield fetchPackage(packageName, url);
163+
yield fetchPackage(packageName);
166164
return false;
167165
}
168166
});

packages/cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"glob": "7.1.2",
2121
"has-yarn": "1.0.0",
2222
"inquirer": "5.1.0",
23-
"lodash": "4.17.10",
23+
"lodash": "4.17.15",
2424
"ora": "2.1.0",
2525
"path-exists": "3.0.0",
2626
"sanitize-filename": "1.6.1"
@@ -31,7 +31,7 @@
3131
"eslint-plugin-prettier": "2.6.0",
3232
"prettier": "1.11.1",
3333
"proxyquire": "2.0.1",
34-
"tap": "11.1.1"
34+
"tap": "14.6.4"
3535
},
3636
"files": [
3737
"bin"

packages/core/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"glob": "7.0.0",
1414
"graphlib": "2.1.1",
1515
"js-beautify": "1.6.3",
16-
"js-yaml": "3.6.1",
17-
"lodash": "4.17.5",
16+
"js-yaml": "3.13.1",
17+
"lodash": "4.17.15",
1818
"markdown-it": "6.0.1",
1919
"node-fetch": "1.6.0",
2020
"recursive-copy": "2.0.8",
@@ -31,12 +31,12 @@
3131
"eslint-plugin-import": "^2.18.2",
3232
"eslint-plugin-prettier": "^3.1.0",
3333
"husky": "0.14.3",
34-
"jsdoc-to-markdown": "3.0.0",
34+
"jsdoc-to-markdown": "5.0.1",
3535
"prettier": "^1.14.3",
3636
"pretty-quick": "^1.11.1",
3737
"rewire": "2.5.2",
3838
"standard-version": "4.3.0",
39-
"tap": "11.1.1"
39+
"tap": "14.6.4"
4040
},
4141
"keywords": [
4242
"Pattern Lab",
@@ -51,8 +51,7 @@
5151
"author": {
5252
"name": "Brian Muenzenmeyer"
5353
},
54-
"contributors": [
55-
{
54+
"contributors": [{
5655
"name": "Geoff Pursell"
5756
},
5857
{

packages/core/src/index.js

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const patternlab_module = function(config) {
9292
* @see {@link ./events.md|all events}
9393
* @returns {Promise} a promise fulfilled when build is complete
9494
*/
95-
build: function(options) {
95+
build: async function(options) {
9696
// process.on('unhandledRejection', (reason, p) => {
9797
// console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
9898
// // application specific logging, throwing an error, or other logic here
@@ -109,53 +109,51 @@ const patternlab_module = function(config) {
109109
}
110110
patternlab.isBusy = true;
111111

112-
return buildPatterns(options.cleanPublic, patternlab, options.data).then(
113-
() => {
114-
return new ui_builder().buildFrontend(patternlab).then(() => {
115-
copier()
116-
.copyAndWatch(patternlab.config.paths, patternlab, options)
117-
.then(() => {
118-
patternlab.isBusy = false;
119-
// only wire up this listener and the one inside serve.js
120-
// figure out how to detect if serve was called. we should not assume it was
121-
if (
122-
patternlab.serverReady //check for server presence
123-
? this.events.listenerCount(
124-
events.PATTERNLAB_PATTERN_CHANGE
125-
) === 1 //if the server is started, it has already setup one listener
126-
: !this.events.listenerCount(
127-
events.PATTERNLAB_PATTERN_CHANGE
128-
) // else, check for the presnce of none
129-
) {
130-
this.events.on(events.PATTERNLAB_PATTERN_CHANGE, () => {
131-
if (!patternlab.isBusy) {
132-
return this.build(options).then(() => {
133-
patternlab.isBusy = false;
134-
});
135-
}
136-
return Promise.resolve();
137-
});
138-
}
112+
return await buildPatterns(
113+
options.cleanPublic,
114+
patternlab,
115+
options.data
116+
).then(() => {
117+
return new ui_builder().buildFrontend(patternlab).then(() => {
118+
copier()
119+
.copyAndWatch(patternlab.config.paths, patternlab, options)
120+
.then(() => {
121+
patternlab.isBusy = false;
122+
// only wire up this listener and the one inside serve.js
123+
// figure out how to detect if serve was called. we should not assume it was
124+
if (
125+
patternlab.serverReady //check for server presence
126+
? this.events.listenerCount(
127+
events.PATTERNLAB_PATTERN_CHANGE
128+
) === 1 //if the server is started, it has already setup one listener
129+
: !this.events.listenerCount(events.PATTERNLAB_PATTERN_CHANGE) // else, check for the presnce of none
130+
) {
131+
this.events.on(events.PATTERNLAB_PATTERN_CHANGE, () => {
132+
if (!patternlab.isBusy) {
133+
return this.build(options).then(() => {
134+
patternlab.isBusy = false;
135+
});
136+
}
137+
return Promise.resolve();
138+
});
139+
}
139140

140-
if (
141-
!this.events.listenerCount(events.PATTERNLAB_GLOBAL_CHANGE)
142-
) {
143-
this.events.on(events.PATTERNLAB_GLOBAL_CHANGE, () => {
144-
if (!patternlab.isBusy) {
145-
return this.build(
146-
Object.assign({}, options, { cleanPublic: true }) // rebuild everything
147-
);
148-
}
149-
return Promise.resolve();
150-
});
151-
}
152-
})
153-
.then(() => {
154-
this.events.emit(events.PATTERNLAB_BUILD_END, patternlab);
155-
});
156-
});
157-
}
158-
);
141+
if (!this.events.listenerCount(events.PATTERNLAB_GLOBAL_CHANGE)) {
142+
this.events.on(events.PATTERNLAB_GLOBAL_CHANGE, () => {
143+
if (!patternlab.isBusy) {
144+
return this.build(
145+
Object.assign({}, options, { cleanPublic: true }) // rebuild everything
146+
);
147+
}
148+
return Promise.resolve();
149+
});
150+
}
151+
})
152+
.then(() => {
153+
this.events.emit(events.PATTERNLAB_BUILD_END, patternlab);
154+
});
155+
});
156+
});
159157
},
160158

161159
/**
@@ -194,7 +192,7 @@ const patternlab_module = function(config) {
194192
installplugin: function(pluginName) {
195193
//get the config
196194
const configPath = path.resolve(process.cwd(), 'patternlab-config.json');
197-
const plugin_manager = new pm(config, configPath);
195+
const plugin_manager = new pm();
198196

199197
plugin_manager.install_plugin(pluginName);
200198
},
@@ -236,19 +234,21 @@ const patternlab_module = function(config) {
236234
* @param {bool} [options.watch=true] whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild
237235
* @returns {Promise} a promise fulfilled when build is complete
238236
*/
239-
patternsonly: function(options) {
237+
patternsonly: async function(options) {
240238
if (patternlab && patternlab.isBusy) {
241239
logger.info(
242240
'Pattern Lab is busy building a previous run - returning early.'
243241
);
244242
return Promise.resolve();
245243
}
246244
patternlab.isBusy = true;
247-
return buildPatterns(options.cleanPublic, patternlab, options.data).then(
248-
() => {
249-
patternlab.isBusy = false;
250-
}
251-
);
245+
return await buildPatterns(
246+
options.cleanPublic,
247+
patternlab,
248+
options.data
249+
).then(() => {
250+
patternlab.isBusy = false;
251+
});
252252
},
253253

254254
/**

packages/core/src/lib/buildPatterns.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const CompileState = require('./object_factory').CompileState;
1414
const processMetaPattern = require('./processMetaPattern');
1515
const pe = require('./pattern_exporter');
1616
const lh = require('./lineage_hunter');
17+
const pm = require('./plugin_manager');
18+
const pluginMananger = new pm();
1719
const markModifiedPatterns = require('./markModifiedPatterns');
1820
const parseAllLinks = require('./parseAllLinks');
1921
const render = require('./render');
@@ -24,8 +26,12 @@ let pattern_exporter = new pe(); // eslint-disable-line
2426

2527
const lineage_hunter = new lh();
2628

27-
module.exports = (deletePatternDir, patternlab, additionalData) => {
28-
patternlab.events.emit(events.PATTERNLAB_BUILD_START, patternlab);
29+
module.exports = async (deletePatternDir, patternlab, additionalData) => {
30+
await pluginMananger.raiseEvent(
31+
patternlab,
32+
events.PATTERNLAB_BUILD_START,
33+
patternlab
34+
);
2935

3036
const paths = patternlab.config.paths;
3137

@@ -63,8 +69,9 @@ module.exports = (deletePatternDir, patternlab, additionalData) => {
6369

6470
return patternlab
6571
.processAllPatternsIterative(paths.source.patterns)
66-
.then(() => {
67-
patternlab.events.emit(
72+
.then(async () => {
73+
await pluginMananger.raiseEvent(
74+
patternlab,
6875
events.PATTERNLAB_PATTERN_ITERATION_END,
6976
patternlab
7077
);
@@ -140,11 +147,12 @@ module.exports = (deletePatternDir, patternlab, additionalData) => {
140147
}
141148
}
142149
//render all patterns last, so lineageR works
143-
const allPatternsPromise = patternsToBuild.map(pattern =>
144-
compose(
145-
pattern,
146-
patternlab
147-
)
150+
const allPatternsPromise = patternsToBuild.map(
151+
async pattern =>
152+
await compose(
153+
pattern,
154+
patternlab
155+
)
148156
);
149157
//copy non-pattern files like JavaScript
150158
const allJS = patternsToBuild.map(pattern => {

0 commit comments

Comments
 (0)