tazuna 0.16.0 → 0.18.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.
@@ -1,19 +1,32 @@
1
1
  /**
2
- * tazuna pack --init-config: VB.NET 以外のプロジェクト(TypeScript 等)で使う
2
+ * tazuna pack --init-config: .sln の無いプロジェクト(TypeScript・Python・Go など)で使う
3
3
  * ための設定ファイル(tazuna.config.json、kind: "generic")を作る(旧 slnmix v0.17.0、設計書 §19)。
4
+ * tazuna init も .sln などが無いときはこれを使う。
4
5
  *
5
6
  * - 既に設定ファイルがあれば(旧名の slnmix.config.json でも)何もしない(冪等。中身は変えない)
6
- * - その場所に .sln / .vbproj があれば作らない(従来の solution 構成で動くため)
7
- * - git のリポジトリの中なら extraRoots を書かない(git が管理しているファイルが対象。設計書 §25.7)
7
+ * - その場所に .sln / .vbproj / .csproj があれば作らない(従来の solution 構成で動くため)
8
+ * - git のリポジトリの中なら extraRoots を書かない(git が管理しているファイルが対象。設計書 §25.7)。
9
+ * v0.18.0 から、実際にあるファイルの拡張子を見て include / exclude を書く(includePlanner.ts)。
10
+ * ファイルがまだ無ければ書かない(すべてが対象)
8
11
  * - git の外では、ソースのディレクトリは「候補名のうち実在するもの」だけを採用する(src / app /
9
12
  * lib / apps / packages → kind: "src"、tests / test / e2e / __tests__ →
10
- * kind: "test")。1 つも無ければ推測で書かずエラーにし、例を示す
13
+ * kind: "test")。候補が無ければ、直下のディレクトリのうち言語の分かるソースを含むものを使う
14
+ * (v0.18.0)。それぞれの include / exclude も中のファイルの拡張子から書く。1 つも無ければ推測で
15
+ * 書かずエラーにし、例を示す
11
16
  *
12
17
  * ファイルシステムは deps 注入(単体テスト可能)。
13
18
  */
14
19
  import * as path from "node:path";
15
20
  import { PACK_COMMAND } from "../brand.js";
21
+ import { planInclude } from "./includePlanner.js";
16
22
  import { CONFIG_FILE_NAME, configFileNameIn, hasConfigFile } from "./slnmixConfig.js";
23
+ /**
24
+ * git の一覧から決める include に、ファイルが無くても入れるもの(init が続けて作る docs/ の Markdown・
25
+ * .gitignore・設定ファイル自身。設定ファイルは AI がパックの範囲を知る手がかりになる)
26
+ */
27
+ export const ALWAYS_INCLUDE = ["**/*.md", "**/.gitignore", CONFIG_FILE_NAME];
28
+ /** git の外で候補のディレクトリが無いとき、直下のディレクトリのうち見ないもの(docs/ は <docs> に入る) */
29
+ const SKIPPED_TOP_DIRECTORIES = new Set(["node_modules", "dist", "build", "bin", "obj", "target", "docs", "__pycache__"]);
17
30
  /** ソースの候補ディレクトリ(この順で並ぶ) */
18
31
  export const SOURCE_DIR_CANDIDATES = ["src", "app", "lib", "apps", "packages"];
19
32
  /** 自動テストの候補ディレクトリ */
@@ -27,8 +40,29 @@ export const EXAMPLE_CONFIG = `{
27
40
  ]
28
41
  }`;
29
42
  function renderConfig(roots) {
30
- const lines = roots.map((root, index) => ` { "path": "${root.path}", "kind": "${root.kind}" }${index === roots.length - 1 ? "" : ","}`);
31
- return ["{", ' "kind": "generic",', ' "extraRoots": [', ...lines, " ]", "}", ""].join("\n");
43
+ return `${JSON.stringify({
44
+ kind: "generic",
45
+ extraRoots: roots.map((root) => {
46
+ const exclude = [
47
+ ...(root.plan?.exclude ?? []),
48
+ ...(root.skippedDirs ?? []).map((dir) => `${dir.relativePath}/**`),
49
+ ];
50
+ return {
51
+ path: root.path,
52
+ kind: root.kind,
53
+ ...(root.plan !== undefined && root.plan.include.length > 0 ? { include: root.plan.include } : {}),
54
+ ...(exclude.length > 0 ? { exclude } : {}),
55
+ };
56
+ }),
57
+ }, null, 2)}\n`;
58
+ }
59
+ /** git が管理しているファイルを対象にし、拡張子から決めた include / exclude を書く generic 構成 */
60
+ export function renderGitGenericConfig(plan) {
61
+ return `${JSON.stringify({
62
+ kind: "generic",
63
+ include: plan.include,
64
+ ...(plan.exclude.length > 0 ? { exclude: plan.exclude } : {}),
65
+ }, null, 2)}\n`;
32
66
  }
33
67
  /** git が管理しているファイルを対象にする generic 構成(extraRoots なし。設計書 §25.7) */
34
68
  export const GIT_GENERIC_CONFIG = `{
@@ -47,18 +81,26 @@ export function initConfig(rootDir, deps, options = {}) {
47
81
  }
48
82
  const configPath = path.join(rootDir, CONFIG_FILE_NAME);
49
83
  const names = deps.listFileNames(rootDir) ?? [];
50
- const solutionFiles = names.filter((name) => /\.(sln|vbproj)$/i.test(name)).sort();
84
+ const solutionFiles = names.filter((name) => /\.(sln|vbproj|csproj)$/i.test(name)).sort();
51
85
  if (solutionFiles.length > 0) {
52
86
  return {
53
87
  kind: "error",
54
88
  message: [
55
- `${rootDir} には ${solutionFiles.join(", ")} があります。VB.NET のプロジェクトは設定なしで npx ${PACK_COMMAND} を実行できます(kind: "generic" は .sln / .vbproj の無いプロジェクト向け)。`,
89
+ `${rootDir} には ${solutionFiles.join(", ")} があります。VB.NET / C# のプロジェクトは設定なしで npx ${PACK_COMMAND} を実行できます(kind: "generic" は .sln / .vbproj / .csproj の無いプロジェクト向け)。`,
56
90
  ].join("\n"),
57
91
  };
58
92
  }
59
93
  if (options.gitRepository === true) {
60
- deps.writeTextFile(configPath, GIT_GENERIC_CONFIG);
61
- return { kind: "created", path: configPath, content: GIT_GENERIC_CONFIG, roots: [] };
94
+ const files = deps.listPackableGitFiles?.(rootDir);
95
+ if (files === undefined || files.length === 0) {
96
+ // まだファイルが無い(新しいリポジトリ)など: 拡張子から決められないので、すべてを対象にする
97
+ deps.writeTextFile(configPath, GIT_GENERIC_CONFIG);
98
+ return { kind: "created", path: configPath, content: GIT_GENERIC_CONFIG, roots: [] };
99
+ }
100
+ const plan = planInclude({ files, readHead: (relativePath) => deps.readHead?.(path.join(rootDir, ...relativePath.split("/"))) }, { alwaysInclude: ALWAYS_INCLUDE });
101
+ const content = renderGitGenericConfig(plan);
102
+ deps.writeTextFile(configPath, content);
103
+ return { kind: "created", path: configPath, content, roots: [], plan };
62
104
  }
63
105
  const roots = [];
64
106
  for (const name of SOURCE_DIR_CANDIDATES) {
@@ -66,16 +108,38 @@ export function initConfig(rootDir, deps, options = {}) {
66
108
  roots.push({ path: name, kind: "src" });
67
109
  }
68
110
  }
