beautyful-test v1.4.0
a 1. After creation and init of repo
```
npm init --scope=@my-org
```
or
```
npm init --scope=@my-username
```
to initialize npm packageMake
.gitignorelib node_modulesInstall
typescriptnpm install --save-dev typescriptCreate
tfconfig.json{ "compilerOptions": { "target": "es5", "module": "commonjs", "declaration": true, "outDir": "./lib", "strict": true }, "include": ["src"], "exclude": ["node_modules", "**/__tests__/*"] }Add in
package.json.scripts"build" : "tsc"Add
linternpm install --save-dev tslint tslint-config-prettierCreate
tslint.json{ "extends": ["tslint:recommended", "tslint-config-prettier"] }Add in
package.json.scripts"lint": "tslint -p tsconfig.json"Create whitelist for npm adding
“files”: [“lib/**/*”]to
package.jsonSetup tests
npm install --save-dev jest ts-jest @types/jestCreate
jestconfig.json{ "transform": { "^.+\\.(t|j)sx?$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"] }Add in
package.json.scripts"test": "jest --config jestconfig.json",Add basic test in
src/__tests__/NameFuncion.test.tsimport { Greeter } from '../index'; test('My Greeter', () => { expect(Greeter('Carl')).toBe('Hello Carl'); });Finish up
package.json"main": "lib/index.js", "types": "lib/index.d.ts",....
"scripts": { "prepare": "npm run build", "prepublishOnly": "npm test && npm run lint", "preversion": "npm run lint", "version": "npm run format && git add -A src", "postversion": "git push && git push --tags" },The package.josn
namefield should be @scope/name to create scoped packagesSetup GitAction
Create new
NPM SECRETCreate new action
name: Node.js Package on: release: types: [created, published] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 # Setup .npmrc file to publish to npm - uses: actions/setup-node@v2 with: node-version: '12.x' registry-url: 'https://registry.npmjs.org' - run: npm install - run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}The action will be triggered either
pushing a tagged commitorcreating anew Release on Git.To publish
publicpackages changenpm publishtonpm publish --access publicUSE
git push origin --tags -fto push tags after releaseref: https://docs.github.com/en/actions/guides/publishing-nodejs-packages https://docs.npmjs.com/creating-and-publishing-private-packages https://itnext.io/step-by-step-building-and-publishing-an-npm-typescript-package-44fe7164964c