@book000/create-ts 0.2.76 → 0.2.78

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 (37) hide show
  1. package/README.md +85 -0
  2. package/dist/index.mjs +37 -32
  3. package/dist/src/generate.d.ts +11 -9
  4. package/dist/src/generate.js +11 -9
  5. package/dist/src/index.js +14 -26
  6. package/dist/src/prompts.d.ts +6 -6
  7. package/dist/src/prompts.js +10 -11
  8. package/dist/src/template.d.ts +4 -4
  9. package/dist/src/template.js +5 -5
  10. package/dist/src/types.d.ts +5 -5
  11. package/dist/src/validate.d.ts +8 -8
  12. package/dist/src/validate.js +8 -8
  13. package/dist/test/generate.test.js +22 -22
  14. package/dist/test/validate.test.js +20 -20
  15. package/dist/tsdown.config.js +2 -2
  16. package/package.json +2 -2
  17. package/templates/nodejs/base/package.json +1 -1
  18. package/templates/nodejs/base/pnpm-lock.yaml +5 -5
  19. package/templates/nodejs/base/src/main.ts +1 -1
  20. package/templates/nodejs/base/test/smoke.test.ts +7 -7
  21. package/templates/nodejs/config-batch/package.json +1 -1
  22. package/templates/nodejs/config-batch/pnpm-lock.yaml +5 -5
  23. package/templates/nodejs/config-batch/src/config.ts +2 -2
  24. package/templates/nodejs/config-batch/src/main.ts +6 -6
  25. package/templates/nodejs/config-batch/test/config.test.ts +8 -9
  26. package/templates/nodejs/discord-bot/package.json +1 -1
  27. package/templates/nodejs/discord-bot/pnpm-lock.yaml +5 -5
  28. package/templates/nodejs/discord-bot/src/config.ts +3 -3
  29. package/templates/nodejs/discord-bot/src/discord.ts +6 -6
  30. package/templates/nodejs/discord-bot/src/main.ts +4 -4
  31. package/templates/nodejs/discord-bot/test/discord.test.ts +9 -9
  32. package/templates/nodejs/fastify/package.json +1 -1
  33. package/templates/nodejs/fastify/pnpm-lock.yaml +5 -5
  34. package/templates/nodejs/fastify/src/main.ts +5 -5
  35. package/templates/nodejs/fastify/test/app.test.ts +8 -8
  36. package/templates/workflows/docker.yml +6 -7
  37. package/templates/workflows/nodejs-ci-pnpm.yml +1 -1
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # create-ts
2
+
3
+ A CLI that scaffolds book000-style TypeScript / Node.js projects. It copies the bundled template for the chosen variant into a directory, fills in the project metadata, and runs `pnpm install`.
4
+
5
+ ## Requirements
6
+
7
+ - Node.js v20 or later (the CLI exits with an error otherwise)
8
+ - pnpm (generated projects reject other package managers with `only-allow`)
9
+ - Network access: dependencies are installed with `pnpm install`, the `LICENSE` text is fetched from the GitHub licenses API (skipped with a warning on failure), and `fixpack` / `fixdevcontainer` are run through `npx` (skipped on failure)
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ pnpm create @book000/ts [outdir] [options]
15
+ ```
16
+
17
+ `outdir` defaults to the current directory and is created if it does not exist. Any value not given as an option is asked interactively. The directory name is offered as the default project name when it is a valid package name.
18
+
19
+ To run without prompts, pass every option:
20
+
21
+ ```bash
22
+ pnpm create @book000/ts my-app \
23
+ --name my-app --org book000 --repo my-app \
24
+ --description "My app" --author book000 --license MIT --homepage "" \
25
+ --bug-url https://github.com/book000/my-app/issues \
26
+ --variant base --no-esm --no-test --no-docker \
27
+ --no-ignore-data --no-add-reviewer --overwrite
28
+ ```
29
+
30
+ ### Options
31
+
32
+ | Option | Description | Default |
33
+ | --- | --- | --- |
34
+ | `--name <name>` | Project name (npm package name rule: lowercase, up to 214 characters) | Asked |
35
+ | `--org <org>` | GitHub organization / user name. The package is named `@<org lowercased>/<name>` | Asked (`book000`) |
36
+ | `--repo <repo>` | Repository name | Asked |
37
+ | `--description <desc>` | Project description | Asked |
38
+ | `--author <author>` | Author name | Asked |
39
+ | `--license <spdx>` | SPDX license identifier (for example `MIT`, `Apache-2.0`) | Asked (`MIT`) |
40
+ | `--homepage <url>` | Homepage URL. An empty string omits the field | Asked |
41
+ | `--bug-url <url>` | Bug report URL | Asked |
42
+ | `--variant <variant>` | `base`, `config-batch`, `fastify` or `discord-bot` | Asked (`base`) |
43
+ | `--esm` / `--no-esm` | ES Modules / CommonJS | Asked (CommonJS) |
44
+ | `--test` / `--no-test` | Add / do not add Jest tests | Asked (no) |
45
+ | `--docker` / `--no-docker` | Add / do not add `Dockerfile`, `entrypoint.sh` and the Docker workflow | Asked (no) |
46
+ | `--ignore-data` / `--no-ignore-data` | Add / do not add `data/` to `.gitignore` | Asked (no) |
47
+ | `--add-reviewer` / `--no-add-reviewer` | Add / do not add the add-reviewer workflow | Asked (no) |
48
+ | `--overwrite` | Overwrite existing files without asking. Without it, you are asked when `package.json`, `tsconfig.json` or `src` already exists | Off |
49
+
50
+ Invalid values for `--name`, `--org`, `--repo`, `--license` or `--variant` make the CLI exit with an error. The prompts and most CLI messages are in Japanese.
51
+
52
+ ### Variants
53
+
54
+ | Variant | Contents |
55
+ | --- | --- |
56
+ | `base` | Minimal setup: `src/main.ts` |
57
+ | `config-batch` | Batch job with a JSON config (`ConfigFramework` from `@book000/node-utils`) and a `generate-schema` script |
58
+ | `fastify` | Fastify HTTP server with `@fastify/cors` |
59
+ | `discord-bot` | discord.js bot with a config and a `generate-schema` script |
60
+
61
+ ### Generated project
62
+
63
+ Every project gets `tsconfig.json`, `.prettierrc.yml`, `eslint.config.mjs`, `renovate.json`, `.depcheckrc.json`, `.fixpackrc`, `pnpm-workspace.yaml`, `.devcontainer/devcontainer.json`, `.gitignore`, `.node-version` (the Node.js version used to run the CLI), `LICENSE` (when it can be fetched), `package.json`, `pnpm-lock.yaml`, `.github/workflows/nodejs-ci-pnpm.yml` and the variant's `src/` files. With `--test`, the variant's test files and `tsconfig.test.json` are added. Without it, Jest packages are removed after install.
64
+
65
+ Inside the generated project, `pnpm run lint`, `pnpm run test` (with `--test`), `pnpm start` and `pnpm run dev` are available.
66
+
67
+ ## Development
68
+
69
+ ```bash
70
+ pnpm install
71
+ pnpm build # bundle src/index.ts to dist/index.mjs with tsdown
72
+ pnpm lint # prettier --check src, eslint, tsc
73
+ pnpm test # vitest
74
+ node dist/index.mjs --help
75
+ ```
76
+
77
+ The Node.js version is pinned in `.node-version` and pnpm in `package.json`. See [AGENTS.md](AGENTS.md) for the code structure and conventions.
78
+
79
+ ## Release
80
+
81
+ Every push to `main` or `master` runs `.github/workflows/release.yml`, which bumps the version from the Conventional Commit types, tags it, and publishes `@book000/create-ts` to npm. Do not bump the version or publish manually.
82
+
83
+ ## License
84
+
85
+ MIT
package/dist/index.mjs CHANGED
@@ -7,19 +7,19 @@ import { fileURLToPath } from "node:url";
7
7
  import { execa } from "execa";
8
8
  // src/template.ts
9
9
  const __dirname$1 = path.dirname(fileURLToPath(import.meta.url));
10
- /** バンドルされたテンプレートのルートディレクトリ */
10
+ /** Root directory of the bundled templates. */
11
11
  const TEMPLATES_DIR = path.join(__dirname$1, "../templates");
12
12
  /**
13
- * バンドルされたテンプレートファイルを文字列として読み込む。
14
- * @param relativePath - テンプレートルートからの相対パス
13
+ * Reads a bundled template file as a string.
14
+ * @param relativePath - Path relative to the templates root
15
15
  */
16
16
  function readTemplate(relativePath) {
17
17
  const filePath = path.join(TEMPLATES_DIR, relativePath);
18
18
  return readFileSync(filePath, "utf8");
19
19
  }
20
20
  /**
21
- * バリアントの template.json を読み込んでパースする。
22
- * @param variant - バリアント名
21
+ * Reads and parses a variant's template.json.
22
+ * @param variant - Variant name
23
23
  */
24
24
  function fetchTemplateConfig(variant) {
25
25
  const content = readTemplate(`nodejs/${variant}/template.json`);
@@ -27,8 +27,10 @@ function fetchTemplateConfig(variant) {
27
27
  }
28
28
  // src/generate.ts
29
29
  /**
30
- * バリアントの package.json にプロジェクト固有の値を適用する。
31
- * テンプレートのプレースホルダーを実際の値で上書きする。
30
+ * Applies project-specific values to a variant's package.json and returns a new object.
31
+ * Sets name (`@<org lowercased>/<name>`), description, license, author, engines.node (`>=<nodeMajor>`), repository and bugs URLs, and homepage if non-empty.
32
+ * With `esm`, sets `type: "module"` (plus the ts-jest ESM config when `test` is also set).
33
+ * Without `test`, removes the `test` script and the `jest` field.
32
34
  */
33
35
  function patchPackageJson(packageJson, options, nodeMajor) {
34
36
  const { name, org, repo, description, author, license, homepage, bugUrl, esm, test } = options;
@@ -56,7 +58,8 @@ function patchPackageJson(packageJson, options, nodeMajor) {
56
58
  return result;
57
59
  }
58
60
  /**
59
- * tsconfig.json にモジュール形式・テスト設定のパッチを適用する。
61
+ * Patches tsconfig.json and returns a new object.
62
+ * With `esm`, sets `compilerOptions.module` to `es2015`; with `test`, adds `jest` to `compilerOptions.types`.
60
63
  */
61
64
  function patchTsConfig(tsconfig, options) {
62
65
  const result = structuredClone(tsconfig);
@@ -69,7 +72,8 @@ function patchTsConfig(tsconfig, options) {
69
72
  return result;
70
73
  }
71
74
  /**
72
- * docker.yml のプレースホルダーをプロジェクト固有の値に置換する。
75
+ * Replaces the placeholders of the bundled docker.yml template.
76
+ * The image name `tomacheese/twitter-dm-memo` becomes `<org>/<repo>` lowercased, and `packageName` becomes `repo` as given.
73
77
  */
74
78
  function patchDockerWorkflow(content, org, repo) {
75
79
  let result = content;
@@ -78,9 +82,7 @@ function patchDockerWorkflow(content, org, repo) {
78
82
  return result;
79
83
  }
80
84
  /**
81
- * .gitignore を生成する。
82
- * バンドルされた Node.gitignore(pnpm セクション付き)をベースに、
83
- * 任意で data/ セクションを追記する。
85
+ * Generates .gitignore from the bundled Node.gitignore (which includes a pnpm section), optionally appending a `data/` section.
84
86
  */
85
87
  function generateGitignore(ignoreData) {
86
88
  let result = readTemplate("gitignore/Node.gitignore");
@@ -88,8 +90,8 @@ function generateGitignore(ignoreData) {
88
90
  return result;
89
91
  }
90
92
  /**
91
- * .depcheckrc.json の ignores 配列を更新する。
92
- * テンプレートの depcheckIgnore と Jest 関連パッケージを追加する(重複除去)。
93
+ * Updates the `ignores` array of .depcheckrc.json without duplicates.
94
+ * Adds the variant's depcheckIgnore entries, plus `@types/jest` when `test` is set.
93
95
  */
94
96
  function updateDepcheck(depcheckJson, depcheckIgnore, test) {
95
97
  const result = structuredClone(depcheckJson);
@@ -101,39 +103,39 @@ function updateDepcheck(depcheckJson, depcheckIgnore, test) {
101
103
  }
102
104
  // src/validate.ts
103
105
  /**
104
- * プロジェクト名を検証する。
105
- * npm パッケージ名規則: 小文字英数字・ハイフン・アンダースコア・ドット、214 文字以下。
106
+ * Validates a project name (npm package name rule): lowercase alphanumerics, hyphens, underscores and dots, starting with an alphanumeric, at most 214 characters.
107
+ * Returns an error message, or undefined if valid.
106
108
  */
107
109
  function validateProjectName(value) {
108
110
  if (!value) return "プロジェクト名は必須です";
109
111
  return value.length > 214 || !/^[a-z0-9][a-z0-9\-_.]*$/.test(value) ? "プロジェクト名は小文字英数字・ハイフン・アンダースコア・ドットのみ使用できます(最大 214 文字)" : void 0;
110
112
  }
111
113
  /**
112
- * GitHub 組織 / ユーザー名を検証する。
113
- * 英数字・ハイフン・ドットのみ許容。
114
+ * Validates a GitHub organization / user name: alphanumerics, hyphens and dots, starting with an alphanumeric.
115
+ * Returns an error message, or undefined if valid.
114
116
  */
115
117
  function validateOrgName(value) {
116
118
  if (!value) return "組織 / ユーザー名は必須です";
117
119
  return /^[a-zA-Z0-9][a-zA-Z0-9\-.]*$/.test(value) ? void 0 : "組織 / ユーザー名は英数字・ハイフン・ドットのみ使用できます";
118
120
  }
119
121
  /**
120
- * リポジトリ名を検証する。
121
- * 英数字・ハイフン・アンダースコア・ドットのみ許容。先頭はアンダースコア可。
122
+ * Validates a repository name: alphanumerics, hyphens, underscores and dots; a leading underscore is allowed.
123
+ * Returns an error message, or undefined if valid.
122
124
  */
123
125
  function validateRepoName(value) {
124
126
  if (!value) return "リポジトリ名は必須です";
125
127
  return /^[a-zA-Z0-9_][a-zA-Z0-9\-_.]*$/.test(value) ? void 0 : "リポジトリ名は英数字・ハイフン・アンダースコア・ドットのみ使用できます";
126
128
  }
127
129
  /**
128
- * SPDX ライセンス識別子を検証する。
129
- * 英数字・ドット・ハイフンのみ許容。
130
+ * Validates an SPDX license identifier by character set only (alphanumerics, dots and hyphens); it does not check that the identifier exists.
131
+ * Returns an error message, or undefined if valid.
130
132
  */
131
133
  function validateLicense(value) {
132
134
  if (!value) return "ライセンス識別子は必須です";
133
135
  return /^[a-zA-Z0-9.-]+$/.test(value) ? void 0 : "ライセンス識別子は英数字・ドット・ハイフンのみ使用できます(例: MIT, Apache-2.0)";
134
136
  }
135
137
  // src/prompts.ts
136
- /** 有効なバリアント値の一覧 */
138
+ /** Valid values for --variant. */
137
139
  const VALID_VARIANTS = [
138
140
  "base",
139
141
  "config-batch",
@@ -141,7 +143,7 @@ const VALID_VARIANTS = [
141
143
  "discord-bot"
142
144
  ];
143
145
  /**
144
- * CLI フラグで渡された値をバリデーションし、不正な場合はプロセスを終了する。
146
+ * Validates flag values given on the command line and exits the process with code 1 if any is invalid.
145
147
  */
146
148
  function validateCliFlags(flags) {
147
149
  if (flags.name !== void 0) {
@@ -177,8 +179,8 @@ function validateCliFlags(flags) {
177
179
  process.exit(1);
178
180
  }
179
181
  /**
180
- * 対話プロンプトで ProjectOptions を収集する。
181
- * CLI フラグで指定済みの項目はスキップする。
182
+ * Collects ProjectOptions interactively.
183
+ * Prompts are skipped for options already given as flags.
182
184
  */
183
185
  async function collectOptions(outDir, flags) {
184
186
  validateCliFlags(flags);
@@ -302,7 +304,7 @@ async function collectOptions(outDir, flags) {
302
304
  };
303
305
  }
304
306
  /**
305
- * セットアップ内容のサマリーを note() で表示する。
307
+ * Shows a summary of the setup with note().
306
308
  */
307
309
  function displaySummary(options) {
308
310
  const lines = [
@@ -318,8 +320,8 @@ function displaySummary(options) {
318
320
  note(lines.join("\n"), "セットアップ内容");
319
321
  }
320
322
  /**
321
- * 既存ファイルの上書き確認を行う。
322
- * キャンセル / 拒否時はプロセスを終了する。
323
+ * Asks whether to overwrite existing files.
324
+ * Exits the process if the user cancels or declines.
323
325
  */
324
326
  async function confirmOverwrite(outDir) {
325
327
  const confirmed = await confirm({ message: `${outDir} に既存のファイルがあります。上書きしますか?` });
@@ -330,13 +332,16 @@ async function confirmOverwrite(outDir) {
330
332
  // src/index.ts
331
333
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
332
334
  const { version } = JSON.parse(readFileSync(path.join(__dirname, "../package.json"), "utf8"));
333
- /** ファイルを書き込む。親ディレクトリが存在しない場合は作成する。 */
335
+ /** Writes a file, creating the parent directory if it does not exist. */
334
336
  function writeFile(filePath, content) {
335
337
  const dir = path.dirname(filePath);
336
338
  if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
337
339
  writeFileSync(filePath, content, "utf8");
338
340
  }
339
- /** node / pnpm の存在と Node.js バージョンを確認する。メジャーバージョンを返す。 */
341
+ /**
342
+ * Checks that node and pnpm are available and that Node.js is v20 or later.
343
+ * Exits the process on failure; otherwise returns the Node.js major version.
344
+ */
340
345
  async function checkPrerequisites() {
341
346
  let nodeMajor;
342
347
  try {
@@ -365,7 +370,7 @@ async function main() {
365
370
  const outDirArg = program.args[0] ?? ".";
366
371
  const outDir = path.resolve(outDirArg);
367
372
  const opts = program.opts();
368
- /** CLI で明示的に指定されたかどうか確認して boolean | undefined を返す */
373
+ /** Returns the flag value only if it was given explicitly (CLI or env); otherwise undefined so the prompt is shown. */
369
374
  const getCLIBoolFlag = (name) => {
370
375
  const source = program.getOptionValueSource(name);
371
376
  return source === "cli" || source === "env" ? opts[name] : void 0;
@@ -1,25 +1,27 @@
1
1
  import type { ProjectOptions } from './types.js';
2
2
  /**
3
- * バリアントの package.json にプロジェクト固有の値を適用する。
4
- * テンプレートのプレースホルダーを実際の値で上書きする。
3
+ * Applies project-specific values to a variant's package.json and returns a new object.
4
+ * Sets name (`@<org lowercased>/<name>`), description, license, author, engines.node (`>=<nodeMajor>`), repository and bugs URLs, and homepage if non-empty.
5
+ * With `esm`, sets `type: "module"` (plus the ts-jest ESM config when `test` is also set).
6
+ * Without `test`, removes the `test` script and the `jest` field.
5
7
  */
6
8
  export declare function patchPackageJson(packageJson: Record<string, unknown>, options: Pick<ProjectOptions, 'name' | 'org' | 'repo' | 'description' | 'author' | 'license' | 'homepage' | 'bugUrl' | 'esm' | 'test'>, nodeMajor: number): Record<string, unknown>;
7
9
  /**
8
- * tsconfig.json にモジュール形式・テスト設定のパッチを適用する。
10
+ * Patches tsconfig.json and returns a new object.
11
+ * With `esm`, sets `compilerOptions.module` to `es2015`; with `test`, adds `jest` to `compilerOptions.types`.
9
12
  */
10
13
  export declare function patchTsConfig(tsconfig: Record<string, unknown>, options: Pick<ProjectOptions, 'esm' | 'test'>): Record<string, unknown>;
11
14
  /**
12
- * docker.yml のプレースホルダーをプロジェクト固有の値に置換する。
15
+ * Replaces the placeholders of the bundled docker.yml template.
16
+ * The image name `tomacheese/twitter-dm-memo` becomes `<org>/<repo>` lowercased, and `packageName` becomes `repo` as given.
13
17
  */
14
18
  export declare function patchDockerWorkflow(content: string, org: string, repo: string): string;
15
19
  /**
16
- * .gitignore を生成する。
17
- * バンドルされた Node.gitignore(pnpm セクション付き)をベースに、
18
- * 任意で data/ セクションを追記する。
20
+ * Generates .gitignore from the bundled Node.gitignore (which includes a pnpm section), optionally appending a `data/` section.
19
21
  */
20
22
  export declare function generateGitignore(ignoreData: boolean): string;
21
23
  /**
22
- * .depcheckrc.json の ignores 配列を更新する。
23
- * テンプレートの depcheckIgnore と Jest 関連パッケージを追加する(重複除去)。
24
+ * Updates the `ignores` array of .depcheckrc.json without duplicates.
25
+ * Adds the variant's depcheckIgnore entries, plus `@types/jest` when `test` is set.
24
26
  */
25
27
  export declare function updateDepcheck(depcheckJson: Record<string, unknown>, depcheckIgnore: string[], test: boolean): Record<string, unknown>;
@@ -1,7 +1,9 @@
1
1
  import { readTemplate } from './template.js';
2
2
  /**
3
- * バリアントの package.json にプロジェクト固有の値を適用する。
4
- * テンプレートのプレースホルダーを実際の値で上書きする。
3
+ * Applies project-specific values to a variant's package.json and returns a new object.
4
+ * Sets name (`@<org lowercased>/<name>`), description, license, author, engines.node (`>=<nodeMajor>`), repository and bugs URLs, and homepage if non-empty.
5
+ * With `esm`, sets `type: "module"` (plus the ts-jest ESM config when `test` is also set).
6
+ * Without `test`, removes the `test` script and the `jest` field.
5
7
  */
6
8
  export function patchPackageJson(packageJson, options, nodeMajor) {
7
9
  const { name, org, repo, description, author, license, homepage, bugUrl, esm, test, } = options;
@@ -36,7 +38,8 @@ export function patchPackageJson(packageJson, options, nodeMajor) {
36
38
  return result;
37
39
  }
38
40
  /**
39
- * tsconfig.json にモジュール形式・テスト設定のパッチを適用する。
41
+ * Patches tsconfig.json and returns a new object.
42
+ * With `esm`, sets `compilerOptions.module` to `es2015`; with `test`, adds `jest` to `compilerOptions.types`.
40
43
  */
41
44
  export function patchTsConfig(tsconfig, options) {
42
45
  const result = structuredClone(tsconfig);
@@ -53,7 +56,8 @@ export function patchTsConfig(tsconfig, options) {
53
56
  return result;
54
57
  }
55
58
  /**
56
- * docker.yml のプレースホルダーをプロジェクト固有の値に置換する。
59
+ * Replaces the placeholders of the bundled docker.yml template.
60
+ * The image name `tomacheese/twitter-dm-memo` becomes `<org>/<repo>` lowercased, and `packageName` becomes `repo` as given.
57
61
  */
58
62
  export function patchDockerWorkflow(content, org, repo) {
59
63
  let result = content;
@@ -62,9 +66,7 @@ export function patchDockerWorkflow(content, org, repo) {
62
66
  return result;
63
67
  }
64
68
  /**
65
- * .gitignore を生成する。
66
- * バンドルされた Node.gitignore(pnpm セクション付き)をベースに、
67
- * 任意で data/ セクションを追記する。
69
+ * Generates .gitignore from the bundled Node.gitignore (which includes a pnpm section), optionally appending a `data/` section.
68
70
  */
69
71
  export function generateGitignore(ignoreData) {
70
72
  let result = readTemplate('gitignore/Node.gitignore');
@@ -74,8 +76,8 @@ export function generateGitignore(ignoreData) {
74
76
  return result;
75
77
  }
76
78
  /**
77
- * .depcheckrc.json の ignores 配列を更新する。
78
- * テンプレートの depcheckIgnore と Jest 関連パッケージを追加する(重複除去)。
79
+ * Updates the `ignores` array of .depcheckrc.json without duplicates.
80
+ * Adds the variant's depcheckIgnore entries, plus `@types/jest` when `test` is set.
79
81
  */
80
82
  export function updateDepcheck(depcheckJson, depcheckIgnore, test) {
81
83
  const result = structuredClone(depcheckJson);
package/dist/src/index.js CHANGED
@@ -10,7 +10,7 @@ import { collectOptions, confirmOverwrite, displaySummary } from './prompts.js';
10
10
  import { fetchTemplateConfig, readTemplate } from './template.js';
11
11
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
12
12
  const { version } = JSON.parse(readFileSync(path.join(__dirname, '../package.json'), 'utf8'));
13
- /** ファイルを書き込む。親ディレクトリが存在しない場合は作成する。 */
13
+ /** Writes a file, creating the parent directory if it does not exist. */
14
14
  function writeFile(filePath, content) {
15
15
  const dir = path.dirname(filePath);
16
16
  if (!existsSync(dir)) {
@@ -18,7 +18,10 @@ function writeFile(filePath, content) {
18
18
  }
19
19
  writeFileSync(filePath, content, 'utf8');
20
20
  }
21
- /** node / pnpm の存在と Node.js バージョンを確認する。メジャーバージョンを返す。 */
21
+ /**
22
+ * Checks that node and pnpm are available and that Node.js is v20 or later.
23
+ * Exits the process on failure; otherwise returns the Node.js major version.
24
+ */
22
25
  async function checkPrerequisites() {
23
26
  let nodeMajor;
24
27
  try {
@@ -73,7 +76,7 @@ async function main() {
73
76
  const outDirArg = program.args[0] ?? '.';
74
77
  const outDir = path.resolve(outDirArg);
75
78
  const opts = program.opts();
76
- /** CLI で明示的に指定されたかどうか確認して boolean | undefined を返す */
79
+ /** Returns the flag value only if it was given explicitly (CLI or env); otherwise undefined so the prompt is shown. */
77
80
  const getCLIBoolFlag = (name) => {
78
81
  const source = program.getOptionValueSource(name);
79
82
  return source === 'cli' || source === 'env'
@@ -81,12 +84,10 @@ async function main() {
81
84
  : undefined;
82
85
  };
83
86
  intro('create-ts');
84
- // ステップ 1: 前提チェック
85
87
  const s = spinner();
86
88
  s.start('前提条件を確認しています...');
87
89
  const nodeMajor = await checkPrerequisites();
88
90
  s.stop('前提条件を確認しました');
89
- // 対話プロンプトでオプション収集
90
91
  const options = await collectOptions(outDir, {
91
92
  name: opts.name,
92
93
  org: opts.org,
@@ -104,7 +105,7 @@ async function main() {
104
105
  addReviewer: getCLIBoolFlag('addReviewer'),
105
106
  overwrite: opts.overwrite,
106
107
  });
107
- // 既存ファイルの確認
108
+ // Ask before overwriting an existing project
108
109
  if (!options.overwrite) {
109
110
  const hasExisting = existsSync(path.join(outDir, 'package.json')) ||
110
111
  existsSync(path.join(outDir, 'tsconfig.json')) ||
@@ -113,18 +114,14 @@ async function main() {
113
114
  await confirmOverwrite(outDir);
114
115
  }
115
116
  }
116
- // サマリー表示
117
117
  displaySummary(options);
118
- // 出力ディレクトリを作成
119
118
  if (!existsSync(outDir)) {
120
119
  mkdirSync(outDir, { recursive: true });
121
120
  }
122
121
  try {
123
- // ステップ 2: template.json の読み込み
124
122
  s.start('テンプレート設定を読み込んでいます...');
125
123
  const templateConfig = fetchTemplateConfig(options.variant);
126
124
  s.stop('テンプレート設定を読み込みました');
127
- // ステップ 3: 共通テンプレートファイルのコピー
128
125
  const commonFiles = [
129
126
  'tsconfig.json',
130
127
  '.prettierrc.yml',
@@ -142,7 +139,7 @@ async function main() {
142
139
  writeFile(path.join(outDir, file), content);
143
140
  }
144
141
  s.stop(`共通ファイルをコピーしました (${commonFiles.length} ファイル)`);
145
- // ステップ 4: バリアント src ファイルのコピー
142
+ // copy the variant's src files (and test files with --test)
146
143
  const filesToCopy = [
147
144
  ...templateConfig.src,
148
145
  ...(options.test && templateConfig.testSrc ? templateConfig.testSrc : []),
@@ -153,12 +150,11 @@ async function main() {
153
150
  writeFile(path.join(outDir, srcFile), content);
154
151
  }
155
152
  s.stop(`src ファイルをコピーしました (${filesToCopy.length} ファイル)`);
156
- // ステップ 5: tsconfig.json のパッチ
157
153
  const tsconfigPath = path.join(outDir, 'tsconfig.json');
158
154
  const tsconfig = JSON.parse(readFileSync(tsconfigPath, 'utf8'));
159
155
  const patchedTsConfig = patchTsConfig(tsconfig, options);
160
156
  writeFileSync(tsconfigPath, JSON.stringify(patchedTsConfig, null, 2) + '\n', 'utf8');
161
- // ステップ 6: .gitignore / .node-version の生成
157
+ // generate .gitignore and .node-version (the running Node.js version)
162
158
  s.start('.gitignore を生成しています...');
163
159
  const gitignoreContent = generateGitignore(options.ignoreData);
164
160
  writeFileSync(path.join(outDir, '.gitignore'), gitignoreContent, 'utf8');
@@ -166,7 +162,7 @@ async function main() {
166
162
  const nodeVersionNumber = nodeVersion.trim().replace('v', '');
167
163
  writeFileSync(path.join(outDir, '.node-version'), `${nodeVersionNumber}\n`, 'utf8');
168
164
  s.stop('.gitignore と .node-version を生成しました');
169
- // ステップ 7: LICENSE の生成
165
+ // generate LICENSE from the GitHub licenses API (failure is non-fatal)
170
166
  s.start('LICENSE を生成しています...');
171
167
  try {
172
168
  const licenseRes = await fetch(`https://api.github.com/licenses/${options.license.toLowerCase()}`);
@@ -183,7 +179,6 @@ async function main() {
183
179
  s.stop('LICENSE の取得をスキップしました(取得失敗)');
184
180
  log.warn('警告: LICENSE の取得に失敗しました。後で手動で追加してください。');
185
181
  }
186
- // ステップ 8: ワークフローファイルのコピー
187
182
  s.start('ワークフローファイルをコピーしています...');
188
183
  const workflowDir = path.join(outDir, '.github', 'workflows');
189
184
  mkdirSync(workflowDir, { recursive: true });
@@ -203,14 +198,10 @@ async function main() {
203
198
  writeFileSync(path.join(workflowDir, 'add-reviewer.yml'), addReviewerYml, 'utf8');
204
199
  }
205
200
  s.stop('ワークフローファイルをコピーしました');
206
- // ステップ 9: package.json の生成
207
201
  s.start('package.json を生成しています...');
208
- // 9-1: バリアントの package.json を読み込み
209
202
  const variantPkgText = readTemplate(`nodejs/${options.variant}/package.json`);
210
203
  const variantPkgJson = JSON.parse(variantPkgText);
211
- // 9-2〜9-4: プロジェクト固有の値を適用
212
204
  const patchedPkgJson = patchPackageJson(variantPkgJson, options, nodeMajor);
213
- // 9-5: .depcheckrc.json の更新
214
205
  const depcheckIgnore = templateConfig.depcheckIgnore ?? [];