111
+ if (roots.length === 0 && deps.listDirectoryFiles !== undefined && deps.listDirectoryNames !== undefined) {
112
+ // 候補名のディレクトリが無ければ、直下のディレクトリのうち言語の分かるソースを含むもの(例: Python の
113
+ // パッケージのディレクトリ)。見つけたものは設定に書くので利用者に見える
114
+ const names = (deps.listDirectoryNames(rootDir) ?? [])
115
+ .filter((name) => !name.startsWith(".") && !SKIPPED_TOP_DIRECTORIES.has(name.toLowerCase()))
116
+ .filter((name) => !TEST_DIR_CANDIDATES.includes(name))
117
+ .sort((a, b) => a.localeCompare(b));
118
+ for (const name of names) {
119
+ if (deps.isFile(path.join(rootDir, name, "pyvenv.cfg"))) {
120
+ continue;
121
+ }
122
+ const planned = planRoot(rootDir, name, deps);
123
+ if (planned?.plan !== undefined && planned.plan.languages.length > 0) {
124
+ roots.push({ path: name, kind: "src", ...planned });
125
+ }
126
+ }
127
+ }
128
+ else {
129
+ for (const root of roots) {
130
+ Object.assign(root, planRoot(rootDir, root.path, deps));
131
+ }
132
+ }
69
133
  for (const name of TEST_DIR_CANDIDATES) {
70
134
  if (deps.isDirectory(path.join(rootDir, name))) {
71
- roots.push({ path: name, kind: "test" });
135
+ roots.push({ path: name, kind: "test", ...planRoot(rootDir, name, deps) });
72
136
  }
73
137
  }
