1.4.0 • Published 3 years ago

beautyful-test v1.4.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

a 1. After creation and init of repo

```
npm init --scope=@my-org
```
or
```
npm init --scope=@my-username
```
to initialize npm package
  1. Make .gitignore

    lib
    node_modules
  2. 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"
  3. 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"
  4. Create whitelist for npm adding

    “files”: [“lib/**/*”]

    to package.json

  5. 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.ts

    import { Greeter } from '../index';
    
    test('My Greeter', () => {
        expect(Greeter('Carl')).toBe('Hello Carl');
    });
  6. 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 packages

  7. Setup 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 or creating anew Release on Git.

    To publish public packages change npm publish to npm publish --access public

    USE git push origin --tags -f to push tags after release

    ref: 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

1.1.1

3 years ago

10.0.0

3 years ago

1.4.0

3 years ago

11.0.0

3 years ago

1.0.6

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago