UNPKG

1.72 kBJavaScriptView Raw
1const path = require('path');
2
3const pathExists = require('path-exists');
4const { copyFiles, json, template } = require('mrm-core');
5
6// These files will be overwritten without any confirmation
7const files = [
8 '.github/ISSUE_TEMPLATE/DOCS.md',
9 '.github/ISSUE_TEMPLATE/SUPPORT.md',
10 '.github/ISSUE_TEMPLATE.md',
11 '.github/CODEOWNERS',
12 '.github/PULL_REQUEST_TEMPLATE.md',
13 '.github/FUNDING.yml',
14 '.editorconfig',
15 '.eslintignore',
16 '.eslintrc.js',
17 '.prettierignore',
18 '.prettierrc.js',
19 'azure-pipelines.yml',
20 'babel.config.js',
21 'commitlint.config.js',
22 'husky.config.js',
23 'lint-staged.config.js',
24 'LICENSE',
25];
26
27const testFiles = [
28 'test/loader.test.js',
29 'test/options.test.js',
30 'test/fixtures/fixture.js',
31 'test/fixtures/foo.js',
32 'test/helpers/compiler.js',
33];
34
35// These files will be created only once
36const filesOnce = [
37 'src/index.js',
38 'src/cjs.js',
39 'src/options.json',
40 'CHANGELOG.md',
41];
42
43const dynamicTemplates = [
44 '.github/CONTRIBUTING.md',
45 '.github/ISSUE_TEMPLATE/BUG.md',
46 '.github/ISSUE_TEMPLATE/FEATURE.md',
47 '.github/ISSUE_TEMPLATE/MODIFICATION.md',
48];
49
50module.exports = () => {
51 const pkg = json('package.json');
52 const templatesDir = path.resolve(__dirname, '../../templates');
53
54 copyFiles(templatesDir, files);
55
56 pathExists('./test').then((exists) => {
57 if (!exists) {
58 copyFiles(templatesDir, testFiles, { overwrite: false });
59 }
60 });
61
62 for (const tmpl of dynamicTemplates) {
63 const file = template(
64 tmpl,
65 path.join(__dirname, `../../templates/${tmpl}`)
66 );
67
68 file
69 .apply({ package: pkg.get('name'), repo: pkg.get('repository') })
70 .save();
71 }
72
73 copyFiles(templatesDir, filesOnce, { overwrite: false });
74};