This repository was archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpatternlab.js
More file actions
109 lines (96 loc) · 3.23 KB
/
patternlab.js
File metadata and controls
109 lines (96 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env node
'use strict';
const cli = require('commander');
const build = require('./cli-actions/build');
const help = require('./cli-actions/help');
const version = require('./cli-actions/version');
const init = require('./cli-actions/init');
const install = require('./cli-actions/install');
const exportPatterns = require('./cli-actions/export');
const serve = require('./cli-actions/serve');
const error = require('./utils').error;
const log = require('./utils').log;
const pkg = require('../package.json');
// Register error logging
log.on('patternlab.error', err => console.log(err)); // eslint-disable-line
// Conditionally register verbose logging
const verboseLogs = verbose => log.on('patternlab.debug', msg => console.log(msg)); // eslint-disable-line
// Conditionally unregister all logging
const silenceLogs = () => {
log.removeAllListeners('patternlab.debug');
log.removeAllListeners('patternlab.error');
};
// Split strings into an array
const list = val => val.split(',');
/**
* Hook up cli version, usage and options
*/
cli
.version(version(pkg), '-V, --version')
.usage('<cmd> [options]')
.arguments('<cmd> [options]')
.option('-c, --config <path>', 'Specify config file. Default looks up the project dir', val => val.trim(), './patternlab-config.json')
.option('-v, --verbose', 'Show verbose console logs', verboseLogs)
.option('--silent', 'Turn off console logs', silenceLogs);
/**
* build
* @desc Setup patternlab's `build` cmd
*/
cli
.command('build')
.alias('compile')
.description('Build the PatternLab. Optionally (re-)build only the patterns')
.option('-p, --patterns-only', 'Whether to only build patterns')
.action(build);
/**
* export
* @desc Export a PatternLab patterns into a compressed format
*/
cli
.command('export')
.description('Export a PatternLab patterns into a compressed format')
.action(exportPatterns);
/**
* init
* @desc Initialize a PatternLab project from scratch or import an edition and/or starterkit
*/
cli
.command('init')
.description('Initialize a PatternLab project from scratch or import an edition and/or starterkit')
.option('-p, --project-dir <path>', 'Specify a project directory')
.option('-e, --edition <name>', 'Specify an edition to install')
.option('-k, --starterkit <name>', 'Specify a starterkit to install')
.action(init);
/**
* install
* @desc Installs Pattern Lab related modules like starterkits or plugins
*/
cli
.command('install')
.alias('add')
.description('Installs Pattern Lab related modules like starterkits or plugins')
.option('--starterkits <names>', 'Specify one or more starterkit to install', list)
.option('--plugins <names>', 'Specify one or more plugins to install', list)
.action(install);
/**
* serve
* @desc Starts a server to inspect files in browser
*/
cli
.command('serve')
.alias('browse')
.description('Starts a server to inspect files in browser')
.option('-w, --watch', 'Start watching for changes')
.action(serve);
// Show additional help
cli.on('--help', help);
/**
* Catch all unsupported commands and delegate to the cli's help
* Parse at the end because Node emit is immediate
*/
cli
.on('*', () => {
error('Invalid command provided. See the help for available commands/options.');
cli.help();
})
.parse(process.argv);