@syntopica/create-baseline 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +85 -0
- package/baseline-versions.json +16 -0
- package/bin/baseline-estate.mjs +85 -0
- package/bin/conformance/applyFixes.mjs +101 -0
- package/bin/conformance/checkActionPins.mjs +43 -0
- package/bin/conformance/checkCiWorkflow.mjs +52 -0
- package/bin/conformance/checkCoverageThresholds.mjs +112 -0
- package/bin/conformance/checkGateCoverage.mjs +128 -0
- package/bin/conformance/checkHooksInstalled.mjs +43 -0
- package/bin/conformance/checkLintFlag.mjs +86 -0
- package/bin/conformance/checkTsconfigPresets.mjs +58 -0
- package/bin/conformance/checkTsconfigProjects.mjs +47 -0
- package/bin/conformance/checkVersionRanges.mjs +51 -0
- package/bin/conformance/ciEntrypoints.mjs +37 -0
- package/bin/conformance/expandScripts.mjs +76 -0
- package/bin/conformance/formatFindings.mjs +36 -0
- package/bin/conformance/loadContext.mjs +175 -0
- package/bin/conformance/loadExceptions.mjs +73 -0
- package/bin/conformance/rangeFloor.mjs +23 -0
- package/bin/conformance/readWorkflows.mjs +29 -0
- package/bin/conformance/runConformance.mjs +57 -0
- package/bin/create-baseline.mjs +432 -0
- package/bin/estate/findConsumers.mjs +46 -0
- package/bin/estate/findPythonConsumers.mjs +58 -0
- package/bin/estate/formatEstate.mjs +67 -0
- package/bin/estate/formatPythonEstate.mjs +37 -0
- package/bin/python/checkGateWorkflow.mjs +33 -0
- package/bin/python/checkLockPin.mjs +36 -0
- package/bin/python/checkQualityGroup.mjs +33 -0
- package/bin/python/loadPythonContext.mjs +32 -0
- package/bin/python/repositoryRoot.mjs +24 -0
- package/bin/python/runPythonConformance.mjs +25 -0
- package/bin/scaffold/actionPins.mjs +34 -0
- package/bin/scaffold/baselineScripts.mjs +44 -0
- package/bin/scaffold/checkPeers.mjs +87 -0
- package/bin/scaffold/ciWorkflow.mjs +144 -0
- package/bin/scaffold/collectDeps.mjs +10 -0
- package/bin/scaffold/composedSubpaths.mjs +41 -0
- package/bin/scaffold/depCruiserConfig.mjs +30 -0
- package/bin/scaffold/detectFramework.mjs +18 -0
- package/bin/scaffold/eslintSubpathPeers.mjs +60 -0
- package/bin/scaffold/knipConfig.mjs +9 -0
- package/bin/scaffold/lefthookConfig.mjs +33 -0
- package/bin/scaffold/oxlintConfig.mjs +19 -0
- package/bin/scaffold/readManifest.mjs +17 -0
- package/bin/scaffold/renovateConfig.mjs +11 -0
- package/bin/scaffold/workspaceRoots.mjs +89 -0
- package/bin/scaffold/writeCiWorkflow.mjs +54 -0
- package/bin/scaffold/writeMissing.mjs +116 -0
- package/package.json +59 -0
- package/python-versions.json +3 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// dependency-cruiser loads CommonJS config only while the shared factory is
|
|
2
|
+
// TypeScript, so the generated file reaches it through jiti. Written for every
|
|
3
|
+
// adopter because the shape is the tool's, not the author's: seven repos
|
|
4
|
+
// adopting the gates by hand wrote this same file, differing only in which
|
|
5
|
+
// directories to exempt from `no-orphans`.
|
|
6
|
+
export function depCruiserConfig() {
|
|
7
|
+
return `// dependency-cruiser loads CommonJS config; the shared factory is TypeScript,
|
|
8
|
+
// so jiti (a direct devDependency for exactly this purpose) transpiles it on
|
|
9
|
+
// the fly.
|
|
10
|
+
//
|
|
11
|
+
// \`tsConfigPath\` is what makes path aliases resolve: without it every aliased
|
|
12
|
+
// import comes back unresolved and the graph is mostly empty.
|
|
13
|
+
const { createJiti } = require('jiti')
|
|
14
|
+
|
|
15
|
+
const jiti = createJiti(__filename)
|
|
16
|
+
const { createDepCruiserConfig } = jiti(
|
|
17
|
+
'@syntopica/quality-config/dependency-cruiser',
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
module.exports = createDepCruiserConfig({
|
|
21
|
+
tsConfigPath: './tsconfig.json',
|
|
22
|
+
orphanExemptions: [
|
|
23
|
+
// Test runners collect these by glob; no module imports a test file.
|
|
24
|
+
'\\\\.test\\\\.(ts|tsx)$',
|
|
25
|
+
// Hand-run maintenance scripts, invoked by path from the shell.
|
|
26
|
+
'(^|/)scripts/',
|
|
27
|
+
],
|
|
28
|
+
})
|
|
29
|
+
`
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// The knip preset key for a project, read from its dependencies.
|
|
2
|
+
//
|
|
3
|
+
// Order matters: a Tauri app also carries vite and react, a Nuxt app also
|
|
4
|
+
// carries vue, and a TanStack Start app carries both react and vite while
|
|
5
|
+
// having neither index.html nor src/main.tsx - so the most specific marker has
|
|
6
|
+
// to win. `ts-package` is the fallback because a library has none of these
|
|
7
|
+
// markers at all.
|
|
8
|
+
export function detectFramework(deps) {
|
|
9
|
+
if (deps['@tauri-apps/api'] || deps['@tauri-apps/cli']) return 'tauri'
|
|
10
|
+
if (deps['nuxt']) return 'nuxt'
|
|
11
|
+
if (deps['astro']) return 'astro'
|
|
12
|
+
if (deps['@nestjs/core']) return 'nestjs'
|
|
13
|
+
if (deps['next']) return 'nextjs'
|
|
14
|
+
if (deps['@tanstack/react-start']) return 'tanstack-start'
|
|
15
|
+
if (deps['vue']) return 'vite-vue'
|
|
16
|
+
if (deps['react']) return 'vite-react'
|
|
17
|
+
return 'ts-package'
|
|
18
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Which packages each `@syntopica/eslint-config` subpath imports by bare
|
|
2
|
+
// specifier. The config ships TypeScript source rather than a build, so these
|
|
3
|
+
// resolve from the consuming project: one missing here fails ESLint before a
|
|
4
|
+
// rule runs, with a message that names neither the baseline nor the subpath
|
|
5
|
+
// that wanted it.
|
|
6
|
+
//
|
|
7
|
+
// Mirrors the stacks table in the eslint-config README.
|
|
8
|
+
export const ESLINT_SUBPATH_PEERS = {
|
|
9
|
+
base: [
|
|
10
|
+
'@eslint/js',
|
|
11
|
+
'eslint-config-prettier',
|
|
12
|
+
'eslint-plugin-import',
|
|
13
|
+
'eslint-import-resolver-typescript',
|
|
14
|
+
'eslint-plugin-promise',
|
|
15
|
+
'eslint-plugin-security',
|
|
16
|
+
'eslint-plugin-unused-imports',
|
|
17
|
+
'typescript-eslint',
|
|
18
|
+
],
|
|
19
|
+
nextjs: [
|
|
20
|
+
'@next/eslint-plugin-next',
|
|
21
|
+
'eslint-plugin-react',
|
|
22
|
+
'eslint-plugin-react-hooks',
|
|
23
|
+
'eslint-plugin-boundaries',
|
|
24
|
+
],
|
|
25
|
+
'vite-react': [
|
|
26
|
+
'eslint-plugin-react',
|
|
27
|
+
'eslint-plugin-react-hooks',
|
|
28
|
+
'eslint-plugin-react-refresh',
|
|
29
|
+
'eslint-plugin-boundaries',
|
|
30
|
+
],
|
|
31
|
+
'vite-vue': [
|
|
32
|
+
'eslint-plugin-vue',
|
|
33
|
+
'eslint-plugin-vuejs-accessibility',
|
|
34
|
+
'vue-eslint-parser',
|
|
35
|
+
'eslint-plugin-unused-imports',
|
|
36
|
+
'typescript-eslint',
|
|
37
|
+
],
|
|
38
|
+
astro: [
|
|
39
|
+
'eslint-plugin-astro',
|
|
40
|
+
'typescript-eslint',
|
|
41
|
+
'eslint-plugin-boundaries',
|
|
42
|
+
],
|
|
43
|
+
node: ['eslint-plugin-unicorn', 'globals'],
|
|
44
|
+
'data-files': [
|
|
45
|
+
'@eslint/markdown',
|
|
46
|
+
'eslint-plugin-jsonc',
|
|
47
|
+
'eslint-plugin-yml',
|
|
48
|
+
],
|
|
49
|
+
nestjs: ['eslint-plugin-unicorn', 'globals'],
|
|
50
|
+
'code-quality': [
|
|
51
|
+
'eslint-plugin-code-policy',
|
|
52
|
+
'eslint-plugin-sonarjs',
|
|
53
|
+
'eslint-plugin-testing-library',
|
|
54
|
+
'@vitest/eslint-plugin',
|
|
55
|
+
],
|
|
56
|
+
testing: ['@vitest/eslint-plugin', 'eslint-plugin-testing-library'],
|
|
57
|
+
accessibility: ['eslint-plugin-jsx-a11y'],
|
|
58
|
+
tailwind: ['eslint-plugin-tailwindcss'],
|
|
59
|
+
'frontend-boundaries': ['eslint-plugin-boundaries'],
|
|
60
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// A knip config that defers to the shared preset. A project with entry points
|
|
2
|
+
// the preset cannot know about - hand-run scripts, e2e specs - extends this
|
|
3
|
+
// afterwards; starting from one line makes that diff readable.
|
|
4
|
+
export function knipConfig(framework) {
|
|
5
|
+
return `import { createKnipConfig } from '@syntopica/quality-config/knip'
|
|
6
|
+
|
|
7
|
+
export default createKnipConfig({ framework: '${framework}' })
|
|
8
|
+
`
|
|
9
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The git hooks every baseline project runs: lint and format on the staged
|
|
2
|
+
// files at commit, secret scan before push. Mirrors createLefthookConfig() in
|
|
3
|
+
// @syntopica/quality-config/lefthook.
|
|
4
|
+
export function lefthookConfig() {
|
|
5
|
+
return `# Mirrors createLefthookConfig() in @syntopica/quality-config/lefthook.
|
|
6
|
+
pre-commit:
|
|
7
|
+
parallel: true
|
|
8
|
+
commands:
|
|
9
|
+
lint:fast:
|
|
10
|
+
glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}'
|
|
11
|
+
run: pnpm exec oxlint --deny-warnings {staged_files}
|
|
12
|
+
lint:
|
|
13
|
+
glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs}'
|
|
14
|
+
run: pnpm exec eslint --max-warnings 0 --no-warn-ignored {staged_files}
|
|
15
|
+
format:
|
|
16
|
+
glob: '*.{js,jsx,ts,tsx,vue,astro,mjs,cjs,json,md,css,yml,yaml}'
|
|
17
|
+
run: pnpm exec prettier --check {staged_files}
|
|
18
|
+
|
|
19
|
+
# The release tooling reads the commit type to pick the semver bump and to
|
|
20
|
+
# build the changelog, so a mistyped subject is a silent release defect. This
|
|
21
|
+
# is the only place it can be caught: by the time the tag is cut the message
|
|
22
|
+
# is already history.
|
|
23
|
+
commit-msg:
|
|
24
|
+
commands:
|
|
25
|
+
commitlint:
|
|
26
|
+
run: pnpm exec commitlint --edit {1}
|
|
27
|
+
|
|
28
|
+
pre-push:
|
|
29
|
+
commands:
|
|
30
|
+
secrets:
|
|
31
|
+
run: gitleaks detect --no-banner --redact
|
|
32
|
+
`
|
|
33
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
|
|
4
|
+
const require = createRequire(import.meta.url)
|
|
5
|
+
|
|
6
|
+
// The oxlint pre-filter config, read from @syntopica/quality-config rather
|
|
7
|
+
// than restated here. oxlint takes a JSON file, not a factory, so the only way
|
|
8
|
+
// to keep one source of truth is to copy the shipped file at scaffold time -
|
|
9
|
+
// and to read it from the package, so a change there reaches new projects
|
|
10
|
+
// without this file being touched.
|
|
11
|
+
export function oxlintConfig() {
|
|
12
|
+
// The path comes from this package's own dependency resolution, not from
|
|
13
|
+
// anything a caller supplies.
|
|
14
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
15
|
+
return readFileSync(
|
|
16
|
+
require.resolve('@syntopica/quality-config/oxlint'),
|
|
17
|
+
'utf8',
|
|
18
|
+
)
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The parsed `package.json` of a project directory.
|
|
6
|
+
*
|
|
7
|
+
* Throws if there is none, or if it is not JSON. Callers decide what that
|
|
8
|
+
* means: the scaffolder treats it as "not a project", the conformance check
|
|
9
|
+
* treats it as a hard stop.
|
|
10
|
+
*/
|
|
11
|
+
export async function readManifest(root) {
|
|
12
|
+
// `root` is the directory this CLI was invoked against, or a workspace of
|
|
13
|
+
// it - reading its manifest is the tool's job, not untrusted input.
|
|
14
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
15
|
+
const raw = await readFile(resolve(root, 'package.json'), 'utf8')
|
|
16
|
+
return JSON.parse(raw)
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Renovate defaults for a baseline project: the shared preset plus a
|
|
2
|
+
// release-age cooldown, so a compromised package has time to be caught before
|
|
3
|
+
// a bot opens the PR that installs it.
|
|
4
|
+
export function renovateConfig() {
|
|
5
|
+
return `{
|
|
6
|
+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
7
|
+
"extends": ["config:recommended", ":dependencyDashboard"],
|
|
8
|
+
"minimumReleaseAge": "3 days"
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { readdir, readFile } from 'node:fs/promises'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
// The directories a monorepo's workspaces live in, resolved from whichever
|
|
5
|
+
// package manager's home for them the repo uses. A repo with neither file is
|
|
6
|
+
// not a monorepo and gets an empty list.
|
|
7
|
+
//
|
|
8
|
+
// Only globs one level deep are followed, which is where pnpm and npm
|
|
9
|
+
// workspaces put packages in practice: `apps/*`, `packages/*`. A deeper or
|
|
10
|
+
// wilder pattern is skipped rather than half-matched.
|
|
11
|
+
export async function workspaceRoots(root) {
|
|
12
|
+
const globs = await workspaceGlobs(root)
|
|
13
|
+
const roots = []
|
|
14
|
+
for (const glob of globs) {
|
|
15
|
+
const [group] = glob.split('/')
|
|
16
|
+
if (!group || group.startsWith('.') || group.includes('*')) continue
|
|
17
|
+
let entries
|
|
18
|
+
try {
|
|
19
|
+
// A path under the project this CLI was invoked against, which is the
|
|
20
|
+
// tool's job to read - not untrusted input.
|
|
21
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
22
|
+
entries = await readdir(resolve(root, group), { withFileTypes: true })
|
|
23
|
+
} catch {
|
|
24
|
+
continue
|
|
25
|
+
}
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
if (entry.isDirectory()) roots.push(resolve(root, group, entry.name))
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return roots
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function workspaceGlobs(root) {
|
|
34
|
+
try {
|
|
35
|
+
const manifest = JSON.parse(
|
|
36
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
37
|
+
await readFile(resolve(root, 'package.json'), 'utf8'),
|
|
38
|
+
)
|
|
39
|
+
if (Array.isArray(manifest.workspaces)) return manifest.workspaces
|
|
40
|
+
if (Array.isArray(manifest.workspaces?.packages)) {
|
|
41
|
+
return manifest.workspaces.packages
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
/* no manifest, or not JSON: fall through to pnpm's file */
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
48
|
+
const raw = await readFile(resolve(root, 'pnpm-workspace.yaml'), 'utf8')
|
|
49
|
+
return pnpmPackages(raw)
|
|
50
|
+
} catch {
|
|
51
|
+
return []
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// One list item under `packages:`. Anchored at both ends and with a capture
|
|
56
|
+
// that admits no whitespace, so no quantifier here can exchange characters
|
|
57
|
+
// with its neighbour.
|
|
58
|
+
const LIST_ITEM = /^[ \t]*-[ \t]*['"]?([^'"\s]+)['"]?[ \t]*$/
|
|
59
|
+
|
|
60
|
+
// The `packages:` block of a pnpm workspace file, read line by line rather
|
|
61
|
+
// than matched as one block.
|
|
62
|
+
//
|
|
63
|
+
// The block regex this replaces was `/^packages:\n((?:\s*-.*\n?)+)/m`, whose
|
|
64
|
+
// `\s*` and `.*` can exchange characters - exponential backtracking on a file
|
|
65
|
+
// this tool reads in every repository it visits. Rewriting it to be linear is
|
|
66
|
+
// possible but delicate; a loop over lines has no backtracking to reason
|
|
67
|
+
// about at all, and says what it does.
|
|
68
|
+
function pnpmPackages(raw) {
|
|
69
|
+
const globs = []
|
|
70
|
+
let inBlock = false
|
|
71
|
+
|
|
72
|
+
for (const line of raw.split('\n')) {
|
|
73
|
+
if (!inBlock) {
|
|
74
|
+
if (line.trimEnd() === 'packages:') inBlock = true
|
|
75
|
+
continue
|
|
76
|
+
}
|
|
77
|
+
const item = LIST_ITEM.exec(line)
|
|
78
|
+
if (item) {
|
|
79
|
+
globs.push(item[1])
|
|
80
|
+
continue
|
|
81
|
+
}
|
|
82
|
+
// A blank line or a comment sits inside the block; anything else is the
|
|
83
|
+
// next top-level key and ends it.
|
|
84
|
+
if (line.trim() === '' || line.trimStart().startsWith('#')) continue
|
|
85
|
+
break
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return globs
|
|
89
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { ciWorkflow } from './ciWorkflow.mjs'
|
|
5
|
+
|
|
6
|
+
const WORKFLOW_DIR = '.github/workflows'
|
|
7
|
+
const WORKFLOW_NAME = 'ci.yml'
|
|
8
|
+
|
|
9
|
+
// A workflow that already runs the baseline entrypoints, whatever it is called.
|
|
10
|
+
// Matching on the command rather than the filename is deliberate: a repo whose
|
|
11
|
+
// gate job lives in `verify.yml` or `main.yml` is wired, and writing a second
|
|
12
|
+
// workflow beside it would run every gate twice on every push.
|
|
13
|
+
const RUNS_BASELINE_GATES = /pnpm\s+(?:run\s+)?check:ci\b/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Writes `.github/workflows/ci.yml` when nothing in the repository already
|
|
17
|
+
* runs the baseline gates, and reports what it found when something does.
|
|
18
|
+
*
|
|
19
|
+
* Returns `{ written, existing }`: `written` is the path if one was created,
|
|
20
|
+
* `existing` is the name of the workflow that made writing unnecessary, and a
|
|
21
|
+
* repository with workflows that do not run the gates gets neither - the
|
|
22
|
+
* caller reports that as a partial wiring rather than writing a file that
|
|
23
|
+
* would duplicate an existing pipeline.
|
|
24
|
+
*/
|
|
25
|
+
export async function writeCiWorkflow(root, { hasBuild }) {
|
|
26
|
+
const dir = resolve(root, WORKFLOW_DIR)
|
|
27
|
+
let entries = []
|
|
28
|
+
try {
|
|
29
|
+
// A fixed path under the directory this CLI was invoked against.
|
|
30
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
31
|
+
entries = (await readdir(dir)).filter((name) => /\.ya?ml$/.test(name))
|
|
32
|
+
} catch {
|
|
33
|
+
/* no workflow directory yet */
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (const name of entries) {
|
|
37
|
+
let raw
|
|
38
|
+
try {
|
|
39
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
40
|
+
raw = await readFile(resolve(dir, name), 'utf8')
|
|
41
|
+
} catch {
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
if (RUNS_BASELINE_GATES.test(raw)) return { written: null, existing: name }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (entries.length) return { written: null, existing: null, partial: entries }
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
50
|
+
await mkdir(dir, { recursive: true })
|
|
51
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
52
|
+
await writeFile(resolve(dir, WORKFLOW_NAME), ciWorkflow({ hasBuild }), 'utf8')
|
|
53
|
+
return { written: `${WORKFLOW_DIR}/${WORKFLOW_NAME}`, existing: null }
|
|
54
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { access, readFile, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { baselineScripts } from './baselineScripts.mjs'
|
|
5
|
+
import { depCruiserConfig } from './depCruiserConfig.mjs'
|
|
6
|
+
import { detectFramework } from './detectFramework.mjs'
|
|
7
|
+
import { knipConfig } from './knipConfig.mjs'
|
|
8
|
+
import { lefthookConfig } from './lefthookConfig.mjs'
|
|
9
|
+
import { oxlintConfig } from './oxlintConfig.mjs'
|
|
10
|
+
import { renovateConfig } from './renovateConfig.mjs'
|
|
11
|
+
import { writeCiWorkflow } from './writeCiWorkflow.mjs'
|
|
12
|
+
|
|
13
|
+
// Writes the quality-gate wiring a project is missing and returns what it did.
|
|
14
|
+
//
|
|
15
|
+
// Never overwrites: a file that exists is the project's, however it got there,
|
|
16
|
+
// and a tuned knip config is exactly the thing an adopter spent time on. Same
|
|
17
|
+
// for scripts - only names the project does not define are added.
|
|
18
|
+
//
|
|
19
|
+
// `alternatives` is every other filename the tool itself would load, not a
|
|
20
|
+
// guess. Miss one and the write is worse than useless: vexa-insight-dashboard
|
|
21
|
+
// carried a `knip.json` that set `project` to `["tsconfig.json"]`, so knip
|
|
22
|
+
// scanned almost nothing and called 34 live dependencies unused. This tool
|
|
23
|
+
// wrote `knip.config.ts` next to it, knip went on loading the json, and the
|
|
24
|
+
// gate stayed broken while looking configured. A shadowed file is reported by
|
|
25
|
+
// name rather than skipped in silence.
|
|
26
|
+
export async function writeMissing(root, deps) {
|
|
27
|
+
const written = []
|
|
28
|
+
const shadowed = []
|
|
29
|
+
const framework = detectFramework(deps)
|
|
30
|
+
|
|
31
|
+
const files = [
|
|
32
|
+
[
|
|
33
|
+
'knip.config.ts',
|
|
34
|
+
() => knipConfig(framework),
|
|
35
|
+
[
|
|
36
|
+
'knip.config.js',
|
|
37
|
+
'knip.config.mjs',
|
|
38
|
+
'knip.config.cjs',
|
|
39
|
+
'knip.json',
|
|
40
|
+
'knip.jsonc',
|
|
41
|
+
'.knip.json',
|
|
42
|
+
'.knip.jsonc',
|
|
43
|
+
],
|
|
44
|
+
],
|
|
45
|
+
['lefthook.yml', lefthookConfig, ['lefthook.yaml', '.lefthook.yml']],
|
|
46
|
+
['.oxlintrc.json', oxlintConfig, ['oxlint.json', '.oxlintrc']],
|
|
47
|
+
[
|
|
48
|
+
'renovate.json',
|
|
49
|
+
renovateConfig,
|
|
50
|
+
[
|
|
51
|
+
'renovate.json5',
|
|
52
|
+
'.renovaterc',
|
|
53
|
+
'.renovaterc.json',
|
|
54
|
+
'.github/renovate.json',
|
|
55
|
+
'.github/renovate.json5',
|
|
56
|
+
],
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
'.dependency-cruiser.cjs',
|
|
60
|
+
depCruiserConfig,
|
|
61
|
+
[
|
|
62
|
+
'.dependency-cruiser.js',
|
|
63
|
+
'.dependency-cruiser.mjs',
|
|
64
|
+
'.dependency-cruiser.json',
|
|
65
|
+
'.dependency-cruiser.jsonc',
|
|
66
|
+
],
|
|
67
|
+
],
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
for (const [name, render, alternatives] of files) {
|
|
71
|
+
let found
|
|
72
|
+
for (const candidate of [name, ...alternatives]) {
|
|
73
|
+
try {
|
|
74
|
+
await access(resolve(root, candidate))
|
|
75
|
+
found = candidate
|
|
76
|
+
break
|
|
77
|
+
} catch {
|
|
78
|
+
/* not there */
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (found) {
|
|
82
|
+
if (found !== name) shadowed.push([found, name])
|
|
83
|
+
continue
|
|
84
|
+
}
|
|
85
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
86
|
+
await writeFile(resolve(root, name), render(), 'utf8')
|
|
87
|
+
written.push(name)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const manifestPath = resolve(root, 'package.json')
|
|
91
|
+
// Fixed filename under the directory the caller chose to run in, which is
|
|
92
|
+
// the whole point of this tool - not untrusted input.
|
|
93
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
94
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'))
|
|
95
|
+
manifest.scripts ??= {}
|
|
96
|
+
const added = []
|
|
97
|
+
for (const [name, command] of Object.entries(baselineScripts())) {
|
|
98
|
+
if (manifest.scripts[name]) continue
|
|
99
|
+
manifest.scripts[name] = command
|
|
100
|
+
added.push(name)
|
|
101
|
+
}
|
|
102
|
+
if (added.length) {
|
|
103
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
104
|
+
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Last, and after the scripts: the workflow it writes calls `check:ci`,
|
|
108
|
+
// `check:quality` and `check:security`, so writing it before those exist
|
|
109
|
+
// would produce a pipeline whose first run fails on a missing script.
|
|
110
|
+
const workflow = await writeCiWorkflow(root, {
|
|
111
|
+
hasBuild: Boolean(manifest.scripts.build),
|
|
112
|
+
})
|
|
113
|
+
if (workflow.written) written.push(workflow.written)
|
|
114
|
+
|
|
115
|
+
return { framework, written, shadowed, scripts: added, workflow }
|
|
116
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@syntopica/create-baseline",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"packageManager": "pnpm@11.25.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"description": "CLI to verify and adopt @syntopica baseline config packages",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/BusiRocket/baseline.git",
|
|
11
|
+
"directory": "packages/create-baseline"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/BusiRocket/baseline/tree/main/packages/create-baseline#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/BusiRocket/baseline/issues"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=20"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"create-baseline": "bin/create-baseline.mjs",
|
|
26
|
+
"baseline-estate": "bin/baseline-estate.mjs"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"LICENSE",
|
|
30
|
+
"README.md",
|
|
31
|
+
"baseline-versions.json",
|
|
32
|
+
"python-versions.json",
|
|
33
|
+
"bin"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"check:self": "node ./bin/create-baseline.mjs --check",
|
|
37
|
+
"lint": "eslint bin tests --max-warnings 0",
|
|
38
|
+
"lint:fix": "eslint bin tests --fix",
|
|
39
|
+
"lint:suppress": "eslint bin tests --suppress-all",
|
|
40
|
+
"lint:prune": "eslint bin tests --prune-suppressions",
|
|
41
|
+
"test": "vitest run --coverage",
|
|
42
|
+
"publish:check": "baseline-licenses && publint --strict && attw --pack . --profile node16"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"eslint",
|
|
46
|
+
"prettier",
|
|
47
|
+
"typescript",
|
|
48
|
+
"baseline"
|
|
49
|
+
],
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
52
|
+
"@syntopica/eslint-config": "workspace:*",
|
|
53
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
54
|
+
"eslint": "^10.9.1",
|
|
55
|
+
"eslint-plugin-regexp": "^3.2.0",
|
|
56
|
+
"publint": "^0.3.24",
|
|
57
|
+
"vitest": "^4.1.11"
|
|
58
|
+
}
|
|
59
|
+
}
|