74
138
  if (!roots.some((root) => root.kind === "src")) {
75
139
  return {
76
140
  kind: "error",
77
141
  message: [
78
- `${rootDir} にソースのディレクトリ(${SOURCE_DIR_CANDIDATES.join(" / ")})が見つかりません。推測では作らないので、${CONFIG_FILE_NAME} を手で作ってください。例:`,
142
+ `${rootDir} にソースのディレクトリ(${SOURCE_DIR_CANDIDATES.join(" / ")}、または言語の分かるソースを含むディレクトリ)が見つかりません。推測では作らないので、${CONFIG_FILE_NAME} を手で作ってください。例:`,
79
143
  EXAMPLE_CONFIG,
80
144
  ].join("\n"),
81
145
  };
@@ -84,3 +148,58 @@ export function initConfig(rootDir, deps, options = {}) {
84
148
  deps.writeTextFile(configPath, content);
85
149
  return { kind: "created", path: configPath, content, roots };
86
150
  }
151
+ /** extraRoots の 1 つのディレクトリの include / exclude を中のファイルから決める(走査できなければ undefined) */
152
+ function planRoot(rootDir, name, deps) {
153
+ const listed = deps.listDirectoryFiles?.(path.join(rootDir, name));
154
+ if (listed === undefined) {
155
+ return undefined;
156
+ }
157
+ const plan = planInclude({
158
+ files: listed.files,
159
+ readHead: (relativePath) => deps.readHead?.(path.join(rootDir, name, ...relativePath.split("/"))),
160
+ });
161
+ return {
162
+ plan: plan.include.length > 0 ? plan : undefined,
163
+ skippedDirs: listed.skippedDirs.length > 0 ? listed.skippedDirs : undefined,
164
+ };
165
+ }
166
+ function formatKiloChars(bytes) {
167
+ return bytes < 1000 ? `${bytes}` : `${Math.round(bytes / 1000)}K`;
168
+ }
169
+ /**
170
+ * 拡張子から決めた include / exclude の説明(init と --init-config の表示用。1 要素 1 行、字下げなし)。
171
+ * @param scope 何から決めたか(例: "git が管理しているファイル"・"src/")
172
+ */
173
+ export function describeIncludePlan(plan, scope) {
174
+ const lines = [];
175
+ lines.push(plan.languages.length === 0
176
+ ? `言語: (${scope}に言語の分かるソースがありません)`
177
+ : `言語: ${plan.languages.map((language) => `${language.name} ${language.count} 件`).join(" / ")}`);
178
+ lines.push(`include: ${plan.include.join(", ")}`);
179
+ if (plan.excluded.length > 0) {
180
+ lines.push(`exclude: ${plan.excluded
181
+ .map((entry) => `${entry.pattern}(${entry.reason}${entry.count > 0 ? ` ${entry.count} 件` : ""})`)
182
+ .join(" / ")}`);
183
+ }
184
+ if (plan.omitted.length > 0) {
185
+ const shown = plan.omitted.slice(0, 8);
186
+ const rest = plan.omitted.length - shown.length;
187
+ lines.push(`入れないもの: ${[
188
+ ...shown.map((entry) => `${entry.label} ${entry.count} 件(${entry.reason}。例: ${entry.example})`),
189
+ ...(rest > 0 ? [`ほか ${rest} 種類`] : []),
190
+ ].join(" / ")}`);
191
+ }
192
+ return lines;
193
+ }
194
+ /** git の一覧から決めたときの、パックの大きさの目安(貼り付けの上限との比較) */
195
+ export function describePackSize(plan, pasteLimit, overhead) {
196
+ const estimate = plan.includedBytes + overhead;
197
+ const head = `ファイルの中身: ${plan.includedCount} 件・約 ${formatKiloChars(plan.includedBytes)} 文字`;
198
+ if (estimate <= pasteLimit) {
199
+ return [`${head}(手順文などを足しても、貼り付けの上限の目安 約 ${formatKiloChars(pasteLimit)} 文字に収まる見込み)`];
200
+ }
201
+ return [
202
+ `${head}。手順文などを足すと貼り付けの上限の目安(約 ${formatKiloChars(pasteLimit)} 文字)を超える見込みで、その場合はパックを添付で渡します(本文用テキストがクリップボードに入ります)`,
203
+ `大きいもの: ${plan.largest.map((file) => `${file.relativePath}(約 ${formatKiloChars(file.size)} 文字)`).join(" / ")}。要らなければ exclude に足してください`,
204
+ ];
205
+ }
@@ -2,7 +2,7 @@
2
2
  * tazuna init: 初回セットアップを 1 コマンドにまとめる(旧 slnmix init + petari init。設計書 §20・§25)。
3
3
  *
4
4
  * 1. 構成: 設定ファイル(tazuna.config.json。旧名 slnmix.config.json も)があればそのまま使う。なければ
5
- * - 直下に .sln / .vbproj があれば設定を作らない(従来どおり自動検出)
5
+ * - 直下に .sln / .vbproj / .csproj があれば設定を作らない(従来どおり自動検出)
6
6
  * - 直下に無く、1 段下のフォルダに .sln が 1 つだけあれば target で指す設定を作る
7
7
  * - どちらも無ければ --init-config と同じ generic 構成を作る
8
8
  * 2. docs/ 連携(--init-docs と同じ)
@@ -22,7 +22,8 @@
22
22
  */
23
23
  import * as path from "node:path";
24
24
  import { GitignoreRules } from "./services/gitignoreMatcher.js";
25
- import { initConfig } from "./initConfig.js";
25
+ import { describeIncludePlan, describePackSize, initConfig, } from "./initConfig.js";
26
+ import { PACK_OVERHEAD_CHARS, PASTE_LIMIT_CHARS } from "./handoff.js";
26
27
  import { initDocs } from "./initDocs.js";
27
28
  import { BUILD_COMMAND, PACK_COMMAND, TOOL_NAME, stateDirectoryName } from "../brand.js";
28
29
  import { CONFIG_TEMPLATE } from "../infra/config.js";
@@ -36,7 +37,7 @@ export const GENERATED_OUTPUTS = [
36
37
  ];
37
38
  /** 1 段下の .sln を探すときに見ないフォルダ(ドットで始まるものも見ない) */
38
39
  const SKIPPED_SUBDIRECTORIES = new Set(["node_modules", "bin", "obj", "packages"]);
39
- const TARGET_EXTENSION = /\.(sln|vbproj)$/i;
40
+ const TARGET_EXTENSION = /\.(sln|vbproj|csproj)$/i;
40
41
  /** .git のある最も近い祖先(自身を含む)。無ければ undefined */
41
42
  export function findRepositoryRoot(directory, exists) {
42
43
  let dir = directory;
@@ -124,8 +125,8 @@ function setUpLayout(rootDir, deps) {
124
125
  return {
125
126
  kind: "error",
126
127
  message: [
127
- `${configName} はありますが、対象が決まりません(直下に .sln / .vbproj が無く、target も kind: "generic" もありません)。`,
128
- `.sln がサブフォルダにあれば "target": "<フォルダ>/<名前>.sln" を、VB.NET 以外なら "kind": "generic" と extraRoots を書いてから、もう一度実行してください。`,
128
+ `${configName} はありますが、対象が決まりません(直下に .sln / .vbproj / .csproj が無く、target も kind: "generic" もありません)。`,
129
+ `.sln がサブフォルダにあれば "target": "<フォルダ>/<名前>.sln" を、.sln の無いプロジェクトなら "kind": "generic" と extraRoots を書いてから、もう一度実行してください。`,
129
130
  ].join("\n"),
130
131
  };
131
132
  }
@@ -170,41 +171,69 @@ function setUpLayout(rootDir, deps) {
170
171
  ].join("\n"),
171
172
  };
172
173
  }
