In this post I'll cover my workflow of creating env-inject-file, a command line utility for populating config files with environment variable placeholders and my first published npm package.
Version management
My advice is protect your branch, write descriptive commit messages, use branch management.
Branch Protection
To enable branch protection, go to repository Settings -> Branches -> Add Rule.
Project structure
.
├── bin
│ └── env-inject-file.js
├── env-inject-file.js
├── LICENSE
├── package.json
├── .travis.yml
├── .npmignore
├── README.md
└── test
├── cmdline.spec.js
└── program.spec.js
README.md
First thing that users see should contain project description, instructions to install and use. Badges in README make it stand out.
Tests
Write unit tests. Tests confirm that code is valid and enrich project documentation.
LICENSE
MIT is a good choice for opensource. Choosing an opensource license is easier with https://choosealicense.com/.
package.json
Initialized with npm init
, contains project information for npm.
.npmignore
Configuration for excluding files from your package. Check that exclusion works with npm pack
.
.travis.yml
Configuration for travis continuous integration:
language: node_js
node_js:
- v10
- v8
- v6
before_install:
- npm i npm@^6 -g
install:
- npm install
script:
- npm test
notifications:
email: false
On every build travis will install dependencies, run tests for 3 versions of node, then update Github PR status to pass or fail.
Publishing
- Create an account with npm, then authenticate in root project console type:
npm login
- After PR merge, you can bump your project version.
npm version patch|minor|major
Command will bump version in package.json
, create a git commit with <version>
message, and git tag v<version>
.
- Push version commit and tag, merge to master
git push && git push --tags
- Publish to npm
npm publish
Unpublishing
You might have accidentally published your library. For packages published less than 72 hours ago, you can use this command:
npm unpublish [email protected] --force
Other reading
You might be interested into publishing to a private github registry.