easy-soft-develop 1.0.0

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.
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "easy-soft-develop",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "homepage": "https://github.com/kityandhero/easy-soft-develop#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/kityandhero/easy-soft-develop/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/kityandhero/easy-soft-develop.git"
12
+ },
13
+ "license": "ISC",
14
+ "author": "",
15
+ "main": "src/index.js",
16
+ "directories": {
17
+ "src": "src"
18
+ },
19
+ "files": [
20
+ "src/"
21
+ ],
22
+ "scripts": {
23
+ "commitlint": "npx commitlint --edit",
24
+ "precz": "git stage -A",
25
+ "cz": "cz",
26
+ "postcz": "git push",
27
+ "test:commitRefresh": "node ./test/commitRefresh.test.js",
28
+ "test:createCleanScriptFile": "node ./test/createCleanScriptFile.test.js",
29
+ "test:createCommitRefreshScriptFile": "node ./test/createCommitRefreshScriptFile.test.js",
30
+ "test:createPackageCheckAllVersionScriptFile": "node ./test/createPackageCheckAllVersionScriptFile.test.js",
31
+ "test:createPackageUpdateAllVersionScriptFile": "node ./test/createPackageUpdateAllVersionScriptFile.test.js",
32
+ "test:createSleepScriptFile": "node ./test/createSleepScriptFile.test.js"
33
+ },
34
+ "dependencies": {},
35
+ "devDependencies": {
36
+ "@commitlint/cli": "^17.4.2",
37
+ "@commitlint/config-conventional": "^17.4.2",
38
+ "@commitlint/config-lerna-scopes": "^17.4.2",
39
+ "@commitlint/cz-commitlint": "^17.4.2",
40
+ "commitizen": "^4.3.0",
41
+ "conventional-changelog-conventionalcommits": "^5.0.0",
42
+ "eslint": "^8.33.0",
43
+ "eslint-config-prettier": "^8.6.0",
44
+ "eslint-formatter-pretty": "^4.1.0",
45
+ "eslint-import-resolver-typescript": "^3.5.3",
46
+ "eslint-plugin-eslint-comments": "^3.2.0",
47
+ "eslint-plugin-import": "^2.27.5",
48
+ "eslint-plugin-prettier": "^4.2.1",
49
+ "eslint-plugin-promise": "^6.1.1",
50
+ "fs-extra": "^11.1.0",
51
+ "husky": "^8.0.3",
52
+ "lint-staged": "^13.1.0",
53
+ "prettier": "^2.8.3",
54
+ "prettier-plugin-packagejson": "^2",
55
+ "rimraf": "^4.1.2",
56
+ "shelljs": "^0.8.5"
57
+ }
58
+ }
package/src/clean.js ADDED
@@ -0,0 +1,45 @@
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 };
@@ -0,0 +1,40 @@
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 };
@@ -0,0 +1,101 @@
1
+ let fs = require('fs');
2
+ const { resolve } = require('path');
3
+
4
+ function createCleanScriptFile() {
5
+ const filePath = resolve('.');
6
+
7
+ const content = `/* eslint-disable import/no-commonjs */
8
+
9
+ const { clean } = require('easy-soft-develop');
10
+
11
+ clean('',['yarn-error.log','yarn.lock','package-lock.json','src/.umi']);
12
+ `;
13
+
14
+ fs.mkdirSync(`${filePath}/develop/assists/`, { recursive: true });
15
+
16
+ fs.writeFileSync(`${filePath}/develop/assists/clean.js`, content, {
17
+ flag: 'w',
18
+ });
19
+ }
20
+
21
+ function createCommitRefreshScriptFile() {
22
+ const filePath = resolve('.');
23
+
24
+ const content = `/* eslint-disable import/no-commonjs */
25
+
26
+ const { createCleanScriptFile } = require('easy-soft-develop');
27
+
28
+ createCleanScriptFile();
29
+ `;
30
+
31
+ fs.mkdirSync(`${filePath}/develop/assists/`, { recursive: true });
32
+
33
+ fs.writeFileSync(`${filePath}/develop/assists/commit.refresh.js`, content, {
34
+ flag: 'w',
35
+ });
36
+ }
37
+
38
+ function createPackageUpdateAllVersionScriptFile() {
39
+ const filePath = resolve('.');
40
+
41
+ const content = `/* eslint-disable import/no-commonjs */
42
+
43
+ const { updateAllPackageVersion } = require('easy-soft-develop');
44
+
45
+ updateAllPackageVersion();
46
+ `;
47
+
48
+ fs.mkdirSync(`${filePath}/develop/assists/`, { recursive: true });
49
+
50
+ const scriptFilePath = `${filePath}/develop/assists/package.update.version.all.js`;
51
+
52
+ fs.writeFileSync(scriptFilePath, content, {
53
+ flag: 'w',
54
+ });
55
+ }
56
+
57
+ function createPackageCheckAllVersionScriptFile() {
58
+ const filePath = resolve('.');
59
+
60
+ const content = `/* eslint-disable import/no-commonjs */
61
+
62
+ const { checkAllPackageVersion } = require('easy-soft-develop');
63
+
64
+ checkAllPackageVersion();
65
+ `;
66
+
67
+ fs.mkdirSync(`${filePath}/develop/assists/`, { recursive: true });
68
+
69
+ const scriptFilePath = `${filePath}/develop/assists/package.check.version.all.js`;
70
+
71
+ fs.writeFileSync(scriptFilePath, content, {
72
+ flag: 'w',
73
+ });
74
+ }
75
+
76
+ function createSleepScriptFile() {
77
+ const filePath = resolve('.');
78
+
79
+ const content = `/* eslint-disable import/no-commonjs */
80
+
81
+ const { sleep } = require('easy-soft-develop');
82
+
83
+ sleep(2);
84
+ `;
85
+
86
+ fs.mkdirSync(`${filePath}/develop/assists/`, { recursive: true });
87
+
88
+ const scriptFilePath = `${filePath}/develop/assists/sleep.js`;
89
+
90
+ fs.writeFileSync(scriptFilePath, content, {
91
+ flag: 'w',
92
+ });
93
+ }
94
+
95
+ module.exports = {
96
+ createCleanScriptFile,
97
+ createCommitRefreshScriptFile,
98
+ createPackageUpdateAllVersionScriptFile,
99
+ createPackageCheckAllVersionScriptFile,
100
+ createSleepScriptFile,
101
+ };
package/src/index.js ADDED
@@ -0,0 +1,39 @@
1
+ const { clean } = require('./clean');
2
+ const { commitRefresh } = require('./commit.refresh');
3
+ const {
4
+ createCleanScriptFile,
5
+ createCommitRefreshScriptFile,
6
+ createPackageUpdateAllVersionScriptFile,
7
+ createPackageCheckAllVersionScriptFile,
8
+ createSleepScriptFile,
9
+ } = require('./develop.assist');
10
+ const { initEnv } = require('./init.env');
11
+ const {
12
+ initGlobalDevDependencePackages,
13
+ } = require('./package.init.global.dependence.dev');
14
+ const { loopPackage } = require('./package.tools');
15
+ const {
16
+ checkAllPackageVersion,
17
+ updateSpecialPackageVersion,
18
+ updateAllPackageVersion,
19
+ } = require('./package.update');
20
+ const { exec } = require('./shell');
21
+ const { sleep } = require('./sleep');
22
+
23
+ module.exports = {
24
+ clean,
25
+ commitRefresh,
26
+ initEnv,
27
+ initGlobalDevDependencePackages,
28
+ loopPackage,
29
+ checkAllPackageVersion,
30
+ updateSpecialPackageVersion,
31
+ updateAllPackageVersion,
32
+ exec,
33
+ sleep,
34
+ createCleanScriptFile,
35
+ createCommitRefreshScriptFile,
36
+ createPackageUpdateAllVersionScriptFile,
37
+ createPackageCheckAllVersionScriptFile,
38
+ createSleepScriptFile,
39
+ };
@@ -0,0 +1,146 @@
1
+ /* eslint-disable promise/no-nesting */
2
+ /* eslint-disable promise/no-promise-in-callback */
3
+ /* eslint-disable import/no-commonjs */
4
+
5
+ const fs = require('fs');
6
+ const fsExtra = require('fs-extra');
7
+ const { resolve } = require('path');
8
+
9
+ const { loopPackage } = require('./package.tools');
10
+ const { exec } = require('./shell');
11
+
12
+ function createMainFile(fileWithContentCollection) {
13
+ if (!Array.isArray(fileWithContentCollection)) {
14
+ return;
15
+ }
16
+
17
+ fileWithContentCollection.forEach((o) => {
18
+ const { name, content } = o;
19
+
20
+ fs.writeFile(name, content, (error) => {
21
+ return console.error(error);
22
+ });
23
+ });
24
+
25
+ console.log(
26
+ `main files [${fileWithContentCollection
27
+ .map((o) => {
28
+ const { name } = o;
29
+ return name;
30
+ })
31
+ .join()}] refresh success`,
32
+ );
33
+ }
34
+
35
+ function createPackageFile(fileWithContentCollection) {
36
+ loopPackage(({ absolutePath }) => {
37
+ const itemPath = absolutePath;
38
+
39
+ if (!Array.isArray(fileWithContentCollection)) {
40
+ return;
41
+ }
42
+
43
+ fileWithContentCollection.forEach((o) => {
44
+ const { name, content } = o;
45
+
46
+ fs.writeFile(`${itemPath}/${name}`, content, (error) => {
47
+ return console.error(error);
48
+ });
49
+ });
50
+ });
51
+
52
+ console.log(
53
+ `package files [${fileWithContentCollection
54
+ .map((o) => {
55
+ const { name } = o;
56
+ return name;
57
+ })
58
+ .join()}] refresh success`,
59
+ );
60
+ }
61
+
62
+ function adjustMainPackageJson({ scripts }) {
63
+ const mainProjectPath = resolve(`./package.json`);
64
+
65
+ fsExtra
66
+ .readJson(mainProjectPath)
67
+ .then((packageJson) => {
68
+ packageJson.scripts = {
69
+ ...(packageJson.scripts || {}),
70
+ ...scripts,
71
+ };
72
+
73
+ fsExtra
74
+ .writeJson(mainProjectPath, packageJson)
75
+ .then(() => {
76
+ console.log('adjust main package.json success');
77
+
78
+ return null;
79
+ })
80
+ .catch((err) => {
81
+ console.error(err);
82
+ return null;
83
+ });
84
+
85
+ return null;
86
+ })
87
+ .catch((err) => {
88
+ console.error(err);
89
+ });
90
+ }
91
+
92
+ function adjustChildrenPackageJson({ scripts }) {
93
+ loopPackage(({ absolutePath }) => {
94
+ const itemPath = absolutePath;
95
+
96
+ const childPackageJsonPath = `${itemPath}/package.json`;
97
+
98
+ fsExtra
99
+ .readJson(childPackageJsonPath)
100
+ .then((packageJson) => {
101
+ packageJson.scripts = {
102
+ ...(packageJson.scripts || {}),
103
+ ...scripts,
104
+ };
105
+
106
+ fsExtra
107
+ .writeJson(childPackageJsonPath, packageJson)
108
+ .then(() => {
109
+ console.log('adjust child package.json success');
110
+
111
+ return null;
112
+ })
113
+ .catch((e) => {
114
+ console.error(e);
115
+
116
+ return null;
117
+ });
118
+
119
+ return null;
120
+ })
121
+ .catch((res) => {
122
+ console.error(res);
123
+
124
+ return null;
125
+ });
126
+ });
127
+ }
128
+
129
+ function initEnv({
130
+ mainFileContentList,
131
+ packageFileContentList,
132
+ mainScripts,
133
+ childScripts,
134
+ }) {
135
+ createMainFile(mainFileContentList);
136
+
137
+ createPackageFile(packageFileContentList);
138
+
139
+ adjustMainPackageJson({ scripts: mainScripts });
140
+
141
+ adjustChildrenPackageJson({ scripts: childScripts });
142
+
143
+ exec('npx prettier --write ./**/package.json');
144
+ }
145
+
146
+ module.exports = { initEnv };
@@ -0,0 +1,29 @@
1
+ /* eslint-disable import/no-commonjs */
2
+
3
+ const { loopPackage } = require('./package.tools');
4
+ const { exec } = require('./shell');
5
+
6
+ function initGlobalDevDependencePackages(packageList) {
7
+ const command = `pnpm install -save-dev ${packageList.join(' ')}`;
8
+
9
+ function adjustMainPackageJson() {
10
+ exec(command);
11
+ }
12
+
13
+ function adjustChildrenPackageJson() {
14
+ loopPackage(({ name }) => {
15
+ exec(`cd ./packages/${name} && ${command}`);
16
+ });
17
+ }
18
+
19
+ console.log(`${packageList.join()} will install`);
20
+ console.log('');
21
+
22
+ adjustChildrenPackageJson();
23
+
24
+ adjustMainPackageJson();
25
+
26
+ console.log('install success');
27
+ }
28
+
29
+ module.exports = { initGlobalDevDependencePackages };
@@ -0,0 +1,32 @@
1
+ const fs = require('fs');
2
+
3
+ const { resolve } = require('path');
4
+
5
+ /**
6
+ * loop all package
7
+ */
8
+ function loopPackage(callback = ({ name, absolutePath, relativePath }) => {}) {
9
+ const packagesDir = './packages/';
10
+
11
+ const packagesPath = resolve(packagesDir);
12
+
13
+ fs.readdir(packagesDir, (err, files) => {
14
+ if (err) {
15
+ throw err;
16
+ }
17
+
18
+ files.forEach((file) => {
19
+ const itemPath = `${packagesPath}/${file}`;
20
+
21
+ if (file && fs.lstatSync(itemPath).isDirectory()) {
22
+ callback({
23
+ name: file,
24
+ absolutePath: itemPath,
25
+ relativePath: `./packages/${file}`,
26
+ });
27
+ }
28
+ });
29
+ });
30
+ }
31
+
32
+ module.exports = { loopPackage };
@@ -0,0 +1,59 @@
1
+ const { loopPackage } = require('./package.tools');
2
+ const { exec } = require('./shell');
3
+
4
+ function adjustMainPackageJson(cmd) {
5
+ exec(cmd);
6
+ }
7
+
8
+ function adjustChildrenPackageJson(cmd) {
9
+ loopPackage(({ name }) => {
10
+ exec(`cd ./packages/${name} && ${cmd}`);
11
+ });
12
+ }
13
+
14
+ function updateSpecialPackageVersion(packageList) {
15
+ const packages = packageList.join(' ');
16
+
17
+ const ncuCommand = `npx ncu -u ${packages} --packageFile package.json`;
18
+
19
+ console.log(`${packageList.join()} will check update`);
20
+ console.log('');
21
+
22
+ adjustMainPackageJson(ncuCommand);
23
+
24
+ adjustChildrenPackageJson(ncuCommand);
25
+
26
+ console.log('update success');
27
+ }
28
+
29
+ function updateAllPackageVersion() {
30
+ const ncuCommand = `npx ncu -u --packageFile package.json`;
31
+
32
+ console.log(`all packages will update`);
33
+ console.log('');
34
+
35
+ adjustMainPackageJson(ncuCommand);
36
+
37
+ adjustChildrenPackageJson(ncuCommand);
38
+
39
+ console.log('update success');
40
+ }
41
+
42
+ function checkAllPackageVersion() {
43
+ const ncuCommand = `npx ncu -u --packageFile package.json`;
44
+
45
+ console.log(`all packages will check update`);
46
+ console.log('');
47
+
48
+ adjustMainPackageJson(ncuCommand);
49
+
50
+ adjustChildrenPackageJson(ncuCommand);
51
+
52
+ console.log('update success');
53
+ }
54
+
55
+ module.exports = {
56
+ checkAllPackageVersion,
57
+ updateSpecialPackageVersion,
58
+ updateAllPackageVersion,
59
+ };
package/src/shell.js ADDED
@@ -0,0 +1,9 @@
1
+ /* eslint-disable import/no-commonjs */
2
+
3
+ const shell = require('shelljs');
4
+
5
+ function exec(cmd) {
6
+ shell.exec(cmd);
7
+ }
8
+
9
+ module.exports = { exec };
package/src/sleep.js ADDED
@@ -0,0 +1,18 @@
1
+ /* eslint-disable no-undef */
2
+ /* eslint-disable import/no-commonjs */
3
+
4
+ function mSleep(n) {
5
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n);
6
+ }
7
+
8
+ function sleep(n) {
9
+ if (n <= 0) {
10
+ return;
11
+ }
12
+
13
+ console.log(`sleep ${n}s`);
14
+
15
+ mSleep(n * 1000);
16
+ }
17
+
18
+ module.exports = { sleep };