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