@fanwang/pack-util 1.0.4 → 1.0.5
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.md +1 -0
- package/bin/index.js +27 -26
- package/package.json +7 -3
package/README.md
CHANGED
package/bin/index.js
CHANGED
|
@@ -1,60 +1,61 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { execa } from 'execa'
|
|
3
|
+
import { execa } from 'execa'
|
|
4
4
|
import { mkdirSync, readdirSync } from 'fs'
|
|
5
|
-
import { Command } from 'commander'
|
|
5
|
+
import { Command } from 'commander'
|
|
6
6
|
|
|
7
|
-
const program = new Command()
|
|
7
|
+
const program = new Command()
|
|
8
8
|
|
|
9
9
|
const getPackageNames = async () => {
|
|
10
|
-
const { stdout } = await execa('npm', ['list','--all'])
|
|
10
|
+
const { stdout } = await execa('npm', ['list', '--all'])
|
|
11
11
|
let packages = stdout.split('\n')
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
packages.splice(0, 1)//去掉首行路径字符串
|
|
13
|
+
return packages.filter(item => !item.includes('deduped'))//去掉重复包
|
|
14
|
+
.map(name => {
|
|
15
|
+
const nameRegex = /(\S+@.+)/g;
|
|
16
|
+
const nameParse = name.match(nameRegex)
|
|
17
|
+
if (nameParse && nameParse.length > 0) return nameParse[0]
|
|
18
|
+
else return ''
|
|
19
|
+
})//解析每行的包名称
|
|
20
|
+
.filter(packageName => packageName.length > 0)//去掉空行
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const packPackage = async (packageName) => {
|
|
24
|
+
const { stdout } = await execa('npm', ['pack', packageName, '--pack-destination=./node_modules_pack'])
|
|
21
25
|
return stdout
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
const publishPackage = async(packageName)=>{
|
|
25
|
-
const {stdout} = await execa('npm',['publish','./node_modules_pack/'+packageName])
|
|
28
|
+
const publishPackage = async (packageName) => {
|
|
29
|
+
const { stdout } = await execa('npm', ['publish', './node_modules_pack/' + packageName])
|
|
26
30
|
return stdout
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
program
|
|
30
34
|
.name('pack-util')
|
|
31
35
|
.description('Pack all installed package in ./node_modules, and publish to Nexus self-hosted Registry.')
|
|
32
|
-
.version('1.0.
|
|
36
|
+
.version('1.0.5')
|
|
33
37
|
|
|
34
38
|
program
|
|
35
39
|
.command('pack')
|
|
36
40
|
.description('Pack all installed package in ./node_modules')
|
|
37
41
|
.action(() => {
|
|
38
|
-
getPackageNames().then(packages=>{
|
|
42
|
+
getPackageNames().then(packages => {
|
|
39
43
|
console.log(`Total ${packages.length} packages to be packed, please wait...`)
|
|
40
|
-
mkdirSync('./node_modules_pack',{recursive:true})
|
|
44
|
+
mkdirSync('./node_modules_pack', { recursive: true })
|
|
41
45
|
packages.forEach(packageName => {
|
|
42
|
-
packPackage(packageName).then(stdout=>console.log(stdout))
|
|
43
|
-
})
|
|
46
|
+
packPackage(packageName).then(stdout => console.log(stdout))
|
|
47
|
+
})
|
|
44
48
|
})
|
|
45
49
|
})
|
|
46
50
|
|
|
47
51
|
program
|
|
48
52
|
.command('publish')
|
|
49
53
|
.description('Publish all packed packages in ./node_modules_pack')
|
|
50
|
-
.action(()=>{
|
|
54
|
+
.action(() => {
|
|
51
55
|
const packages = readdirSync('./node_modules_pack')
|
|
52
|
-
// console.log('Publish all packed packages in ./node_modules_pack')
|
|
53
|
-
// console.log(packages)
|
|
54
56
|
packages.forEach(packageName => {
|
|
55
|
-
publishPackage(packageName).then(stdout=>console.log(stdout))
|
|
57
|
+
publishPackage(packageName).then(stdout => console.log(stdout))
|
|
56
58
|
})
|
|
57
59
|
})
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
program.parse();
|
|
61
|
+
program.parse()
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fanwang/pack-util",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Pack all installed package in ./node_modules, and publish to Nexus self-hosted Registry.",
|
|
5
|
-
"bin":{
|
|
5
|
+
"bin": {
|
|
6
6
|
"pack-util": "./bin/index.js"
|
|
7
7
|
},
|
|
8
8
|
"publishConfig": {
|
|
@@ -19,7 +19,11 @@
|
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "https://gitee.com/vampirefan/pack-util.git"
|
|
21
21
|
},
|
|
22
|
-
"keywords": [
|
|
22
|
+
"keywords": [
|
|
23
|
+
"npm",
|
|
24
|
+
"pack",
|
|
25
|
+
"publish"
|
|
26
|
+
],
|
|
23
27
|
"author": "fanwang",
|
|
24
28
|
"license": "MIT",
|
|
25
29
|
"dependencies": {
|