## 添加发布脚本 - 2019.06.04

#### 说明:

- `scripts/install.js`为包发布脚本,通过 npm scripts 的 postinstall 进行执行

#### 操作方式:


1. 测试发布插件

新建JenkinsJob,选择Pipeline模式,JenkinsJob名称为`产品名称-插件名称-publish` 例如：`icuauth-quiauth-publish`

添加`Pipeline script`,然后粘贴如下代码

```
node {
    def nodeHome = tool 'NodeJS_8.12'
    stage('Check out') {
        // todo credentialsId为秘钥ID，url为你的git地址
        git credentialsId: 'xxxxx', url: 'https://xxx/xxxx.git'
    }
    stage('Publish') {
      echo "${ nodeHome }/bin"
      withEnv(["PATH+NODE=${ nodeHome }/bin"]) {
        dir('angular') { // 改为自己项目中需要发布插件的前端目录，一次发布多个插件jenkinsjob请参考 icuiFrame-ngicui-publish
            sh "npm config set registry='http://192.168.11.22:8081/repository/npm-group/'"
            // sh "npm config set registry='http://192.168.11.22:8081/repository/npm-hosted/'"
            sh "npm install"
            sh "npm run build:publish"
            sh "echo 'registry = http://192.168.11.22:8081/repository/npm-hosted/' > .npmrc"
            sh "echo 'email=admin@example.org' >> .npmrc"
            sh "echo 'always-auth=true' >> .npmrc"
            sh "echo '_auth=cGp4OmFkbWluMTIz' >> .npmrc"
            // sh "echo '_authToken=NpmToken.2e582644-a196-3fa5-99fe-ce3cd5d33f8d' >> .npmrc"
            sh "npm --allow-same-version version 0.0.1"  // 发布测试请不要使用超过1.0.0的版本号
            sh "npm publish"
        }
      }
    }
}
```

通过本地安装测试版本的插件依赖进行测试，测试库地址，测试通过后交由QA正式发布（正式发布前，请修改package.json正确的版本号）。

2. 安装模块

在`universal`项目中使用如下命令安装模块

```
npm install [模块名称] --register [仓库地址]
```

模块文件会自动安装到 `public/plugins/` 目录下

> 注意模块发布和安装需要使用内部仓库地址,插件名称是`package.json`中的`name`字段
