@liuli-util/cli 3.17.2 → 3.19.1

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 (55) hide show
  1. package/CHANGELOG.md +17 -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/SyncProgram.d.ts.map +1 -1
  16. package/dist/commands/sync/when.d.ts.map +1 -1
  17. package/dist/index.esm.js +5 -3
  18. package/dist/index.esm.js.map +2 -2
  19. package/dist/index.js +5 -3
  20. package/dist/index.js.map +2 -2
  21. package/package.json +73 -73
  22. package/src/commands/deploy/DeployService.ts +76 -45
  23. package/src/commands/deploy/__tests__/.temp/test.lock +0 -0
  24. package/src/commands/deploy/__tests__/DeployService.test.ts +52 -20
  25. package/src/commands/deploy/__tests__/conf.test.ts +0 -1
  26. package/src/commands/deploy/__tests__/simpleGit.test.ts +6 -3
  27. package/src/commands/deploy/__tests__/util/deployGhPageWorker.ts +3 -2
  28. package/src/commands/deploy/util/validate.ts +18 -0
  29. package/src/commands/esbuild/ESBuildProgram.ts +25 -5
  30. package/src/commands/esbuild/__tests__/.temp/package.json +1 -0
  31. package/src/commands/esbuild/__tests__/.temp/src/index.ts +1 -0
  32. package/src/commands/esbuild/__tests__/ESBuildProgram.test.ts +50 -13
  33. package/src/commands/esbuild/index.ts +26 -13
  34. package/src/commands/esbuild/util/esbuildPlugins.ts +37 -1
  35. package/src/commands/generate/__tests__/.temp/README.md +1 -0
  36. package/src/commands/generate/__tests__/.temp/package.json +3 -0
  37. package/src/commands/generate/__tests__/.temp/test-cli/CHANGELOG.md +1 -0
  38. package/src/commands/generate/__tests__/.temp/test-cli/README.md +1 -0
  39. package/src/commands/generate/__tests__/.temp/test-cli/bin.js +3 -0
  40. package/src/commands/generate/__tests__/.temp/test-cli/package.json +33 -0
  41. package/src/commands/generate/__tests__/.temp/test-cli/src/bin.ts +13 -0
  42. package/src/commands/generate/__tests__/.temp/test-cli/src/index.ts +1 -0
  43. package/src/commands/generate/__tests__/.temp/test-cli/tsconfig.json +28 -0
  44. package/src/commands/sync/SyncProgram.ts +5 -7
  45. package/src/commands/sync/__tests__/SyncProgram.test.ts +1 -1
  46. package/src/commands/sync/__tests__/when.test.ts +3 -7
  47. package/src/commands/sync/when.ts +8 -23
  48. package/templates/cli/package.json +5 -10
  49. package/templates/cli/src/bin.ts +1 -1
  50. package/templates/lib/package.json +4 -11
  51. package/LICENSE +0 -21
  52. package/dist/commands/deploy/util/FileLock.d.ts +0 -14
  53. package/dist/commands/deploy/util/FileLock.d.ts.map +0 -1
  54. package/src/commands/deploy/__tests__/FileLock.test.ts +0 -27
  55. package/src/commands/deploy/util/FileLock.ts +0 -31
@@ -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,28 @@
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
- "@types/lodash": "^4.14.173",
30
25
  "@types/node": "^16.9.6",
31
26
  "esno": "^0.9.1",
32
- "jest": "^27.2.1",
27
+ "jest": "^27.4.7",
33
28
  "rimraf": "^3.0.2",
34
- "ts-jest": "^27.0.5",
29
+ "ts-jest": "^27.1.3",
35
30
  "type-fest": "^2.3.4",
36
- "typescript": "^4.4.3"
31
+ "typescript": "^4.5.5"
37
32
  }
38
33
  }
@@ -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 () => {
@@ -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
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 rxliuli
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -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
- }