easy-soft-develop 1.0.2 → 2.0.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/bin/cli.js +96 -3
  2. package/package.json +32 -22
  3. package/src/cliCollection/check-all-package-version.js +5 -0
  4. package/src/cliCollection/clear-all-dependence.js +39 -0
  5. package/src/cliCollection/commit-refresh.js +12 -0
  6. package/src/cliCollection/create-assist-scripts.cli.js +19 -0
  7. package/src/cliCollection/create-lerna-project.js +9 -0
  8. package/src/cliCollection/create-project-with-template.js +61 -0
  9. package/src/cliCollection/sleep.js +9 -0
  10. package/src/cliCollection/update-all-package-version.js +5 -0
  11. package/src/cliCollection/update-package-from-package.js +149 -0
  12. package/src/index.js +30 -22
  13. package/src/project/initProject.js +258 -0
  14. package/src/templates/babel.config.template.js +21 -0
  15. package/src/templates/commitlint.config.template.js +124 -0
  16. package/src/templates/editor.template.js +36 -0
  17. package/src/templates/eslint.template.js +249 -0
  18. package/src/templates/git.template.js +67 -0
  19. package/src/templates/lint-staged.template.js +35 -0
  20. package/src/templates/package.template.js +190 -0
  21. package/src/templates/prettier.template.js +133 -0
  22. package/src/templates/stylelint.template.js +79 -0
  23. package/src/templates/template.config.js +8 -0
  24. package/src/tools/clean.js +50 -0
  25. package/src/tools/commit.refresh.js +40 -0
  26. package/src/tools/develop.file.js +443 -0
  27. package/src/tools/initial.environment.js +118 -0
  28. package/src/tools/meta.js +242 -0
  29. package/src/tools/package.install.global.develop.dependence.js +92 -0
  30. package/src/tools/package.script.js +75 -0
  31. package/src/tools/package.tools.js +33 -0
  32. package/src/{package.update.js → tools/package.update.js} +16 -11
  33. package/src/tools/prettier.file.js +11 -0
  34. package/src/tools/prettier.package.json.js +17 -0
  35. package/src/{sleep.js → tools/sleep.js} +6 -3
  36. package/src/clean.js +0 -45
  37. package/src/commit.refresh.js +0 -40
  38. package/src/develop.assist.js +0 -110
  39. package/src/init.env.js +0 -146
  40. package/src/package.init.global.dependence.dev.js +0 -29
  41. package/src/package.tools.js +0 -32
  42. package/src/shell.js +0 -9
