@liuli-util/cli 3.13.1 → 3.17.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +100 -74
  2. package/LICENSE +21 -0
  3. package/dist/bin.js +96 -77
  4. package/dist/bin.js.map +3 -3
  5. package/dist/commands/deploy/DeployService.d.ts +52 -0
  6. package/dist/commands/deploy/DeployService.d.ts.map +1 -0
  7. package/dist/commands/deploy/deploy.d.ts +3 -0
  8. package/dist/commands/deploy/deploy.d.ts.map +1 -0
  9. package/dist/commands/deploy/index.d.ts +3 -0
  10. package/dist/commands/deploy/index.d.ts.map +1 -0
  11. package/dist/commands/deploy/util/FileLock.d.ts +14 -0
  12. package/dist/commands/deploy/util/FileLock.d.ts.map +1 -0
  13. package/dist/commands/deploy/util/PromiseUtil.d.ts +14 -0
  14. package/dist/commands/deploy/util/PromiseUtil.d.ts.map +1 -0
  15. package/dist/commands/deploy/util/createArchive.d.ts +10 -0
  16. package/dist/commands/deploy/util/createArchive.d.ts.map +1 -0
  17. package/dist/commands/deploy/util/execPromise.d.ts +4 -0
  18. package/dist/commands/deploy/util/execPromise.d.ts.map +1 -0
  19. package/dist/commands/deploy/util/wait.d.ts +9 -0
  20. package/dist/commands/deploy/util/wait.d.ts.map +1 -0
  21. package/dist/commands/esbuild/ESBuildProgram.d.ts +1 -2
  22. package/dist/commands/esbuild/ESBuildProgram.d.ts.map +1 -1
  23. package/dist/commands/generate/GenerateProgram.d.ts.map +1 -1
  24. package/dist/commands/sync/SyncProgram.d.ts.map +1 -1
  25. package/dist/index.esm.js +1 -1
  26. package/dist/index.esm.js.map +2 -2
  27. package/dist/index.js +2 -2
  28. package/dist/index.js.map +2 -2
  29. package/dist/utils/nodeCacheDir.d.ts +2 -0
  30. package/dist/utils/nodeCacheDir.d.ts.map +1 -0
  31. package/package.json +73 -66
  32. package/src/bin.ts +3 -2
  33. package/src/commands/deploy/DeployService.ts +174 -0
  34. package/src/commands/deploy/__tests__/DeployService.test.ts +75 -0
  35. package/src/commands/deploy/__tests__/FileLock.test.ts +27 -0
  36. package/src/commands/deploy/__tests__/conf.test.ts +29 -0
  37. package/src/commands/deploy/__tests__/simpleGit.test.ts +34 -0
  38. package/src/commands/deploy/__tests__/util/deployGhPageWorker.ts +16 -0
  39. package/src/commands/deploy/deploy.ts +48 -0
  40. package/src/commands/deploy/index.ts +8 -0
  41. package/src/commands/deploy/util/FileLock.ts +31 -0
  42. package/src/commands/deploy/util/PromiseUtil.ts +34 -0
  43. package/src/commands/deploy/util/createArchive.ts +30 -0
  44. package/src/commands/deploy/util/execPromise.ts +13 -0
  45. package/src/commands/deploy/util/wait.ts +23 -0
  46. package/src/commands/esbuild/ESBuildProgram.ts +3 -12
  47. package/src/commands/esbuild/__tests__/.temp/getDeps/package.json +1 -0
  48. package/src/commands/esbuild/__tests__/ESBuildProgram.test.ts +0 -1
  49. package/src/commands/generate/GenerateProgram.ts +3 -1
  50. package/src/commands/generate/__tests__/.temp/test-cli/CHANGELOG.md +1 -0
  51. package/src/commands/generate/__tests__/.temp/test-cli/README.md +1 -0
  52. package/src/commands/generate/__tests__/.temp/test-cli/bin.js +3 -0
  53. package/src/commands/generate/__tests__/.temp/test-cli/package.json +44 -0
  54. package/src/commands/generate/__tests__/.temp/test-cli/src/bin.ts +13 -0
  55. package/src/commands/generate/__tests__/.temp/test-cli/src/index.ts +1 -0
  56. package/src/commands/generate/__tests__/.temp/test-cli/tsconfig.json +28 -0
  57. package/src/commands/generate/__tests__/GenerateProgram.test.ts +17 -17
  58. package/src/commands/sync/SyncProgram.ts +15 -41
  59. package/src/commands/sync/__tests__/SyncProgram.test.ts +13 -1
  60. package/src/utils/__tests__/nodeCacheDir.test.ts +6 -0
  61. package/src/utils/nodeCacheDir.ts +54 -0
  62. package/templates/cli/package.json +4 -10
  63. package/templates/cli/tsconfig.json +28 -28
  64. package/templates/lib/package.json +2 -8
  65. package/templates/lib/tsconfig.json +28 -28
  66. package/tsconfig.json +34 -34
  67. package/src/commands/sync/__tests__/.temp/lerna.json +0 -6
  68. package/src/commands/sync/__tests__/.temp/package.json +0 -58
