Skip to content

Commit 4ef3f08

Browse files
Merge pull request #859 from pattern-lab/watches-with-events
Watches with events
2 parents 662cd01 + 104d489 commit 4ef3f08

36 files changed

+1049
-849
lines changed

packages/cli/bin/archive.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,43 @@ const debug = require('./utils').debug;
1111
* @param {object} config - The passed Pattern Lab config.
1212
*/
1313
function exportPatterns(config) {
14-
if (!isValidConfig) {
15-
throw new TypeError(
16-
'export: Expects config not to be empty OR of type object if not empty.'
17-
);
18-
}
14+
if (!isValidConfig) {
15+
throw new TypeError(
16+
'export: Expects config not to be empty OR of type object if not empty.'
17+
);
18+
}
1919

20-
const archive = new Archiver('zip', {});
21-
const exportsPath = path.resolve(
22-
'./',
23-
config.patternExportDirectory,
24-
'patterns.zip'
25-
);
26-
const output = fs.createWriteStream(exportsPath);
20+
const archive = new Archiver('zip', {});
21+
const exportsPath = path.resolve(
22+
'./',
23+
config.patternExportDirectory,
24+
'patterns.zip'
25+
);
26+
const output = fs.createWriteStream(exportsPath);
2727

28-
output.on('close', () => {
29-
debug(
30-
`export: Exported patterns in ${exportsPath} - ${archive.pointer()} total bytes.`
31-
);
32-
});
28+
output.on('close', () => {
29+
debug(
30+
`export: Exported patterns in ${exportsPath} - ${archive.pointer()} total bytes.`
31+
);
32+
});
3333

34-
archive.on('error', function(err) {
35-
throw new TypeError(
36-
`export: An error occured during zipping the patterns: ${err}`
37-
);
38-
});
34+
archive.on('error', function(err) {
35+
throw new TypeError(
36+
`export: An error occured during zipping the patterns: ${err}`
37+
);
38+
});
3939

40-
archive.pipe(output);
40+
archive.pipe(output);
4141

42-
archive
43-
.glob(
44-
'?(_patterns|_data|_meta|_annotations)/**',
45-
{
46-
cwd: config.paths.source.root,
47-
},
48-
{}
49-
)
50-
.finalize();
42+
archive
43+
.glob(
44+
'?(_patterns|_data|_meta|_annotations)/**',
45+
{
46+
cwd: config.paths.source.root,
47+
},
48+
{}
49+
)
50+
.finalize();
5151
}
5252

5353
module.exports = exportPatterns;

packages/cli/bin/ask.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,37 @@ const ask = inquirer.prompt;
1313
* @param {boolean} options.force - Flag whether to force install in existing project directory. May overwrite stuff.
1414
*/
1515
const init = options =>
16-
wrapsAsync(function*() {
17-
/**
18-
* @property {string} project_root="./" - Path to the project root directory
19-
* @property {string|Symbol} edition - The name of the edition npm package or a Symbol for no install
20-
*/
21-
const editionAnswers = yield ask(editionSetup);
16+
wrapsAsync(function*() {
17+
/**
18+
* @property {string} project_root="./" - Path to the project root directory
19+
* @property {string|Symbol} edition - The name of the edition npm package or a Symbol for no install
20+
*/
21+
const editionAnswers = yield ask(editionSetup);
2222

23-
/**
24-
* @property {object|Symbol} starterkit - The name of a starterkit npm package or a Symbol for no install
25-
*/
26-
const starterkitAnswers = yield ask(starterkitSetup);
23+
/**
24+
* @property {object|Symbol} starterkit - The name of a starterkit npm package or a Symbol for no install
25+
*/
26+
const starterkitAnswers = yield ask(starterkitSetup);
2727

28-
/**
29-
* @property {boolean} confirm - A bool hold the confirmation status
30-
*/
31-
const confirmation = yield ask(confirmSetup);
28+
/**
29+
* @property {boolean} confirm - A bool hold the confirmation status
30+
*/
31+
const confirmation = yield ask(confirmSetup);
3232

33-
// IF we have no confirmation we start all over again.
34-
if (!confirmation.confirm) {
35-
return init(options);
36-
}
33+
// IF we have no confirmation we start all over again.
34+
if (!confirmation.confirm) {
35+
return init(options);
36+
}
3737

38-
return {
39-
// Destructure the answers
40-
projectDir: editionAnswers.project_root,
41-
edition: editionAnswers.edition !== false ? editionAnswers.edition : '',
42-
starterkit:
43-
starterkitAnswers.starterkit !== false
44-
? starterkitAnswers.starterkit
45-
: '',
46-
};
47-
});
38+
return {
39+
// Destructure the answers
40+
projectDir: editionAnswers.project_root,
41+
edition: editionAnswers.edition !== false ? editionAnswers.edition : '',
42+
starterkit:
43+
starterkitAnswers.starterkit !== false
44+
? starterkitAnswers.starterkit
45+
: '',
46+
};
47+
});
4848