@@ -0,0 +1,242 @@
1
+ const fs = require('fs');
2
+ const console = require('console');
3
+ const fsExtra = require('fs-extra');
4
+ const term = require('terminal-kit').terminal;
5
+ const { resolve } = require('path');
6
+ const shell = require('shelljs');
7
+
8
+ function exec(cmd) {
9
+ shell.exec(cmd);
10
+ }
11
+
12
+ function cd(path) {
13
+ // eslint-disable-next-line no-undef
14
+ process.chdir(path);
15
+ }
16
+
17
+ function resolvePath(path) {
18
+ return resolve(path);
19
+ }
20
+
21
+ function isObject(value) {
22
+ return value !== null && typeof value === 'object';
23
+ }
24
+
25
+ function isArray(value) {
26
+ return Array.isArray(value);
27
+ }
28
+
29
+ function exit() {
30
+ // eslint-disable-next-line no-undef
31
+ return process.exit();
32
+ }
33
+
34
+ function getArgCollection() {
35
+ // eslint-disable-next-line no-undef
36
+ return process.argv;
37
+ }
38
+
39
+ function checkStringIsEmpty(v) {
40
+ v = ((v || null) == null ? '' : toString(v))
41
+ .trim()
42
+ .replace(/\t/g, ' ')
43
+ .replace(/\r/g, ' ')
44
+ .replace(/\n/g, ' ')
45
+ .replace(/\s*/g, '');
46
+
47
+ while (v.indexOf(' ') >= 0) {
48
+ v = v.replace(/ {2}/g, ' ');
49
+ }
50
+
51
+ return !v;
52
+ }
53
+
54
+ function assignObject(source, ...mergeData) {
55
+ let result = source;
56
+
57
+ if (!Array.isArray(mergeData)) {
58
+ if (!isObject(mergeData)) {
59
+ return result;
60
+ }
61
+
62
+ return Object.assign(source, mergeData);
63
+ }
64
+
65
+ mergeData.forEach((o) => {
66
+ if (!isObject(o)) {
67
+ return;
68
+ }
69
+
70
+ result = Object.assign(result, o);
71
+ });
72
+
73
+ return result;
74
+ }
75
+
76
+ function promptLine() {
77
+ term.gray('----------------------------------------\r\n');
78
+ }
79
+
80
+ function promptEmptyLine() {
81
+ console.log('');
82
+ }
83
+
84
+ function promptSuccess(message) {
85
+ term.green(`${message}\r\n`);
86
+ promptEmptyLine();
87
+ }
88
+
89
+ function promptWarn(message) {
90
+ term.magenta(`${message}\r\n`);
91
+ promptEmptyLine();
92
+ }
93
+
94
+ function promptInfo(message) {
95
+ term.white(`${message}\r\n`);
96
+ promptEmptyLine();
97
+ }
98
+
99
+ function promptError(error) {
100
+ console.error(error);
101
+
102
+ promptEmptyLine();
103
+ }
104
+
105
+ function existFileSync(path) {
106
+ try {
107
+ fs.accessSync(path, fs.F_OK);
108
+ } catch (error) {
109
+ return false;
110
+ }
111
+
112
+ if (!path || typeof path !== 'string') {
113
+ throw new TypeError('file path not allow empty');
114
+ }
115
+
116
+ const p = resolvePath(path);
117
+
118
+ const state = fs.statSync(p);
119
+
120
+ return state.isFile();
121
+ }
122
+
123
+ function existDirectorySync(path) {
124
+ if (!path || typeof path !== 'string') {
125
+ throw new TypeError('directory path not allow empty');
126
+ }
127
+
128
+ try {
129
+ fs.accessSync(path, fs.F_OK);
130
+ } catch (error) {
131
+ return false;
132
+ }
133
+
134
+ const p = resolvePath(path);
135
+
136
+ const state = fs.statSync(p);
137
+
138
+ return state.isDirectory();
139
+ }
140
+
141
+ function mkdirSync(path) {
142
+ if (checkStringIsEmpty(path)) {
143
+ promptError('path disallow empty');
144
+
145
+ return;
146
+ }
147
+
148
+ fs.mkdirSync(path, { recursive: true });
149
+ }
150
+
151
+ function writeFileSync(path, content, options = { coverFile: false }) {
152
+ const { coverFile } = options;
153
+
154
+ if (!coverFile) {
155
+ if (existFileSync(path)) {
156
+ promptInfo(`${path} already exist, ignore create`);
157
+
158
+ return false;
159
+ }
160
+
161
+ fs.writeFileSync(path, content, { flag: 'wx' });
162
+ } else {
163
+ fs.writeFileSync(path, content, { flag: 'w' });
164
+ }
165
+
166
+ return true;
167
+ }
168
+
169
+ function writeFileWithFolderAndNameSync(
170
+ folderPath,
171
+ fileName,
172
+ fileContent,
173
+ coverFile = false,
174
+ ) {
175
+ mkdirSync(folderPath);
176
+
177
+ return writeFileSync(`${folderPath}/${fileName}`, fileContent, {
178
+ coverFile: coverFile,
179
+ });
180
+ }
181
+
182
+ function writeFileWithOptionsSync({
183
+ folderPath,
184
+ fileName,
185
+ fileContent,
186
+ coverFile = false,
187
+ }) {
188
+ return writeFileWithFolderAndNameSync(
189
+ folderPath,
190
+ fileName,
191
+ fileContent,
192
+ coverFile,
193
+ );
194
+ }
195
+
196
+ function writeJsonFileSync(path, json, options = { coverFile: false }) {
197
+ const { coverFile } = options;
198
+
199
+ if (!coverFile) {
200
+ if (existFileSync(path)) {
201
+ promptInfo(`${path} exist, ignore create`);
202
+
203
+ return false;
204
+ }
205
+
206
+ fsExtra.writeJsonSync(path, json, { flag: 'wx' });
207
+ } else {
208
+ fsExtra.writeJsonSync(path, json, { flag: 'w' });
209
+ }
210
+
211
+ return true;
212
+ }
213
+
214
+ function readJsonFileSync(path) {
215
+ return fsExtra.readJsonSync(path);
216
+ }
217
+
218
+ module.exports = {
219
+ exec,
220
+ cd,
221
+ getArgCollection,
222
+ existFileSync,
223
+ existDirectorySync,
224
+ writeFileSync,
225
+ checkStringIsEmpty,
226
+ promptLine,
227
+ promptEmptyLine,
228
+ promptSuccess,
229
+ promptInfo,
230
+ promptWarn,
231
+ promptError,
232
+ isObject,
233
+ isArray,
234
+ assignObject,
235
+ mkdirSync,
236
+ readJsonFileSync,
237
+ writeJsonFileSync,
238
+ writeFileWithFolderAndNameSync,
239
+ writeFileWithOptionsSync,
240
+ resolvePath,
241
+ exit,
242
+ };
@@ -0,0 +1,92 @@
1
+ const {
2
+ promptSuccess,
3
+ promptInfo,
4
+ readJsonFileSync,
5
+ assignObject,
6
+ isArray,
7
+ checkStringIsEmpty,
8
+ writeJsonFileSync,
9
+ exec,
10
+ } = require('./meta');
11
+ const { getGlobalPackages } = require('./package.script');
12
+ const { loopPackage } = require('./package.tools');
13
+ const { updateSpecialPackageVersion } = require('./package.update');
14
+ const { prettierAllPackageJson } = require('./prettier.package.json');
15
+
16
+ function buildPackageObject(packageList) {
17
+ if (!isArray(packageList) || packageList.length <= 0) {
18
+ return {};
19
+ }
20
+
21
+ const o = {};
22
+
23
+ packageList.forEach((one) => {
24
+ if (checkStringIsEmpty(one)) {
25
+ return;
26
+ }
27
+
28
+ o[one] = '^0.0.1';
29
+ });
30
+
31
+ return o;
32
+ }
33
+
34
+ function adjustMainPackageJson(packageList) {
35
+ if (!isArray(packageList) || packageList.length <= 0) {
36
+ return;
37
+ }
38
+
39
+ const o = buildPackageObject(packageList);
40
+
41
+ const packageJson = readJsonFileSync('./package.json');
42
+
43
+ packageJson.devDependencies = assignObject(
44
+ o,
45
+ packageJson.devDependencies || {},
46
+ );
47
+
48
+ writeJsonFileSync('./package.json', packageJson, { coverFile: true });
49
+ }
50
+
51
+ function adjustChildrenPackageJson(packageList) {
52
+ if (!isArray(packageList) || packageList.length <= 0) {
53
+ return;
54
+ }
55
+
56
+ const o = buildPackageObject(packageList);
57
+
58
+ loopPackage(({ relativePath }) => {
59
+ const packageJson = readJsonFileSync(`${relativePath}/package.json`);
60
+
61
+ packageJson.devDependencies = assignObject(
62
+ o,
63
+ packageJson.devDependencies || {},
64
+ );
65
+
66
+ writeJsonFileSync(`${relativePath}/package.json`, packageJson, {
67
+ coverFile: true,
68
+ });
69
+ });
70
+ }
71
+
72
+ function installGlobalDevelopDependencePackages(packageList) {
73
+ const packages = getGlobalPackages().concat(packageList);
74
+
75
+ promptInfo(`${packages.join()} will install`);
76
+
77
+ adjustChildrenPackageJson(packages);
78
+
79
+ adjustMainPackageJson(packages);
80
+
81
+ prettierAllPackageJson();
82
+
83
+ updateSpecialPackageVersion(packages);
84
+
85
+ exec('npm run z:install');
86
+
87
+ promptSuccess('install success');
88
+ }
89
+
90
+ module.exports = {
91
+ installGlobalDevelopDependencePackages,
92
+ };
@@ -0,0 +1,75 @@
1
+ const globalScript = {
2
+ 'z:initial:environment': 'node ./develop/assists/initial.environment.js',
3
+ };
4
+
5
+ const packageScript = {};
6
+
7
+ function getGlobalPackages() {
8
+ let packages = [];
9
+
10
+ packages = packages.concat([
11
+ '@babel/core',
12
+ '@babel/eslint-parser',
13
+ '@babel/plugin-external-helpers',
14
+ '@babel/plugin-proposal-class-properties',
15
+ '@babel/plugin-proposal-decorators',
16
+ '@babel/plugin-transform-runtime',
17
+ '@babel/preset-env',
18
+ '@babel/preset-react',
19
+ ]);
20
+
21
+ packages = packages.concat([
22
+ '@commitlint/cli',
23
+ '@commitlint/config-conventional',
24
+ '@commitlint/config-lerna-scopes',
25
+ '@commitlint/cz-commitlint',
26
+ '@pmmmwh/react-refresh-webpack-plugin',
27
+ 'commitizen',
28
+ 'conventional-changelog-conventionalcommits',
29
+ ]);
30
+
31
+ packages = packages.concat([
32
+ 'eslint',
33
+ 'eslint-config-airbnb',
34
+ 'eslint-config-airbnb-typescript',
35
+ 'eslint-config-prettier',
36
+ 'eslint-formatter-pretty',
37
+ 'eslint-import-resolver-typescript',
38
+ 'eslint-plugin-eslint-comments',
39
+ 'eslint-plugin-import',
40
+ 'eslint-plugin-jest',
41
+ 'eslint-plugin-jsx-a11y',
42
+ 'eslint-plugin-prettier',
43
+ 'eslint-plugin-promise',
44
+ 'eslint-plugin-react',
45
+ 'eslint-plugin-react-hooks',
46
+ 'eslint-plugin-simple-import-sort',
47
+ 'eslint-plugin-unicorn',
48
+ ]);
49
+
50
+ packages = packages.concat([
51
+ 'prettier',
52
+ 'prettier-plugin-organize-imports',
53
+ 'prettier-plugin-packagejson',
54
+ ]);
55
+
56
+ packages = packages.concat([
57
+ 'stylelint',
58
+ 'stylelint-config-prettier',
59
+ 'stylelint-config-standard',
60
+ ]);
61
+
62
+ packages = packages.concat(
63
+ 'rimraf',
64
+ 'lint-staged',
65
+ 'husky',
66
+ 'shelljs',
67
+ 'terminal-kit',
68
+ );
69
+
70
+ packages = packages.concat('easy-soft-develop');
71
+
72
+ return packages;
73
+ }
74
+
75
+ module.exports = { globalScript, packageScript, getGlobalPackages };
@@ -0,0 +1,33 @@
1
+ const fs = require('fs');
2
+
3
+ const { resolvePath, existDirectorySync } = require('./meta');
4
+
5
+ /**
6
+ * loop all package
7
+ */
8
+ // eslint-disable-next-line no-unused-vars
9
+ function loopPackage(callback = ({ name, absolutePath, relativePath }) => {}) {
10
+ const packagesDir = './packages/';
11
+
12
+ if (!existDirectorySync(resolvePath(packagesDir))) {
13
+ return;
14
+ }
15
+
16
+ const packagesPath = resolvePath(packagesDir);
17
+
18
+ const files = fs.readdirSync(packagesDir);
19
+
20
+ files.forEach((file) => {
21
+ const itemPath = `${packagesPath}/${file}`;
22
+
23
+ if (file && fs.lstatSync(itemPath).isDirectory()) {
24
+ callback({
25
+ name: file,
26
+ absolutePath: itemPath,
27
+ relativePath: `./packages/${file}`,
28
+ });
29
+ }
30
+ });
31
+ }
32
+
33
+ module.exports = { loopPackage };
@@ -1,5 +1,5 @@
1
+ const { promptInfo, promptSuccess, exec } = require('./meta');
1
2
  const { loopPackage } = require('./package.tools');