@@ -13,13 +13,9 @@ import { PathUtil } from '../../PathUtil'
13
13
 
14
14
  export async function mergeJson(base: string, json: object): Promise<void> {
15
15
  const pkgJsonFilePath = path.resolve(base, './package.json')
16
- await writeJson(
17
- pkgJsonFilePath,
18
- merge(await readJson(pkgJsonFilePath), json),
19
- {
20
- spaces: 2,
21
- },
22
- )
16
+ await writeJson(pkgJsonFilePath, merge(await readJson(pkgJsonFilePath), json), {
17
+ spaces: 2,
18
+ })
23
19
  }
24
20
 
25
21
  export type SyncConfigType =
@@ -68,10 +64,7 @@ export class SyncProgram {
68
64
  } as PackageJson)
69
65
  },
70
66
  async when(): Promise<boolean> {
71
- return (
72
- (await isNpmPackage()) &&
73
- ((await isYarnRoot()) || !(await isYarnSubModule()))
74
- )
67
+ return (await isNpmPackage()) && ((await isYarnRoot()) || !(await isYarnSubModule()))
75
68
  },
76
69
  },
77
70
  {
@@ -91,23 +84,14 @@ export class SyncProgram {
91
84
  } as PackageJson)
92
85
  },
93
86
  async when(): Promise<boolean> {
94
- return (
95
- (await isNpmPackage()) &&
96
- ((await isYarnRoot()) || !(await isYarnSubModule()))
97
- )
87
+ return (await isNpmPackage()) && ((await isYarnRoot()) || !(await isYarnSubModule()))
98
88
  },
99
89
  },
100
90
  {
101
91
  type: 'gitignore',
102
92
  handler: async () => {
103
93
  const gitignorePath = path.resolve(this.base, '.gitignore')
104
- await writeFile(
105
- gitignorePath,
106
- await readFile(
107
- path.resolve(PathUtil.RootPath, '_gitignore'),
108
- 'utf-8',
109
- ),
110
- )
94
+ await writeFile(gitignorePath, await readFile(path.resolve(PathUtil.RootPath, '_gitignore'), 'utf-8'))
111
95
  },
112
96
  },
113
97
  {
@@ -123,11 +107,7 @@ export class SyncProgram {
123
107
  } as PackageJson)
124
108
  },
125
109
  async when(): Promise<boolean> {
126
- return (
127
- (await isNpmPackage()) &&
128
- !(await isIncludeDep(['vue'])) &&
129
- !(await isIncludeDep(['react']))
130
- )
110
+ return (await isNpmPackage()) && !(await isIncludeDep(['vue'])) && !(await isIncludeDep(['react']))
131
111
  },
132
112
  },
133
113
  {
@@ -154,6 +134,10 @@ export class SyncProgram {
154
134
  preset: 'ts-jest',
155
135
  testMatch: ['<rootDir>/src/**/__tests__/*.test.ts'],
156
136
  },
137
+ devDependencies: {
138
+ jest: '^27.4.3',
139
+ 'ts-jest': '^27.0.7',
140
+ },
157
141
  })
158
142
  },
159
143
  },
@@ -171,10 +155,7 @@ export class SyncProgram {
171
155
  }
172
156
  let config = {
173
157
  scripts: {
174
- postinstall: appendScript(
175
- json?.scripts?.postinstall,
176
- 'npx simple-git-hooks',
177
- ),
158
+ postinstall: appendScript(json?.scripts?.postinstall, 'npx simple-git-hooks'),
178
159
  },
179
160
  'simple-git-hooks': {
180
161
  'pre-commit': 'yarn lint-staged',
@@ -197,26 +178,19 @@ export class SyncProgram {
197
178
  await mergeJson(this.base, config as PackageJson)
198
179
  },
199
180
  async when(): Promise<boolean> {
200
- return (
201
- (await isNpmPackage()) &&
202
- ((await isYarnRoot()) || !(await isYarnSubModule()))
203
- )
181
+ return (await isNpmPackage()) && ((await isYarnRoot()) || !(await isYarnSubModule()))
204
182
  },
205
183
  },
206
184
  ]
