@tyyyho/treg 0.1.2 → 0.1.6
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/README.md +52 -45
- package/dist/init-project/cli.js +228 -0
- package/dist/init-project/frameworks/index.js +39 -0
- package/dist/init-project/frameworks/next/index.js +9 -0
- package/dist/init-project/frameworks/node/index.js +8 -0
- package/dist/init-project/frameworks/nuxt/index.js +9 -0
- package/dist/init-project/frameworks/react/index.js +27 -0
- package/dist/init-project/frameworks/react/v18/index.js +6 -0
- package/dist/init-project/frameworks/react/v19/index.js +6 -0
- package/dist/init-project/frameworks/svelte/index.js +9 -0
- package/dist/init-project/frameworks/vue/index.js +9 -0
- package/dist/init-project/index.js +65 -0
- package/dist/init-project/mrm-core.js +3 -0
- package/dist/init-project/mrm-rules/ai-skills.js +200 -0
- package/dist/init-project/mrm-rules/format.js +44 -0
- package/dist/init-project/mrm-rules/husky.js +61 -0
- package/dist/init-project/mrm-rules/index.js +33 -0
- package/dist/init-project/mrm-rules/lint.js +16 -0
- package/dist/init-project/mrm-rules/shared.js +91 -0
- package/dist/init-project/mrm-rules/test-jest.js +48 -0
- package/dist/init-project/mrm-rules/test-vitest.js +46 -0
- package/dist/init-project/mrm-rules/typescript.js +40 -0
- package/dist/init-project/package-manager.js +57 -0
- package/dist/init-project/types.js +1 -0
- package/dist/init-project/utils.js +9 -0
- package/dist/init-project.js +6 -0
- package/dist/package.json +3 -0
- package/package.json +10 -5
- package/scripts/init-project/cli.mjs +0 -173
- package/scripts/init-project/cli.test.mjs +0 -116
- package/scripts/init-project/frameworks/index.mjs +0 -48
- package/scripts/init-project/frameworks/next/index.mjs +0 -10
- package/scripts/init-project/frameworks/node/index.mjs +0 -8
- package/scripts/init-project/frameworks/nuxt/index.mjs +0 -10
- package/scripts/init-project/frameworks/react/index.mjs +0 -35
- package/scripts/init-project/frameworks/react/v18/index.mjs +0 -6
- package/scripts/init-project/frameworks/react/v19/index.mjs +0 -6
- package/scripts/init-project/frameworks/svelte/index.mjs +0 -10
- package/scripts/init-project/frameworks/vue/index.mjs +0 -10
- package/scripts/init-project/frameworks.test.mjs +0 -63
- package/scripts/init-project/index.mjs +0 -89
- package/scripts/init-project/mrm-core.mjs +0 -5
- package/scripts/init-project/mrm-rules/ai-skills.mjs +0 -220
- package/scripts/init-project/mrm-rules/ai-skills.test.mjs +0 -91
- package/scripts/init-project/mrm-rules/format.mjs +0 -55
- package/scripts/init-project/mrm-rules/husky.mjs +0 -78
- package/scripts/init-project/mrm-rules/index.mjs +0 -35
- package/scripts/init-project/mrm-rules/lint.mjs +0 -18
- package/scripts/init-project/mrm-rules/shared.mjs +0 -61
- package/scripts/init-project/mrm-rules/test-jest.mjs +0 -75
- package/scripts/init-project/mrm-rules/test-vitest.mjs +0 -64
- package/scripts/init-project/mrm-rules/typescript.mjs +0 -44
- package/scripts/init-project/package-manager.mjs +0 -68
- package/scripts/init-project/package-manager.test.mjs +0 -21
- package/scripts/init-project/utils.mjs +0 -12
- package/scripts/init-project/utils.test.mjs +0 -22
- package/scripts/init-project.mjs +0 -7
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { json, packageJson } from "../mrm-core.mjs"
|
|
2
|
-
import { installPackages, withProjectCwd } from "./shared.mjs"
|
|
3
|
-
|
|
4
|
-
const TS_REQUIRED_OPTIONS = {
|
|
5
|
-
noImplicitAny: true,
|
|
6
|
-
noImplicitThis: true,
|
|
7
|
-
exactOptionalPropertyTypes: true,
|
|
8
|
-
noUncheckedIndexedAccess: true,
|
|
9
|
-
noUnusedLocals: true,
|
|
10
|
-
noUnusedParameters: true,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function runTypescriptRule(context) {
|
|
14
|
-
const { framework, projectDir, pm, dryRun } = context
|
|
15
|
-
installPackages(projectDir, pm, ["typescript"], true, dryRun)
|
|
16
|
-
|
|
17
|
-
withProjectCwd(projectDir, () => {
|
|
18
|
-
if (dryRun) {
|
|
19
|
-
console.log("[dry-run] Would update tsconfig.json")
|
|
20
|
-
console.log("[dry-run] Would set package script: type-check")
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const tsconfig = json("tsconfig.json", {
|
|
25
|
-
compilerOptions: {},
|
|
26
|
-
exclude: [],
|
|
27
|
-
})
|
|
28
|
-
const mergedCompilerOptions = {
|
|
29
|
-
...(tsconfig.get("compilerOptions") ?? {}),
|
|
30
|
-
...TS_REQUIRED_OPTIONS,
|
|
31
|
-
}
|
|
32
|
-
const exclude = new Set(tsconfig.get("exclude", []))
|
|
33
|
-
for (const entry of framework.tsRequiredExcludes) {
|
|
34
|
-
exclude.add(entry)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
tsconfig
|
|
38
|
-
.set("compilerOptions", mergedCompilerOptions)
|
|
39
|
-
.set("exclude", Array.from(exclude))
|
|
40
|
-
.save()
|
|
41
|
-
|
|
42
|
-
packageJson().setScript("type-check", "tsc --noEmit").save()
|
|
43
|
-
})
|
|
44
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { execSync } from "node:child_process"
|
|
2
|
-
import { existsSync } from "node:fs"
|
|
3
|
-
import path from "node:path"
|
|
4
|
-
|
|
5
|
-
export function detectPackageManager(projectDir) {
|
|
6
|
-
if (existsSync(path.join(projectDir, "pnpm-lock.yaml"))) {
|
|
7
|
-
return "pnpm"
|
|
8
|
-
}
|
|
9
|
-
if (existsSync(path.join(projectDir, "yarn.lock"))) {
|
|
10
|
-
return "yarn"
|
|
11
|
-
}
|
|
12
|
-
if (existsSync(path.join(projectDir, "package-lock.json"))) {
|
|
13
|
-
return "npm"
|
|
14
|
-
}
|
|
15
|
-
return "npm"
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function getRunCommand(pm) {
|
|
19
|
-
if (pm === "pnpm") return "pnpm"
|
|
20
|
-
if (pm === "yarn") return "yarn"
|
|
21
|
-
return "npm run"
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function runCommand(command, cwd, dryRun = false) {
|
|
25
|
-
if (dryRun) {
|
|
26
|
-
console.log(`[dry-run] Would run: ${command}`)
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
execSync(command, { cwd, stdio: "inherit" })
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function runScript(pm, scriptName, cwd, dryRun = false) {
|
|
33
|
-
if (pm === "pnpm") {
|
|
34
|
-
runCommand(`pnpm ${scriptName}`, cwd, dryRun)
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
if (pm === "yarn") {
|
|
38
|
-
runCommand(`yarn ${scriptName}`, cwd, dryRun)
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
runCommand(`npm run ${scriptName}`, cwd, dryRun)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function installPackages(
|
|
45
|
-
pm,
|
|
46
|
-
projectDir,
|
|
47
|
-
packages,
|
|
48
|
-
isDev,
|
|
49
|
-
dryRun = false
|
|
50
|
-
) {
|
|
51
|
-
if (packages.length === 0) return
|
|
52
|
-
|
|
53
|
-
const list = packages.join(" ")
|
|
54
|
-
let command = ""
|
|
55
|
-
|
|
56
|
-
if (pm === "pnpm") {
|
|
57
|
-
command = `pnpm add ${isDev ? "-D " : ""}${list}`
|
|
58
|
-
} else if (pm === "yarn") {
|
|
59
|
-
command = `yarn add ${isDev ? "-D " : ""}${list}`
|
|
60
|
-
} else {
|
|
61
|
-
command = `npm install ${isDev ? "-D " : ""}${list}`
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
console.log(
|
|
65
|
-
`${dryRun ? "[dry-run] " : ""}Installing ${isDev ? "dev " : ""}dependencies: ${packages.join(", ")}`
|
|
66
|
-
)
|
|
67
|
-
runCommand(command, projectDir, dryRun)
|
|
68
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, writeFile } from "node:fs/promises"
|
|
2
|
-
import os from "node:os"
|
|
3
|
-
import path from "node:path"
|
|
4
|
-
import { describe, expect, it } from "@jest/globals"
|
|
5
|
-
import { detectPackageManager } from "./package-manager.mjs"
|
|
6
|
-
|
|
7
|
-
describe("detectPackageManager", () => {
|
|
8
|
-
it("defaults to npm when no lockfile exists", async () => {
|
|
9
|
-
const baseDir = await mkdtemp(path.join(os.tmpdir(), "treg-pm-"))
|
|
10
|
-
expect(detectPackageManager(baseDir)).toBe("npm")
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it("detects pnpm from lockfile", async () => {
|
|
14
|
-
const baseDir = await mkdtemp(path.join(os.tmpdir(), "treg-pm-"))
|
|
15
|
-
await writeFile(
|
|
16
|
-
path.join(baseDir, "pnpm-lock.yaml"),
|
|
17
|
-
"lockfileVersion: 9\n"
|
|
18
|
-
)
|
|
19
|
-
expect(detectPackageManager(baseDir)).toBe("pnpm")
|
|
20
|
-
})
|
|
21
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function hasPackage(pkg, name) {
|
|
2
|
-
return Boolean(
|
|
3
|
-
pkg.dependencies?.[name] ||
|
|
4
|
-
pkg.devDependencies?.[name] ||
|
|
5
|
-
pkg.peerDependencies?.[name]
|
|
6
|
-
)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function formatStep(step, total, message, dryRun) {
|
|
10
|
-
const suffix = dryRun ? " [dry-run]" : ""
|
|
11
|
-
return `[${step}/${total}] ${message}${suffix}`
|
|
12
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "@jest/globals"
|
|
2
|
-
import { formatStep, hasPackage } from "./utils.mjs"
|
|
3
|
-
|
|
4
|
-
describe("hasPackage", () => {
|
|
5
|
-
it("checks dependencies and devDependencies", () => {
|
|
6
|
-
const pkg = {
|
|
7
|
-
dependencies: { react: "^19.0.0" },
|
|
8
|
-
devDependencies: { eslint: "^9.0.0" },
|
|
9
|
-
}
|
|
10
|
-
expect(hasPackage(pkg, "react")).toBe(true)
|
|
11
|
-
expect(hasPackage(pkg, "eslint")).toBe(true)
|
|
12
|
-
expect(hasPackage(pkg, "typescript")).toBe(false)
|
|
13
|
-
})
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
describe("formatStep", () => {
|
|
17
|
-
it("appends dry-run suffix when needed", () => {
|
|
18
|
-
expect(formatStep(2, 3, "Run mrm rules", true)).toBe(
|
|
19
|
-
"[2/3] Run mrm rules [dry-run]"
|
|
20
|
-
)
|
|
21
|
-
})
|
|
22
|
-
})
|