@fanwang/pack-util 1.0.3 → 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.
Files changed (3) hide show
  1. package/README.md +33 -0
  2. package/bin/index.js +27 -26
  3. package/package.json +7 -3
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # pack-util
2
+ 打包工具,可以将 ./node_modules 中安装的包遍历后打包,并放在 ./node_modules_pack 文件夹中,然后批量发布到 nexus 搭建的 npm 私服上。
3
+ Pack all installed package in ./node_modules, and publish to Nexus hosted Registry.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install -g @fanwang/pack-util
9
+ ```
10
+
11
+ ## Usage: pack-util [command]
12
+
13
+ ### Pack all installed package in ./node_modules
14
+ ```sh
15
+ cd your_project
16
+ pack-util pack
17
+ ```
18
+
19
+ ### Publish all packed packages in ./node_modules_pack
20
+ copy node_modules_pack along with your project.
21
+ 1. change registry
22
+ ```sh
23
+ npm config set registry http://xx.xx.xx.xx:xxxx/repository/xxxx/
24
+ ```
25
+ 2. adduser
26
+ ```sh
27
+ npm adduser -registry http://xx.xx.xx.xx:xxxx/repository/xxxx/
28
+ ```
29
+ 2. batch publish
30
+ ```sh
31
+ cd your_project
32
+ pack-util publish
33
+ ```
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
- .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'])
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.3');
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",
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": {