207
185
 
208
186
  async sync(): Promise<void> {
209
- const { sync } = (await readJson(
210
- path.resolve(this.base, 'package.json'),
211
- )) as {
187
+ const { sync } = (await readJson(path.resolve(this.base, 'package.json'))) as {
212
188
  sync?: SyncConfigType[]
213
189
  }
214
190
  if (!sync) {
215
191
  return
216
192
  }
217
- const syncConfigs = this.syncConfigs.filter((config) =>
218
- sync.includes(config.type),
219
- )
193
+ const syncConfigs = this.syncConfigs.filter((config) => sync.includes(config.type))
220
194
  for (const syncConfig of syncConfigs) {
221
195
  await syncConfig.handler()
222
196
  }
@@ -30,7 +30,7 @@ describe('测试 SyncProgram', () => {
30
30
  workspaces,
31
31
  } as PackageJson)
32
32
  await syncProgram.sync()
33
- }, 100_000)
33
+ })
34
34
 
35
35
  it.skip('测试初始化同步配置', async () => {
36
36
  await writeJson(path.resolve(tempPath, 'lerna.json'), {})
@@ -42,6 +42,18 @@ describe('测试 SyncProgram', () => {
42
42
  await syncProgram.init()
43
43
  expect(((await readJson(file)).sync as string[]).length).toBeGreaterThan(0)
44
44
  }, 100_000)
45
+
46
+ it('测试同步 jest', async () => {
47
+ const jsonPath = path.resolve(tempPath, 'package.json')
48
+ await writeJson(jsonPath, {
49
+ name: 'temp',
50
+ sync: ['jest'] as SyncConfigType[],
51
+ } as PackageJson)
52
+ await syncProgram.sync()
53
+ const json = (await readJson(jsonPath)) as PackageJson
54
+ const devDeps = Object.keys(json.devDependencies!)
55
+ expect(devDeps.includes('jest') && devDeps.includes('ts-jest')).toBeTruthy()
56
+ })
45
57
  })
46
58
 
