@fanwang/pack-util 3.0.1 → 3.1.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.
- package/bin/index.js +23 -14
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -15,7 +15,7 @@ const program = new Command()
|
|
|
15
15
|
program
|
|
16
16
|
.name('pack-util')
|
|
17
17
|
.description('Pack all installed package in ./node_modules, and publish to Nexus self-hosted Registry.')
|
|
18
|
-
.version('3.0
|
|
18
|
+
.version('3.1.0')
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
const limit = pLimit(10)
|
|
@@ -51,18 +51,20 @@ const getPackageInfos = async (packageManager) => {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
var index = 0
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
// 利用 npm pack 在外网上对 dependencies 中的所有包打包。
|
|
57
|
+
// const packPackage = async (packageName) => {
|
|
58
|
+
// const { stdout } = await execa('npm', ['pack', packageName, '--pack-destination=./node_modules_pack'])
|
|
59
|
+
// index++
|
|
60
|
+
// // console.log(`${index}: ${stdout}`)
|
|
61
|
+
// process.stdout.clearLine()
|
|
62
|
+
// process.stdout.cursorTo(0)
|
|
63
|
+
// process.stdout.write(`${index}: ${stdout}`) // 在同一行打印处理进度
|
|
64
|
+
// return stdout
|
|
65
|
+
// }
|
|
65
66
|
|
|
67
|
+
// 直接利用依赖包的下载地址进行下载
|
|
66
68
|
const downloadPackage = async (packageUrl) => {
|
|
67
69
|
const urlObj = url.parse(packageUrl)
|
|
68
70
|
const filename = urlObj.pathname.substring(urlObj.pathname.lastIndexOf('/') + 1)
|
|
@@ -142,9 +144,16 @@ program
|
|
|
142
144
|
)
|
|
143
145
|
await Promise.all(downloadTasks)
|
|
144
146
|
} else {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
)
|
|
147
|
+
const { stdout } = await execa('npm', ['config', 'get', 'registry'])
|
|
148
|
+
const registryUrl = stdout.endsWith('/') ? stdout : `${stdout}/`;
|
|
149
|
+
const packTasks = packages.map((packageName) => {
|
|
150
|
+
const atIndex = packageName.lastIndexOf('@')
|
|
151
|
+
const fullname = packageName.substring(0, atIndex)
|
|
152
|
+
const name = fullname.includes('/') ? fullname.split('/')[1] : fullname
|
|
153
|
+
const version = packageName.substring(atIndex + 1)
|
|
154
|
+
const packageUrl = `${registryUrl}${fullname}/-/${name}-${version}.tgz`;
|
|
155
|
+
return limit(() => downloadPackage(packageUrl))
|
|
156
|
+
})
|
|
148
157
|
await Promise.all(packTasks)
|
|
149
158
|
}
|
|
150
159
|
console.log('\nAll packages are successfully packed in ./node_modules_pack!')
|