diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..4c45a4c --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,28 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Publish to NPM + +on: + push: + branches: [ "main", "publish-test" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js (22.x) + uses: actions/setup-node@v4 + with: + node-version: 22.x + registry-url: https://registry.npmjs.org/ + cache: 'npm' + - run: npm ci + - run: npm run build --if-present + - run: npm test --if-present + - run: npm run bump --if-present + - run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/config/.gitignore b/config/.gitignore new file mode 120000 index 0000000..3e4e48b --- /dev/null +++ b/config/.gitignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/config/eslint.config.js b/config/eslint.config.js new file mode 100644 index 0000000..9f08050 --- /dev/null +++ b/config/eslint.config.js @@ -0,0 +1,9 @@ +// eslint.config.js +module.exports = [ + { + rules: { + semi: "error", + "prefer-const": "error" + } + } +]; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..fc79320 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,43 @@ +{ + "name": "@fauna/typescript", + "version": "0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@fauna/typescript", + "version": "0.0.1", + "license": "MPL-2.0", + "dependencies": { + "parse-commit-message": "^5.0.4" + } + }, + "node_modules/collect-mentions": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/collect-mentions/-/collect-mentions-2.0.1.tgz", + "integrity": "sha512-3/MkmIZDerSapDxlRLGJ2M38Zs2+GMJ6i3X4d9ilyB82PcSFVzA5VVH6A6SKXPIuzcyeE+xAS+4XdY0O1MVAxQ==" + }, + "node_modules/mixin-deep": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-2.0.1.tgz", + "integrity": "sha512-imbHQNRglyaplMmjBLL3V5R6Bfq5oM+ivds3SKgc6oRtzErEnBUUc5No11Z2pilkUvl42gJvi285xTNswcKCMA==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/parse-commit-message": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/parse-commit-message/-/parse-commit-message-5.0.4.tgz", + "integrity": "sha512-Gf/4BeROJw6nb/ajGbF1ymDwnyQjV8ffwnyouv2uX08Tq5MFFiY+MNMiidz7cqBGvxvLhyYGjyjQGUy3w4a/7g==", + "license": "MPL-2.0", + "dependencies": { + "collect-mentions": "^2.0.1", + "mixin-deep": "^2.0.1" + }, + "engines": { + "node": ">=20" + } + } + } +} diff --git a/package.json b/package.json index 9f52a6c..0cb276f 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,12 @@ "description": "A collection of lint, format, and build configs used at Fauna for TypeScript projects.", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "bump": "node ./scripts/version-bump.js" }, + "files": [ + "config/**" + ], "repository": { "type": "git", "url": "git+https://github.com/fauna/typescript.git" @@ -15,5 +19,8 @@ "bugs": { "url": "https://github.com/fauna/typescript/issues" }, - "homepage": "https://github.com/fauna/typescript#readme" + "homepage": "https://github.com/fauna/typescript#readme", + "dependencies": { + "parse-commit-message": "^5.0.4" + } } diff --git a/scripts/version-bump.js b/scripts/version-bump.js new file mode 100755 index 0000000..20dfb11 --- /dev/null +++ b/scripts/version-bump.js @@ -0,0 +1,23 @@ +#!/usr/bin/env node + +const { execSync } = require('node:child_process'); +const { parseHeader } = require('parse-commit-message'); + +const latestCommitMessage = execSync("git log -1 --pretty=%B"); +const { type, scope } = parseHeader(latestCommitMessage); + +let flag; +if (scope === 'patch' || ['fix', 'chore', 'docs', 'refactor', 'perf', 'test', 'build'].includes(type)) { + flag = '--patch'; +} else if (scope === 'minor' || ['feat', 'feature'].includes(type)) { + flag = '--minor'; +} else if (scope === 'major') { + flag = '--major'; +} else { + flag = '--patch'; +} + +execSync(`npm version ${flag}`); +execSync("git add package.json"); +execSync("git commit --amend --no-edit"); +execSync("git push --force");