Skip to content

Commit 52238dc

Browse files
Merge pull request #641 from pattern-lab/dev
Pattern Lab Node Core 2.9.0
2 parents 4693676 + 6e10b68 commit 52238dc

11 files changed

+120
-49
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ source/css/style.css.map
1010
public
1111
!test/patterns/public/.gitkeep
1212
!test/patterns/testDependencyGraph.json
13+
.nyc_output/

README.md

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,98 @@
1+
![Pattern Lab Logo](patternlab.svg)
2+
13
[![Build Status](https://travis-ci.org/pattern-lab/patternlab-node.svg?branch=master)](https://travis-ci.org/pattern-lab/patternlab-node) ![current release](https://img.shields.io/github/release/pattern-lab/patternlab-node.svg) ![license](https://img.shields.io/github/license/pattern-lab/patternlab-node.svg) [![Join the chat at Gitter](https://badges.gitter.im/pattern-lab/node.svg)](https://gitter.im/pattern-lab/node)
24

35
# Pattern Lab Node Core
46

5-
This repository contains the core functionality for Pattern Lab Node. Pattern Lab Core is designed to be included as a dependency within [Node Editions](https://github.com/pattern-lab?utf8=%E2%9C%93&query=edition-node).
6-
If this looks **REALLY DIFFERENT** from what you expected, check out the [ChangeLog](https://github.com/pattern-lab/patternlab-node/wiki/ChangeLog).
7+
This repository contains the core functionality for Pattern Lab Node. Pattern Lab helps you and your team build thoughtful, pattern-driven user interfaces using atomic design principles.
8+
9+
[Online Demo of Pattern Lab Output](http://demo.patternlab.io/)
10+
11+
## Installation
12+
13+
Pattern Lab Node Core is designed to be consumed, and by default is included as a dependency within two example [Node Editions](https://github.com/pattern-lab?utf8=%E2%9C%93&query=edition-node).
14+
715

816
* [Pattern Lab/Node: Gulp Edition](https://github.com/pattern-lab/edition-node-gulp) contains info how to get started within a Gulp task running environment.
917
* [Pattern Lab/Node: Grunt Edition](https://github.com/pattern-lab/edition-node-grunt) contains info how to get started within a Grunt task running environment.
1018

11-
## Core Team
19+
![Pattern Lab Ecosystem](http://patternlab.io/assets/pattern-lab-2-image_18-large-opt.png)
1220

13-
* [@bmuenzenmeyer](https://github.com/bmuenzenmeyer) - Lead Maintainer
14-
* [@geoffp](https://github.com/geoffp) - Core Contributor
15-
* [@raphaelokon](https://github.com/raphaelokon) - CLI Contributor
16-
* [@tburny](https://github.com/tburny) - Core Contributor
21+
Core, and Editions, are part of the [Pattern Lab Ecosystem](http://patternlab.io/docs/advanced-ecosystem-overview.html). With this architecture, we encourage people to write and maintain their own editions.
22+
23+
## Usage
24+
25+
``` javascript
26+
const config = require('./patternlab-config.json');
27+
const patternlab = require('patternlab-node')(config);
28+
patternlab.build(doneCallBack, boolCleanOutputDir);
29+
```
30+
31+
* Read more about configuration via `patternlab-config.json`: https://github.com/pattern-lab/patternlab-node/wiki/Configuration
32+
* The rest of the [api / command line interface](https://github.com/pattern-lab/patternlab-node/wiki/Command-Line-Interface) is documented in the wiki, and already implemented for you within [Node Editions](https://github.com/pattern-lab?utf8=%E2%9C%93&query=edition-node).
33+
A [full-featured command line interface](https://github.com/pattern-lab/patternlab-node-cli) is in the works, courtesy of [@raphaelokon](https://github.com/raphaelokon).
34+
35+
36+
## Development Installation / Workflow
37+
38+
If you are interested in [contributing to Pattern Lab](https://github.com/pattern-lab/patternlab-node/blob/master/.github/CONTRIBUTING.md), it's suggested to install an Edition of your choice and then run a local copy of this repository via [`npm link`](https://docs.npmjs.com/cli/link).
39+
40+
``` bash
41+
mkdir /patternlab-node
42+
cd /patternlab-node
43+
git clone https://github.com/pattern-lab/patternlab-node.git
44+
npm install
45+
npm link
46+
cd location/of/edition
47+
npm link patternlab-node
48+
```
49+
50+
The above is a bit verbose, but illustrates:
51+
52+
1. how to clone this repository to an arbitrary location
53+
2. install all dependencies (run `npm install --dev` if your NODE_ENV is production for some reason)
54+
3. setup the `npm link` to your local copy
55+
4. use the local copy of patternlab-node in your edition
56+
57+
> Make sure to change to whichever branch you intend to hack on or test within your cloned repository, such as `dev` or `bugfix/fixes-broken-unittest`
1758
1859
## Upgrading
1960

2061
If you find yourself here and are looking to upgrade, check out how to upgrade from version to version of Pattern Lab Node here: [https://github.com/pattern-lab/patternlab-node/wiki/Upgrading](https://github.com/pattern-lab/patternlab-node/wiki/Upgrading)
2162

22-
## Command Line Interface
23-
24-
The rudimentary [command line interface](https://github.com/pattern-lab/patternlab-node/wiki/Command-Line-Interface) is documented in the wiki, and already implemented for you within [Node Editions](https://github.com/pattern-lab?utf8=%E2%9C%93&query=edition-node).
25-
A [full-featured command line interface](https://github.com/pattern-lab/patternlab-node-cli) is in the works, courtesy of [@raphaelokon](https://github.com/raphaelokon).
63+
View the [ChangeLog](https://github.com/pattern-lab/patternlab-node/wiki/ChangeLog) for the latest Pattern Lab Node updates.
2664

2765
## Contributing
2866

2967
If you'd like to contribute to Pattern Lab Node, please do so! There is always a lot of ground to cover and something for your wheelhouse.
3068

31-
No pull request is too small. Check out any [up for grabs issues](https://github.com/pattern-lab/patternlab-node/labels/help%20wanted%20%2F%20up%20for%20grabs) as a good way to get your feet wet, or add some more unit tests.
69+
Please read the guidelines: https://github.com/pattern-lab/patternlab-node/blob/master/.github/CONTRIBUTING.md
3270

33-
## Guidelines
34-
1. Please keep your pull requests concise and limited to **ONE** substantive change at a time. This makes reviewing and testing so much easier.
35-
2. _ALWAYS_ submit pull requests against the [dev branch](https://github.com/pattern-lab/patternlab-node/tree/dev). If this does not occur, I will first, try to redirect you gently, second, port over your contribution manually if time allows, and/or third, close your pull request. If you have a major feature to stabilize over time, talk to @bmuenzenmeyer about making a dedicated `feature-branch`
36-
3. If you can, add some unit tests using the existing patterns in the `./test` directory
37-
4. To help hack on core from an edition, read [this wiki page](https://github.com/pattern-lab/patternlab-node/wiki/Running-an-Edition-Against-Local-Core)
3871

39-
## Coding style
40-
Two files combine within the project to define and maintain our coding style.
72+
## Core Team
4173

42-
* The `.editorconfig` controls spaces / tabs within supported editors. Check out their [site](http://editorconfig.org/).
43-
* The `.eslintrc` defines our javascript standards. Some editors will evaluate this real-time - otherwise it's run using `grunt|gulp build`
74+
* [@bmuenzenmeyer](https://github.com/bmuenzenmeyer) - Lead Maintainer
75+
* [@geoffp](https://github.com/geoffp) - Core Contributor
76+
* [@raphaelokon](https://github.com/raphaelokon) - CLI Contributor
77+
* [@tburny](https://github.com/tburny) - Core Contributor
4478

45-
## Gitter
79+
## Community
4680

4781
The Pattern Lab Node team uses [our gitter.im channel, pattern-lab/node](https://gitter.im/pattern-lab/node) to keep in sync, share updates, and talk shop. Please stop by to say hello or as a first place to turn if stuck. Other channels in the Pattern Lab organization can be found on gitter too.
82+
83+
There is also a dedicated Pattern Lab channel on the [design system slack](designsystems.herokuapp.com) run by [@jina](https://twitter.com/jina).
84+
85+
Ask or answer Pattern Lab questions on Stack Overflow: http://stackoverflow.com/questions/tagged/patternlab.io
86+
87+
## Support Pattern Lab Node
88+
89+
Pattern Lab Node is on [Patreon account](https://www.patreon.com/patternlab) to allow users and organizations to directly support continued work on the Pattern Lab Node project.
90+
91+
I (Brian talking) need help and support to make Pattern Lab Node a sustained success. I devote a lot of free time and would-be sleep to make the project what it is, but nothing compares to hearing back from users. It means the world to me when people find value in Pattern Lab Node. I am ridiculously humbled to hear and see what you all build with it.
92+
93+
If you find yourself here and balk and the idea of supporting open source software monetarily - I understand. Carry on, but please do share what you build - we all learn more together.
94+
- [Pattern Lab on Patreon](https://www.patreon.com/patternlab)
95+
96+
## License
97+
98+
[MIT](https://github.com/pattern-lab/patternlab-node/blob/master/LICENSE)

core/lib/annotation_exporter.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
var path = require('path'),
44
glob = require('glob'),
55
fs = require('fs-extra'),
6-
JSON5 = require('json5'),
76
_ = require('lodash'),
87
mp = require('./markdown_parser');
98

@@ -30,7 +29,7 @@ var annotations_exporter = function (pl) {
3029
oldAnnotations = oldAnnotations.replace('};', '}');
3130

3231
try {
33-
var oldAnnotationsJSON = JSON5.parse(oldAnnotations);
32+
var oldAnnotationsJSON = JSON.parse(oldAnnotations);
3433
} catch (ex) {
3534
console.log('There was an error parsing JSON for ' + paths.source.annotations + 'annotations.js');
3635
console.log(ex);

core/lib/json_copy.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
3+
const plutils = require('./utilities');
4+
const json_copy = (data, callee) => {
5+
try {
6+
return JSON.parse(JSON.stringify(data));
7+
} catch (e) {
8+
//this is unlikely to be hit due to the passed in data already being loaded using JSON parsers
9+
plutils.error(`JSON provided by ${callee} is invalid and cannot be copied`);
10+
return {};
11+
}
12+
};
13+
14+
module.exports = json_copy;

core/lib/list_item_hunter.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
var list_item_hunter = function () {
44

55
var extend = require('util')._extend,
6-
JSON5 = require('json5'),
76
pa = require('./pattern_assembler'),
87
smh = require('./style_modifier_hunter'),
98
plutils = require('./utilities'),
9+
jsonCopy = require('./json_copy'),
1010
Pattern = require('./object_factory').Pattern;
1111

1212
var pattern_assembler = new pa(),
@@ -42,7 +42,7 @@ var list_item_hunter = function () {
4242
//check for a local listitems.json file
4343
var listData;
4444
try {
45-
listData = JSON5.parse(JSON5.stringify(patternlab.listitems));
45+
listData = jsonCopy(patternlab.listitems, 'config.paths.source.data listitems');
4646
} catch (err) {
4747
console.log('There was an error parsing JSON for ' + pattern.relPath);
4848
console.log(err);
@@ -62,8 +62,8 @@ var list_item_hunter = function () {
6262
var globalData;
6363
var localData;
6464
try {
65-
globalData = JSON5.parse(JSON5.stringify(patternlab.data));
66-
localData = JSON5.parse(JSON5.stringify(pattern.jsonFileData));
65+
globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
66+
localData = jsonCopy(pattern.jsonFileData, `${pattern.patternPartial} data`);
6767
} catch (err) {
6868
console.log('There was an error parsing JSON for ' + pattern.relPath);
6969
console.log(err);
@@ -87,7 +87,8 @@ var list_item_hunter = function () {
8787
//create a copy of the partial so as to not pollute it after the get_pattern_by_key call.
8888
var cleanPartialPattern;
8989
try {
90-
cleanPartialPattern = JSON5.parse(JSON5.stringify(partialPattern));
90+
cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));
91+
cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partialName}`);
9192
} catch (err) {
9293
console.log('There was an error parsing JSON for ' + pattern.relPath);
9394
console.log(err);

core/lib/parameter_hunter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
var parameter_hunter = function () {
44

55
var extend = require('util')._extend,
6-
JSON5 = require('json5'),
76
pa = require('./pattern_assembler'),
87
smh = require('./style_modifier_hunter'),
98
plutils = require('./utilities'),
109
style_modifier_hunter = new smh(),
10+
jsonCopy = require('./json_copy'),
1111
pattern_assembler = new pa();
1212

1313
/**
@@ -19,7 +19,7 @@ var parameter_hunter = function () {
1919
* The steps on a high-level are as follows:
2020
* * Further escape all escaped quotes and colons. Use the string
2121
* representation of their unicodes for this. This has the added bonus
22-
* of being interpreted correctly by JSON5.parse() without further
22+
* of being interpreted correctly by JSON.parse() without further
2323
* modification. This will be useful later in the function.
2424
* * Once escaped quotes are out of the way, we know the remaining quotes
2525
* are either key/value wrappers or wrapped within those wrappers. We know
@@ -260,9 +260,9 @@ var parameter_hunter = function () {
260260
var localData = {};
261261

262262
try {
263-
paramData = JSON5.parse(paramStringWellFormed);
264-
globalData = JSON5.parse(JSON5.stringify(patternlab.data));
265-
localData = JSON5.parse(JSON5.stringify(pattern.jsonFileData || {}));
263+
paramData = JSON.parse(paramStringWellFormed);
264+
globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
265+
localData = jsonCopy(pattern.jsonFileData || {}, `pattern ${pattern.patternPartial} data`);
266266
} catch (err) {
267267
console.log('There was an error parsing JSON for ' + pattern.relPath);
268268
console.log(err);

core/lib/pattern_assembler.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ var path = require('path'),
1313
lih = require('./list_item_hunter'),
1414
smh = require('./style_modifier_hunter'),
1515
ph = require('./parameter_hunter'),
16-
ch = require('./changes_hunter'),
17-
JSON5 = require('json5');
16+
jsonCopy = require('./json_copy'),
17+
ch = require('./changes_hunter');
1818

1919
const markdown_parser = new mp();
2020
const changes_hunter = new ch();
@@ -476,7 +476,7 @@ var pattern_assembler = function () {
476476
//complete assembly of extended template
477477
//create a copy of the partial so as to not pollute it after the getPartial call.
478478
var partialPattern = getPartial(partial, patternlab);
479-
var cleanPartialPattern = JSON5.parse(JSON5.stringify(partialPattern));
479+
var cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partial}`);
480480

481481
//if partial has style modifier data, replace the styleModifier value
482482
if (currentPattern.stylePartials && currentPattern.stylePartials.length > 0) {
@@ -494,7 +494,7 @@ var pattern_assembler = function () {
494494
linkRE = /(?:'|")(link\.[A-z0-9-_]+)(?:'|")/g;
495495

496496
//stringify the passed in object
497-
dataObjAsString = JSON5.stringify(obj);
497+
dataObjAsString = JSON.stringify(obj);
498498
if (!dataObjAsString) { return obj; }
499499

500500
//find matches
@@ -533,7 +533,7 @@ var pattern_assembler = function () {
533533

534534
var dataObj;
535535
try {
536-
dataObj = JSON5.parse(dataObjAsString);
536+
dataObj = JSON.parse(dataObjAsString);
537537
} catch (err) {
538538
console.log('There was an error parsing JSON for ' + key);
539539
console.log(err);

core/lib/patternlab.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v2.8.0 - 2017
2+
* patternlab-node - v2.9.0 - 2017
33
*
44
* Brian Muenzenmeyer, Geoff Pursell, Raphael Okon, tburny and the web community.
55
* Licensed under the MIT license.
@@ -21,6 +21,7 @@ var diveSync = require('diveSync'),
2121
fs = require('fs-extra'),
2222
packageInfo = require('../../package.json'),
2323
plutils = require('./utilities'),
24+
jsonCopy = require('./json_copy'),
2425
PatternGraph = require('./pattern_graph').PatternGraph;
2526

2627
//register our log events
@@ -146,8 +147,7 @@ inherits(PatternLabEventEmitter, EventEmitter);
146147
var patternlab_engine = function (config) {
147148
'use strict';
148149

149-
var JSON5 = require('json5'),
150-
pa = require('./pattern_assembler'),
150+
var pa = require('./pattern_assembler'),
151151
pe = require('./pattern_exporter'),
152152
lh = require('./lineage_hunter'),
153153
ui = require('./ui_builder'),
@@ -180,7 +180,7 @@ var patternlab_engine = function (config) {
180180
console.log(patternlab.package.version);
181181
}
182182

183-
function getSupportedTemplateExtensions(){
183+
function getSupportedTemplateExtensions() {
184184
return patternlab.engines.getSupportedFileExtensions();
185185
}
186186

@@ -370,7 +370,7 @@ var patternlab_engine = function (config) {
370370
//render the pattern, but first consolidate any data we may have
371371
var allData;
372372
try {
373-
allData = JSON5.parse(JSON5.stringify(patternlab.data));
373+
allData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
374374
} catch (err) {
375375
console.log('There was an error parsing JSON for ' + pattern.relPath);
376376
console.log(err);
@@ -421,7 +421,7 @@ var patternlab_engine = function (config) {
421421

422422
var allFooterData;
423423
try {
424-
allFooterData = JSON5.parse(JSON5.stringify(patternlab.data));
424+
allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data global data');
425425
} catch (err) {
426426
console.log('There was an error parsing JSON for ' + pattern.relPath);
427427
console.log(err);

core/lib/ui_builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

33
var path = require('path');
4-
var JSON5 = require('json5');
54
var fs = require('fs-extra');
65
var ae = require('./annotation_exporter');
76
var of = require('./object_factory');
@@ -10,6 +9,7 @@ var pattern_assembler = require('./pattern_assembler')();
109
var plutils = require('./utilities');
1110
var eol = require('os').EOL;
1211
var _ = require('lodash');
12+
var jsonCopy = require('./json_copy');
1313

1414
var ui_builder = function () {
1515

@@ -435,7 +435,7 @@ var ui_builder = function () {
435435

436436
var allFooterData;
437437
try {
438-
allFooterData = JSON5.parse(JSON5.stringify(patternlab.data));
438+
allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data plus patterns data');
439439
} catch (err) {
440440
console.log('There was an error parsing JSON for patternlab.data');
441441
console.log(err);

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "patternlab-node",
33
"description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).",
4-
"version": "2.8.0",
4+
"version": "2.9.0",
55
"main": "./core/lib/patternlab.js",
66
"dependencies": {
77
"chalk": "^1.1.3",
@@ -10,7 +10,6 @@
1010
"glob": "^7.0.0",
1111
"js-beautify": "^1.6.3",
1212
"js-yaml": "^3.6.1",
13-
"json5": "^0.5.0",
1413
"lodash": "~4.13.1",
1514
"markdown-it": "^6.0.1",
1615
"node-fetch": "^1.6.0",

0 commit comments

Comments
 (0)