beautyful-test
v1.4.0
Published
This is a test, i'll delete this nice testa after
Downloads
2
Readme
a
After creation and init of repo
npm init --scope=@my-org
or
npm init --scope=@my-username
to initialize npm package
Make
.gitignore
lib node_modules
Install
typescript
npm install --save-dev typescript
Create
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
linter
npm install --save-dev tslint tslint-config-prettier
Create
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.json
Setup tests
npm install --save-dev jest ts-jest @types/jest
Create
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
name
field should be @scope/name to create scoped packagesSetup GitAction
Create new
NPM SECRET
Create 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 commit
orcreating anew Release on Git
.To publish
public
packages changenpm publish
tonpm publish --access public
USE
git push origin --tags -f
to 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