@ts-for-gir/cli 4.0.0-beta.9 → 4.0.0-rc.10

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 (86) hide show
  1. package/README.md +335 -86
  2. package/bin/ts-for-gir +28832 -0
  3. package/bin/ts-for-gir-dev +43 -0
  4. package/bin/ts-for-gir-gjs +348955 -0
  5. package/dist-templates/types-locally/.ts-for-girrc.js +6 -0
  6. package/dist-templates/types-locally/README.md +15 -0
  7. package/dist-templates/types-locally/esbuild.ts +10 -0
  8. package/dist-templates/types-locally/main.ts +21 -0
  9. package/dist-templates/types-locally/package.json +18 -0
  10. package/dist-templates/types-locally/tsconfig.json +17 -0
  11. package/dist-templates/types-npm/README.md +14 -0
  12. package/dist-templates/types-npm/esbuild.ts +10 -0
  13. package/dist-templates/types-npm/main.ts +19 -0
  14. package/dist-templates/types-npm/package.json +23 -0
  15. package/dist-templates/types-npm/tsconfig.json +15 -0
  16. package/dist-templates/types-workspace/.ts-for-girrc.js +12 -0
  17. package/dist-templates/types-workspace/README.md +26 -0
  18. package/dist-templates/types-workspace/package.json +22 -0
  19. package/dist-templates/types-workspace/packages/app/esbuild.ts +10 -0
  20. package/dist-templates/types-workspace/packages/app/main.ts +19 -0
  21. package/dist-templates/types-workspace/packages/app/package.json +23 -0
  22. package/dist-templates/types-workspace/packages/app/tsconfig.json +15 -0
  23. package/dist-templates/types-workspace/tsconfig.json +11 -0
  24. package/package.json +60 -37
  25. package/src/commands/analyze.ts +344 -0
  26. package/src/commands/command-builder.ts +30 -0
  27. package/src/commands/copy.ts +71 -76
  28. package/src/commands/create.ts +223 -0
  29. package/src/commands/doc.ts +44 -47
  30. package/src/commands/generate.ts +35 -79
  31. package/src/commands/index.ts +8 -4
  32. package/src/commands/json.ts +43 -0
  33. package/src/commands/list.ts +71 -90
  34. package/src/commands/run-generation-command.ts +75 -0
  35. package/src/commands/self-update.ts +142 -0
  36. package/src/config/config-loader.ts +238 -0
  37. package/src/config/config-writer.ts +52 -0
  38. package/src/config/defaults.ts +68 -0
  39. package/src/config/index.ts +16 -0
  40. package/src/config/options.ts +365 -0
  41. package/src/config.ts +3 -456
  42. package/src/formatters/typescript-formatter.ts +17 -0
  43. package/src/generation-handler.ts +122 -67
  44. package/src/index.ts +4 -4
  45. package/src/module-loader/dependency-resolver.ts +100 -0
  46. package/src/module-loader/file-finder.ts +65 -0
  47. package/src/module-loader/index.ts +8 -0
  48. package/src/module-loader/module-grouper.ts +77 -0
  49. package/src/module-loader/prompt-handler.ts +111 -0
  50. package/src/module-loader.ts +321 -578
  51. package/src/start.ts +36 -15
  52. package/src/types/command-args.ts +154 -0
  53. package/src/types/command-definition.ts +17 -0
  54. package/src/types/commands.ts +30 -0
  55. package/src/types/index.ts +15 -0
  56. package/src/types/report-types.ts +34 -0
  57. package/lib/commands/copy.d.ts +0 -12
  58. package/lib/commands/copy.js +0 -80
  59. package/lib/commands/copy.js.map +0 -1
  60. package/lib/commands/doc.d.ts +0 -12
  61. package/lib/commands/doc.js +0 -40
  62. package/lib/commands/doc.js.map +0 -1
  63. package/lib/commands/generate.d.ts +0 -12
  64. package/lib/commands/generate.js +0 -71
  65. package/lib/commands/generate.js.map +0 -1
  66. package/lib/commands/index.d.ts +0 -4
  67. package/lib/commands/index.js +0 -5
  68. package/lib/commands/index.js.map +0 -1
  69. package/lib/commands/list.d.ts +0 -12
  70. package/lib/commands/list.js +0 -81
  71. package/lib/commands/list.js.map +0 -1
  72. package/lib/config.d.ts +0 -108
  73. package/lib/config.js +0 -410
  74. package/lib/config.js.map +0 -1
  75. package/lib/generation-handler.d.ts +0 -10
  76. package/lib/generation-handler.js +0 -48
  77. package/lib/generation-handler.js.map +0 -1
  78. package/lib/index.d.ts +0 -4
  79. package/lib/index.js +0 -5
  80. package/lib/index.js.map +0 -1
  81. package/lib/module-loader.d.ts +0 -148
  82. package/lib/module-loader.js +0 -468
  83. package/lib/module-loader.js.map +0 -1
  84. package/lib/start.d.ts +0 -2
  85. package/lib/start.js +0 -16
  86. package/lib/start.js.map +0 -1
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Default configuration values for ts-for-gir CLI
3
+ */
4
+
5
+ import { existsSync } from "node:fs";
6
+ import { join } from "node:path";
7
+
8
+ /**
9
+ * Default CLI flag and argument values
10
+ */
11
+ export const defaults = {
12
+ print: false,
13
+ configName: ".ts-for-girrc.js",
14
+ root: process.cwd(),
15
+ outdir: "./@types",
16
+ /** Default output directory for `ts-for-gir doc` (HTML documentation). */
17
+ docOutdir: "./docs",
18
+ girDirectories: getDefaultGirDirectories(),
19
+ modules: ["*"],
20
+ ignore: [],
21
+ verbose: false,
22
+ ignoreVersionConflicts: false,
23
+ noNamespace: false,
24
+ noComments: false,
25
+ promisify: true,
26
+ npmScope: "@girs",
27
+ workspace: false,
28
+ onlyVersionPrefix: false,
29
+ noPrettyPrint: false,
30
+ noAdvancedVariants: false,
31
+ package: false,
32
+ reporter: false,
33
+ reporterOutput: "ts-for-gir-report.json",
34
+ externalDeps: false,
35
+ allowMissingDeps: false,
36
+ combined: true,
37
+ /** Default theme for `ts-for-gir doc` (HTML documentation). */
38
+ theme: "gi-docgen",
39
+ };
40
+
41
+ /**
42
+ * Get default GIR directories based on the system configuration
43
+ */
44
+ function getDefaultGirDirectories(): string[] {
45
+ const girDirectories = [
46
+ "/usr/local/share/gir-1.0",
47
+ "/usr/share/gir-1.0",
48
+ "/usr/share/*/gir-1.0",
49
+ "/usr/share/gnome-shell",
50
+ "/usr/share/gnome-shell/gir-1.0",
51
+ "/usr/lib64/mutter-*",
52
+ "/usr/lib/mutter-*",
53
+ "/usr/lib/x86_64-linux-gnu/mutter-*",
54
+ ];
55
+
56
+ // NixOS and other distributions does not have a /usr/local/share directory.
57
+ // Instead, the nix store paths with Gir files are set as XDG_DATA_DIRS.
58
+ // See https://github.com/NixOS/nixpkgs/blob/96e18717904dfedcd884541e5a92bf9ff632cf39/pkgs/development/libraries/gobject-introspection/setup-hook.sh#L7-L10
59
+ const dataDirs = process.env.XDG_DATA_DIRS?.split(":") || [];
60
+ for (let dataDir of dataDirs) {
61
+ dataDir = join(dataDir, "gir-1.0");
62
+ if (!girDirectories.includes(dataDir) && existsSync(dataDir)) {
63
+ girDirectories.push(dataDir);
64
+ }
65
+ }
66
+
67
+ return girDirectories;
68
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Config module exports
3
+ */
4
+
5
+ export { getOptionsGeneration, load, validate } from "./config-loader.ts";
6
+ export { addToConfig, configFilePath } from "./config-writer.ts";
7
+ export { defaults } from "./defaults.ts";
8
+ export {
9
+ analyzeOptions,
10
+ copyOptions,
11
+ createOptions,
12
+ docOptions,
13
+ generateOptions,
14
+ listOptions,
15
+ options,
16
+ } from "./options.ts";
@@ -0,0 +1,365 @@
1
+ /**
2
+ * CLI options definitions for ts-for-gir commands
3
+ */
4
+
5
+ import type { Options } from "yargs";
6
+ import { defaults } from "./defaults.ts";
7
+
8
+ /**
9
+ * CLI options used in commands/generate.ts and commands/list.ts
10
+ */
11
+ export const options: { [name: string]: Options } = {
12
+ modules: {
13
+ description: "GIR modules to load, e.g. 'Gio-2.0'. Accepts multiple modules",
14
+ array: true,
15
+ default: defaults.modules,
16
+ normalize: true,
17
+ },
18
+ girDirectories: {
19
+ type: "string",
20
+ alias: "g",
21
+ description: "GIR directories",
22
+ array: true,
23
+ default: defaults.girDirectories,
24
+ normalize: true,
25
+ },
26
+ root: {
27
+ type: "string",
28
+ description: "Root directory of your project",
29
+ default: defaults.root,
30
+ normalize: true,
31
+ },
32
+ outdir: {
33
+ type: "string",
34
+ alias: "o",
35
+ description: "Directory to output to",
36
+ default: defaults.outdir,
37
+ normalize: true,
38
+ },
39
+ ignore: {
40
+ type: "string",
41
+ alias: "i",
42
+ description: "Modules that should be ignored",
43
+ array: true,
44
+ default: defaults.ignore,
45
+ normalize: true,
46
+ },
47
+ verbose: {
48
+ type: "boolean",
49
+ alias: "v",
50
+ description: "Switch on/off the verbose mode",
51
+ default: defaults.verbose,
52
+ normalize: true,
53
+ },
54
+ ignoreVersionConflicts: {
55
+ type: "boolean",
56
+ description: "Skip prompts for library version selection when multiple versions are detected",
57
+ default: defaults.ignoreVersionConflicts,
58
+ normalize: true,
59
+ },
60
+ print: {
61
+ type: "boolean",
62
+ alias: "p",
63
+ description: "Print the output to console and create no files",
64
+ default: defaults.print,
65
+ normalize: true,
66
+ },
67
+ configName: {
68
+ type: "string",
69
+ description: "Specify a custom name for the configuration file",
70
+ default: defaults.configName,
71
+ normalize: true,
72
+ },
73
+ noNamespace: {
74
+ type: "boolean",
75
+ alias: "d",
76
+ description: "Do not export all symbols for each module as a namespace",
77
+ default: defaults.noNamespace,
78
+ normalize: true,
79
+ },
80
+ noComments: {
81
+ type: "boolean",
82
+ alias: "n",
83
+ description: "Do not generate documentation comments",
84
+ default: defaults.noComments,
85
+ normalize: true,
86
+ },
87
+ promisify: {
88
+ type: "boolean",
89
+ description: "Generate promisified functions for async/finish calls",
90
+ default: defaults.promisify,
91
+ normalize: true,
92
+ },
93
+ npmScope: {
94
+ type: "string",
95
+ description: "Scope of the generated NPM packages",
96
+ default: defaults.npmScope,
97
+ normalize: true,
98
+ },
99
+ workspace: {
100
+ type: "boolean",
101
+ description:
102
+ "Uses the workspace protocol for the generated packages which can be used with package managers like Yarn and PNPM",
103
+ default: defaults.workspace,
104
+ normalize: true,
105
+ },
106
+ depVersionFormat: {
107
+ type: "string",
108
+ description:
109
+ "Dependency version spec format in generated package.json files. Defaults to 'workspace' when --workspace, else 'exact'",
110
+ choices: ["workspace", "caret", "any", "exact"] as const,
111
+ },
112
+ onlyVersionPrefix: {
113
+ type: "boolean",
114
+ description:
115
+ "Only use the version prefix for the ambient module exports. This is useful if, for whatever reason, you want to use different library versions of the same library in your project.",
116
+ default: defaults.onlyVersionPrefix,
117
+ normalize: true,
118
+ },
119
+ noPrettyPrint: {
120
+ type: "boolean",
121
+ description: "Do not prettify the generated types",
122
+ default: defaults.noPrettyPrint,
123
+ normalize: true,
124
+ },
125
+ noAdvancedVariants: {
126
+ type: "boolean",
127
+ description: "Disable GLib.Variant class with string parsing",
128
+ default: defaults.noAdvancedVariants,
129
+ normalize: true,
130
+ },
131
+ package: {
132
+ type: "boolean",
133
+ description: "Generate the typescript types with package.json support",
134
+ default: defaults.package,
135
+ normalize: true,
136
+ },
137
+ reporter: {
138
+ type: "boolean",
139
+ description: "Enable generation problem reporter and create a detailed report file",
140
+ default: defaults.reporter,
141
+ normalize: true,
142
+ },
143
+ reporterOutput: {
144
+ type: "string",
145
+ description: "Output file path for the reporter (default: ts-for-gir-report.json)",
146
+ default: defaults.reporterOutput,
147
+ normalize: true,
148
+ },
149
+ externalDeps: {
150
+ type: "boolean",
151
+ description:
152
+ "Emit imports from installed @girs/* npm packages instead of regenerating dep types. Implies single-file ambient .d.ts output. Designed for project-local Vala/C bridges. Strict by default — missing transitive dep GIRs abort the run; pass --allow-missing-deps to override.",
153
+ default: defaults.externalDeps,
154
+ normalize: true,
155
+ },
156
+ allowMissingDeps: {
157
+ type: "boolean",
158
+ description:
159
+ "In --external-deps mode, allow generation to proceed when app-specific transitive dep GIRs are missing (e.g. CI without libsoup3-devel). Note: GLib/Gio/GObject GIRs are still architecturally required for class-hierarchy resolution. Default strict behavior prevents silent type-quality drift between environments.",
160
+ default: defaults.allowMissingDeps,
161
+ normalize: true,
162
+ },
163
+ externalPackage: {
164
+ type: "string",
165
+ description:
166
+ "Override the default namespace→npm package mapping for --external-deps mode. Repeatable. Format: 'Namespace=@scope/pkg'. Example: --external-package Soup=@girs/soup-3.0",
167
+ array: true,
168
+ },
169
+ };
170
+
171
+ /**
172
+ * CLI flags used in commands/generate.ts
173
+ */
174
+ export const generateOptions = {
175
+ modules: options.modules,
176
+ girDirectories: options.girDirectories,
177
+ root: options.root,
178
+ outdir: options.outdir,
179
+ ignore: options.ignore,
180
+ verbose: options.verbose,
181
+ ignoreVersionConflicts: options.ignoreVersionConflicts,
182
+ print: options.print,
183
+ configName: options.configName,
184
+ noNamespace: options.noNamespace,
185
+ noComments: options.noComments,
186
+ promisify: options.promisify,
187
+ npmScope: options.npmScope,
188
+ workspace: options.workspace,
189
+ depVersionFormat: options.depVersionFormat,
190
+ onlyVersionPrefix: options.onlyVersionPrefix,
191
+ noPrettyPrint: options.noPrettyPrint,
192
+ noAdvancedVariants: options.noAdvancedVariants,
193
+ package: options.package,
194
+ reporter: options.reporter,
195
+ reporterOutput: options.reporterOutput,
196
+ externalDeps: options.externalDeps,
197
+ allowMissingDeps: options.allowMissingDeps,
198
+ externalPackage: options.externalPackage,
199
+ };
200
+
201
+ export const listOptions = {
202
+ modules: options.modules,
203
+ girDirectories: options.girDirectories,
204
+ root: options.root,
205
+ ignore: options.ignore,
206
+ configName: options.configName,
207
+ verbose: options.verbose,
208
+ };
209
+
210
+ export const copyOptions = {
211
+ modules: options.modules,
212
+ girDirectories: options.girDirectories,
213
+ root: options.root,
214
+ outdir: options.outdir,
215
+ ignore: options.ignore,
216
+ configName: options.configName,
217
+ verbose: options.verbose,
218
+ };
219
+
220
+ export const docOptions = {
221
+ ...generateOptions,
222
+ outdir: { ...options.outdir, default: defaults.docOutdir },
223
+ combined: {
224
+ type: "boolean" as const,
225
+ description:
226
+ "Generate a single unified documentation for all modules (use --no-combined for separate per-module docs)",
227
+ default: defaults.combined,
228
+ },
229
+ sourceLinkTemplate: {
230
+ type: "string" as const,
231
+ description:
232
+ "URL template for source links in generated documentation. Supports {path}, {line}, {gitRevision} placeholders. Example: https://github.com/user/repo/blob/main/{path}#L{line}",
233
+ },
234
+ theme: {
235
+ type: "string" as const,
236
+ description:
237
+ 'Theme for HTML documentation generation (default: "gi-docgen"). Use "default" for TypeDoc\'s built-in theme.',
238
+ default: defaults.theme,
239
+ },
240
+ readme: {
241
+ type: "string" as const,
242
+ description:
243
+ 'Path to a README file for the documentation index page. Use "none" to disable. If not set, TypeDoc auto-discovers README.md from packages.',
244
+ },
245
+ merge: {
246
+ type: "boolean" as const,
247
+ description: "Use TypeDoc merge mode to generate HTML from pre-generated JSON files (requires --jsonDir)",
248
+ default: false,
249
+ },
250
+ jsonDir: {
251
+ type: "string" as const,
252
+ description: "Directory containing pre-generated TypeDoc JSON files for merge mode (from 'ts-for-gir json')",
253
+ },
254
+ };
255
+
256
+ export const createOptions = {
257
+ template: {
258
+ type: "string" as const,
259
+ alias: "t",
260
+ description: "Template to scaffold (types-locally, types-npm, types-workspace)",
261
+ choices: ["types-locally", "types-npm", "types-workspace"] as const,
262
+ },
263
+ install: {
264
+ type: "boolean" as const,
265
+ description: "Run npm install after scaffolding (use --no-install to skip)",
266
+ default: true,
267
+ },
268
+ force: {
269
+ type: "boolean" as const,
270
+ description: "Allow scaffolding into a non-empty target directory",
271
+ default: false,
272
+ },
273
+ verbose: options.verbose,
274
+ };
275
+
276
+ export const analyzeOptions = {
277
+ reportFile: {
278
+ type: "string" as const,
279
+ alias: "f",
280
+ description: "Path to the report file to analyze",
281
+ demandOption: true,
282
+ normalize: true,
283
+ },
284
+ severity: {
285
+ type: "string" as const,
286
+ alias: "s",
287
+ description: "Filter by problem severity (debug, info, warning, error, critical)",
288
+ array: true,
289
+ choices: ["debug", "info", "warning", "error", "critical"],
290
+ },
291
+ category: {
292
+ type: "string" as const,
293
+ alias: "c",
294
+ description: "Filter by problem category",
295
+ array: true,
296
+ choices: [
297
+ "type_resolution",
298
+ "parsing_failure",
299
+ "generation_failure",
300
+ "type_conflict",
301
+ "dependency_issue",
302
+ "configuration",
303
+ "io_error",
304
+ "general",
305
+ ],
306
+ },
307
+ namespace: {
308
+ type: "string" as const,
309
+ alias: "n",
310
+ description: "Filter by namespace/module",
311
+ array: true,
312
+ },
313
+ type: {
314
+ type: "string" as const,
315
+ alias: "t",
316
+ description: "Filter by specific type name",
317
+ array: true,
318
+ },
319
+ top: {
320
+ type: "number" as const,
321
+ description: "Show top N most problematic items",
322
+ default: 10,
323
+ },
324
+ export: {
325
+ type: "string" as const,
326
+ alias: "e",
327
+ description: "Export filtered results to file",
328
+ normalize: true,
329
+ },
330
+ format: {
331
+ type: "string" as const,
332
+ description: "Output format (json, csv, table)",
333
+ choices: ["json", "csv", "table"],
334
+ default: "table",
335
+ },
336
+ detailed: {
337
+ type: "boolean" as const,
338
+ alias: "d",
339
+ description: "Show detailed problem information",
340
+ default: false,
341
+ },
342
+ summary: {
343
+ type: "boolean" as const,
344
+ description: "Show summary statistics only",
345
+ default: false,
346
+ },
347
+ search: {
348
+ type: "string" as const,
349
+ description: "Search for problems containing specific text",
350
+ },
351
+ since: {
352
+ type: "string" as const,
353
+ description: "Show problems from a specific time range (ISO date)",
354
+ },
355
+ until: {
356
+ type: "string" as const,
357
+ description: "Show problems until a specific time (ISO date)",
358
+ },
359
+ verbose: {
360
+ type: "boolean" as const,
361
+ alias: "v",
362
+ description: "Switch on/off the verbose mode",
363
+ default: false,
364
+ },
365
+ };