forked from pattern-lab/patternlab-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscaffold.js
More file actions
38 lines (36 loc) · 1.32 KB
/
scaffold.js
File metadata and controls
38 lines (36 loc) · 1.32 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
'use strict';
const path = require('path');
const execa = require('execa');
const fs = require('fs');
const wrapAsync = require('./utils').wrapAsync;
const mkdirsAsync = require('./utils').mkdirsAsync;
/**
* @func scaffold
* @desc Generate file and folder structure for a Pattern Lab project
* @param {string} projectDir - The project root directory path.
* @param {string} sourceDir - The source root directory path.
* @param {string} publicDir - The public root directory path.
* @param {string} exportDir - The export root directory path.
* @return {void}
*/
const scaffold = (projectDir, sourceDir, publicDir, exportDir) =>
wrapAsync(function*() {
const projectPath = path.join(process.cwd(), projectDir);
if (!fs.existsSync(path.join(projectPath, 'package.json'))) {
execa.sync('npm', ['init', '-y'], {
cwd: projectPath,
});
}
/**
* Create mandatory files structure
* 1. Create project source directory
* 2. Create project public directory
* 3. Create project export directory
*/
yield Promise.all([
mkdirsAsync(path.resolve(projectDir, path.normalize(sourceDir))), // 1
mkdirsAsync(path.resolve(projectDir, path.normalize(publicDir))), // 2
mkdirsAsync(path.resolve(projectDir, path.normalize(exportDir))), // 3
]);
});
module.exports = scaffold;