初始化项目时指定程序入口和相关变异命令
{ "name": "keypress-event", "version": "1.1.1", "description": "Listen to the key press", "main": "dist/index.js", "scripts": { "build": "tsc", "test": "echo \"no test specified\" && exit 0" }, "repository": { "type": "git", "url": "git+ssh://git@github.com/linyimin-bupt/keypress-event.git" }, "keywords": [ "typescript", "iohook", "keypress", "keycode" ], "author": "Yimin Lin", "license": "MIT", "bugs": { "url": "https://github.com/linyimin-bupt/keypress-event/issues" }, "homepage": "https://github.com/linyimin-bupt/keypress-event#readme", "dependencies": { "iohook": "^0.2.0", "typescript": "^3.0.1" } }
上述文件中,name对应npm包名称,version对应npm包版本,main对应npm包程序的入口文件,dist对应编译文件指定的文件夹.
编写.travis.yml文件
language : node_js node_js: - "10" - "9" install: - npm install os: - linux stages: - test - name: deploy jobs: include: - stage: test script: - node --version - npm --version - echo "Testing Started ..." - npm test - echo "Testing Finished." - stage: deploy script: - echo "NPM Deploying Started ..." - npm version - npm run build - echo "NPM Building Finished." deploy: provider: npm email: linyimin520812@gmail.com api_key: "$NPM_TOKEN" skip_cleanup: true on: all_branches: true
使用github登录Travis
Travis官网,并使用github登录.
选择指定的github仓库
进入相关项目后,选择右上角的
More options
中的Settings
,填写token变量NPM_TOKEN
(在.travis.yml文件中使用)填写token变量
npm token的变量在~/.npmrc文件中
$ cat ~/.npmrc
更改npm版本
npm包发布时, 版本必须要不一致,否则会出现以下错误
npm ERR! publish Failed PUT 403 npm ERR! code E403 npm ERR! You cannot publish over the previously published versions: 1.0.5. : upload-image-to-oss
所以,在push代码到仓库之前,需要更改项目的版本号.在commit所有更改代码之后,使用以下命令可以实现版本号的更改,并且自动完成commit
$ npm version parch
push相关代码,自动完成npm发布
push相关代码之后,点击commit,可以看到已经自动开始构建发布
点击小黄点(正在构建)或者绿勾(已经构建完成)进入travis的构建页面
点击相关任务,可以查看具体构建过程中的日志,如果出错,可以根据日志更改相关内容,再次提交进行构建发布
使用travis CI自动发布npm包
最新推荐文章于 2024-05-13 13:26:07 发布