@tyyyho/treg 0.1.12 → 0.1.13

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 CHANGED
@@ -8,11 +8,13 @@ It applies infra setup such as lint, format, TypeScript, test, husky, and AI ski
8
8
  ## Quick Start
9
9
 
10
10
  ```bash
11
- pnpm dlx @tyyyho/treg init
12
- # or
13
11
  npx @tyyyho/treg init
14
12
  ```
15
13
 
14
+ ```bash
15
+ pnpm dlx @tyyyho/treg init
16
+ ```
17
+
16
18
  `init` auto-detects framework from dependencies.
17
19
 
18
20
  ## Commands
@@ -23,13 +25,16 @@ npx @tyyyho/treg <command> [options]
23
25
 
24
26
  - `init`: Initialize infra rules (framework auto-detected from dependencies)
25
27
  - `add`: Add selected infra features to an existing project
26
- - `list`: List supported frameworks, features, and test runners
28
+ - `list`: List supported frameworks, features, formatters, and test runners
27
29
 
28
30
  ## Options
29
31
 
30
32
  - `--framework <node|react|next|vue|svelte|nuxt>`: Optional framework override
31
33
  - `--features <lint,format,typescript,test,husky>`: Features to install (defaults to all)
34
+ - `--no-format`: Skip format feature setup and avoid changing format configs/scripts
35
+ - `--no-test-runner`: Skip test feature setup and avoid changing test runner/config
32
36
  - `--dir <path>`: Target directory (defaults to current directory)
37
+ - `--formatter <prettier|oxfmt>`: Formatter for format feature (default: `prettier`)
33
38
  - `--test-runner <jest|vitest>`: Optional test runner override when test feature is enabled
34
39
  - `--pm <pnpm|npm|yarn|auto>`: Package manager (auto-detected by default)
35
40
  - `--force`: Overwrite existing config files
@@ -69,6 +74,18 @@ Add only lint + format:
69
74
  npx @tyyyho/treg add --features lint,format
70
75
  ```
71
76
 
77
+ Use oxfmt instead of prettier:
78
+
79
+ ```bash
80
+ npx @tyyyho/treg add --features format --formatter oxfmt
81
+ ```
82
+
83
+ Skip format/test setup to keep existing project rules untouched:
84
+
85
+ ```bash
86
+ npx @tyyyho/treg add --no-format --no-test-runner
87
+ ```
88
+
72
89
  Use Vitest for test feature:
73
90
 
74
91
  ```bash
@@ -98,6 +115,8 @@ npx @tyyyho/treg init --framework react --dir ./packages/web
98
115
  - `init` auto-detects framework from repo dependencies.
99
116
  - Detection order is `nuxt -> next -> react -> vue -> svelte -> node`.
100
117
  - Default test runner is `vitest` for `vue`/`nuxt`, and `jest` for other frameworks.
118
+ - Default formatter is `prettier` (`--formatter oxfmt` to override).
119
+ - `--no-format` and `--no-test-runner` let you skip format/test setup to avoid overriding existing project config.
101
120
  - `add` lets you install only the features you specify.
102
121
  - Framework setup uses one stable config per framework (no `--framework-version` variants).
103
122
  - `--dry-run` prints the full plan and does not write files.
package/README.zh-hant.md CHANGED
@@ -8,11 +8,13 @@
8
8
  ## 快速開始
9
9
 
10
10
  ```bash
11
- pnpm dlx @tyyyho/treg init
12
- # 或
13
11
  npx @tyyyho/treg init
14
12
  ```
15
13
 
14
+ ```bash
15
+ pnpm dlx @tyyyho/treg init
16
+ ```
17
+
16
18
  `init` 會依照依賴自動偵測 framework。
17
19
 
18
20
  ## 指令
@@ -23,13 +25,16 @@ npx @tyyyho/treg <command> [options]
23
25
 
24
26
  - `init`:初始化基礎規範(依賴自動偵測 framework)
25
27
  - `add`:在既有專案中新增指定 feature
26
- - `list`:列出支援的 framework、feature 與 test runner
28
+ - `list`:列出支援的 framework、feature、formatter 與 test runner
27
29
 
28
30
  ## 參數
29
31
 
30
32
  - `--framework <node|react|next|vue|svelte|nuxt>`:可選,手動覆寫 framework
31
33
  - `--features <lint,format,typescript,test,husky>`:指定要安裝的 feature(預設全部)
34
+ - `--no-format`:略過 format feature,避免覆寫既有格式化設定與 scripts
35
+ - `--no-test-runner`:略過 test feature,避免覆寫既有測試 runner 與設定
32
36
  - `--dir <path>`:指定目標目錄(預設為目前目錄)
37
+ - `--formatter <prettier|oxfmt>`:format feature 使用的 formatter(預設為 `prettier`)
33
38
  - `--test-runner <jest|vitest>`:可選,啟用 test feature 時覆寫測試框架
