Skip to content

Commit

Permalink
ci: codebase health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarletFlash committed Nov 10, 2024
1 parent 48db048 commit 942b2e0
Show file tree
Hide file tree
Showing 13 changed files with 1,463 additions and 925 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
push:
branches:
- "main"
- 'main'
release:
types: [published]

Expand All @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
name: Build and publish
steps:
- name: "Fetch all required Git history"
- name: 'Fetch all required Git history'
uses: actions/checkout@v4
with:
fetch-depth: 2
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Check

on:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}-${{ github.event_name }}
cancel-in-progress: true

defaults:
run:
shell: bash

jobs:
check:
runs-on: ubuntu-latest
name: Check
steps:
- name: 'Fetch all required Git history'
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Setup PNPM
uses: pnpm/action-setup@v4
with:
package_json_file: package.json

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Check formatting
run: pnpm run formatter:check

- name: Run unit tests
run: pnpm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
coverage
dist
.*cache
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
coverage
dist
.*cache
21 changes: 21 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "always",
"requirePragma": false,
"insertPragma": false,
"proseWrap": "always",
"htmlWhitespaceSensitivity": "css",
"vueIndentScriptAndStyle": false,
"endOfLine": "lf",
"embeddedLanguageFormatting": "auto",
"singleAttributePerLine": true
}
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ export default function Layout({ children }: PropsWithChildren): ReactElement {
#### Into this:

```tsx
import { FlatProvider } from "flat-provider";
import { FlatProvider } from 'flat-provider';

export default function Layout({ children }: PropsWithChildren): ReactElement {
// ...

return FlatProvider
.append(UserTrackingProvider, { apiKey: process.env.TRACKING_API_KEY })
return FlatProvider.append(UserTrackingProvider, { apiKey: process.env.TRACKING_API_KEY })
.append(AuthProvider, { session })
.append(UiKitProvider)
.append(ThemeProvider)
Expand All @@ -47,4 +46,7 @@ export default function Layout({ children }: PropsWithChildren): ReactElement {

- 100% test-coverage
- Type-safe
- Great match for [react/jsx-max-depth](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-max-depth.md) ESLint rule
- Great match for
[react/jsx-max-depth](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-max-depth.md)
ESLint rule
- Fully compatible with client and server components ― no hooks inside
86 changes: 41 additions & 45 deletions build.script.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,85 @@
import { resolve } from "path";
import { build, LibraryOptions, resolveConfig, ResolvedConfig } from "vite";
import { resolve } from 'path';
import { build, LibraryOptions, resolveConfig, ResolvedConfig } from 'vite';

import { PackageJSON } from "@npm/types";
import { access, cp, readFile, writeFile } from "fs/promises";
import { PackageJSON } from '@npm/types';
import { access, cp, readFile, writeFile } from 'fs/promises';

const encoding: "utf-8" = "utf-8";
const encoding: 'utf-8' = 'utf-8';
const packageJsonKeysToKeep: Set<string | number> = new Set<keyof PackageJSON>([
"author",
"bugs",
"bundleDependencies",
"bundledDependencies",
"contributors",
"dependencies",
"description",
"files",
"funding",
"homepage",
"keywords",
"license",
"main",
"man",
"name",
"optionalDependencies",
"peerDependencies",
"peerDependenciesMeta",
"repository",
"types",
"version",
'author',
'bugs',
'bundleDependencies',
'bundledDependencies',
'contributors',
'dependencies',
'description',
'files',
'funding',
'homepage',
'keywords',
'license',
'main',
'man',
'name',
'optionalDependencies',
'peerDependencies',
'peerDependenciesMeta',
'repository',
'types',
'version'
]);

(async () => {
const configFile: string = resolve(__dirname, "vite.config.ts");
const configFile: string = resolve(__dirname, 'vite.config.ts');
await access(configFile);

await build({
configFile,
configFile
});

const {
build: { outDir, lib },
build: { outDir, lib }
}: ResolvedConfig = await resolveConfig(
{
configFile,
configFile
},
"build"
'build'
);
if (typeof lib === "boolean") {
throw new Error(
"Vite config / build / lib is expected to be LibraryOptions"
);
if (typeof lib === 'boolean') {
throw new Error('Vite config / build / lib is expected to be LibraryOptions');
}
const { fileName }: LibraryOptions = lib;

const licenseFileName: string = "LICENSE.md";
const licenseFileName: string = 'LICENSE.md';
const licenseFile: string = resolve(__dirname, licenseFileName);
await access(licenseFile);
await cp(licenseFile, resolve(__dirname, outDir, licenseFileName));

const readMeFileName: string = "README.md";
const readMeFileName: string = 'README.md';
const readMeFile: string = resolve(__dirname, readMeFileName);
await access(readMeFile);
await cp(readMeFile, resolve(__dirname, outDir, readMeFileName));

const packageJsonFile: string = resolve(__dirname, "package.json");
const packageJsonFile: string = resolve(__dirname, 'package.json');
const packageJson: PackageJSON = JSON.parse(
await readFile(packageJsonFile, {
encoding,
encoding
})
);
const modifiedPackageJson: Record<string, unknown> = Object.fromEntries(
Object.entries(packageJson).filter(([key]) =>
packageJsonKeysToKeep.has(key)
)
Object.entries(packageJson).filter(([key]) => packageJsonKeysToKeep.has(key))
);
await writeFile(
resolve(__dirname, outDir, "package.json"),
resolve(__dirname, outDir, 'package.json'),
JSON.stringify({
...modifiedPackageJson,
main: `${fileName}.mjs`,
browser: `${fileName}.mjs`,
types: `${fileName}.d.ts`,
license: "MIT",
license: 'MIT'
} satisfies Partial<PackageJSON>),
{
encoding,
encoding
}
);
})();
14 changes: 7 additions & 7 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { createDefaultPreset, JestConfigWithTsJest } from "ts-jest";
import { createDefaultPreset, JestConfigWithTsJest } from 'ts-jest';

module.exports = {
...createDefaultPreset({
tsconfig: "<rootDir>/tsconfig.test.json",
tsconfig: '<rootDir>/tsconfig.test.json'
}),
roots: ["<rootDir>"],
testEnvironment: "jsdom",
roots: ['<rootDir>'],
testEnvironment: 'jsdom',
collectCoverage: true,
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
statements: 100
}
}
} satisfies JestConfigWithTsJest;
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
},
"scripts": {
"build": "ts-node --project tsconfig.root.json ./build.script.ts",
"test": "jest --config ./jest.config.ts"
"test": "jest --config ./jest.config.ts",
"formatter:check": "prettier --cache --cache-location .prettiercache --cache-strategy content --check .",
"formatter:fix": "prettier --cache --cache-location .prettiercache --cache-strategy content --write ."
},
"peerDependencies": {
"react": "^18.0.0"
Expand All @@ -38,7 +40,8 @@
"ts-node": "^10.0.0",
"typescript": "^5.0.0",
"vite": "^5.0.0",
"vite-plugin-dts": "^4.0.0"
"vite-plugin-dts": "^4.0.0",
"prettier": "^3.0.0"
},
"engines": {
"pnpm": "9.12.2",
Expand Down
Loading

0 comments on commit 942b2e0

Please sign in to comment.