diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d3f1e77..70ec7ce 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: matrix: os: - ubuntu-latest - node: [18.x] + node: [16.x, 17.x, 18.x] steps: - uses: actions/checkout@v3 diff --git a/README.md b/README.md index e51a0a5..3554f9d 100644 --- a/README.md +++ b/README.md @@ -83,20 +83,10 @@ import { Num } from 'typescript-npm-package-template'; console.log(new Num(5).add(new Num(6)).val() === 11) ``` -## Publishing your package -### Manual publishing only to NPM - -Log in: - -```bash -npm adduser -``` +## CI Testing +Every commit and pull request is tested automatically on Node 16.x, 17.x and 18.x. You can set which node versions the tests should run on here: **.github/workflows/test.yml:30**. -And publish: - -```bash -npm publish -``` +## Publishing your package ### Using a Github Release (CI): - Publish your package to NPM and Github Packages at the same time! @@ -124,6 +114,7 @@ Follow [npm's official](https://docs.npmjs.com/creating-and-viewing-access-token
On the page of your newly created or existing GitHub repo, click **Settings** -> **Secrets** -> **New repository secret**, the Name should be `NPM_TOKEN` and the Value should be your npm token. + ### Publishing to Github Packages The default configuration of this example package **assumes you publish package with an unscoped name to npm**. GitHub Packages must be named with a scope name such as "@warstekhun/typescript-npm-package-template". @@ -131,10 +122,24 @@ Change `scope: '@warstekhun'` to your own scope in **.github/workflows/publish.y If you want to publish your package with a scoped name, change the name property in **package.json** and the scope from *@warstekhun* to yours at **.github/workflows/publish.yml:49**. +(You might have noticed `secret.GITHUB_TOKEN` in **.github/workflows/publish.yml**. You don't need to set up a secret named `GITHUB_TOKEN` actually, it is [automatically created](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#about-the-github_token-secret)) + + +### Manual publishing only to NPM + If you publish your package to npm only, and don't want to publish to GitHub Packages, then delete the lines from `- name: Setup .npmrc file to publish to GitHub Packages` to the end of the file in **.github/workflows/publish.yml**. -(You might have noticed `secret.GITHUB_TOKEN` in **.github/workflows/publish.yml**. You don't need to set up a secret named `GITHUB_TOKEN` actually, it is [automatically created](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#about-the-github_token-secret)) +Log in: +```bash +npm adduser +``` + +And publish: + +```bash +npm publish +``` ## References - [Creating and publishing unscoped public packages - npm docs](https://docs.npmjs.com/creating-and-publishing-unscoped-public-packages) diff --git a/package-lock.json b/package-lock.json index 7791934..ae31a2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@warstekhun/typescript-npm-package-template", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@warstekhun/typescript-npm-package-template", - "version": "1.1.0", + "version": "1.1.1", "license": "MIT", "devDependencies": { "@types/jest": "^27.0.1", diff --git a/package.json b/package.json index 586e790..1c96199 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@warstekhun/typescript-npm-package-template", - "version": "1.1.0", + "version": "1.1.1", "description": "Typescript NPM package template that is ready for NPM and Github Packages publish.", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", @@ -21,7 +21,7 @@ "test:cov-build": "jest --coverage --no-cache --runInBand && jest-coverage-badges-ts --output \"./.coverage-badges\"", "format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"", "format:fix": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", - "release": "npm run package && node tools/versionManager.js" + "release": "rimraf ./*.tgz -g && npm run package && node tools/versionManager.js" }, "files": [ "dist" diff --git a/tools/versionManager.js b/tools/versionManager.js index 3446354..1d4dd73 100644 --- a/tools/versionManager.js +++ b/tools/versionManager.js @@ -1,7 +1,6 @@ const prompt = require("prompt"); const { exec, ChildProcess } = require("child_process"); const colors = require("@colors/colors"); -const rimraf = require("rimraf"); prompt.start({ colors: true, @@ -25,10 +24,6 @@ async function waitForProcess(args) { console.log(colors.bold("\n------------------------\nWelcome to the Version Manager!")); console.log("Every new version you create will be automatically commited, pushed, and then released to Github Packages and NPM."); - rimraf.moveRemove("./*.tgz", { - glob: true - }) - const version = (await prompt.get({ pattern: /^((major|minor|patch|premajor|preminor|prepatch|prerelease|from-git)|\d+.\d+.\d+)$/, message: "Should be: major|minor|patch|premajor|preminor|prepatch|prerelease|from-git will increase version number by npm standards. Custom input is possible. Example: x.x.x",