4949
module.exports = init;

packages/cli/bin/build.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ const isValidConfig = require('./validate-config');
1010
* @param {object} options - Additional opts to specify build mode.
1111
*/
1212
function build(config, options) {
13-
if (!isValidConfig) {
14-
throw new TypeError(
15-
'build: Expects config not to be empty and of type object.'
16-
);
17-
}
13+
if (!isValidConfig) {
14+
throw new TypeError(
15+
'build: Expects config not to be empty and of type object.'
16+
);
17+
}
1818

19-
// Initiate Pattern Lab core with the config
20-
const patternLab = pl(config);
19+
// Initiate Pattern Lab core with the config
20+
const patternLab = pl(config);
2121

22-
/**
23-
* Check whether a flag was passed for build
24-
* 1. Build only patterns
25-
* 2. Normal build
26-
*/
27-
if (options && options.patternsOnly) {
28-
// 1
29-
debug(`build: Building only patterns now into ${config.paths.public.root}`);
30-
return patternLab.patternsonly(config.cleanPublic);
31-
} else {
32-
// 2
33-
debug(`build: Building your project now into ${config.paths.public.root}`);
34-
return patternLab.build(config.cleanPublic);
35-
}
22+
/**
23+
* Check whether a flag was passed for build
24+
* 1. Build only patterns
25+
* 2. Normal build
26+
*/
27+
if (options && options.patternsOnly) {
28+
// 1
29+
debug(`build: Building only patterns now into ${config.paths.public.root}`);
30+
return patternLab.patternsonly(config.cleanPublic);
31+
} else {
32+
// 2
33+
debug(`build: Building your project now into ${config.paths.public.root}`);
34+
return patternLab.build(config.cleanPublic);
35+
}
3636
}
3737

3838
module.exports = build;

packages/cli/bin/cli-actions/build.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const resolveConfig = require('../resolve-config');
55
const { error, info, wrapAsync } = require('../utils');
66

77
const build = options =>
8-
wrapAsync(function*() {
9-
try {
10-
const config = yield resolveConfig(options.parent.config);
11-
yield copyFiles(config.paths);
12-
yield buildPatterns(config, options);
13-
info(`build: Yay, your Pattern Lab project was successfully built ☺`);
14-
} catch (err) {
15-
error(err);
16-
}
17-
});
8+
wrapAsync(function*() {
9+
try {
10+
const config = yield resolveConfig(options.parent.config);
11+
yield copyFiles(config.paths);
12+
yield buildPatterns(config, options);
13+
info(`build: Yay, your Pattern Lab project was successfully built ☺`);
14+
} catch (err) {
15+
error(err);
16+
}
17+
});
1818

1919
module.exports = build;

packages/cli/bin/cli-actions/disable.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@ const writeJsonAsync = require('../utils').writeJsonAsync;
1111
* @param {object} options
1212
*/
1313
const enable = options =>
14-
wrapAsync(function*() {
15-
const { parent: { config: configPath }, plugins } = options;
16-
const config = yield resolveConfig(configPath);
14+
wrapAsync(function*() {
15+
const { parent: { config: configPath }, plugins } = options;
16+
const config = yield resolveConfig(configPath);
1717

18-
const spinner = ora(`⊙ patternlab → Disable …`).start();
18+
const spinner = ora(`⊙ patternlab → Disable …`).start();
1919

20-
if (plugins && Array.isArray(plugins)) {
21-
spinner.succeed(
22-
`⊙ patternlab → Disable following plugins: ${plugins.join(', ')}`
23-
);
24-
plugins.map(plugin => {
25-
if (_.has(config, `plugins[${plugin}]`)) {
26-
_.set(config, `plugins[${plugin}]['enabled']`, false);
27-
spinner.succeed(
28-
`⊙ patternlab → Disabled following plugin: ${plugin}`
29-
);
30-
} else {
31-
spinner.warn(`⊙ patternlab → Couldn't find plugin: ${plugin}`);
32-
}
33-
});
34-
}
35-
yield writeJsonAsync(options.parent.config, config);
36-
spinner.succeed(`⊙ patternlab → Updated config`);
37-
});
20+
if (plugins && Array.isArray(plugins)) {
21+
spinner.succeed(
22+
`⊙ patternlab → Disable following plugins: ${plugins.join(', ')}`
23+
);
24+
plugins.map(plugin => {
25+
if (_.has(config, `plugins[${plugin}]`)) {
26+
_.set(config, `plugins[${plugin}]['enabled']`, false);
27+
spinner.succeed(
28+
`⊙ patternlab → Disabled following plugin: ${plugin}`
29+
);
30+
} else {
31+
spinner.warn(`⊙ patternlab → Couldn't find plugin: ${plugin}`);
32+
}
33+
});
34+
}
35+
yield writeJsonAsync(options.parent.config, config);
36+
spinner.succeed(`⊙ patternlab → Updated config`);
37+
});
3838

