diff --git a/.gitignore b/.gitignore index e5a709278..d1ddc139e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ source/css/style.css.map public !test/patterns/public/.gitkeep !test/patterns/testDependencyGraph.json +.nyc_output/ diff --git a/README.md b/README.md index 58bd30c02..6517e52f3 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,98 @@ +![Pattern Lab Logo](patternlab.svg) + [![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) # Pattern Lab Node Core -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). -If this looks **REALLY DIFFERENT** from what you expected, check out the [ChangeLog](https://github.com/pattern-lab/patternlab-node/wiki/ChangeLog). +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. + +[Online Demo of Pattern Lab Output](http://demo.patternlab.io/) + +## Installation + +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). + * [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. * [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. -## Core Team +![Pattern Lab Ecosystem](http://patternlab.io/assets/pattern-lab-2-image_18-large-opt.png) -* [@bmuenzenmeyer](https://github.com/bmuenzenmeyer) - Lead Maintainer -* [@geoffp](https://github.com/geoffp) - Core Contributor -* [@raphaelokon](https://github.com/raphaelokon) - CLI Contributor -* [@tburny](https://github.com/tburny) - Core Contributor +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. + +## Usage + +``` javascript +const config = require('./patternlab-config.json'); +const patternlab = require('patternlab-node')(config); +patternlab.build(doneCallBack, boolCleanOutputDir); +``` + +* Read more about configuration via `patternlab-config.json`: https://github.com/pattern-lab/patternlab-node/wiki/Configuration +* 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). +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). + + +## Development Installation / Workflow + +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). + +``` bash +mkdir /patternlab-node +cd /patternlab-node +git clone https://github.com/pattern-lab/patternlab-node.git +npm install +npm link +cd location/of/edition +npm link patternlab-node +``` + +The above is a bit verbose, but illustrates: + +1. how to clone this repository to an arbitrary location +2. install all dependencies (run `npm install --dev` if your NODE_ENV is production for some reason) +3. setup the `npm link` to your local copy +4. use the local copy of patternlab-node in your edition + +> 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` ## Upgrading 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) -## Command Line Interface - -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). -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). +View the [ChangeLog](https://github.com/pattern-lab/patternlab-node/wiki/ChangeLog) for the latest Pattern Lab Node updates. ## Contributing 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. -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. +Please read the guidelines: https://github.com/pattern-lab/patternlab-node/blob/master/.github/CONTRIBUTING.md -## Guidelines -1. Please keep your pull requests concise and limited to **ONE** substantive change at a time. This makes reviewing and testing so much easier. -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` -3. If you can, add some unit tests using the existing patterns in the `./test` directory -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) -## Coding style -Two files combine within the project to define and maintain our coding style. +## Core Team -* The `.editorconfig` controls spaces / tabs within supported editors. Check out their [site](http://editorconfig.org/). -* The `.eslintrc` defines our javascript standards. Some editors will evaluate this real-time - otherwise it's run using `grunt|gulp build` +* [@bmuenzenmeyer](https://github.com/bmuenzenmeyer) - Lead Maintainer +* [@geoffp](https://github.com/geoffp) - Core Contributor +* [@raphaelokon](https://github.com/raphaelokon) - CLI Contributor +* [@tburny](https://github.com/tburny) - Core Contributor -## Gitter +## Community 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. + +There is also a dedicated Pattern Lab channel on the [design system slack](designsystems.herokuapp.com) run by [@jina](https://twitter.com/jina). + +Ask or answer Pattern Lab questions on Stack Overflow: http://stackoverflow.com/questions/tagged/patternlab.io + +## Support Pattern Lab Node + +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. + +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. + +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. +- [Pattern Lab on Patreon](https://www.patreon.com/patternlab) + +## License + +[MIT](https://github.com/pattern-lab/patternlab-node/blob/master/LICENSE) diff --git a/core/lib/annotation_exporter.js b/core/lib/annotation_exporter.js index d12054145..bd9cb72e8 100644 --- a/core/lib/annotation_exporter.js +++ b/core/lib/annotation_exporter.js @@ -3,7 +3,6 @@ var path = require('path'), glob = require('glob'), fs = require('fs-extra'), - JSON5 = require('json5'), _ = require('lodash'), mp = require('./markdown_parser'); @@ -30,7 +29,7 @@ var annotations_exporter = function (pl) { oldAnnotations = oldAnnotations.replace('};', '}'); try { - var oldAnnotationsJSON = JSON5.parse(oldAnnotations); + var oldAnnotationsJSON = JSON.parse(oldAnnotations); } catch (ex) { console.log('There was an error parsing JSON for ' + paths.source.annotations + 'annotations.js'); console.log(ex); diff --git a/core/lib/json_copy.js b/core/lib/json_copy.js new file mode 100644 index 000000000..84c9e249d --- /dev/null +++ b/core/lib/json_copy.js @@ -0,0 +1,14 @@ +"use strict"; + +const plutils = require('./utilities'); +const json_copy = (data, callee) => { + try { + return JSON.parse(JSON.stringify(data)); + } catch (e) { + //this is unlikely to be hit due to the passed in data already being loaded using JSON parsers + plutils.error(`JSON provided by ${callee} is invalid and cannot be copied`); + return {}; + } +}; + +module.exports = json_copy; diff --git a/core/lib/list_item_hunter.js b/core/lib/list_item_hunter.js index be55f35c5..d04b6d0a7 100644 --- a/core/lib/list_item_hunter.js +++ b/core/lib/list_item_hunter.js @@ -3,10 +3,10 @@ var list_item_hunter = function () { var extend = require('util')._extend, - JSON5 = require('json5'), pa = require('./pattern_assembler'), smh = require('./style_modifier_hunter'), plutils = require('./utilities'), + jsonCopy = require('./json_copy'), Pattern = require('./object_factory').Pattern; var pattern_assembler = new pa(), @@ -42,7 +42,7 @@ var list_item_hunter = function () { //check for a local listitems.json file var listData; try { - listData = JSON5.parse(JSON5.stringify(patternlab.listitems)); + listData = jsonCopy(patternlab.listitems, 'config.paths.source.data listitems'); } catch (err) { console.log('There was an error parsing JSON for ' + pattern.relPath); console.log(err); @@ -62,8 +62,8 @@ var list_item_hunter = function () { var globalData; var localData; try { - globalData = JSON5.parse(JSON5.stringify(patternlab.data)); - localData = JSON5.parse(JSON5.stringify(pattern.jsonFileData)); + globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data'); + localData = jsonCopy(pattern.jsonFileData, `${pattern.patternPartial} data`); } catch (err) { console.log('There was an error parsing JSON for ' + pattern.relPath); console.log(err); @@ -87,7 +87,8 @@ var list_item_hunter = function () { //create a copy of the partial so as to not pollute it after the get_pattern_by_key call. var cleanPartialPattern; try { - cleanPartialPattern = JSON5.parse(JSON5.stringify(partialPattern)); + cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern)); + cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partialName}`); } catch (err) { console.log('There was an error parsing JSON for ' + pattern.relPath); console.log(err); diff --git a/core/lib/parameter_hunter.js b/core/lib/parameter_hunter.js index 6f2d50f1e..44f33adeb 100644 --- a/core/lib/parameter_hunter.js +++ b/core/lib/parameter_hunter.js @@ -3,11 +3,11 @@ var parameter_hunter = function () { var extend = require('util')._extend, - JSON5 = require('json5'), pa = require('./pattern_assembler'), smh = require('./style_modifier_hunter'), plutils = require('./utilities'), style_modifier_hunter = new smh(), + jsonCopy = require('./json_copy'), pattern_assembler = new pa(); /** @@ -19,7 +19,7 @@ var parameter_hunter = function () { * The steps on a high-level are as follows: * * Further escape all escaped quotes and colons. Use the string * representation of their unicodes for this. This has the added bonus - * of being interpreted correctly by JSON5.parse() without further + * of being interpreted correctly by JSON.parse() without further * modification. This will be useful later in the function. * * Once escaped quotes are out of the way, we know the remaining quotes * are either key/value wrappers or wrapped within those wrappers. We know @@ -260,9 +260,9 @@ var parameter_hunter = function () { var localData = {}; try { - paramData = JSON5.parse(paramStringWellFormed); - globalData = JSON5.parse(JSON5.stringify(patternlab.data)); - localData = JSON5.parse(JSON5.stringify(pattern.jsonFileData || {})); + paramData = JSON.parse(paramStringWellFormed); + globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data'); + localData = jsonCopy(pattern.jsonFileData || {}, `pattern ${pattern.patternPartial} data`); } catch (err) { console.log('There was an error parsing JSON for ' + pattern.relPath); console.log(err); diff --git a/core/lib/pattern_assembler.js b/core/lib/pattern_assembler.js index b85867d88..dc76832a6 100644 --- a/core/lib/pattern_assembler.js +++ b/core/lib/pattern_assembler.js @@ -13,8 +13,8 @@ var path = require('path'), lih = require('./list_item_hunter'), smh = require('./style_modifier_hunter'), ph = require('./parameter_hunter'), - ch = require('./changes_hunter'), - JSON5 = require('json5'); + jsonCopy = require('./json_copy'), + ch = require('./changes_hunter'); const markdown_parser = new mp(); const changes_hunter = new ch(); @@ -476,7 +476,7 @@ var pattern_assembler = function () { //complete assembly of extended template //create a copy of the partial so as to not pollute it after the getPartial call. var partialPattern = getPartial(partial, patternlab); - var cleanPartialPattern = JSON5.parse(JSON5.stringify(partialPattern)); + var cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partial}`); //if partial has style modifier data, replace the styleModifier value if (currentPattern.stylePartials && currentPattern.stylePartials.length > 0) { @@ -494,7 +494,7 @@ var pattern_assembler = function () { linkRE = /(?:'|")(link\.[A-z0-9-_]+)(?:'|")/g; //stringify the passed in object - dataObjAsString = JSON5.stringify(obj); + dataObjAsString = JSON.stringify(obj); if (!dataObjAsString) { return obj; } //find matches @@ -533,7 +533,7 @@ var pattern_assembler = function () { var dataObj; try { - dataObj = JSON5.parse(dataObjAsString); + dataObj = JSON.parse(dataObjAsString); } catch (err) { console.log('There was an error parsing JSON for ' + key); console.log(err); diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index cfdc88c0c..92e6e447b 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v2.8.0 - 2017 + * patternlab-node - v2.9.0 - 2017 * * Brian Muenzenmeyer, Geoff Pursell, Raphael Okon, tburny and the web community. * Licensed under the MIT license. @@ -21,6 +21,7 @@ var diveSync = require('diveSync'), fs = require('fs-extra'), packageInfo = require('../../package.json'), plutils = require('./utilities'), + jsonCopy = require('./json_copy'), PatternGraph = require('./pattern_graph').PatternGraph; //register our log events @@ -146,8 +147,7 @@ inherits(PatternLabEventEmitter, EventEmitter); var patternlab_engine = function (config) { 'use strict'; - var JSON5 = require('json5'), - pa = require('./pattern_assembler'), + var pa = require('./pattern_assembler'), pe = require('./pattern_exporter'), lh = require('./lineage_hunter'), ui = require('./ui_builder'), @@ -180,7 +180,7 @@ var patternlab_engine = function (config) { console.log(patternlab.package.version); } - function getSupportedTemplateExtensions(){ + function getSupportedTemplateExtensions() { return patternlab.engines.getSupportedFileExtensions(); } @@ -370,7 +370,7 @@ var patternlab_engine = function (config) { //render the pattern, but first consolidate any data we may have var allData; try { - allData = JSON5.parse(JSON5.stringify(patternlab.data)); + allData = jsonCopy(patternlab.data, 'config.paths.source.data global data'); } catch (err) { console.log('There was an error parsing JSON for ' + pattern.relPath); console.log(err); @@ -421,7 +421,7 @@ var patternlab_engine = function (config) { var allFooterData; try { - allFooterData = JSON5.parse(JSON5.stringify(patternlab.data)); + allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data global data'); } catch (err) { console.log('There was an error parsing JSON for ' + pattern.relPath); console.log(err); diff --git a/core/lib/ui_builder.js b/core/lib/ui_builder.js index c62ea9193..21865a2dd 100644 --- a/core/lib/ui_builder.js +++ b/core/lib/ui_builder.js @@ -1,7 +1,6 @@ "use strict"; var path = require('path'); -var JSON5 = require('json5'); var fs = require('fs-extra'); var ae = require('./annotation_exporter'); var of = require('./object_factory'); @@ -10,6 +9,7 @@ var pattern_assembler = require('./pattern_assembler')(); var plutils = require('./utilities'); var eol = require('os').EOL; var _ = require('lodash'); +var jsonCopy = require('./json_copy'); var ui_builder = function () { @@ -435,7 +435,7 @@ var ui_builder = function () { var allFooterData; try { - allFooterData = JSON5.parse(JSON5.stringify(patternlab.data)); + allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data plus patterns data'); } catch (err) { console.log('There was an error parsing JSON for patternlab.data'); console.log(err); diff --git a/package.json b/package.json index 0f615b509..c4b5fb642 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "patternlab-node", "description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).", - "version": "2.8.0", + "version": "2.9.0", "main": "./core/lib/patternlab.js", "dependencies": { "chalk": "^1.1.3", @@ -10,7 +10,6 @@ "glob": "^7.0.0", "js-beautify": "^1.6.3", "js-yaml": "^3.6.1", - "json5": "^0.5.0", "lodash": "~4.13.1", "markdown-it": "^6.0.1", "node-fetch": "^1.6.0", diff --git a/patternlab.svg b/patternlab.svg new file mode 100644 index 000000000..b1980ba91 --- /dev/null +++ b/patternlab.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file