Skip to content

Commit 0368ff0

Browse files
Merge branch 'dev' into fix-1019
2 parents ad3c130 + 7763bed commit 0368ff0

File tree

10 files changed

+132
-62
lines changed

10 files changed

+132
-62
lines changed

CUTTING_A_RELEASE.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# How To Cut a Pattern Lab Release
2+
3+
We use a handful of tools to help automate and simplify the process of cutting a new Pattern Lab release. The most important ones being [Lerna](https://github.com/lerna/lerna) and [Auto](https://intuit.github.io/auto/).
4+
5+
## Release Prep
6+
7+
1. Make sure any/all the code ready to get released is merged down to the `dev` branch and all CI checks, etc are passing as expected
8+
9+
2. Git checkout the `dev` branch locally and make sure:
10+
- You've run `yarn` to install the latest dependencies
11+
- You don't have any local changes pending
12+
13+
```
14+
git checkout dev
15+
git pull
16+
yarn
17+
git status # confirm no pending changes
18+
```
19+
20+
3. Before running the publish command, I also like to run the `build` command to be extra sure everything compiles fine locally (ex. Node.js version matches with the version of Sass that's installed, gotchas like that)
21+
22+
```
23+
yarn build
24+
```
25+
26+
4. You'll also want to make sure you have a `.env` file in your PL Node repo root (and create one if you don't)
27+
28+
You can grab the NPM + Github tokens needed here by heading to https://github.com/settings/tokens/new (grant repo access) and https://www.npmjs.com/settings/NPM_USER/tokens
29+
30+
```
31+
## .env
32+
export GH_TOKEN=PASTE_GITHUB_TOKEN_HERE
33+
export NPM_TOKEN=PASTE_NPM_TOKEN_HERE
34+
```
35+
36+
I personally like to use zsh's `env` plugin (already installed with Oh My ZSH) which has instructions for enabling here https://github.com/johnhamelink/env-zsh
37+
38+
> Pro tip: you can quickly check to see if your env variable tokens are available for these CLI commands by running `npx auto release --dry-run` which will throw an error if the tokens above can't be found!
39+
40+
5. Finally you'll also want to confirm that you're logged into your NPM account with access to publish to the Pattern Lab NPM org by running `npm login` and following the prompts.
41+
42+
## Cutting The Release
43+
44+
6. Run the `publish` command
45+
46+
Ok - with all that prep out of the way, the actual release process is pretty quick and should be super straightforward.
47+
48+
Simply run the `yarn run publish` command and include the type of SEMVER release you want to cut.
49+
50+
So for example:
51+
52+
```
53+
yarn run publish minor
54+
55+
## alternatively you can include the exact version you want to publish
56+
yarn run publish v5.14.0
57+
```
58+
59+
Lerna should prompt you with a confirmation that the version about to get released matches up with what you expect ^
60+
61+
7. Manually (re)run the `auto release` command?
62+
63+
Ok, if everything built and published successfully, this final step may or may not be required...
64+
65+
Normally the `auto release` command should run automatically after Lerna finishes publishing to NPM. This command will create the Github release associated with the latest Git tag, add any relevant release notes, and comment on related PRs, however the last couple of releases required this last step to get re-run manually.
66+
67+
Note that you'll need to replace the `from` and `use-version` version numbers to match the last previous Git tag and this next release getting cut.
68+
69+
```
70+
npx auto release --from v5.11.1 --use-version v5.12.0
71+
```
72+
73+
8. Confirm the [Github release](https://github.com/pattern-lab/patternlab-node/releases) was added and manually tweak any release notes as needed.

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)