3939
module.exports = enable;

packages/cli/bin/cli-actions/enable.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ const writeJsonAsync = require('../utils').writeJsonAsync;
1111
* @param {object} options
1212
*/
1313
const enable = options =>
14-
wrapAsync(function*() {
15-
const { parent: { config: configPath }, plugins } = options;
16-
const config = yield resolveConfig(configPath);
14+
wrapAsync(function*() {
15+
const { parent: { config: configPath }, plugins } = options;
16+
const config = yield resolveConfig(configPath);
1717

18-
const spinner = ora(`⊙ patternlab → Enable …`).start();
18+
const spinner = ora(`⊙ patternlab → Enable …`).start();
1919

20-
if (plugins && Array.isArray(plugins)) {
21-
spinner.succeed(
22-
`⊙ patternlab → Enable following plugins: ${plugins.join(', ')}`
23-
);
24-
plugins.map(plugin => {
25-
if (_.has(config, `plugins[${plugin}]`)) {
26-
_.set(config, `plugins[${plugin}]['enabled']`, true);
27-
spinner.succeed(`⊙ patternlab → Enabled following plugin: ${plugin}`);
28-
} else {
29-
spinner.warn(`⊙ patternlab → Couldn't find plugin: ${plugin}`);
30-
}
31-
});
32-
}
33-
yield writeJsonAsync(options.parent.config, config);
34-
spinner.succeed(`⊙ patternlab → Updated config`);
35-
});
20+
if (plugins && Array.isArray(plugins)) {
21+
spinner.succeed(
22+
`⊙ patternlab → Enable following plugins: ${plugins.join(', ')}`
23+
);
24+
plugins.map(plugin => {
25+
if (_.has(config, `plugins[${plugin}]`)) {
26+
_.set(config, `plugins[${plugin}]['enabled']`, true);
27+
spinner.succeed(`⊙ patternlab → Enabled following plugin: ${plugin}`);
28+
} else {
29+
spinner.warn(`⊙ patternlab → Couldn't find plugin: ${plugin}`);
30+
}
31+
});
32+
}
33+
yield writeJsonAsync(options.parent.config, config);
34+
spinner.succeed(`⊙ patternlab → Updated config`);
35+
});
3636

3737
module.exports = enable;

packages/cli/bin/cli-actions/export.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const resolveConfig = require('../resolve-config');
44
const wrapAsync = require('../utils').wrapAsync;
55

66
const _export = options =>
7-
wrapAsync(function*() {
8-
const config = yield resolveConfig(options.parent.config);
9-
archive(config);
10-
});
7+
wrapAsync(function*() {
8+
const config = yield resolveConfig(options.parent.config);
9+
archive(config);
10+
});
1111

1212
module.exports = _export;

packages/cli/bin/cli-actions/help.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22
module.exports = () => {
3-
/* eslint-disable */
4-
console.log(`
3+
/* eslint-disable */
4+
console.log(`
55
Examples:
66
$ patternlab init # Initialize a Pattern Lab project.');
77
$ patternlab <cmd> # Builds Pattern Lab from the current dir');
88
$ patternlab <cmd> --config <path/to/patternlab-config> # Pattern Lab from a config in a specified directory');`);
9-
/* eslint-enable */
9+
/* eslint-enable */
1010
};

0 commit comments

Comments
 (0)