34
39
  - `--pm <pnpm|npm|yarn|auto>`:套件管理器(預設自動偵測)
35
40
  - `--force`:覆寫既有設定檔
@@ -69,6 +74,18 @@ npx @tyyyho/treg init --framework react
69
74
  npx @tyyyho/treg add --features lint,format
70
75
  ```
71
76
 
77
+ 改用 oxfmt(不使用 prettier):
78
+
79
+ ```bash
80
+ npx @tyyyho/treg add --features format --formatter oxfmt
81
+ ```
82
+
83
+ 若要保留既有設定,可跳過 format/test 安裝:
84
+
85
+ ```bash
86
+ npx @tyyyho/treg add --no-format --no-test-runner
87
+ ```
88
+
72
89
  test feature 使用 Vitest:
73
90
 
74
91
  ```bash
@@ -98,6 +115,8 @@ npx @tyyyho/treg init --framework react --dir ./packages/web
98
115
  - `init` 會依 repo 依賴自動偵測 framework。
99
116
  - 偵測順序:`nuxt -> next -> react -> vue -> svelte -> node`。
100
117
  - 預設測試工具為:`vue`/`nuxt` 使用 `vitest`,其他 framework 使用 `jest`。
118
+ - 預設 formatter 為 `prettier`(可用 `--formatter oxfmt` 覆寫)。
119
+ - 可透過 `--no-format` 與 `--no-test-runner` 跳過對 format/test 的設定,避免覆寫既有專案規則。
101
120
  - `add` 可只安裝你指定的 features。
102
121
  - 每個 framework 僅提供單一穩定設定,不支援 `--framework-version` 版本變體。
103
122
  - `--dry-run` 會輸出完整計畫且不寫入任何檔案。
@@ -21,19 +21,23 @@ const ALLOWED_FEATURES = [
21
21
  "husky",
22
22
  ];
23
23
  const ALLOWED_TEST_RUNNERS = ["jest", "vitest"];
24
+ const ALLOWED_FORMATTERS = ["prettier", "oxfmt"];
24
25
  export const USAGE = `Usage: treg <command> [options]
25
26
 
26
27
  Commands:
27
28
  init Initialize infra rules in a project (framework auto-detected from dependencies)
28
29
  add Add selected infra features to an existing project
29
- list List supported frameworks, features, and test runners
30
+ list List supported frameworks, features, formatters, and test runners
30
31
 
31
32
  Options:
32
33
  --framework <node|react|next|vue|svelte|nuxt>
33
34
  Optional framework override (default: auto-detected)
34
35
  --features <lint,format,typescript,test,husky>
35
36
  Features to install (all selected by default)
37
+ --no-format Skip format feature setup and avoid changing format config/scripts
38
+ --no-test-runner Skip test feature setup and avoid changing test runner/config
36
39
  --dir <path> Target directory (defaults to current directory)
40
+ --formatter <prettier|oxfmt> Formatter for format feature (default: prettier)
37
41
  --test-runner <jest|vitest> Optional test runner override (default: vue/nuxt=vitest, others=jest)
38
42
  --pm <pnpm|npm|yarn|auto> Package manager (auto-detected if omitted)
39
43
  --force Overwrite existing config files
@@ -61,16 +65,22 @@ function isFeatureName(value) {
61
65
  function isTestRunner(value) {
62
66
  return includes(ALLOWED_TEST_RUNNERS, value);
63
67
  }
68
+ function isFormatter(value) {
69
+ return includes(ALLOWED_FORMATTERS, value);
70
+ }
64
71
  export function parseArgs(argv) {
65
72
  const options = {
66
73
  command: "init",
67
74
  projectDir: null,
68
75
  framework: null,
76
+ formatter: "prettier",
69
77
  features: [],
70
78
  testRunner: null,
71
79
  pm: null,
72
80
  force: false,
73
81
  dryRun: false,
82
+ noFormat: false,
83
+ noTestRunner: false,
74
84
  skipHuskyInstall: false,
75
85
  skills: true,
76
86
  help: false,
@@ -110,6 +120,13 @@ export function parseArgs(argv) {
110
120
  else if (arg.startsWith("--dir=")) {
111
121
  options.projectDir = readInlineFlagValue(arg, "--dir");
112
122
  }
123
+ else if (arg === "--formatter") {
124
+ options.formatter = readFlagValue(argv, i, "--formatter");
125
+ i += 1;
126
+ }
127
+ else if (arg.startsWith("--formatter=")) {
128
+ options.formatter = readInlineFlagValue(arg, "--formatter");
129
+ }
113
130
  else if (arg === "--test-runner") {
114
131
  options.testRunner = readFlagValue(argv, i, "--test-runner");
115
132
  i += 1;
@@ -130,6 +147,12 @@ export function parseArgs(argv) {
130
147
  else if (arg === "--dry-run") {
131
148
  options.dryRun = true;
132
149
  }
150
+ else if (arg === "--no-format") {
151
+ options.noFormat = true;
152
+ }
153
+ else if (arg === "--no-test-runner") {
154
+ options.noTestRunner = true;
155
+ }
133
156
  else if (arg === "--skip-husky-install") {
134
157
  options.skipHuskyInstall = true;
135
158
  }
@@ -182,6 +205,9 @@ function validateParsedOptions(options) {
182
205
  if (options.framework && !isFrameworkId(options.framework)) {
183
206
  throw new Error(`Unsupported framework: ${options.framework}`);
184
207
  }
208
+ if (!isFormatter(options.formatter)) {
209
+ throw new Error(`Unsupported formatter: ${options.formatter}`);
210
+ }
185
211
  if (options.testRunner && !isTestRunner(options.testRunner)) {
186
212
  throw new Error(`Unsupported test runner: ${options.testRunner}`);
187
213
  }
@@ -193,6 +219,12 @@ function validateParsedOptions(options) {
193
219
  }
194
220
  export function resolveFeatures(options) {
195
221
  const selected = new Set(options.features.length > 0 ? options.features : ALLOWED_FEATURES);
222
+ if (options.noFormat) {
223
+ selected.delete("format");
224
+ }
225
+ if (options.noTestRunner) {
226
+ selected.delete("test");
227
+ }
196
228
  return {
197
229
  lint: selected.has("lint"),
198
230
  format: selected.has("format"),
@@ -204,6 +236,7 @@ export function resolveFeatures(options) {
204
236
  export function printSupportedTargets() {
205
237
  console.log("Frameworks: node, react, next, vue, svelte, nuxt");
206
238
  console.log("Features: lint, format, typescript, test, husky");
239
+ console.log("Formatters: prettier, oxfmt");
207
240
  console.log("Test runners: jest, vitest");
208
241
  }
209
242
  export function resolveTestRunner(frameworkId, testRunner) {
@@ -52,7 +52,7 @@ export async function main(argv = process.argv.slice(2)) {
52
52
  console.log(`${options.dryRun ? "[dry-run] " : ""}Framework=${framework.id}, features=${Object.entries(enabledFeatures)
53
53
  .filter(([, enabled]) => enabled)
54
54
  .map(([name]) => name)
55
- .join(", ")}, testRunner=${testRunner}`);
55
+ .join(", ")}, formatter=${options.formatter}, testRunner=${testRunner}`);
56
56
  console.log(formatStep(2, TOTAL_STEPS, "Run mrm rules", options.dryRun));