47
59
  it('测试 lodash-es.merge', () => {
@@ -0,0 +1,6 @@
1
+ import { nodeCacheDir } from '../nodeCacheDir'
2
+
3
+ it('测试 nodeCacheDir', () => {
4
+ const res = nodeCacheDir('liuli-cli')
5
+ console.log(res)
6
+ })
@@ -0,0 +1,54 @@
1
+ /*
2
+ copy by https://github.com/LinusU/node-cachedir
3
+ */
4
+ import * as os from 'os'
5
+ import * as path from 'path'
6
+
7
+ function posix(id: string) {
8
+ const cacheHome = process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache')
9
+ return path.join(cacheHome, id)
10
+ }
11
+
12
+ function darwin(id: string) {
13
+ return path.join(os.homedir(), 'Library', 'Caches', id)
14
+ }
15
+
16
+ function win32(id: string) {
17
+ const appData = process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local')
18
+ return path.join(appData, id, 'Cache')
19
+ }
20
+
21
+ const implementation = (function () {
22
+ switch (os.platform()) {
23
+ case 'darwin':
24
+ return darwin
25
+ case 'win32':
26
+ return win32
27
+ case 'aix':
28
+ case 'android':
29
+ case 'freebsd':
30
+ case 'linux':
31
+ case 'netbsd':
32
+ case 'openbsd':
33
+ case 'sunos':
34
+ return posix
35
+ default:
36
+ console.error(
37
+ `(node:${
38
+ process.pid
39
+ }) [cachedir] Warning: the platform "${os.platform()}" is not currently supported by node-cachedir, falling back to "posix". Please file an issue with your platform here: https://github.com/LinusU/node-cachedir/issues/new`,
40
+ )
41
+ return posix
42
+ }
43
+ })()
44
+
45
+ export function nodeCacheDir(id: string): string {
46
+ if (id.length === 0) {
47
+ throw new Error('id cannot be empty')
48
+ }
49
+ if (/[^0-9a-zA-Z-]/.test(id)) {
50
+ throw new Error('id cannot contain special characters')
51
+ }
52
+
53
+ return implementation(id)
54
+ }
@@ -8,11 +8,7 @@
8
8
  "scripts": {
9
9
  "build": "rimraf dist && liuli-cli build cli",
10
10
  "dev": "liuli-cli build cli -w",
11
- "start": "esno src/bin.ts",
12
- "docs:server": "live-server docs",
13
- "docs:dev": "typedoc --watch",
14
- "docs:build": "rimraf docs && typedoc",
15
- "docs:deploy": "yarn docs:build && gh-pages -d docs/ -e / -a"
11
+ "start": "esno src/bin.ts"
16
12
  },
17
13
  "bin": {
18
14
  "cli-name": "./bin.js"
@@ -22,23 +18,21 @@
22
18
  },
23
19
  "dependencies": {
24
20
  "commander": "^8.2.0",
25
- "fs-extra": "^10.0.0",
26
- "inquirer": "^8.1.5"
21
+ "enquirer": "^2.3.6",
22
+ "fs-extra": "^10.0.0"
27
23
  },
28
24
  "devDependencies": {
29
- "@liuli-util/cli": "^3.11.1",
25
+ "@liuli-util/cli": "workspace:*",
30
26
  "@types/fs-extra": "^9.0.13",
31
27
  "@types/inquirer": "^8.1.2",
32
28
  "@types/jest": "^27.0.2",
33
29
  "@types/lodash": "^4.14.173",
34
30
  "@types/node": "^16.9.6",
35
31
  "esno": "^0.9.1",
36
- "gh-pages": "^3.2.3",
37
32
  "jest": "^27.2.1",
38
33
  "rimraf": "^3.0.2",
39
34
  "ts-jest": "^27.0.5",
40
35
  "type-fest": "^2.3.4",
41
- "typedoc": "^0.22.4",
42
36
  "typescript": "^4.4.3"
43
37
  }
44
38
  }
@@ -1,28 +1,28 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "lib": [
5
- "ESNext"
6
- ],
7
- "outDir": "./dist",
8
- "skipLibCheck": true,
9
- "esModuleInterop": true,
10
- "strict": true,
11
- "module": "ESNext",
12
- "moduleResolution": "node",
13
- "sourceMap": true,
14
- "declaration": true,
15
- "declarationMap": true
16
- },
17
- "include": [
18
- "src"
19
- ],
20
- "typedocOptions": {
21
- "entryPoints": [
22
- "src/index.ts"
23
- ],
24
- "out": "docs",
25
- "readme": "README.md",
26
- "gitRemote": "origin"
27
- }
28
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "lib": [
5
+ "ESNext"
6
+ ],
7
+ "outDir": "./dist",
8
+ "skipLibCheck": true,
9
+ "esModuleInterop": true,
10
+ "strict": true,
11
+ "module": "ESNext",
12
+ "moduleResolution": "node",
13
+ "sourceMap": true,
14
+ "declaration": true,
15
+ "declarationMap": true
16
+ },
17
+ "include": [
18
+ "src"
19
+ ],
20
+ "typedocOptions": {
21
+ "entryPoints": [
22
+ "src/index.ts"
23
+ ],
24
+ "out": "docs",
25
+ "readme": "README.md",
26
+ "gitRemote": "origin"
27
+ }
28
+ }
@@ -8,25 +8,19 @@
8
8
  "license": "MIT",
9
9
  "scripts": {
10
10
  "build": "rimraf dist && liuli-cli build pkg",
11
- "dev": "liuli-cli build pkg -w",
12
- "docs:server": "live-server docs",
13
- "docs:dev": "typedoc --watch",
14
- "docs:build": "rimraf docs && typedoc",
15
- "docs:deploy": "yarn docs:build && gh-pages -d docs/ -e / -a"
11
+ "dev": "liuli-cli build pkg -w"
16
12
  },
17
13
  "jest": {
18
14
  "preset": "ts-jest"
19
15
  },
20
16
  "devDependencies": {
21
- "@liuli-util/cli": "^3.11.1",
17
+ "@liuli-util/cli": "workspace:*",
22
18
  "@types/jest": "^27.0.2",
23
19
  "esno": "^0.9.1",
24
- "gh-pages": "^3.2.3",
25
20
  "jest": "^27.2.1",
26
21
  "rimraf": "^3.0.2",
27
22
  "ts-jest": "^27.0.5",
28
23
  "type-fest": "^2.3.4",
29
- "typedoc": "^0.22.4",
30
24
  "typescript": "^4.4.3"
31
25
  }
32
26
  }
