Skip to content

Commit 66a0992

Browse files
Merge branch 'dev' into feature-enable-doc-tables
2 parents 8cdfbb6 + 7763bed commit 66a0992

File tree

9 files changed

+59
-62
lines changed

9 files changed

+59
-62
lines changed

packages/cli/bin/build.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ function build(config, options) {
1919
// Initiate Pattern Lab core with the config
2020
const patternLab = pl(config);
2121

22+
if (options && options.watch) {
23+
config.watch = options.watch;
24+
}
25+
2226
/**
2327
* Check whether a flag was passed for build
2428
* 1. Build only patterns
@@ -31,7 +35,7 @@ function build(config, options) {
3135
} else {
3236
// 2
3337
debug(`build: Building your project now into ${config.paths.public.root}`);
34-
return patternLab.build(config.cleanPublic);
38+
return patternLab.build(config);
3539
}
3640
}
3741

packages/cli/bin/patternlab.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ log.on('patternlab.error', err => console.log(err)); // eslint-disable-line
2020
log.on('patternlab.info', msg => console.log(msg)); // eslint-disable-line
2121

2222
// Conditionally register verbose logging
23-
const verboseLogs = verbose =>
24-
log.on('patternlab.debug', msg => console.log(msg)); // eslint-disable-line
23+
const verboseLogs = () => log.on('patternlab.debug', msg => console.log(msg)); // eslint-disable-line
2524

2625
// Conditionally unregister all logging
2726
const silenceLogs = () => {
@@ -58,7 +57,7 @@ cli
5857
.alias('compile')
5958
.description('Build Pattern Lab. Optionally (re-)build only the patterns')
6059
.option('-p, --patterns-only', 'Whether to only build patterns')
61-
.option('--no-watch', 'Start watching for changes')
60+
.option('--watch', 'Start watching for changes')
6261
.action(build);
6362

6463
/**

packages/core/src/lib/object_factory.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ const Pattern = function(
4141
const info = this.getPatternInfo(
4242
pathObj,
4343
patternlab,
44-
isPromoteToFlatPatternRun
44+
isPromoteToFlatPatternRun ||
45+
(patternlab &&
46+
patternlab.config &&
47+
patternlab.config.allPatternsAreDeeplyNested)
4548
);
4649

4750
this.fileName = pathObj.name; // '00-colors'
@@ -258,7 +261,7 @@ Pattern.prototype = {
258261
*
259262
* @param {Patternlab} patternlab Current patternlab instance
260263
*/
261-
promoteFromFlatPatternToDirectory: function(patternlab) {
264+
promoteFromDirectoryToFlatPattern: function(patternlab) {
262265
const p = new Pattern(this.relPath, this.jsonFileData, patternlab, true);
263266
// Only reset the specific fields, not everything
264267
Object.assign(this, {
@@ -287,7 +290,7 @@ Pattern.prototype = {
287290
const info = {
288291
// 00-colors(.mustache) is deeply nested in 00-atoms-/00-global/00-colors
289292
patternlab: patternlab,
290-
patternHasOwnDir: !isPromoteToFlatPatternRun
293+
patternHasOwnDir: isPromoteToFlatPatternRun
291294
? path.basename(pathObj.dir).replace(prefixMatcher, '') ===
292295
pathObj.name.replace(prefixMatcher, '') ||
293296
path.basename(pathObj.dir).replace(prefixMatcher, '') ===

packages/core/src/lib/patternlab.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ module.exports = class PatternLab {
307307
// dive once to perform iterative populating of patternlab object
308308
processAllPatternsIterative(patterns_dir) {
309309
const self = this;
310+
311+
// before updating the patterns has to be reset, otherwise
312+
// deleted pattern would still be present in the patterns array
313+
this.patterns = [];
314+
310315
const promiseAllPatternFiles = new Promise(function(resolve) {
311316
dive(
312317
patterns_dir,

packages/core/src/lib/plugin_manager.js

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,8 @@
11
'use strict';
22

33
const plugin_manager = function() {
4-
const path = require('path');
54
const logger = require('./log');
65

7-
const pluginMatcher = /^plugin-(.*)$/;
8-
9-
/**
10-
* Loads a plugin
11-
*
12-
* @param modulePath {string} the path to the plugin
13-
* @return {object} the loaded plugin
14-
*/
15-
function loadPlugin(modulePath) {
16-
return require(modulePath);
17-
}
18-
19-
/**
20-
* Given a path: return the plugin name if the path points to a valid plugin
21-
* module directory, or false if it doesn't.
22-
* @param filePath
23-
* @returns Plugin name if exists or FALSE
24-
*/
25-
function isPlugin(filePath) {
26-
const baseName = path.basename(filePath);
27-
const pluginMatch = baseName.match(pluginMatcher);
28-
29-
if (pluginMatch) {
30-
return pluginMatch[1];
31-
}
32-
return false;
33-
}
34-
356
/**
367
* Looks for installed plugins, loads them, and invokes them
378
* @param {object} patternlab
@@ -41,7 +12,7 @@ const plugin_manager = function() {
4112
foundPlugins.forEach(plugin => {
4213
logger.info(`Found plugin: ${plugin}`);
4314
logger.info(`Attempting to load and initialize plugin.`);
44-
const pluginModule = loadPlugin(plugin);
15+
const pluginModule = require(plugin);
4516
pluginModule(patternlab);
4617
});
4718
}
@@ -61,12 +32,6 @@ const plugin_manager = function() {
6132
intialize_plugins: patternlab => {
6233
initializePlugins(patternlab);
6334
},
64-
load_plugin: modulePath => {
65-
return loadPlugin(modulePath);
66-
},
67-
is_plugin: filePath => {
68-
return isPlugin(filePath);
69-
},
7035
raiseEvent: async (patternlab, eventName, ...args) => {
7136
await raiseEvent(patternlab, eventName, args);
7237
},

packages/core/src/lib/readDocumentation.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ module.exports = function(pattern, patternlab) {
5656
}
5757

5858
if (
59-
!markdownObject.hasOwnProperty('deeplyNested') ||
60-
(markdownObject.hasOwnProperty('deeplyNested') &&
61-
!markdownObject.deeplyNested)
59+
markdownObject.hasOwnProperty('deeplyNested') &&
60+
markdownObject.deeplyNested
6261
) {
6362
// Reset to pattern without own pattern-directory
64-
pattern.promoteFromFlatPatternToDirectory(patternlab);
63+
pattern.promoteFromDirectoryToFlatPattern(patternlab);
6564
}
6665
} else {
6766
logger.warning(`error processing markdown for ${pattern.patternPartial}`);

packages/core/src/lib/watchPatternLabFiles.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,31 @@ const watchPatternLabFiles = (
131131
file: p,
132132
}
133133
);
134+
})
135+
// the watcher does not react on unlink and unlinkDir
136+
// events, so patterns are never removed
137+
.on('unlink', async p => {
138+
patternlab.graph.sync();
139+
patternlab.graph.upgradeVersion();
140+
await pluginMananger.raiseEvent(
141+
patternlab,
142+
events.PATTERNLAB_PATTERN_CHANGE,
143+
{
144+
file: p,
145+
}
146+
);
147+
})
148+
.on('unlinkDir', async p => {
149+
patternlab.graph.sync();
150+
patternlab.graph.upgradeVersion();
151+
await pluginMananger.raiseEvent(
152+
patternlab,
153+
events.PATTERNLAB_PATTERN_CHANGE,
154+
{
155+
file: p,
156+
}
157+
);
134158
});
135-
136159
patternlab.watchers[patternWatchPath] = patternWatcher;
137160
});
138161

packages/core/test/object_factory_tests.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ tap.test(
7979
path.sep +
8080
'colors.mustache'
8181
);
82-
test.equals(p.name, '00-atoms-00-global-00-colors');
82+
test.equals(p.name, '00-atoms-00-global-colors');
8383
test.equals(p.subdir, path.join('00-atoms', '00-global', '00-colors'));
8484
test.equals(p.fileName, 'colors');
8585
test.equals(p.fileExtension, '.mustache');
@@ -88,9 +88,9 @@ tap.test(
8888
test.equals(p.patternName, 'Colors');
8989
test.equals(
9090
p.getPatternLink(pl),
91-
'00-atoms-00-global-00-colors' +
91+
'00-atoms-00-global-colors' +
9292
path.sep +
93-
'00-atoms-00-global-00-colors.rendered.html'
93+
'00-atoms-00-global-colors.rendered.html'
9494
);
9595
test.equals(p.patternGroup, 'atoms');
9696
test.equals(p.patternSubGroup, 'global');
@@ -117,8 +117,8 @@ tap.test('test Pattern name for variants correctly initialzed', function(test) {
117117
d: 123,
118118
}
119119
);
120-
test.equals(p1.name, '00-atoms-00-global-00-colors-variant');
121-
test.equals(p2.name, '00-atoms-00-global-00-colors-variant-minus');
120+
test.equals(p1.name, '00-atoms-00-global-colors-variant');
121+
test.equals(p2.name, '00-atoms-00-global-colors-variant-minus');
122122
test.end();
123123
});
124124

@@ -153,10 +153,10 @@ tap.test('test Pattern with own-directory gets resetted as expected', function(
153153
test
154154
) {
155155
var p = new Pattern('00-atoms/00-button/button.mustache', { d: 123 }, pl);
156-
p.promoteFromFlatPatternToDirectory(pl);
156+
p.promoteFromDirectoryToFlatPattern(pl);
157157

158158
test.equals(p.relPath, path.join('00-atoms', '00-button', 'button.mustache'));
159-
test.equals(p.name, '00-atoms-00-button-button');
159+
test.equals(p.name, '00-atoms-00-button');
160160
test.equals(p.subdir, path.join('00-atoms', '00-button'));
161161
test.equals(p.fileName, 'button');
162162
test.equals(p.fileExtension, '.mustache');
@@ -165,13 +165,10 @@ tap.test('test Pattern with own-directory gets resetted as expected', function(
165165
test.equals(p.patternName, 'Button');
166166
test.equals(
167167
p.getPatternLink(pl),
168-
path.join(
169-
'00-atoms-00-button-button',
170-
'00-atoms-00-button-button.rendered.html'
171-
)
168+
path.join('00-atoms-00-button', '00-atoms-00-button.rendered.html')
172169
);
173170
test.equals(p.patternGroup, 'atoms');
174-
test.equals(p.flatPatternPath, '00-atoms-00-button');
171+
test.equals(p.flatPatternPath, '00-atoms');
175172
test.equals(p.patternPartial, 'atoms-button');
176173
test.equals(p.template, '');
177174
test.equals(p.lineage.length, 0);
@@ -255,7 +252,7 @@ tap.test(
255252
'00-atoms/00-global/00-colors-alt/colors-alt~variant.mustache',
256253
{ d: 123 }
257254
);
258-
test.equals(p.name, '00-atoms-00-global-00-colors-alt-variant');
255+
test.equals(p.name, '00-atoms-00-global-colors-alt-variant');
259256
test.equals(p.flatPatternPath, '00-atoms-00-global');
260257
test.equals(p.patternBaseName, 'colors-alt-variant');
261258

@@ -295,7 +292,7 @@ tap.test('test Patterns that are nested deeper without own directory', function(
295292
'00-atoms/00-global/00-random-folder/00-another-folder/00-colors-alt/colors-alt.mustache',
296293
{ d: 123 }
297294
);
298-
test.equals(p.name, '00-atoms-00-global-00-colors-alt');
295+
test.equals(p.name, '00-atoms-00-global-colors-alt');
299296
test.equals(p.flatPatternPath, '00-atoms-00-global');
300297

301298
var p = new Pattern(

packages/docs/src/docs/pattern-organization.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ The `deeplyNested` attribute is used to toggle the pattern building behavior and
5959

6060
- **deeplyNested not set or false** - Pattern won't be handled as a deeply nested pattern
6161
- **deeplyNested: true** - Pattern will be handled like mentioned under [Deeper Nesting](#heading-deeper-nesting)
62+
63+
To turn on this behavior globally, just add `"allPatternsAreDeeplyNested": true` to your `patternlab-config.json`.

0 commit comments

Comments
 (0)