173
- // VB.NET 以外のプロジェクト。git のリポジトリなら git が管理しているファイルを対象にする
174
+ // .sln の無いプロジェクト。git のリポジトリなら git が管理しているファイルを対象にする
174
175
  const result = initConfig(rootDir, deps, { gitRepository: findRepositoryRoot(rootDir, deps.exists) !== undefined });
175
176
  if (result.kind === "error") {
176
177
  return {
177
178
  kind: "error",
178
179
  message: [
179
- `.sln / .vbproj が直下にも 1 段下のフォルダにもありません。VB.NET のプロジェクトなら ${configName} に "target": "<フォルダ>/<名前>.sln" を書いてから、もう一度実行してください。`,
180
- `VB.NET 以外のプロジェクトの場合: ${result.message}`,
180
+ `.sln / .vbproj / .csproj が直下にも 1 段下のフォルダにもありません。VB.NET / C# のプロジェクトなら ${configName} に "target": "<フォルダ>/<名前>.sln" を書いてから、もう一度実行してください。`,
181
+ `.sln の無いプロジェクトの場合: ${result.message}`,
181
182
  ].join("\n"),
182
183
  };
183
184
  }
184
185
  if (result.kind === "kept") {
185
186
  return { kind: "ok", layout: "generic", lines: [`1. 構成: 既存の ${configName}(変更なし)`] };
186
187
  }
187
- if (result.roots.length === 0) {
188
- return {
189
- kind: "ok",
190
- layout: "generic",
191
- lines: [
192
- `1. 構成: generic(.sln / .vbproj が無いため、git が管理しているファイルを対象にする ${configName} を作りました)`,
193
- ` 対象を絞るときは .repomixignore に除外を書くか、${configName} の extraRoots にディレクトリを書いてください`,
194
- ` VB.NET のプロジェクトで .sln が 2 段以上深い場合は見つけられません。kind の代わりに "target": "<パス>/<名前>.sln" を書いてください`,
195
- ],
196
- };
197
- }
188
+ const heading = result.roots.length > 0
189
+ ? `1. 構成: generic(.sln / .vbproj / .csproj が無いため ${configName} を作りました)`
190
+ : result.plan === undefined
191
+ ? `1. 構成: generic(.sln / .vbproj / .csproj が無いため、git が管理しているファイルを対象にする ${configName} を作りました)`
192
+ : `1. 構成: generic(.sln / .vbproj / .csproj が無いため、git が管理しているファイルの拡張子を見て ${configName} を作りました)`;
198
193
  return {
199
194
  kind: "ok",
200
195
  layout: "generic",
201
196
  lines: [
202
- `1. 構成: generic(.sln / .vbproj が無いため ${configName} を作りました)`,
203
- ...result.roots.map((root) => ` extraRoots: ${root.path}/(kind: "${root.kind}")`),
204
- ` VB.NET のプロジェクトで .sln が 2 段以上深い場合は見つけられません。kind と extraRoots の代わりに "target": "<パス>/<名前>.sln" を書いてください`,
197
+ heading,
198
+ ...describeCreatedGenericConfig(result, configName).map((line) => ` ${line}`),
199
+ ` VB.NET / C# のプロジェクトで .sln が 2 段以上深い場合は見つけられません。kind${result.roots.length === 0 ? "" : " と extraRoots"}${result.plan === undefined ? "" : "・include・exclude"} の代わりに "target": "<パス>/<名前>.sln" を書いてください`,
205
200
  ],
206
201
  };
