@kubric/creative-renderer v0.2.0
jslib-scaffolding
Scaffoling for setting up an open source libarary with the following stack
- code in JS/TypeScript
- Build with Rollup
- Test with Jest
- Publish to npm with CircleCI
For the discussion below, assume that the code resides in the src folder and the entry point is index.ts/index.ts.
package.json
- Change the following fields
name,version,description,repository,author,license,bugs.urlandhomepageas required - Change/remove
mainas per requirement. - Change/remove
moduleas per requirement. - Change/remove
browseras per requirement. - Run
npm install - Add additional packages required by the library
Typescript
typesinpackage.jsonshould point to the types declaration file generated for the library.- Write code in
index.tsinsrcfolder - Change the
tsconfig.jsonfile as required - Change all
inputinrollup.config.jstosrc/index.ts
JavaScipt
- Remove
typesand packages related to TypeScript fromdevDependenciesinpackage.json - Remove
tsconfig.json - Remove the entry
@babel/preset-typescriptfrom.babelrc - Write code in
index.tsinsrcfolder - Remove
import typescript from 'rollup-plugin-typescript';inrollup.config.js - Remove
typescript()call frompluginsinrollup.config.js - Change all
inputinrollup.config.jstosrc/index.ts
If you have other rollup built libraries as dependencies, and you use some named exports from those libraries, these imports will have to be explicitly declared in your rollup.config.js as named exports. If these dependencies are peer dependencies, you can mark them as external in your rollup.config.js and avoid having to declare all named imports.
Build
npm run build will build the library
Tests
- Write your tests in the
testsdirectory as files ending in.test.js - Change the Jest config as required in
jest.config.js npm testwill run the tests and print the results
Publish
- Login into Circle CI and follow the github project where the library resides
- Change the node version in
.circleci/config.ymlif required - Do
npm loginin local and extract the auth token from${HOME}/.npmrc - The token can be configured in 2 ways
- In the Circle CI organization settings, create a context named
npmand add and environment variable namednpm_TOKENwith the copied auth token as it's value. This is the default approach configured in.circleci/config.yml. - Otherwise, create an environment variable
npm_TOKENin Circle CI under project settings and paste the copied auth token as it's value. Afterwards, delete the linecontext: npm(line 68) from.circleci/config.yml
- In the Circle CI organization settings, create a context named
Once all the above steps have been completed and the library is ready, commit to github.
- The tests will be run in CircleCI for every branch and tag
- Publish to npm will happen whenever a commit is tagged with
v${versionNumber}.
Before tagging a commit for publish, make sure that the correct version number is updated in
package.json