From 6b67f8d80aec95933ce9e5087d84899540681d21 Mon Sep 17 00:00:00 2001 From: Ashton Eby Date: Tue, 22 Oct 2024 12:34:05 -0700 Subject: [PATCH] feat: set up shareable config - adds .gitignore (in config dir and copy of it for local use) - adds config dir for shared configuration - creates config/eslint.config.js with placeholder info - adds version bump script - adds github job for publishing --- .github/workflows/npm-publish.yml | 49 ++++++++++++++++++++++++++++++ .gitignore | 1 + README.md | 6 +++- config/.gitignore | 5 ++++ config/eslint.config.js | 9 ++++++ package-lock.json | 50 +++++++++++++++++++++++++++++++ package.json | 16 ++++++++-- scripts/version-bump.js | 29 ++++++++++++++++++ 8 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/npm-publish.yml create mode 100644 .gitignore create mode 100644 config/.gitignore create mode 100644 config/eslint.config.js create mode 100644 package-lock.json create mode 100755 scripts/version-bump.js diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..e33deff --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,49 @@ +# 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" ] + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # added or changed files to the repository. + contents: write + id-token: write + + steps: + - uses: actions/checkout@v4 + with: + # Fetch the last 2 commits instead of just 1. (Fetching just 1 commit would overwrite the whole history) + fetch-depth: 2 + - 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 bump + - name: Get last commit message + id: last-commit + run: | + echo "message=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT + echo "author=$(git log -1 --pretty=\"%an <%ae>\")" >> $GITHUB_OUTPUT + # Commit changes to package.json back to the repository + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_author: ${{ steps.last-commit.outputs.author }} + file_pattern: 'package.json' + commit_message: ${{ steps.last-commit.outputs.message }} + commit_options: '--amend --no-edit' + push_options: '--force' + skip_fetch: true + - run: npm publish --access public --loglevel verbose --dry-run + 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/README.md b/README.md index 06a39a7..9fa1e6a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ -# typescript +# TypeScript A collection of lint, format, and build configs used at Fauna for TypeScript projects. + +## Included configs (`./config/`) +- `eslint.config.js`, a minimal placeholder eslint config. +- `.gitignore`, a minimal placeholder .gitignore file. diff --git a/config/.gitignore b/config/.gitignore new file mode 100644 index 0000000..eac4fc4 --- /dev/null +++ b/config/.gitignore @@ -0,0 +1,5 @@ +# DO NOT EDIT THIS FILE AT $PROJECT_ROOT/.gitignore +# instead, edit it at $PROJECT_ROOT/config/.gitignore +# the project's build step copies it from /config + +node_modules 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..aedb904 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,50 @@ +{ + "name": "@fauna/typescript", + "version": "0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@fauna/typescript", + "version": "0.0.1", + "license": "MPL-2.0", + "dependencies": { + "mentions-regex": "^2.0.3", + "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/mentions-regex": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/mentions-regex/-/mentions-regex-2.0.3.tgz", + "integrity": "sha512-136g0tOWk7/Y7LK/Y6FZa6TxLqwxFCAUoY6z/GC5o5ulK8oXzEU4knnTAoeVscQUTTEkNCOZcKWSxkCNmgSWHQ==", + "license": "MIT" + }, + "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..6c00a96 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,13 @@ "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", + "build": "cp ./config/.gitignore .gitignore", + "bump": "node ./scripts/version-bump.js" }, + "files": [ + "config/**" + ], "repository": { "type": "git", "url": "git+https://github.com/fauna/typescript.git" @@ -15,5 +20,12 @@ "bugs": { "url": "https://github.com/fauna/typescript/issues" }, - "homepage": "https://github.com/fauna/typescript#readme" + "homepage": "https://github.com/fauna/typescript#readme", + "dependencies": { + "mentions-regex": "^2.0.3", + "parse-commit-message": "^5.0.4" + }, + "publishConfig": { + "registry": "https://registry.npmjs.org/" + } } diff --git a/scripts/version-bump.js b/scripts/version-bump.js new file mode 100755 index 0000000..6f66e8d --- /dev/null +++ b/scripts/version-bump.js @@ -0,0 +1,29 @@ +#!/usr/bin/env node + +const { execSync } = require('node:child_process'); +const { parseHeader } = require('parse-commit-message'); + +const latestCommitMessage = execSync("git log -1 --pretty=%B", { encoding: "utf-8" }); +let versionType, type, scope; + +try { + const header = parseHeader(latestCommitMessage); + type = header.type; + scope = header.scope; +} catch (e) { + scope = undefined; + type = undefined; +} + +if (scope === 'patch' || ['fix', 'chore', 'docs', 'refactor', 'perf', 'test', 'build'].includes(type)) { + versionType = 'patch'; +} else if (scope === 'minor' || ['feat', 'feature'].includes(type)) { + versionType = 'minor'; +} else if (scope === 'major') { + versionType = 'major'; +} else { + versionType = 'patch'; +} + +console.log(`Parsed commit message:\n${latestCommitMessage}\n\nDetermined the version as ${versionType} (from scope ${scope} and change type ${type}).\n`); +console.log(execSync(`npm version ${versionType} --no-git-tag-version`, { encoding: "utf-8" }));