From 97cf45b08f4928fce363e47844a0edfa2585f46a Mon Sep 17 00:00:00 2001 From: Dimi Kot Date: Sun, 14 Jan 2024 03:28:02 -0800 Subject: [PATCH] Add a framework to reuse some build files across multiple open-source projects --- .eslintrc.base.js | 3 ++- .eslintrc.js | 8 ++++---- .gitignore | 3 ++- .npmignore | 9 +++++---- .vscode/extensions.json | 8 ++++++++ .vscode/tasks.json | 20 ++++++++++++++++++++ internal/clean.sh | 4 ++++ internal/deploy.sh | 7 +++++++ internal/docs.sh | 6 ++++++ internal/lint.sh | 4 ++++ jest.config.js | 4 +++- package.json | 8 ++++---- tsconfig.base.json | 31 +++++++++++++++++++++++++++++++ tsconfig.json | 31 ++----------------------------- typedoc.config.js | 20 ++++++++++++++++++++ typedoc.json | 22 ---------------------- 16 files changed, 122 insertions(+), 66 deletions(-) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/tasks.json create mode 100644 internal/clean.sh create mode 100644 internal/deploy.sh create mode 100644 internal/docs.sh create mode 100644 internal/lint.sh create mode 100644 tsconfig.base.json create mode 100644 typedoc.config.js delete mode 100644 typedoc.json diff --git a/.eslintrc.base.js b/.eslintrc.base.js index 5d45f7a..9684533 100644 --- a/.eslintrc.base.js +++ b/.eslintrc.base.js @@ -1,5 +1,5 @@ "use strict"; -module.exports = (projectRoot) => ({ +module.exports = (projectRoot, extraRules = {}) => ({ root: true, // fix possible "Plugin %s was conflicted between %s.json and %s.json" errors env: { jest: true, @@ -430,5 +430,6 @@ module.exports = (projectRoot) => ({ ], quotes: ["error", "double", { avoidEscape: true }], + ...extraRules, }, }); diff --git a/.eslintrc.js b/.eslintrc.js index cbbe5b4..ef85b86 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,5 @@ "use strict"; -const config = require("./.eslintrc.base.js")(__dirname); -config.rules["import/no-extraneous-dependencies"] = "error"; -config.rules["lodash/import-scope"] = ["error", "method"]; -module.exports = config; +module.exports = require("./.eslintrc.base.js")(__dirname, { + "import/no-extraneous-dependencies": "error", + "lodash/import-scope": ["error", "method"], +}); diff --git a/.gitignore b/.gitignore index af9aba5..6314675 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ dist +# Common in both .gitignore and .npmignore node_modules package-lock.json -pnpm-lock.yaml yarn.lock +pnpm-lock.yaml .DS_Store *.log *.tmp diff --git a/.npmignore b/.npmignore index 7220835..7ec72e7 100644 --- a/.npmignore +++ b/.npmignore @@ -1,12 +1,13 @@ -__tests__ +dist/__tests__ +dist/**/__tests__ +dist/tsconfig.tsbuildinfo .npmrc -tsconfig.tsbuildinfo -.github +# Common in both .gitignore and .npmignore node_modules package-lock.json -pnpm-lock.yaml yarn.lock +pnpm-lock.yaml .DS_Store *.log *.tmp diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..69c81d9 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode", + "mhutchie.git-graph", + "trentrand.git-rebase-shortcuts" + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7076e3d --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,20 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "git grok: push local commits as individual PRs", + "detail": "Install git-grok first: https://github.com/dimikot/git-grok", + "type": "shell", + "command": "git grok", + "problemMatcher": [], + "hide": false + }, + { + "label": "git rebase --interactive", + "detail": "Opens a UI for interactive rebase (install \"Git rebase shortcuts\" extension).", + "type": "shell", + "command": "GIT_EDITOR=\"code --wait\" git rebase -i", + "problemMatcher": [] + } + ] +} diff --git a/internal/clean.sh b/internal/clean.sh new file mode 100644 index 0000000..f82a4a1 --- /dev/null +++ b/internal/clean.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +rm -rf dist yarn.lock package-lock.json pnpm-lock.yaml *.log diff --git a/internal/deploy.sh b/internal/deploy.sh new file mode 100644 index 0000000..7b12dc6 --- /dev/null +++ b/internal/deploy.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e + +npm run build +npm run lint +npm run test +npm publish --access=public diff --git a/internal/docs.sh b/internal/docs.sh new file mode 100644 index 0000000..ea628f6 --- /dev/null +++ b/internal/docs.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e + +rm -rf docs +typedoc --plugin typedoc-plugin-markdown --plugin typedoc-plugin-merge-modules +sed -i '' -E 's#packages/[^/]+/##g' $(find docs -type f -name '*.md') diff --git a/internal/lint.sh b/internal/lint.sh new file mode 100644 index 0000000..8815fd6 --- /dev/null +++ b/internal/lint.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +eslint . --ext .ts --cache --cache-location dist/.eslintcache diff --git a/jest.config.js b/jest.config.js index 822985a..c0ea465 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,7 +4,9 @@ module.exports = { testMatch: ["**/*.test.ts"], clearMocks: true, restoreMocks: true, - ...(process.env.IN_JEST_PROJECT ? {} : { forceExit: true }), + ...(process.env.IN_JEST_PROJECT + ? {} + : { forceExit: true, testTimeout: 30000, forceExit: true }), transform: { "\\.ts$": "ts-jest", }, diff --git a/package.json b/package.json index b9fa107..3c3a3d7 100644 --- a/package.json +++ b/package.json @@ -24,13 +24,13 @@ "scripts": { "build": "tsc", "dev": "tsc --watch --preserveWatchOutput", - "lint": "eslint . --ext .ts --cache --cache-location dist/.eslintcache", + "lint": "bash internal/lint.sh", "test": "jest", - "docs": "rm -rf docs && typedoc --plugin typedoc-plugin-markdown --plugin typedoc-plugin-merge-modules && sed -i '' -E 's#packages/[^/]+/##g' $(find docs -type f -name '*.md')", - "clean": "rm -rf dist node_modules yarn.lock package-lock.json pnpm-lock.yaml *.log", + "docs": "bash internal/docs.sh", + "clean": "bash internal/clean.sh", "copy-package-to-public-dir": "copy-package-to-public-dir.sh", "backport-package-from-public-dir": "backport-package-from-public-dir.sh", - "deploy": "npm run build && npm run lint && npm run test && npm publish --access=public" + "deploy": "bash internal/deploy.sh" }, "dependencies": { "abort-controller": "^3.0.0", diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000..783953d --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,31 @@ +{ + "include": ["src/**/*"], + "compilerOptions": { + "allowJs": true, + "declaration": true, + "declarationMap": true, + "disableReferencedProjectLoad": true, + "disableSourceOfProjectReferenceRedirect": true, + "esModuleInterop": true, + "experimentalDecorators": true, + "incremental": true, + "lib": ["ES2019"], + "module": "Node16", + "noEmitOnError": true, + "noErrorTruncation": true, + "noImplicitOverride": true, + "noImplicitReturns": true, + "noPropertyAccessFromIndexSignature": true, + "outDir": "dist", + "pretty": true, + "removeComments": false, + "resolveJsonModule": true, + "rootDir": "src", + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "target": "ES2019", + "tsBuildInfoFile": "dist/tsconfig.tsbuildinfo", + "types": ["node", "jest"] + } +} diff --git a/tsconfig.json b/tsconfig.json index 783953d..8342ac4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,31 +1,4 @@ { - "include": ["src/**/*"], - "compilerOptions": { - "allowJs": true, - "declaration": true, - "declarationMap": true, - "disableReferencedProjectLoad": true, - "disableSourceOfProjectReferenceRedirect": true, - "esModuleInterop": true, - "experimentalDecorators": true, - "incremental": true, - "lib": ["ES2019"], - "module": "Node16", - "noEmitOnError": true, - "noErrorTruncation": true, - "noImplicitOverride": true, - "noImplicitReturns": true, - "noPropertyAccessFromIndexSignature": true, - "outDir": "dist", - "pretty": true, - "removeComments": false, - "resolveJsonModule": true, - "rootDir": "src", - "skipLibCheck": true, - "sourceMap": true, - "strict": true, - "target": "ES2019", - "tsBuildInfoFile": "dist/tsconfig.tsbuildinfo", - "types": ["node", "jest"] - } + "extends": "./tsconfig.base.json", + "include": ["src/**/*"] } diff --git a/typedoc.config.js b/typedoc.config.js new file mode 100644 index 0000000..bc744b8 --- /dev/null +++ b/typedoc.config.js @@ -0,0 +1,20 @@ +"use strict"; +const { basename } = require("path"); + +module.exports = { + entryPoints: ["src"], + exclude: ["**/internal/**", "**/__tests__/**", "**/node_modules/**"], + entryPointStrategy: "expand", + mergeModulesMergeMode: "project", + sort: ["source-order"], + out: "docs", + logLevel: "Warn", + hideGenerator: true, + excludeInternal: true, + excludePrivate: true, + categorizeByGroup: true, + hideInPageTOC: true, + gitRevision: "master", + sourceLinkTemplate: `https://github.com/clickup/${basename(__dirname)}/blob/master/{path}#L{line}`, + basePath: ".", +}; diff --git a/typedoc.json b/typedoc.json deleted file mode 100644 index d568b9e..0000000 --- a/typedoc.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "entryPoints": ["src"], - "exclude": [ - "**/internal/**", - "**/__tests__/**", - "**/node_modules/**", - "**/node-fetch/**" - ], - "entryPointStrategy": "expand", - "mergeModulesMergeMode": "project", - "sort": ["source-order"], - "out": "docs", - "logLevel": "Warn", - "hideGenerator": true, - "excludeInternal": true, - "excludePrivate": true, - "categorizeByGroup": true, - "hideInPageTOC": true, - "gitRevision": "master", - "sourceLinkTemplate": "https://github.com/clickup/rest-client/blob/master/{path}#L{line}", - "basePath": "." -}