@liuli-util/cli 3.17.1 → 3.19.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 (54) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +30 -42
  3. package/README.zh-CN.md +130 -0
  4. package/dist/bin.js +114 -94
  5. package/dist/bin.js.map +3 -3
  6. package/dist/commands/deploy/DeployService.d.ts +25 -7
  7. package/dist/commands/deploy/DeployService.d.ts.map +1 -1
  8. package/dist/commands/deploy/util/validate.d.ts +8 -0
  9. package/dist/commands/deploy/util/validate.d.ts.map +1 -0
  10. package/dist/commands/esbuild/ESBuildProgram.d.ts +5 -2
  11. package/dist/commands/esbuild/ESBuildProgram.d.ts.map +1 -1
  12. package/dist/commands/esbuild/index.d.ts.map +1 -1
  13. package/dist/commands/esbuild/util/esbuildPlugins.d.ts +1 -0
  14. package/dist/commands/esbuild/util/esbuildPlugins.d.ts.map +1 -1
  15. package/dist/commands/sync/when.d.ts.map +1 -1
  16. package/dist/index.esm.js +4 -2
  17. package/dist/index.esm.js.map +2 -2
  18. package/dist/index.js +4 -2
  19. package/dist/index.js.map +2 -2
  20. package/package.json +16 -15
  21. package/src/commands/deploy/DeployService.ts +83 -45
  22. package/src/commands/deploy/__tests__/.temp/test.lock +0 -0
  23. package/src/commands/deploy/__tests__/DeployService.test.ts +52 -20
  24. package/src/commands/deploy/__tests__/conf.test.ts +0 -1
  25. package/src/commands/deploy/__tests__/simpleGit.test.ts +24 -1
  26. package/src/commands/deploy/__tests__/util/deployGhPageWorker.ts +3 -2
  27. package/src/commands/deploy/util/validate.ts +18 -0
  28. package/src/commands/esbuild/ESBuildProgram.ts +25 -5
  29. package/src/commands/esbuild/__tests__/.temp/package.json +1 -0
  30. package/src/commands/esbuild/__tests__/.temp/src/index.ts +1 -0
  31. package/src/commands/esbuild/__tests__/ESBuildProgram.test.ts +50 -13
  32. package/src/commands/esbuild/index.ts +26 -13
  33. package/src/commands/esbuild/util/esbuildPlugins.ts +37 -1
  34. package/src/commands/generate/__tests__/.temp/README.md +1 -0
  35. package/src/commands/generate/__tests__/.temp/package.json +3 -0
  36. package/src/commands/generate/__tests__/.temp/test-cli/package.json +8 -18
  37. package/src/commands/generate/__tests__/.temp/test-cli/src/bin.ts +1 -1
  38. package/src/commands/generate/__tests__/.temp/test-cli/tsconfig.json +28 -28
  39. package/src/commands/sync/SyncProgram.ts +1 -1
  40. package/src/commands/sync/__tests__/.temp/package.json +16 -0
  41. package/src/commands/sync/__tests__/SyncProgram.test.ts +1 -1
  42. package/src/commands/sync/__tests__/when.test.ts +3 -7
  43. package/src/commands/sync/when.ts +8 -23
  44. package/templates/cli/package.json +5 -9
  45. package/templates/cli/src/bin.ts +1 -1
  46. package/templates/cli/tsconfig.json +28 -28
  47. package/templates/lib/package.json +4 -11
  48. package/templates/lib/tsconfig.json +28 -28
  49. package/tsconfig.json +34 -34
  50. package/dist/commands/deploy/util/FileLock.d.ts +0 -14
  51. package/dist/commands/deploy/util/FileLock.d.ts.map +0 -1
  52. package/src/commands/deploy/__tests__/FileLock.test.ts +0 -27
  53. package/src/commands/deploy/util/FileLock.ts +0 -31
  54. package/src/commands/esbuild/__tests__/.temp/getDeps/package.json +0 -1
@@ -1,5 +1,5 @@
1
1
  import { pathExists, readJson } from 'fs-extra'
2
- import path from 'path'
2
+ import * as path from 'path'
3
3
  import { PackageJson } from 'type-fest'
4
4
  import { findParent } from '../../utils'
5
5
 
