1 | const path = require('path');
|
2 |
|
3 | const pathExists = require('path-exists');
|
4 | const { copyFiles, json, template } = require('mrm-core');
|
5 |
|
6 |
|
7 | const 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 |
|
27 | const 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 |
|
36 | const filesOnce = [
|
37 | 'src/index.js',
|
38 | 'src/cjs.js',
|
39 | 'src/options.json',
|
40 | 'CHANGELOG.md',
|
41 | ];
|
42 |
|
43 | const 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 |
|
50 | module.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 | };
|