@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.
Files changed (57) hide show
  1. package/README.md +52 -45
  2. package/dist/init-project/cli.js +228 -0
  3. package/dist/init-project/frameworks/index.js +39 -0
  4. package/dist/init-project/frameworks/next/index.js +9 -0
  5. package/dist/init-project/frameworks/node/index.js +8 -0
  6. package/dist/init-project/frameworks/nuxt/index.js +9 -0
  7. package/dist/init-project/frameworks/react/index.js +27 -0
  8. package/dist/init-project/frameworks/react/v18/index.js +6 -0
  9. package/dist/init-project/frameworks/react/v19/index.js +6 -0
  10. package/dist/init-project/frameworks/svelte/index.js +9 -0
  11. package/dist/init-project/frameworks/vue/index.js +9 -0
  12. package/dist/init-project/index.js +65 -0
  13. package/dist/init-project/mrm-core.js +3 -0
  14. package/dist/init-project/mrm-rules/ai-skills.js +200 -0
  15. package/dist/init-project/mrm-rules/format.js +44 -0
  16. package/dist/init-project/mrm-rules/husky.js +61 -0
  17. package/dist/init-project/mrm-rules/index.js +33 -0
  18. package/dist/init-project/mrm-rules/lint.js +16 -0
  19. package/dist/init-project/mrm-rules/shared.js +91 -0
  20. package/dist/init-project/mrm-rules/test-jest.js +48 -0
  21. package/dist/init-project/mrm-rules/test-vitest.js +46 -0
  22. package/dist/init-project/mrm-rules/typescript.js +40 -0
  23. package/dist/init-project/package-manager.js +57 -0
  24. package/dist/init-project/types.js +1 -0
  25. package/dist/init-project/utils.js +9 -0
  26. package/dist/init-project.js +6 -0
  27. package/dist/package.json +3 -0
  28. package/package.json +10 -5
  29. package/scripts/init-project/cli.mjs +0 -173
  30. package/scripts/init-project/cli.test.mjs +0 -116
  31. package/scripts/init-project/frameworks/index.mjs +0 -48
  32. package/scripts/init-project/frameworks/next/index.mjs +0 -10
  33. package/scripts/init-project/frameworks/node/index.mjs +0 -8
  34. package/scripts/init-project/frameworks/nuxt/index.mjs +0 -10
  35. package/scripts/init-project/frameworks/react/index.mjs +0 -35
  36. package/scripts/init-project/frameworks/react/v18/index.mjs +0 -6
  37. package/scripts/init-project/frameworks/react/v19/index.mjs +0 -6
  38. package/scripts/init-project/frameworks/svelte/index.mjs +0 -10
  39. package/scripts/init-project/frameworks/vue/index.mjs +0 -10
  40. package/scripts/init-project/frameworks.test.mjs +0 -63
  41. package/scripts/init-project/index.mjs +0 -89
  42. package/scripts/init-project/mrm-core.mjs +0 -5
  43. package/scripts/init-project/mrm-rules/ai-skills.mjs +0 -220
  44. package/scripts/init-project/mrm-rules/ai-skills.test.mjs +0 -91
  45. package/scripts/init-project/mrm-rules/format.mjs +0 -55
  46. package/scripts/init-project/mrm-rules/husky.mjs +0 -78
  47. package/scripts/init-project/mrm-rules/index.mjs +0 -35
  48. package/scripts/init-project/mrm-rules/lint.mjs +0 -18
  49. package/scripts/init-project/mrm-rules/shared.mjs +0 -61
  50. package/scripts/init-project/mrm-rules/test-jest.mjs +0 -75
  51. package/scripts/init-project/mrm-rules/test-vitest.mjs +0 -64
  52. package/scripts/init-project/mrm-rules/typescript.mjs +0 -44
  53. package/scripts/init-project/package-manager.mjs +0 -68
  54. package/scripts/init-project/package-manager.test.mjs +0 -21
  55. package/scripts/init-project/utils.mjs +0 -12
  56. package/scripts/init-project/utils.test.mjs +0 -22
  57. 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
- })
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- import { main } from "./init-project/index.mjs"
3
-
4
- main().catch(error => {
5
- console.error(error)
6
- process.exitCode = 1
7
- })