207
202
  }
203
+ /**
204
+ * initConfig が作った generic 構成の説明(init と pack --init-config の表示用。字下げなし)。
205
+ * 拡張子から決めた include / exclude・入れないもの・大きさの目安
206
+ */
207
+ export function describeCreatedGenericConfig(result, configName) {
208
+ if (result.roots.length > 0) {
209
+ return [
210
+ ...result.roots.flatMap((root) => [
211
+ `extraRoots: ${root.path}/(kind: "${root.kind}")`,
212
+ ...describeRootPlan(root).map((line) => ` ${line}`),
213
+ ]),
214
+ `git のリポジトリでないため、extraRoots のディレクトリだけが対象です(直下のファイルは入りません。git のリポジトリにすると、git が管理しているファイルを対象にできます)`,
215
+ ];
216
+ }
217
+ if (result.plan === undefined) {
218
+ return [
219
+ `まだファイルが無いため、拡張子から include を決めていません(git が管理しているファイルがすべて対象。ファイルを足した後で ${configName} に include を書けます)`,
220
+ `対象を絞るときは ${configName} に include / exclude を書くか、.repomixignore に除外を書いてください`,
221
+ ];
222
+ }
223
+ return [
224
+ ...describeIncludePlan(result.plan, "git が管理しているファイル"),
225
+ ...describePackSize(result.plan, PASTE_LIMIT_CHARS, PACK_OVERHEAD_CHARS),
226
+ `対象を変えるときは ${configName} の include / exclude を書き換えてください(include に一致しないものはパックに入りません)`,
227
+ ];
228
+ }
229
+ /** git の外の extraRoots の 1 つについて、決めた include / exclude の説明 */
230
+ function describeRootPlan(root) {
231
+ const skipped = (root.skippedDirs ?? []).map((dir) => ({ pattern: `${dir.relativePath}/**`, reason: dir.reason, count: 0 }));
232
+ if (root.plan === undefined) {
233
+ return skipped.length === 0 ? [] : [`exclude: ${skipped.map((entry) => `${entry.pattern}(${entry.reason})`).join(" / ")}`];
234
+ }
235
+ return describeIncludePlan({ ...root.plan, excluded: [...root.plan.excluded, ...skipped] }, `${root.path}/ `);
236
+ }
208
237
  function toRelative(rootDir, absolutePath) {
209
238
  return path.relative(rootDir, absolutePath).split(path.sep).join("/");
210
239
  }
