1 | #!/usr/bin/env node
|
2 |
|
3 | const exec = require('child_process').exec;
|
4 | const fs = require('fs');
|
5 | const lodash = require('lodash');
|
6 | const mkdirp = require('mkdirp');
|
7 | const path = require('path');
|
8 |
|
9 | const pkg = require(path.join(process.cwd(), 'package.json'));
|
10 | const initDir = path.join(__dirname, '..', 'init');
|
11 | const files = [
|
12 | // Base editor / git config.
|
13 | '.editorconfig',
|
14 | '.gitignore',
|
15 |
|
16 | // Tooling config.
|
17 | './karma.conf.js',
|
18 | './rollup.config.js',
|
19 | './webpack.config.js',
|
20 | '.travis.yml',
|
21 |
|
22 | // Metadata.
|
23 | 'LICENSE',
|
24 | 'README.md',
|
25 |
|
26 | // Source.
|
27 | 'src/index.js',
|
28 | 'test/perf.js',
|
29 | 'test/unit.js'
|
30 | ];
|
31 |
|
32 | files.forEach((file) => {
|
33 | let srcFile = file;
|
34 |
|
35 | // NPM Renames .gitignore to .npmignore when installing if no .npmignore exists.
|
36 | if (srcFile === '.gitignore') {
|
37 | srcFile = '.npmignore';
|
38 | }
|
39 |
|
40 | const src = path.join(initDir, srcFile);
|
41 | const dst = path.join(process.cwd(), file);
|
42 |
|
43 | fs.readFile(src, (err, content) => {
|
44 | fs.exists(dst, (exists) => {
|
45 | if (!exists) {
|
46 | mkdirp(path.dirname(dst), () => {
|
47 | fs.writeFile(dst, lodash.template(content)(pkg));
|
48 | });
|
49 | }
|
50 | });
|
51 | });
|
52 | });
|
53 |
|
54 | // Init commitizen.
|
55 | exec('commitizen init cz-conventional-changelog');
|