forked from pattern-lab/patternlab-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
82 lines (75 loc) · 2.67 KB
/
init.js
File metadata and controls
82 lines (75 loc) · 2.67 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
'use strict';
const patternlab = require('@pattern-lab/core');
const merge = require('deepmerge');
const ask = require('../ask');
const scaffold = require('../scaffold');
const installEdition = require('../install-edition');
const installStarterkit = require('../install-starterkit');
const replaceConfigPaths = require('../replace-config');
const ora = require('ora');
const path = require('path');
const wrapAsync = require('../utils').wrapAsync;
const writeJsonAsync = require('../utils').writeJsonAsync;
const defaultPatternlabConfig = patternlab.getDefaultConfig();
const init = options =>
wrapAsync(function*() {
const sourceDir = 'source';
const publicDir = 'public';
const exportDir = 'pattern_exports';
const answers = options.projectDir ? options : yield ask(options);
const projectDir = answers.projectDir || './';
const edition = answers.edition;
const starterkit = answers.starterkit;
/**
* Process the init routines
* 1 Replace config paths
* 2. Scaffold the folder structure
* 3. If `edition` is present:
* 3.1 Install edition
* 3.2 Reassign adjustedconfig
* 4. If `starterkit` is present install it and copy over the mandatory starterkit files to sourceDir
* 5. Save patternlab-config.json in projectDir
*/
const spinner = ora(`Setting up Pattern Lab in ${projectDir}`).start();
let patternlabConfig = replaceConfigPaths(
defaultPatternlabConfig,
projectDir,
sourceDir,
publicDir,
exportDir
); // 1
yield scaffold(projectDir, sourceDir, publicDir, exportDir); // 2
if (edition) {
spinner.text = `⊙ patternlab → Installing edition: ${edition}`;
const newConf = yield installEdition(
edition,
patternlabConfig,
projectDir
); // 3.1
if (newConf) {
patternlabConfig = merge(patternlabConfig, newConf); // 3.2
}
spinner.succeed(`⊙ patternlab → Installed edition: ${edition}`);
}
if (starterkit) {
spinner.text = `⊙ patternlab → Installing starterkit ${starterkit}`;
spinner.start();
const starterkitConfig = yield installStarterkit(
starterkit,
patternlabConfig
);
spinner.succeed(`⊙ patternlab → Installed starterkit: ${starterkit}`);
if (starterkitConfig) {
patternlabConfig = merge(patternlabConfig, starterkitConfig);
}
} // 4
yield writeJsonAsync(
path.resolve(projectDir, 'patternlab-config.json'),
patternlabConfig
); // 5
spinner.succeed(
`⊙ patternlab → Yay ☺. Pattern Lab Node was successfully initialized in ${projectDir}`
);
return true;
});
module.exports = init;