UNPKG

1.21 kBPlain TextView Raw
1#!/usr/bin/env node
2
3const exec = require('child_process').exec;
4const fs = require('fs');
5const lodash = require('lodash');
6const mkdirp = require('mkdirp');
7const path = require('path');
8
9const pkg = require(path.join(process.cwd(), 'package.json'));
10const initDir = path.join(__dirname, '..', 'init');
11const 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
32files.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.
55exec('commitizen init cz-conventional-changelog');