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 | '.eslintrc',
|
15 | '.gitignore',
|
16 |
|
17 | // Tooling config.
|
18 | './karma.conf.js',
|
19 | './rollup.config.js',
|
20 | './webpack.config.js',
|
21 | '.travis.yml',
|
22 |
|
23 | // Metadata.
|
24 | 'LICENSE',
|
25 | 'README.md',
|
26 |
|
27 | // Source.
|
28 | 'src/index.js',
|
29 | 'test/perf.js',
|
30 | 'test/unit.js',
|
31 | ];
|
32 |
|
33 | files.forEach((file) => {
|
34 | let srcFile = file;
|
35 |
|
36 | // NPM Renames .gitignore to .npmignore when installing if no .npmignore exists.
|
37 | if (srcFile === '.gitignore') {
|
38 | srcFile = '.npmignore';
|
39 | }
|
40 |
|
41 | const src = path.join(initDir, srcFile);
|
42 | const dst = path.join(process.cwd(), file);
|
43 |
|
44 | fs.readFile(src, (err, content) => {
|
45 | fs.exists(dst, (exists) => {
|
46 | if (!exists) {
|
47 | mkdirp(path.dirname(dst), () => {
|
48 | fs.writeFile(dst, lodash.template(content)(pkg));
|
49 | });
|
50 | }
|
51 | });
|
52 | });
|
53 | });
|
54 |
|
55 | // Init commitizen.
|
56 | exec('commitizen init cz-conventional-changelog');
|