57
57
  await runFeatureRules(context);
58
58
  console.log(formatStep(3, TOTAL_STEPS, "Finalize", options.dryRun));
@@ -25,20 +25,35 @@ const PRETTIER_IGNORE = [
25
25
  "package-lock.json",
26
26
  "yarn.lock",
27
27
  ];
28
+ function getFormatterScripts(formatter) {
29
+ if (formatter === "oxfmt") {
30
+ return {
31
+ format: "oxfmt --write .",
32
+ formatCheck: "oxfmt --check .",
33
+ };
34
+ }
35
+ return {
36
+ format: "prettier --write .",
37
+ formatCheck: "prettier --check .",
38
+ };
39
+ }
28
40
  export async function runFormatRule(context) {
29
- const { projectDir, pm, force, dryRun } = context;
30
- installPackages(projectDir, pm, ["prettier"], true, dryRun);
31
- await writeFile(projectDir, ".prettierrc.json", PRETTIER_CONFIG, force, dryRun);
41
+ const { projectDir, pm, force, dryRun, formatter } = context;
42
+ const { format, formatCheck } = getFormatterScripts(formatter);
43
+ installPackages(projectDir, pm, [formatter], true, dryRun);
44
+ if (formatter === "prettier") {
45
+ await writeFile(projectDir, ".prettierrc.json", PRETTIER_CONFIG, force, dryRun);
46
+ }
32
47
  withProjectCwd(projectDir, () => {
33
48
  if (dryRun) {
34
49
  console.log("[dry-run] Would update .prettierignore");
35
- console.log("[dry-run] Would set package scripts: format, format:check");
50
+ console.log(`[dry-run] Would set package scripts: format (${format}), format:check (${formatCheck})`);
36
51
  return;
37
52
  }
38
53
  lines(".prettierignore").add(PRETTIER_IGNORE).save();
39
54
  packageJson()
40
- .setScript("format", "prettier --write .")
41
- .setScript("format:check", "prettier --check .")
55
+ .setScript("format", format)
56
+ .setScript("format:check", formatCheck)
42
57
  .save();
43
58
  });
44
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tyyyho/treg",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "CLI tool for initializing development conventions in existing projects.",
5
5
  "license": "MIT",
6
6
  "repository": {