@fanwang/pack-util 2.0.0 → 2.0.4

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/README.en-US.md CHANGED
@@ -32,13 +32,12 @@ pack-util upload
32
32
  ```
33
33
 
34
34
  2. Input some params
35
-
36
- ```
37
- ? Please input your Nexus url host (eg: http://xx.xx.xx.xx:xxxx): http://xx.xx.xx.xx:8081/
38
- ? Please input your Nexus npm repository (eg: localNpm): localNpm
39
- ? login to Nexus by username: admin
40
- ? password: [hidden]
41
- ```
35
+ ```
36
+ ? Please input your Nexus url host (eg: http://xx.xx.xx.xx:xxxx): http://xx.xx.xx.xx:8081/
37
+ ? Please input your Nexus npm repository (eg: localNpm): localNpm
38
+ ? login to Nexus by username: admin
39
+ ? password: [hidden]
40
+ ```
42
41
 
43
42
  3. If there is upload error, delete other packages within the ./node_modules_pack, and upload again.
44
43
 
package/README.md CHANGED
@@ -21,8 +21,9 @@ npm install -g @fanwang/pack-util
21
21
  Set-ExecutionPolicy RemoteSigned
22
22
  ```
23
23
 
24
- 建议先将源仓库设为阿里镜像仓库,这样打包速度更快:
24
+ 建议先将源仓库设为阿里镜像仓库,这样打包速度更快(yarn 和 npm 需要同时设置):
25
25
  ```sh
26
+ yarn config set registry https://registry.npmmirror.com
26
27
  npm config set registry https://registry.npmmirror.com
27
28
  ```
28
29
 
@@ -41,13 +42,12 @@ pack-util upload
41
42
  ```
42
43
 
43
44
  2. 输入参数
44
-
45
- ```
46
- ? Please input your Nexus url host (eg: http://xx.xx.xx.xx:xxxx): http://xx.xx.xx.xx:8081/
47
- ? Please input your Nexus npm repository (eg: localNpm): localNpm
48
- ? login to Nexus by username: admin
49
- ? password: [hidden]
50
- ```
45
+ ```
46
+ ? Please input your Nexus url host (eg: http://xx.xx.xx.xx:xxxx): http://xx.xx.xx.xx:8081/
47
+ ? Please input your Nexus npm repository (eg: localNpm): localNpm
48
+ ? login to Nexus by username: admin
49
+ ? password: [hidden]
50
+ ```
51
51
 
52
52
  3. 如果出现上传失败,删除其他成功上传的包,然后重新执行上传(也可以直接重试上传)。
53
53
 
package/bin/index.js CHANGED
@@ -12,7 +12,7 @@ const program = new Command()
12
12
  program
13
13
  .name('pack-util')
14
14
  .description('Pack all installed package in ./node_modules, and publish to Nexus self-hosted Registry.')
15
- .version('2.0.0')
15
+ .version('2.0.4')
16
16
 
17
17
  const getPackageInfos = async (packageManager) => {
18
18
  if (packageManager === 'yarn') {
@@ -52,14 +52,32 @@ const packPackage = async (packageName) => {
52
52
  const downloadPackage = async (packageUrl) => {
53
53
  const urlObj = url.parse(packageUrl)
54
54
  const filename = urlObj.pathname.substring(urlObj.pathname.lastIndexOf('/') + 1)
55
- await fetch(packageUrl).then(res => {
56
- res.body.pipe(createWriteStream('./node_modules_pack/' + filename))
57
- })
58
- index++
59
- process.stdout.clearLine()
60
- process.stdout.cursorTo(0)
61
- process.stdout.write(`${index}: ${filename}`) // 在同一行打印处理进度
62
- return filename
55
+ const fileStream = createWriteStream('./node_modules_pack/' + filename)
56
+ let res
57
+ try {
58
+ res = await fetch(packageUrl)
59
+ } catch (error) {
60
+ console.error(`Failed to download package ${packageUrl}: ${error.message}`)
61
+ return filename
62
+ }
63
+ if (!res?.ok) {
64
+ console.error(`Failed to download package ${filename}: ${res.status} ${res.statusText}`)
65
+ return filename
66
+ } else {
67
+ res.body.pipe(fileStream)
68
+ await new Promise((resolve, reject) => {
69
+ fileStream.on('finish', () => {
70
+ fileStream.close()
71
+ index++
72
+ process.stdout.clearLine()
73
+ process.stdout.cursorTo(0)
74
+ process.stdout.write(`${index}: ${filename}`) // 在同一行打印处理进度
75
+ resolve(filename)
76
+ })
77
+ fileStream.on('error', reject)
78
+ })
79
+ return filename
80
+ }
63
81
  }
64
82
 
65
83
 
@@ -108,16 +126,16 @@ program
108
126
  },
109
127
  ]
110
128
  inquirer.prompt(questions).then(options => {
111
- getPackageInfos(options.packageManager).then(packages => {
129
+ getPackageInfos(options.packageManager).then(async (packages) => {
112
130
  console.log(`Total ${packages.length} packages to be packed, please wait...`)
113
131
  mkdirSync('./node_modules_pack', { recursive: true })
114
132
  if (options.packageManager === 'yarn') {
115
133
  for (const packageUrl of packages) {
116
- downloadPackage(packageUrl)
134
+ await downloadPackage(packageUrl)
117
135
  }
118
136
  } else {
119
137
  for (const packageName of packages) {
120
- packPackage(packageName)
138
+ await packPackage(packageName)
121
139
  }
122
140
  }
123
141
  })
package/package.json CHANGED
@@ -1,36 +1,40 @@
1
- {
2
- "name": "@fanwang/pack-util",
3
- "version": "2.0.0",
4
- "description": "Pack all installed package in ./node_modules, and publish to Nexus self-hosted Registry.",
5
- "bin": {
6
- "pack-util": "./bin/index.js"
7
- },
8
- "publishConfig": {
9
- "access": "public"
10
- },
11
- "engines": {
12
- "node": ">= 12.9.0"
13
- },
14
- "type": "module",
15
- "scripts": {
16
- "test": "echo \"Error: no test specified\" && exit 1"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "https://gitee.com/vampirefan/pack-util.git"
21
- },
22
- "keywords": [
23
- "npm",
24
- "pack",
25
- "publish"
26
- ],
27
- "author": "fanwang",
28
- "license": "MIT",
29
- "dependencies": {
30
- "commander": "^9.4.1",
31
- "execa": "^6.1.0",
32
- "form-data": "^4.0.0",
33
- "inquirer": "^9.1.3",
34
- "node-fetch": "^3.3.0"
35
- }
36
- }
1
+ {
2
+ "name": "@fanwang/pack-util",
3
+ "version": "2.0.4",
4
+ "description": "Pack all installed package in ./node_modules, and publish to Nexus self-hosted Registry.",
5
+ "bin": {
6
+ "pack-util": "./bin/index.js"
7
+ },
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "engines": {
12
+ "node": ">= 16.17.0"
13
+ },
14
+ "type": "module",
15
+ "scripts": {
16
+ "test": "echo \"Error: no test specified\" && exit 1",
17
+ "release": "bumpp package.json bin/index.js"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://gitee.com/vampirefan/pack-util.git"
22
+ },
23
+ "keywords": [
24
+ "npm",
25
+ "pack",
26
+ "publish"
27
+ ],
28
+ "author": "fanwang",
29
+ "license": "MIT",
30
+ "dependencies": {
31
+ "commander": "^9.4.1",
32
+ "execa": "^6.1.0",
33
+ "form-data": "^4.0.0",
34
+ "inquirer": "^9.1.3",
35
+ "node-fetch": "^3.3.0"
36
+ },
37
+ "devDependencies": {
38
+ "bumpp": "^9.2.0"
39
+ }
40
+ }