@@ -7,9 +7,7 @@ import { findParent } from '../../utils'
7
7
  * 判断是否包含 package.json
8
8
  * @param cwd
9
9
  */
10
- export async function isNpmPackage(
11
- cwd: string = process.cwd(),
12
- ): Promise<boolean> {
10
+ export async function isNpmPackage(cwd: string = process.cwd()): Promise<boolean> {
13
11
  return await pathExists(path.resolve(cwd, './package.json'))
14
12
  }
15
13
 
@@ -17,24 +15,18 @@ export async function isNpmPackage(
17
15
  * 判断是 yarn2 monorepo 项目
18
16
  * @param cwd
19
17
  */
20
- export async function isYarnRoot(
21
- cwd: string = process.cwd(),
22
- ): Promise<boolean> {
18
+ export async function isYarnRoot(cwd: string = process.cwd()): Promise<boolean> {
23
19
  if (!(await isNpmPackage(cwd))) {
24
20
  return false
25
21
  }
26
- const json = (await readJson(
27
- path.resolve(cwd, './package.json'),
28
- )) as PackageJson
22
+ const json = (await readJson(path.resolve(cwd, './package.json'))) as PackageJson
29
23
  return !!json.workspaces
30
24
  }
31
25
 
32
26
  /**
33
27
  * 判断是 yarn2 monorepo 的子模块
34
28
  */
35
- export async function isYarnSubModule(
36
- cwd: string = process.cwd(),
37
- ): Promise<boolean> {
29
+ export async function isYarnSubModule(cwd: string = process.cwd()): Promise<boolean> {
38
30
  if (!(await isNpmPackage(cwd))) {
39
31
  return false
40
32
  }
@@ -50,18 +42,11 @@ export async function isYarnSubModule(
50
42
  * @param deps
51
43
  * @param cwd
52
44
  */
53
- export async function isIncludeDep(
54
- deps: string[],
55
- cwd: string = process.cwd(),
56
- ): Promise<boolean> {
45
+ export async function isIncludeDep(deps: string[], cwd: string = process.cwd()): Promise<boolean> {
57
46
  if (!(await isNpmPackage(cwd))) {
58
47
  return false
59
48
  }
60
- const json = (await readJson(
61
- path.resolve(cwd, './package.json'),
62
- )) as PackageJson
63
- const set = new Set(
64
- Object.keys({ ...json.dependencies, ...json.devDependencies }),
65
- )
49
+ const json = (await readJson(path.resolve(cwd, './package.json'))) as PackageJson
50
+ const set = new Set(Object.keys({ ...json.dependencies, ...json.devDependencies }))
66
51
  return deps.every((dep) => set.has(dep))
67
52
  }
@@ -6,33 +6,29 @@
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
8
8
  "scripts": {
9
- "build": "rimraf dist && liuli-cli build cli",
9
+ "build": "liuli-cli build cli",
10
10
  "dev": "liuli-cli build cli -w",
11
11
  "start": "esno src/bin.ts"
12
12
  },
13
13
  "bin": {
14
14
  "cli-name": "./bin.js"
15
15
  },
16
- "jest": {
17
- "preset": "ts-jest"
18
- },
19
16
  "dependencies": {
20
17
  "commander": "^8.2.0",
21
18
  "enquirer": "^2.3.6",
22
19
  "fs-extra": "^10.0.0"
23
20
  },
24
21
  "devDependencies": {
25
- "@liuli-util/cli": "workspace:*",
22
+ "@liuli-util/cli": "^3.18.0",
26
23
  "@types/fs-extra": "^9.0.13",
27
- "@types/inquirer": "^8.1.2",
28
24
  "@types/jest": "^27.0.2",
29
25
  "@types/lodash": "^4.14.173",
30
26
  "@types/node": "^16.9.6",
31
27
  "esno": "^0.9.1",
32
- "jest": "^27.2.1",
28
+ "jest": "^27.4.7",
33
29
  "rimraf": "^3.0.2",
34
- "ts-jest": "^27.0.5",
30
+ "ts-jest": "^27.1.3",
35
31
  "type-fest": "^2.3.4",
36
- "typescript": "^4.4.3"
32
+ "typescript": "^4.5.5"
37
33
  }
38
34
  }
@@ -1,5 +1,5 @@
1
1
  import { Command } from 'commander'
2
- import { prompt } from 'inquirer'
2
+ import { prompt } from 'enquirer'
3
3
 
4
4
  new Command()
5
5
  .action(async () => {
@@ -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
+ }
@@ -7,20 +7,13 @@
7
7
  "types": "dist/index.d.ts",
8
8
  "license": "MIT",
9
9
  "scripts": {
10
- "build": "rimraf dist && liuli-cli build pkg",
11
- "dev": "liuli-cli build pkg -w"
12
- },
13
- "jest": {
14
- "preset": "ts-jest"
10
+ "build": "liuli-cli build lib",
11
+ "dev": "liuli-cli build lib -w"
15
12
  },
16
13
  "devDependencies": {
17
- "@liuli-util/cli": "workspace:*",
18
- "@types/jest": "^27.0.2",
19
- "esno": "^0.9.1",
20
- "jest": "^27.2.1",
14
+ "@liuli-util/cli": "^3.18.0",
21
15
  "rimraf": "^3.0.2",
22
- "ts-jest": "^27.0.5",
23
16
  "type-fest": "^2.3.4",
24
- "typescript": "^4.4.3"
17
+ "typescript": "^4.5.5"
25
18
  }
26
19
  }
@@ -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,14 +0,0 @@
1
- export declare class FileLock {
2
- private readonly lockFilePath;
3
- constructor(lockFilePath: string);
4
- private lockId?;
5
- /**
6
- * 加锁
7
- */
8
- lock(): Promise<boolean>;
9
- /**
10
- * 解锁
11
- */
12
- unlock(): Promise<void>;
13
- }
14
- //# sourceMappingURL=FileLock.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FileLock.d.ts","sourceRoot":"","sources":["../../../../src/commands/deploy/util/FileLock.ts"],"names":[],"mappings":"AAGA,qBAAa,QAAQ;IACP,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAAZ,YAAY,EAAE,MAAM;IAEjD,OAAO,CAAC,MAAM,CAAC,CAAQ;IAEvB;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAS9B;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAO9B"}
@@ -1,27 +0,0 @@
1
- import * as path from 'path'
2
- import { FileLock } from '../util/FileLock'
3
- import { AsyncArray } from '../../../utils'
4
- import { wait } from '../util/wait'
5
-
6
- describe('测试文件锁', () => {
7
- const tempPath = path.resolve(__dirname, '.temp/test.lock')
8
- it('基本示例', async () => {
9
- const fileLock = new FileLock(tempPath)
10
- expect(await fileLock.lock()).toBeTruthy()
11
- expect(await fileLock.lock()).toBeFalsy()
12
- await fileLock.unlock()
13
- expect(await fileLock.lock()).toBeTruthy()
14
- await fileLock.unlock()
15
- })
16
- it('测试并发调用', async () => {
17
- const start = Date.now()
18
- await AsyncArray.forEach(Array(10).fill(0), async () => {
19
- const fileLock = new FileLock(tempPath)
20
- await wait(() => fileLock.lock())
21
- await wait(100)
22
- await fileLock.unlock()
23
- })
24
- const time = Date.now() - start
25
- expect(time).toBeLessThan(3000)
26
- })
27
- })
@@ -1,31 +0,0 @@
1
- import { close, open, remove } from 'fs-extra'
2
- import path from 'path'
3
-
4
- export class FileLock {
5
- constructor(private readonly lockFilePath: string) {}
6
-
7
- private lockId?: number
8
-
9
- /**
10
- * 加锁
11
- */
12
- async lock(): Promise<boolean> {
13
- try {
14
- this.lockId = await open(path.resolve(this.lockFilePath), 'wx')
15
- return true
16
- } catch (e) {
17
- return false
18
- }
19
- }
20
-
21
- /**
22
- * 解锁
23
- */
24
- async unlock(): Promise<void> {
25
- if (!this.lockId) {
26
- throw new Error('未加锁')
27
- }
28
- await remove(path.resolve(this.lockFilePath))
29
- close(this.lockId)
30
- }
31
- }
@@ -1 +0,0 @@
1
- {"devDependencies":{"@types/node":"16"},"dependencies":{"ora":"^6"},"peerDependencies":{"typescript":"^4"}}