1 |
|
2 | const path = require('path');
|
3 |
|
4 | const meta = require('user-meta');
|
5 | const gitUsername = require('git-username');
|
6 | const { json, install } = require('mrm-core');
|
7 |
|
8 | const packages = ['schema-utils', 'loader-utils'];
|
9 |
|
10 | const devPackages = [
|
11 |
|
12 | 'del',
|
13 | 'del-cli',
|
14 | 'cross-env',
|
15 | 'memfs',
|
16 | 'standard-version',
|
17 | '@commitlint/cli',
|
18 | '@commitlint/config-conventional',
|
19 | 'commitlint-azure-pipelines-cli',
|
20 | 'husky',
|
21 | 'npm-run-all',
|
22 |
|
23 |
|
24 | 'jest',
|
25 | 'jest-junit',
|
26 | 'babel-jest',
|
27 |
|
28 |
|
29 | '@babel/cli',
|
30 | '@babel/core',
|
31 | '@babel/preset-env',
|
32 |
|
33 |
|
34 | 'eslint',
|
35 | 'eslint-plugin-import',
|
36 | 'eslint-config-prettier',
|
37 | 'lint-staged',
|
38 | 'prettier',
|
39 |
|
40 |
|
41 | 'webpack',
|
42 |
|
43 |
|
44 | '@webpack-contrib/defaults',
|
45 | '@webpack-contrib/eslint-config-webpack',
|
46 | ];
|
47 |
|
48 | module.exports = () => {
|
49 | const { name } = meta;
|
50 | const github = gitUsername();
|
51 | const packageName = path.basename(process.cwd());
|
52 | const repository = `${github}/${packageName}`;
|
53 |
|
54 | const file = json('package.json');
|
55 | const existing = file.get();
|
56 |
|
57 | json('package.json')
|
58 | .set({
|
59 | name: existing.name || `${packageName}`,
|
60 | version: existing.version || '1.0.0',
|
61 | description: existing.description || '',
|
62 | license: existing.license || 'MIT',
|
63 | repository: `${repository}`,
|
64 | author: existing.author || `${name}`,
|
65 | homepage: `https://github.com/${repository}`,
|
66 | bugs: `https://github.com/${repository}/issues`,
|
67 | main: existing.main || 'dist/cjs.js',
|
68 | engines: {
|
69 | node: `>= 10.13.0`,
|
70 | },
|
71 | scripts: {
|
72 | start: 'npm run build -- -w',
|
73 | clean: 'del-cli dist',
|
74 | prebuild: 'npm run clean',
|
75 | build: 'cross-env NODE_ENV=production babel src -d dist --copy-files',
|
76 | commitlint: 'commitlint --from=master',
|
77 | security: 'npm audit',
|
78 | 'lint:prettier':
|
79 | 'prettier "{**/*,*}.{js,json,md,yml,css,ts}" --list-different',
|
80 | 'lint:js': 'eslint --cache .',
|
81 | lint: 'npm-run-all -l -p "lint:**"',
|
82 | 'test:only': 'cross-env NODE_ENV=test jest',
|
83 | 'test:watch': 'npm run test:only -- --watch',
|
84 | 'test:coverage':
|
85 | 'npm run test:only -- --collectCoverageFrom="src/**/*.js" --coverage',
|
86 | pretest: 'npm run lint',
|
87 | test: 'npm run test:coverage',
|
88 | prepare: 'npm run build',
|
89 | release: 'standard-version',
|
90 | defaults: existing.scripts.defaults || 'webpack-defaults',
|
91 | },
|
92 | files: existing.files || ['dist/', 'lib/', 'index.js'],
|
93 | peerDependencies: existing.peerDependencies || {
|
94 | webpack: '^4.0.0 || ^5.0.0',
|
95 | },
|
96 | dependencies: existing.dependencies || {},
|
97 | devDependencies: existing.devDependencies || {},
|
98 | keywords: existing.keywords || ['webpack'],
|
99 | })
|
100 | .save();
|
101 |
|
102 | install(packages, { dev: false });
|
103 | install(devPackages);
|
104 | };
|