Publish my Node.js project to npm by Travis CI

Referenced: https://www.npmjs.com/package/travis-deploy-exampleReferenced: https://docs.travis-ci.com/user/dep […]

広告ここから
広告ここまで

目次

    Referenced: https://www.npmjs.com/package/travis-deploy-example
    Referenced: https://docs.travis-ci.com/user/deployment/npm/

    Step by Step

    1: Create npm token

    We have to get npm token to publish your packages from Travis CI. You can get the token byhttps://www.npmjs.com/settings/{YOUR_USERNAME}/tokens to put theCreate New Tokenbutton.

    2: Set an environment variable in the Travis CI

    You can put the token as an environment variable in the Travis CI. Let’s put the token into it name likeNPM_TOKEN.

    Note: You can encrypt the token by Travis command.

    3: Define publish conf into the .travis.yml

    You can define the publishing configuration like this.

    language: node_js
    node_js:
      - '8'
    install:
      - npm install
    script:
      - npm run lint
      - npm test
    deploy:
      provider: npm
      email: '[email protected]'
      api_key: $NPM_TOKEN
      on:
        tags: true

    In this case, you can publish your packages only push tagged artifact like git tag vx.x.x. If you want to publish productionbranch, you can define like this.

    deploy:
      ...
      on:
        branch: production

    4: Publish

    Finally, you can publish your package by only Git command.

    $ git add ./
    $ git commit -m "new feature"
    $ git tag v1.0.0
    $ git push origin master v1.0.0

    After running these command, we need to just wait for the email from npm that publishing complete.

    広告ここから
    広告ここまで

    Random posts

    Home
    Search
    Bookmark