2
- const { exec } = require('./shell');
3
3
 
4
4
  function adjustMainPackageJson(cmd) {
5
5
  exec(cmd);
@@ -12,44 +12,49 @@ function adjustChildrenPackageJson(cmd) {
12
12
  }
13
13
 
14
14
  function updateSpecialPackageVersion(packageList) {
15
+ exec('npm run z:initial:environment');
16
+
15
17
  const packages = packageList.join(' ');
16
18
 
17
19
  const ncuCommand = `npx ncu -u ${packages} --packageFile package.json`;
18
20
 
19
- console.log(`${packageList.join()} will check update`);
20
- console.log('');
21
+ promptInfo(`${packageList.join()} will check update`);
21
22
 
22
23
  adjustMainPackageJson(ncuCommand);
23
24
 
24
25
  adjustChildrenPackageJson(ncuCommand);
25
26
 
26
- console.log('update success');
27
+ promptSuccess('check success');
27
28
  }
28
29
 
29
30
  function updateAllPackageVersion() {
31
+ exec('npm run z:initial:environment');
32
+
30
33
  const ncuCommand = `npx ncu -u --packageFile package.json`;
31
34
 
32
- console.log(`all packages will update`);
33
- console.log('');
35
+ promptInfo(`all packages version will update`);
34
36
 
35
37
  adjustMainPackageJson(ncuCommand);
36
38
 
37
39
  adjustChildrenPackageJson(ncuCommand);
38
40
 
39
- console.log('update success');
41
+ promptSuccess('update success, exec install with z:install');
42
+
43
+ exec('npm run z:install');
40
44
  }
41
45
 
42
46
  function checkAllPackageVersion() {
43
- const ncuCommand = `npx ncu -u --packageFile package.json`;
47
+ const ncuCommand = `npx ncu --packageFile package.json`;
44
48
 
45
- console.log(`all packages will check update`);
46
- console.log('');
49
+ promptInfo(`all packages version will check update`);
47
50
 
48
51
  adjustMainPackageJson(ncuCommand);
49
52
 
50
53
  adjustChildrenPackageJson(ncuCommand);
51
54
 
52
- console.log('update success');
55
+ promptSuccess('update success, exec install with z:install');
56
+
57
+ exec('npm run z:install');
53
58
  }
54
59
 
55
60
  module.exports = {
@@ -0,0 +1,11 @@
1
+ const { exec } = require('./meta');
2
+
3
+ function prettierAllFile() {
4
+ exec('npx prettier --cache --write .');
5
+ }
6
+
7
+ function prettierChangeFile() {
8
+ exec('npx prettier --cache --write ./package.json');
9
+ }
10
+
11
+ module.exports = { prettierAllFile, prettierChangeFile };
@@ -0,0 +1,17 @@
1
+ const { promptInfo, promptEmptyLine, exec } = require('./meta');
2
+
3
+ function prettierAllPackageJson() {
4
+ promptInfo('will format all package.json');
5
+ promptEmptyLine();
6
+
7
+ exec('npx prettier --write ./**/package.json');
8
+ }
9
+
10
+ function prettierCurrentPackageJson() {
11
+ promptInfo('will format current package.json');
12
+ promptEmptyLine();
13
+
14
+ exec('npx prettier --write ./package.json');
15
+ }
16
+
17
+ module.exports = { prettierAllPackageJson, prettierCurrentPackageJson };
@@ -1,16 +1,19 @@
1
1
  /* eslint-disable no-undef */
2
- /* eslint-disable import/no-commonjs */
2
+
3
+ const { promptInfo } = require('./meta');
3
4
 
4
5
  function mSleep(n) {
5
6
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n);
6
7
  }
7
8
 
8
- function sleep(n) {
9
+ function sleep(n, showLog = false) {
9
10
  if (n <= 0) {
10
11
  return;
11
12
  }
12
13
 
13
- console.log(`sleep ${n}s`);
14
+ if (showLog) {
15
+ promptInfo(`sleep ${n}s`);
16
+ }
14
17
 
15
18
  mSleep(n * 1000);
16
19
  }
package/src/clean.js DELETED
@@ -1,45 +0,0 @@
1
- /* eslint-disable import/no-commonjs */
2
-
3
- const { exec } = require('./shell');
4
-
5
- function clean(preCmd, ...targets) {
6
- try {
7
- const { loopPackage } = require('./package.assist');
8
-
9
- const list = targets.push('node_modules');
10
-
11
- const command = list
12
- .map((o) => {
13
- if (o) {
14
- return `npx rimraf ./${o}`;
15
- }
16
- return '';
17
- })
18
- .join(' && ');
19
-
20
- function adjustMainPackageJson() {
21
- exec(command);
22
- }
23
-
24
- function adjustChildrenPackageJson() {
25
- loopPackage(({ name }) => {
26
- exec(`cd ./packages/${name} && ${command}`);
27
- });
28
- }
29
-
30
- console.log(`clean start`);
31
- console.log('');
32
-
33
- if (preCmd) {
34
- exec(preCmd);
35
- }
36
-
37
- adjustChildrenPackageJson();
38
-
39
- adjustMainPackageJson();
40
-
41
- console.log('clean success');
42
- } catch {}
43
- }
44
-
45
- module.exports = { clean };
@@ -1,40 +0,0 @@
1
- /* eslint-disable import/no-commonjs */
2
-
3
- let fs = require('fs');
4
- const { resolve } = require('path');
5
-
6
- function commitRefresh(
7
- filename = 'commit.flag.json',
8
- relativeFolder = 'develop/flags',
9
- ) {
10
- function prompt(err) {
11
- if (err) {
12
- return console.error(err);
13
- }
14
-
15
- console.log('commit.flag.json update success');
16
- }
17
-
18
- const now = new Date();
19
-
20
- const datetime = `${now.getFullYear()}-${
21
- now.getMonth() + 1
22
- }-${now.getDate()} ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`;
23
-
24
- let content = JSON.stringify({
25
- datetime: datetime,
26
- });
27
-
28
- const filePath = resolve('.');
29
-
30
- fs.mkdirSync(`${filePath}/${relativeFolder}/`, { recursive: true });
31
-
32
- fs.writeFile(
33
- `${filePath}/${relativeFolder}/${filename}`,
34
- content,
35
- { flag: 'w' },
36
- prompt,
37
- );
38
- }
39
-
40
- module.exports = { commitRefresh };