@fanwang/pack-util 2.0.1 → 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
@@ -42,13 +42,12 @@ pack-util upload
42
42
  ```
43
43
 
44
44
  2. 输入参数
45
-
46
- ```
47
- ? Please input your Nexus url host (eg: http://xx.xx.xx.xx:xxxx): http://xx.xx.xx.xx:8081/
48
- ? Please input your Nexus npm repository (eg: localNpm): localNpm
49
- ? login to Nexus by username: admin
50
- ? password: [hidden]
51
- ```
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
+ ```
52
51
 
53
52
  3. 如果出现上传失败,删除其他成功上传的包,然后重新执行上传(也可以直接重试上传)。
54
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.1')
15
+ .version('2.0.4')
16
16
 
17
17
  const getPackageInfos = async (packageManager) => {
18
18
  if (packageManager === 'yarn') {
@@ -53,17 +53,31 @@ const downloadPackage = async (packageUrl) => {
53
53
  const urlObj = url.parse(packageUrl)
54
54
  const filename = urlObj.pathname.substring(urlObj.pathname.lastIndexOf('/') + 1)
55
55
  const fileStream = createWriteStream('./node_modules_pack/' + filename)
56
- await fetch(packageUrl).then(res => {
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 {
57
67
  res.body.pipe(fileStream)
58
- })
59
- fileStream.on('finish', () => {
60
- fileStream.close()
61
- index++
62
- process.stdout.clearLine()
63
- process.stdout.cursorTo(0)
64
- process.stdout.write(`${index}: ${filename}`) // 在同一行打印处理进度
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
+ })
65
79
  return filename
66
- })
80
+ }
67
81
  }
68
82
 
69
83
 
@@ -112,16 +126,16 @@ program
112
126
  },
113
127
  ]
114
128
  inquirer.prompt(questions).then(options => {
115
- getPackageInfos(options.packageManager).then(packages => {
129
+ getPackageInfos(options.packageManager).then(async (packages) => {
116
130
  console.log(`Total ${packages.length} packages to be packed, please wait...`)
117
131
  mkdirSync('./node_modules_pack', { recursive: true })
118
132
  if (options.packageManager === 'yarn') {
119
133
  for (const packageUrl of packages) {
120
- downloadPackage(packageUrl)
134
+ await downloadPackage(packageUrl)
121
135
  }
122
136
  } else {
123
137
  for (const packageName of packages) {
124
- packPackage(packageName)
138
+ await packPackage(packageName)
125
139
  }
126
140
  }
127
141
  })
package/package.json CHANGED
@@ -1,36 +1,40 @@
1
- {
2
- "name": "@fanwang/pack-util",
3
- "version": "2.0.1",
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
- },
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
+ }