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