From 64311a155f82ddd86806087ad165b9ed880118f3 Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Fri, 14 Sep 2018 10:03:44 -0500 Subject: [PATCH 1/4] fix(cli): remove copy-source-files closes #833 --- packages/cli/bin/cli-actions/build.js | 2 -- packages/cli/bin/copy-source-files.js | 27 --------------------------- 2 files changed, 29 deletions(-) delete mode 100644 packages/cli/bin/copy-source-files.js diff --git a/packages/cli/bin/cli-actions/build.js b/packages/cli/bin/cli-actions/build.js index d6cf99c51..c6a34434a 100644 --- a/packages/cli/bin/cli-actions/build.js +++ b/packages/cli/bin/cli-actions/build.js @@ -1,6 +1,5 @@ 'use strict'; const buildPatterns = require('../build'); -const copyFiles = require('../copy-source-files'); const resolveConfig = require('../resolve-config'); const { error, info, wrapAsync } = require('../utils'); @@ -8,7 +7,6 @@ const build = options => wrapAsync(function*() { try { const config = yield resolveConfig(options.parent.config); - yield copyFiles(config.paths); yield buildPatterns(config, options); info(`build: Yay, your Pattern Lab project was successfully built ☺`); } catch (err) { diff --git a/packages/cli/bin/copy-source-files.js b/packages/cli/bin/copy-source-files.js deleted file mode 100644 index 509e17862..000000000 --- a/packages/cli/bin/copy-source-files.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; -const copy = require('./utils').copyWithPattern; -const debug = require('./utils').debug; -const wrapAsync = require('./utils').wrapAsync; - -/** - * @func copyFilesFromSourceToPublic - * @desc Copies files from the source path to the public path. - * @param {object} paths - The passed Pattern Lab config paths member. - * @return {Array} - */ -const copyFilesFromSourceToPublic = paths => - wrapAsync(function*() { - // Copy files over - const copiedFiles = [ - copy(paths.source.styleguide, '*', paths.public.root), - copy(paths.source.js, '**/*.js', paths.public.js), - copy(paths.source.css, '*.css', paths.public.css), - copy(paths.source.images, '*', paths.public.images), - copy(paths.source.fonts, '*', paths.public.fonts), - copy(paths.source.root, 'favicon.ico', paths.public.root), - ]; - debug(`build: Your files were copied over to ${paths.public.root}`); - return yield Promise.all(copiedFiles); - }); - -module.exports = copyFilesFromSourceToPublic; From 663d8e185efd951ae67a37e3ec97f76d6cec0d5e Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Fri, 14 Sep 2018 10:22:43 -0500 Subject: [PATCH 2/4] fix(cli): do not call build before serve serve calls build. with both of these running, they both setup watches and conflict with each other fixes #917 --- packages/cli/bin/cli-actions/serve.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/cli/bin/cli-actions/serve.js b/packages/cli/bin/cli-actions/serve.js index 2ee267194..fd1785d12 100644 --- a/packages/cli/bin/cli-actions/serve.js +++ b/packages/cli/bin/cli-actions/serve.js @@ -1,13 +1,12 @@ 'use strict'; const resolveConfig = require('../resolve-config'); -const build = require('./build'); const servePatterns = require('../serve'); const wrapAsync = require('../utils').wrapAsync; const serve = options => wrapAsync(function*() { const config = yield resolveConfig(options.parent.config); - yield build(options); + servePatterns(config, options); servePatterns(config, options.watch); }); From 8bf186b8e2ea2ea5ddcd2d6242b670275b65567f Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Fri, 14 Sep 2018 10:23:36 -0500 Subject: [PATCH 3/4] fix(cli): pass watch options cleanly to core --- packages/cli/bin/cli-actions/serve.js | 1 - packages/cli/bin/patternlab.js | 3 ++- packages/cli/bin/serve.js | 5 +++-- packages/core/src/index.js | 5 ++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/cli/bin/cli-actions/serve.js b/packages/cli/bin/cli-actions/serve.js index fd1785d12..6e2cc8fd2 100644 --- a/packages/cli/bin/cli-actions/serve.js +++ b/packages/cli/bin/cli-actions/serve.js @@ -7,7 +7,6 @@ const serve = options => wrapAsync(function*() { const config = yield resolveConfig(options.parent.config); servePatterns(config, options); - servePatterns(config, options.watch); }); module.exports = serve; diff --git a/packages/cli/bin/patternlab.js b/packages/cli/bin/patternlab.js index 8800dd2fd..0e7eeed22 100755 --- a/packages/cli/bin/patternlab.js +++ b/packages/cli/bin/patternlab.js @@ -57,6 +57,7 @@ cli .alias('compile') .description('Build Pattern Lab. Optionally (re-)build only the patterns') .option('-p, --patterns-only', 'Whether to only build patterns') + .option('--no-watch', 'Start watching for changes') .action(build); /** @@ -130,7 +131,7 @@ cli .command('serve') .alias('browse') .description('Starts a server to inspect files in browser') - .option('-w, --watch', 'Start watching for changes') + .option('--no-watch', 'Start watching for changes') .action(serve); // Show additional help diff --git a/packages/cli/bin/serve.js b/packages/cli/bin/serve.js index e473a4390..a7502b65f 100644 --- a/packages/cli/bin/serve.js +++ b/packages/cli/bin/serve.js @@ -9,8 +9,9 @@ const { error, info } = require('./utils'); * @func serve * @desc Start a browser-sync server in the Pattern Lab public dir * @param {object} config - The passed Pattern Lab config + * @param {object} options - The passed options at invocation time */ -function serve(config) { +function serve(config, options) { if (!isValidConfig) { throw new TypeError( 'serve: Expects config not to be empty and of type object.' @@ -37,7 +38,7 @@ function serve(config) { try { info(`serve: Serving your files …`); const pl = patternlab(config); - pl.server.serve({}); + pl.server.serve(options); } catch (err) { error(err); } diff --git a/packages/core/src/index.js b/packages/core/src/index.js index eb20f4af0..f79c1ba36 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -266,13 +266,12 @@ const patternlab_module = function(config) { * @param {object} options an object used to control build behavior * @param {bool} options.cleanPublic whether or not to delete the configured output location (usually `public/`) before build * @param {object} options.data additional data to be merged with global data prior to build - * @param {bool} options.watch **ALWAYS OVERRIDDEN to `true`** whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild + * @param {bool} [true] options.watch whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild * @returns {Promise} a promise fulfilled when build is complete */ serve: options => { - const _options = Object.assign({}, options, { watch: true }); return _api - .build(_options) + .build(options) .then(() => server.serve()) .catch(e => logger.error(`error inside core index.js server serve: ${e}`) From 830c568dae28e743917a9d19860a5ec13641c8d8 Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Fri, 14 Sep 2018 10:30:28 -0500 Subject: [PATCH 4/4] fix(docs): regenerate API documentation --- packages/core/docs/README.md | 34 +++++++++++++++++----------------- packages/core/docs/events.md | 2 +- packages/core/src/index.js | 18 +++++++++--------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/core/docs/README.md b/packages/core/docs/README.md index 9eaf02714..7317083f6 100644 --- a/packages/core/docs/README.md +++ b/packages/core/docs/README.md @@ -63,12 +63,12 @@ Builds patterns, copies assets, and constructs user interface **Emits**: event:PATTERNLAB_BUILD_START, event:PATTERNLAB_BUILD_END **See**: [all events](./events.md) -| Param | Type | Description | -| --- | --- | --- | -| options | object | an object used to control build behavior | -| options.cleanPublic | bool | whether or not to delete the configured output location (usually `public/`) before build | -| options.data | object | additional data to be merged with global data prior to build | -| options.watch | bool | whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild | +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| options | object | | an object used to control build behavior | +| [options.cleanPublic] | bool | true | whether or not to delete the configured output location (usually `public/`) before build | +| [options.data] | object | {} | additional data to be merged with global data prior to build | +| [options.watch] | bool | true | whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild | @@ -122,11 +122,11 @@ Builds patterns only, leaving existing user interface files intact **Kind**: instance property of [patternlab](#patternlab) **Returns**: Promise - a promise fulfilled when build is complete -| Param | Type | Description | -| --- | --- | --- | -| options | object | an object used to control build behavior | -| options.cleanPublic | bool | whether or not to delete the configured output location (usually `public/`) before build | -| options.data | object | additional data to be merged with global data prior to build | +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| [options.cleanPublic] | bool | true | whether or not to delete the configured output location (usually `public/`) before build | +| [options.data] | object | {} | additional data to be merged with global data prior to build | +| [options.watch] | bool | true | whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild | @@ -162,12 +162,12 @@ Build patterns, copies assets, and constructs user interface. Watches configured **Kind**: static method of [server](#patternlab.server) **Returns**: Promise - a promise fulfilled when build is complete -| Param | Type | Description | -| --- | --- | --- | -| options | object | an object used to control build behavior | -| options.cleanPublic | bool | whether or not to delete the configured output location (usually `public/`) before build | -| options.data | object | additional data to be merged with global data prior to build | -| options.watch | bool | **ALWAYS OVERRIDDEN to `true`** whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild | +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| options | object | | an object used to control build behavior | +| [options.cleanPublic] | bool | true | whether or not to delete the configured output location (usually `public/`) before build | +| [options.data] | object | {} | additional data to be merged with global data prior to build | +| [options.watch] | bool | true | whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild | diff --git a/packages/core/docs/events.md b/packages/core/docs/events.md index 6b01e90d7..2df8191d1 100644 --- a/packages/core/docs/events.md +++ b/packages/core/docs/events.md @@ -5,7 +5,7 @@ Pattern Lab emits numerous events during the [build](../docs/) process. Some uses of events: * Core uses `patternlab-pattern-change` events when watching for changes in order to trigger another build -* Plugins such as [plugin-node-tab](https://github.com/pattern-lab/plugin-node-tab) can use an event like `patternlab-pattern-write-end` to define additional code tabs to the pattern viewer / modal +* Plugins such as [plugin-tab](https://github.com/pattern-lab/patternlab-node/tree/master/packages/plugin-tab) can use an event like `patternlab-pattern-write-end` to define additional code tabs to the pattern viewer / modal Learn more about [Creating Plugins](https://github.com/pattern-lab/patternlab-node/wiki/Creating-Plugins). diff --git a/packages/core/src/index.js b/packages/core/src/index.js index f79c1ba36..653a9f731 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -84,9 +84,9 @@ const patternlab_module = function(config) { * @name build * @instance * @param {object} options an object used to control build behavior - * @param {bool} options.cleanPublic whether or not to delete the configured output location (usually `public/`) before build - * @param {object} options.data additional data to be merged with global data prior to build - * @param {bool} options.watch whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild + * @param {bool} [options.cleanPublic=true] whether or not to delete the configured output location (usually `public/`) before build + * @param {object} [options.data={}] additional data to be merged with global data prior to build + * @param {bool} [options.watch=true] whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild * @emits PATTERNLAB_BUILD_START * @emits PATTERNLAB_BUILD_END * @see {@link ./events.md|all events} @@ -231,9 +231,9 @@ const patternlab_module = function(config) { * @memberof patternlab * @name patternsonly * @instance - * @param {object} options an object used to control build behavior - * @param {bool} options.cleanPublic whether or not to delete the configured output location (usually `public/`) before build - * @param {object} options.data additional data to be merged with global data prior to build + * @param {bool} [options.cleanPublic=true] whether or not to delete the configured output location (usually `public/`) before build + * @param {object} [options.data={}] additional data to be merged with global data prior to build + * @param {bool} [options.watch=true] whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild * @returns {Promise} a promise fulfilled when build is complete */ patternsonly: function(options) { @@ -264,9 +264,9 @@ const patternlab_module = function(config) { * @method serve * @memberof patternlab.server * @param {object} options an object used to control build behavior - * @param {bool} options.cleanPublic whether or not to delete the configured output location (usually `public/`) before build - * @param {object} options.data additional data to be merged with global data prior to build - * @param {bool} [true] options.watch whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild + * @param {bool} [options.cleanPublic=true] whether or not to delete the configured output location (usually `public/`) before build + * @param {object} [options.data={}] additional data to be merged with global data prior to build + * @param {bool} [options.watch=true] whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild * @returns {Promise} a promise fulfilled when build is complete */ serve: options => {