@@ -10,7 +10,7 @@
10
10
  const UNSPLITTABLE = /[$@%]\(|[*?]/;
11
11
  function projectLabelOf(projectPath) {
12
12
  const fileName = projectPath.split(/[\\/]/).pop() ?? projectPath;
13
- return fileName.replace(/\.vbproj$/i, "");
13
+ return fileName.replace(/\.(vbproj|csproj)$/i, "");
14
14
  }
15
15
  function compareNodes(a, b) {
16
16
  // 警告 → フォルダ → ファイルの順。同種はラベルの大文字小文字を無視した昇順
@@ -92,6 +92,7 @@ export function resolveProcedure(options, rootDir, cwd, deps) {
92
92
  tests: options.tests === true,
93
93
  db: options.db === true,
94
94
  layout: options.layout ?? DEFAULT_PROCEDURE_LAYOUT,
95
+ languages: options.languages,
95
96
  };
96
97
  if (options.explicitPath !== undefined) {
97
98
  const absolutePath = path.resolve(cwd, options.explicitPath);
@@ -0,0 +1,67 @@
1
+ /**
2
+ * .sln に入るプロジェクトの言語(Visual Basic の .vbproj と C# の .csproj。C# は tazuna 0.17.0 から)。
3
+ *
4
+ * プロジェクトファイルの形式(旧スタイル / SDK スタイル、ItemGroup の Compile)は言語によらず同じで、
5
+ * 違うのはソースの拡張子・SDK の既定の Compile グロブ・Designer のファイル名・言語の版の決まり方だけ。
6
+ * VB だけのソリューションの出力は C# 対応の前と同じに保つため、表記は含まれる言語から作る
7
+ * (projectFilesLabel)。
8
+ */
9
+ export const LANGUAGES = {
10
+ vb: {
11
+ projectExtension: ".vbproj",
12
+ sourceExtension: ".vb",
13
+ displayName: "Visual Basic",
14
+ defaultCompileGlob: "**/*.vb",
15
+ designerSuffix: ".designer.vb",
16
+ },
17
+ cs: {
18
+ projectExtension: ".csproj",
19
+ sourceExtension: ".cs",
20
+ displayName: "C#",
21
+ defaultCompileGlob: "**/*.cs",
22
+ designerSuffix: ".designer.cs",
23
+ },
24
+ };
25
+ /** 対応しているプロジェクトファイル(.vbproj / .csproj) */
26
+ export const PROJECT_FILE = /\.(vbproj|csproj)$/i;
27
+ /** 対応している入力(.sln とプロジェクトファイル) */
28
+ export const TARGET_FILE = /\.(sln|vbproj|csproj)$/i;
29
+ /** プロジェクトファイルの言語(対応していない拡張子は undefined) */
30
+ export function projectLanguageOf(filePath) {
31
+ if (/\.vbproj$/i.test(filePath)) {
32
+ return "vb";
33
+ }
34
+ if (/\.csproj$/i.test(filePath)) {
35
+ return "cs";
36
+ }
37
+ return undefined;
38
+ }
39
+ /** 言語の並び(VB を先に。表記を安定させる) */
40
+ function ordered(languages) {
41
+ const set = new Set(languages);
42
+ return ["vb", "cs"].filter((language) => set.has(language));
43
+ }
44
+ /**
45
+ * 含まれる言語のプロジェクトファイルの表記(".vbproj" / ".csproj" / ".vbproj / .csproj")。
46
+ * 言語が無いときは VB(C# 対応の前の表記)
47
+ */
48
+ export function projectFilesLabel(languages) {
49
+ const list = ordered(languages);
50
+ return (list.length === 0 ? ["vb"] : list).map((language) => LANGUAGES[language].projectExtension).join(" / ");
51
+ }
52
+ /** 含まれる言語の表示名("Visual Basic" / "C#" / "Visual Basic / C#")。言語が無いときは VB */
53
+ export function languageNamesLabel(languages) {
54
+ const list = ordered(languages);
55
+ return (list.length === 0 ? ["vb"] : list).map((language) => LANGUAGES[language].displayName).join(" / ");
56
+ }
57
+ /** ファイル名が Designer ファイル(X.Designer.vb / X.Designer.cs)なら、その言語 */
58
+ export function designerLanguageOf(fileName) {
59
+ const lower = fileName.toLowerCase();
60
+ if (lower.endsWith(LANGUAGES.vb.designerSuffix)) {
61
+ return "vb";
62
+ }
63
+ if (lower.endsWith(LANGUAGES.cs.designerSuffix)) {
64
+ return "cs";
65
+ }
66
+ return undefined;
67
+ }