@@ -1,28 +1,28 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "lib": [
5
- "ESNext"
6
- ],
7
- "outDir": "./dist",
8
- "skipLibCheck": true,
9
- "esModuleInterop": true,
10
- "strict": true,
11
- "module": "ESNext",
12
- "moduleResolution": "node",
13
- "sourceMap": true,
14
- "declaration": true,
15
- "declarationMap": true
16
- },
17
- "include": [
18
- "src"
19
- ],
20
- "typedocOptions": {
21
- "entryPoints": [
22
- "src/index.ts"
23
- ],
24
- "out": "docs",
25
- "readme": "README.md",
26
- "gitRemote": "origin"
27
- }
28
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "lib": [
5
+ "ESNext"
6
+ ],
7
+ "outDir": "./dist",
8
+ "skipLibCheck": true,
9
+ "esModuleInterop": true,
10
+ "strict": true,
11
+ "module": "ESNext",
12
+ "moduleResolution": "node",
13
+ "sourceMap": true,
14
+ "declaration": true,
15
+ "declarationMap": true
16
+ },
17
+ "include": [
18
+ "src"
19
+ ],
20
+ "typedocOptions": {
21
+ "entryPoints": [
22
+ "src/index.ts"
23
+ ],
24
+ "out": "docs",
25
+ "readme": "README.md",
26
+ "gitRemote": "origin"
27
+ }
28
+ }
package/tsconfig.json CHANGED
@@ -1,34 +1,34 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "lib": [
5
- "ESNext"
6
- ],
7
- "outDir": "./dist",
8
- "skipLibCheck": true,
9
- "esModuleInterop": true,
10
- "strict": true,
11
- "module": "ESNext",
12
- "moduleResolution": "node",
13
- "sourceMap": true,
14
- "declaration": true,
15
- "declarationMap": true,
16
- "resolveJsonModule": true
17
- },
18
- "include": [
19
- "src"
20
- ],
21
- "typedocOptions": {
22
- "entryPoints": [
23
- "src/index.ts"
24
- ],
25
- "out": "docs",
26
- "readme": "README.md",
27
- "gitRemote": "origin"
28
- },
29
- "ts-node": {
30
- "compilerOptions": {
31
- "module": "CommonJS"
32
- }
33
- }
34
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "lib": [
5
+ "ESNext"
6
+ ],
7
+ "outDir": "./dist",
8
+ "skipLibCheck": true,
9
+ "esModuleInterop": true,
10
+ "strict": true,
11
+ "module": "ESNext",
12
+ "moduleResolution": "node",
13
+ "sourceMap": true,
14
+ "declaration": true,
15
+ "declarationMap": true,
16
+ "resolveJsonModule": true
17
+ },
18
+ "include": [
19
+ "src"
20
+ ],
21
+ "typedocOptions": {
22
+ "entryPoints": [
23
+ "src/index.ts"
24
+ ],
25
+ "out": "docs",
26
+ "readme": "README.md",
27
+ "gitRemote": "origin"
28
+ },
29
+ "ts-node": {
30
+ "compilerOptions": {
31
+ "module": "CommonJS"
32
+ }
33
+ }
34
+ }
@@ -1,6 +0,0 @@
1
- {
2
- "packages": [
3
- "packages/common/*",
4
- "apps/*"
5
- ]
6
- }
@@ -1,58 +0,0 @@
1
- {
2
- "name": "temp",
3
- "license": "mit",
4
- "private": true,
5
- "sync": [
6
- "prettier",
7
- "commitlint",
8
- "workspaces",
9
- "gitignore",
10
- "simplehooks",
11
- "eslint-ts",
12
- "jest"
13
- ],
14
- "workspaces": [
15
- "packages/common/*",
16
- "apps/*"
17
- ],
18
- "prettier": "@liuli-util/prettier-standard-config",
19
- "devDependencies": {
20
- "prettier": "^2.3.2",
21
- "@liuli-util/prettier-standard-config": "^0.1.0",
22
- "@commitlint/cli": "^12.1.4",
23
- "@liuli-util/commitlint-standard-config": "^0.1.6",
24
- "@liuli-util/eslint-config-ts": "^0.2.0",
25
- "simple-git-hooks": "^2.5.1",
26
- "lint-staged": "^11.1.1"
27
- },
28
- "simple-git-hooks": {
29
- "commit-msg": "yarn commitlint --edit $1",
30
- "pre-commit": "yarn lint-staged"
31
- },
32
- "commitlint": {
33
- "extends": [
34
- "@liuli-util/commitlint-standard-config"
35
- ]
36
- },
37
- "eslintConfig": {
38
- "extends": [
39
- "@liuli-util/eslint-config-ts"
40
- ]
41
- },
42
- "jest": {
43
- "preset": "ts-jest",
44
- "testMatch": [
45
- "<rootDir>/src/**/__tests__/*.test.ts"
46
- ]
47
- },
48
- "scripts": {
49
- "postinstall": "npx simple-git-hooks"
50
- },
51
- "lint-staged": {
52
- "*.{ts,tsx,js,jsx,css,vue}": [
53
- "prettier --write",
54
- "eslint --fix",
55
- "git add"
56
- ]
57
- }
58
- }