215
206
  if (depcheckIgnore.length > 0 || options.test) {
216
207
  const depcheckPath = path.join(outDir, '.depcheckrc.json');
@@ -218,26 +209,24 @@ async function main() {
218
209
  const updatedDepcheck = updateDepcheck(depcheckJson, depcheckIgnore, options.test);
219
210
  writeFileSync(depcheckPath, JSON.stringify(updatedDepcheck, null, 2) + '\n', 'utf8');
220
211
  }
221
- // 9-6: schema/ ディレクトリの作成
212
+ // create schema/ (output directory of generate-schema)
222
213
  if (templateConfig.configSchema) {
223
214
  mkdirSync(path.join(outDir, 'schema'), { recursive: true });
224
215
  }
225
- // 9-7: package.json の保存
226
216
  writeFileSync(path.join(outDir, 'package.json'), JSON.stringify(patchedPkgJson, null, 2) + '\n', 'utf8');
227
217
  s.stop('package.json を生成しました');
228
- // ステップ 10: pnpm-lock.yaml のコピー
218
+ // copy the variant's pnpm-lock.yaml (used by --frozen-lockfile)
229
219
  s.start('pnpm-lock.yaml をコピーしています...');
230
220
  const pnpmLock = readTemplate(`nodejs/${options.variant}/pnpm-lock.yaml`);
231
221
  writeFileSync(path.join(outDir, 'pnpm-lock.yaml'), pnpmLock, 'utf8');
232
222
  s.stop('pnpm-lock.yaml をコピーしました');
233
- // ステップ 11: pnpm install
234
223
  s.start('pnpm install を実行しています...');
235
224
  await execa('pnpm', ['install', '--frozen-lockfile'], {
236
225
  cwd: outDir,
237
226
  stdio: 'inherit',
238
227
  });
239
228
  s.stop('依存パッケージをインストールしました');
240
- // ステップ 12: jest 関連の除去(テストなし時)
229
+ // the variant lockfile includes jest, so remove it without --test
241
230
  if (!options.test) {
242
231
  s.start('Jest 関連パッケージを削除しています...');
243
232
  await execa('pnpm', ['remove', 'jest', '@types/jest', 'ts-jest'], {
@@ -245,7 +234,7 @@ async function main() {
245
234
  });
246
235
  s.stop('Jest 関連パッケージを削除しました');
247
236
  }
248
- // ステップ 13: fixpack / fixdevcontainer
237
+ // fixpack / fixdevcontainer (failures are non-fatal)
249
238
  s.start('fixpack を実行しています...');
250
239
  try {
251
240
  await execa('npx', ['--yes', 'fixpack'], { cwd: outDir });
@@ -261,7 +250,6 @@ async function main() {
261
250
  catch {
262
251
  log.warn('fixdevcontainer をスキップしました(失敗)');
263
252
  }
264
- // ステップ 14: 完了メッセージ
265
253
  const completionLines = [
266
254
  '=== セットアップ完了! ===',
267
255
  '',
@@ -1,5 +1,5 @@
1
1
  import type { ProjectOptions } from './types.js';
2
- /** CLI フラグから渡される部分的なオプション */
2
+ /** Partial options given as CLI flags. */
3
3
  export interface CliFlags {
4
4
  name?: string;
5
5
  org?: string;
@@ -18,16 +18,16 @@ export interface CliFlags {
18
18
  overwrite?: boolean;
19
19
  }
20
20
  /**
21
- * 対話プロンプトで ProjectOptions を収集する。
22
- * CLI フラグで指定済みの項目はスキップする。
21
+ * Collects ProjectOptions interactively.
22
+ * Prompts are skipped for options already given as flags.
23
23
  */
24
24
  export declare function collectOptions(outDir: string, flags: CliFlags): Promise<ProjectOptions>;
25
25
  /**
26
- * セットアップ内容のサマリーを note() で表示する。
26
+ * Shows a summary of the setup with note().
27
27
  */
28
28
  export declare function displaySummary(options: ProjectOptions): void;
29
29
  /**
30
- * 既存ファイルの上書き確認を行う。
31
- * キャンセル / 拒否時はプロセスを終了する。
30
+ * Asks whether to overwrite existing files.
31
+ * Exits the process if the user cancels or declines.
32
32
  */
33
33
  export declare function confirmOverwrite(outDir: string): Promise<void>;
@@ -1,10 +1,10 @@
1
1
  import { cancel, confirm, group, isCancel, log, note, select, text, } from '@clack/prompts';
2
2
  import path from 'node:path';
3
3
  import { validateLicense, validateOrgName, validateProjectName, validateRepoName, } from './validate.js';
4
- /** 有効なバリアント値の一覧 */
4
+ /** Valid values for --variant. */
5
5
  const VALID_VARIANTS = ['base', 'config-batch', 'fastify', 'discord-bot'];
6
6
  /**
7
- * CLI フラグで渡された値をバリデーションし、不正な場合はプロセスを終了する。
7
+ * Validates flag values given on the command line and exits the process with code 1 if any is invalid.
8
8
  */
9
9
  function validateCliFlags(flags) {
10
10
  if (flags.name !== undefined) {
@@ -47,11 +47,10 @@ function validateCliFlags(flags) {
47
47
  process.exit(1);
48
48
  }
49
49
  /**
50
- * 対話プロンプトで ProjectOptions を収集する。
51
- * CLI フラグで指定済みの項目はスキップする。
50
+ * Collects ProjectOptions interactively.
51
+ * Prompts are skipped for options already given as flags.
52
52
  */
53
53
  export async function collectOptions(outDir, flags) {
54
- // CLI フラグの値を事前検証する(不正な場合はプロセスを終了)
55
54
  validateCliFlags(flags);
56
55
  const resolvedDir = path.resolve(outDir);
57
56
  const dirBasename = path.basename(resolvedDir);
@@ -59,7 +58,7 @@ export async function collectOptions(outDir, flags) {
59
58
  ? dirBasename
60
59
  : undefined;
61
60
  const answers = await group({
62
- // グループ 1: プロジェクト情報
61
+ // Group 1: project info
63
62
  name: () => flags.name === undefined
64
63
  ? text({
65
64
  message: 'プロジェクト名',
@@ -110,7 +109,7 @@ export async function collectOptions(outDir, flags) {
110
109
  initialValue: `https://github.com/${results.org ?? 'book000'}/${results.repo ?? 'my-app'}/issues`,
111
110
  })
112
111
  : Promise.resolve(flags.bugUrl),
113
- // グループ 2: テンプレート選択
112
+ // Group 2: template selection
114
113
  variant: () => flags.variant === undefined
115
114
  ? select({
116
115
  message: 'バリアント',
@@ -153,7 +152,7 @@ export async function collectOptions(outDir, flags) {
153
152
  initialValue: 'cjs',
154
153
  })
155
154
  : Promise.resolve(flags.esm ? 'esm' : 'cjs'),
156
- // グループ 3: オプション
155
+ // Group 3: options
157
156
  test: () => flags.test === undefined
158
157
  ? confirm({
159
158
  message: 'Jest テストを追加しますか?',
@@ -205,7 +204,7 @@ export async function collectOptions(outDir, flags) {
205
204
  };
206
205
  }
207
206
  /**
208
- * セットアップ内容のサマリーを note() で表示する。
207
+ * Shows a summary of the setup with note().
209
208
  */
210
209
  export function displaySummary(options) {
211
210
  const lines = [
@@ -221,8 +220,8 @@ export function displaySummary(options) {
221
220
  note(lines.join('\n'), 'セットアップ内容');
222
221
  }
223
222
  /**
224
- * 既存ファイルの上書き確認を行う。
225
- * キャンセル / 拒否時はプロセスを終了する。
223
+ * Asks whether to overwrite existing files.
224
+ * Exits the process if the user cancels or declines.
226
225
  */
227
226
  export async function confirmOverwrite(outDir) {
228
227
  const confirmed = await confirm({