@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,223 @@
1
+ /**
2
+ * Everything you need for the `ts-for-gir create` command is located here
3
+ */
4
+
5
+ import { spawnSync } from "node:child_process";
6
+ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
7
+ import { dirname, join, resolve } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ import { input, select } from "@inquirer/prompts";
11
+ import { APP_NAME, type ConfigFlags, Logger } from "@ts-for-gir/lib";
12
+
13
+ import { createOptions } from "../config.ts";
14
+ import type { CreateCommandArgs, CreateTemplateId } from "../types/index.ts";
15
+ import { createBuilder } from "./command-builder.ts";
16
+
17
+ const command = "create [name]";
18
+
19
+ const description = "Scaffold a new GJS TypeScript project from a template";
20
+
21
+ const examples: ReadonlyArray<[string, string?]> = [
22
+ [`${APP_NAME} create my-app --template types-npm`, "Scaffold using the @girs/* NPM types"],
23
+ [`${APP_NAME} create my-app --template types-locally`, "Scaffold and generate types into ./@types/ locally"],
24
+ [
25
+ `${APP_NAME} create my-app --template types-workspace`,
26
+ "Scaffold an npm workspace with types as workspace packages",
27
+ ],
28
+ [`${APP_NAME} create`, "Interactive: prompts for name and template"],
29
+ ];
30
+
31
+ const TEMPLATE_CHOICES: ReadonlyArray<{ value: CreateTemplateId; name: string; description: string }> = [
32
+ {
33
+ value: "types-locally",
34
+ name: "types-locally",
35
+ description: "Generate GIR types directly into ./@types/ (no package format, no @girs/* deps)",
36
+ },
37
+ {
38
+ value: "types-npm",
39
+ name: "types-npm",
40
+ description: "Use pre-generated types from the @girs/* NPM packages",
41
+ },
42
+ {
43
+ value: "types-workspace",
44
+ name: "types-workspace",
45
+ description: "npm workspace; generate @girs/* as workspace packages under ./@girs/",
46
+ },
47
+ ];
48
+
49
+ const PROJECT_NAME_PLACEHOLDER = "__PROJECT_NAME__";
50
+
51
+ const TEXT_FILE_EXT = new Set([".json", ".md", ".ts", ".tsx", ".js", ".mjs", ".cjs"]);
52
+
53
+ const builder = createBuilder<CreateCommandArgs>(createOptions, examples);
54
+
55
+ function findTemplatesRoot(): string {
56
+ const __filename = fileURLToPath(import.meta.url);
57
+ const __dirname = dirname(__filename);
58
+ const candidates = [
59
+ // Bundled production binary (bin/ts-for-gir): ../dist-templates
60
+ resolve(__dirname, "..", "dist-templates"),
61
+ // Source layout (src/commands/create.ts): ../../dist-templates then ../../templates
62
+ resolve(__dirname, "..", "..", "dist-templates"),
63
+ resolve(__dirname, "..", "..", "templates"),
64
+ ];
65
+ for (const path of candidates) {
66
+ if (existsSync(path)) return path;
67
+ }
68
+ throw new Error(
69
+ `Could not locate templates directory. Looked in:\n ${candidates.join("\n ")}\n` +
70
+ "If you are running from source, make sure packages/cli/templates/ exists. " +
71
+ "If you are running the published CLI, make sure dist-templates/ was packed.",
72
+ );
73
+ }
74
+
75
+ function listTemplates(templatesRoot: string): CreateTemplateId[] {
76
+ const knownIds = TEMPLATE_CHOICES.map((c) => c.value) as readonly string[];
77
+ return readdirSync(templatesRoot, { withFileTypes: true })
78
+ .filter((entry) => entry.isDirectory())
79
+ .map((entry) => entry.name)
80
+ .filter((name): name is CreateTemplateId => knownIds.includes(name));
81
+ }
82
+
83
+ function sanitizeProjectName(raw: string): string {
84
+ const trimmed = raw.trim();
85
+ if (!trimmed) throw new Error("Project name cannot be empty");
86
+ // npm package name rules: lowercase letters, digits, dashes, underscores, dots; no leading dot/underscore
87
+ const cleaned = trimmed
88
+ .toLowerCase()
89
+ .replace(/[^a-z0-9._-]+/g, "-")
90
+ .replace(/^[._-]+/, "")
91
+ .replace(/[._-]+$/, "");
92
+ if (!cleaned) throw new Error(`"${raw}" is not a valid npm package name`);
93
+ return cleaned;
94
+ }
95
+
96
+ function isDirEmpty(path: string): boolean {
97
+ if (!existsSync(path)) return true;
98
+ return readdirSync(path).length === 0;
99
+ }
100
+
101
+ function substituteInFile(filePath: string, projectName: string): void {
102
+ const content = readFileSync(filePath, "utf8");
103
+ if (!content.includes(PROJECT_NAME_PLACEHOLDER)) return;
104
+ writeFileSync(filePath, content.replaceAll(PROJECT_NAME_PLACEHOLDER, projectName));
105
+ }
106
+
107
+ function walkAndSubstitute(rootDir: string, projectName: string): void {
108
+ for (const entry of readdirSync(rootDir, { withFileTypes: true })) {
109
+ const full = join(rootDir, entry.name);
110
+ if (entry.isDirectory()) {
111
+ if (entry.name === "node_modules") continue;
112
+ walkAndSubstitute(full, projectName);
113
+ continue;
114
+ }
115
+ if (!entry.isFile()) continue;
116
+ const ext = entry.name.slice(entry.name.lastIndexOf("."));
117
+ if (!TEXT_FILE_EXT.has(ext)) continue;
118
+ substituteInFile(full, projectName);
119
+ }
120
+ }
121
+
122
+ declare const __GJS_BUNDLE__: boolean | undefined;
123
+
124
+ const handler = async (args: ConfigFlags) => {
125
+ if (typeof __GJS_BUNDLE__ !== "undefined") {
126
+ process.stderr.write(
127
+ "The 'create' command is not yet supported in the GJS bundle.\nUse Node.js instead: npx @ts-for-gir/cli create ...\n",
128
+ );
129
+ process.exitCode = 1;
130
+ return;
131
+ }
132
+ const opts = args as unknown as CreateCommandArgs;
133
+ const log = new Logger(opts.verbose ?? false, "CreateCommand");
134
+
135
+ const templatesRoot = findTemplatesRoot();
136
+ const available = listTemplates(templatesRoot);
137
+ if (available.length === 0) {
138
+ throw new Error(`No templates found in ${templatesRoot}`);
139
+ }
140
+
141
+ let template: CreateTemplateId | undefined = opts.template;
142
+ if (template && !available.includes(template)) {
143
+ throw new Error(`Unknown template "${template}". Available: ${available.join(", ")}`);
144
+ }
145
+ if (!template) {
146
+ if (!process.stdin.isTTY) {
147
+ throw new Error(`--template is required (non-TTY). Available: ${available.join(", ")}`);
148
+ }
149
+ template = await select<CreateTemplateId>({
150
+ message: "Choose a template:",
151
+ choices: TEMPLATE_CHOICES.filter((c) => available.includes(c.value)).map((c) => ({
152
+ value: c.value,
153
+ name: c.name,
154
+ description: c.description,
155
+ })),
156
+ });
157
+ }
158
+
159
+ let nameRaw = opts.name;
160
+ if (!nameRaw) {
161
+ if (!process.stdin.isTTY) {
162
+ throw new Error("Project name is required (non-TTY). Pass it as the first positional argument.");
163
+ }
164
+ nameRaw = await input({
165
+ message: "Project name:",
166
+ default: "my-gjs-app",
167
+ validate: (v) => (v.trim().length > 0 ? true : "Project name cannot be empty"),
168
+ });
169
+ }
170
+ const projectName = sanitizeProjectName(nameRaw);
171
+
172
+ const targetDir = resolve(process.cwd(), projectName);
173
+ if (existsSync(targetDir) && !isDirEmpty(targetDir) && !opts.force) {
174
+ throw new Error(
175
+ `Target directory ${targetDir} exists and is not empty. Use --force to scaffold into a non-empty directory.`,
176
+ );
177
+ }
178
+ mkdirSync(targetDir, { recursive: true });
179
+
180
+ const templateDir = join(templatesRoot, template);
181
+ cpSync(templateDir, targetDir, { recursive: true });
182
+ walkAndSubstitute(targetDir, projectName);
183
+
184
+ log.success(`Scaffolded ${template} into ${targetDir}`);
185
+
186
+ if (opts.install) {
187
+ log.info("Running npm install...");
188
+ const result = spawnSync("npm", ["install", "--no-audit", "--no-fund"], {
189
+ cwd: targetDir,
190
+ stdio: "inherit",
191
+ });
192
+ if (result.status !== 0) {
193
+ log.warn("npm install failed; you can re-run it manually in the project directory.");
194
+ }
195
+ }
196
+
197
+ log.info("\nNext steps:");
198
+ log.white(` cd ${projectName}`);
199
+ if (!opts.install) log.white(" npm install");
200
+ switch (template) {
201
+ case "types-locally":
202
+ log.white(" npm run generate");
203
+ log.white(" npm run check:types");
204
+ log.white(" npm run build && npm start");
205
+ break;
206
+ case "types-npm":
207
+ log.white(" npm run check");
208
+ log.white(" npm run build && npm start");
209
+ break;
210
+ case "types-workspace":
211
+ log.white(" npm run build:types && npm install");
212
+ log.white(" npm run build:app && npm start");
213
+ break;
214
+ }
215
+ };
216
+
217
+ export const create = {
218
+ command,
219
+ description,
220
+ builder,
221
+ handler,
222
+ examples,
223
+ };
@@ -1,58 +1,55 @@
1
1
  /**
2
- * Everything you need for the `ts-for-gir generate` command is located here
2
+ * Everything you need for the `ts-for-gir doc` command is located here
3
3
  */
4
4
 
5
- import { Argv, BuilderCallback } from 'yargs'
6
- import { Logger, ERROR_NO_MODULES_FOUND } from '@ts-for-gir/lib'
7
- import { GeneratorType } from '@ts-for-gir/generator-base'
8
- import { GenerationHandler } from '../generation-handler.js'
9
- import { Config } from '../config.js'
10
- import { ModuleLoader } from '../module-loader.js'
5
+ import { GeneratorType } from "@ts-for-gir/generator-base";
6
+ import { HtmlDocGenerator } from "@ts-for-gir/generator-html-doc";
7
+ import { APP_NAME, type ConfigFlags, NSRegistry } from "@ts-for-gir/lib";
8
+ import { docOptions, getOptionsGeneration, load } from "../config.ts";
9
+ import { TypeScriptFormatter } from "../formatters/typescript-formatter.ts";
10
+ import type { DocCommandArgs } from "../types/index.ts";
11
+ import { createBuilder } from "./command-builder.ts";
12
+ import { runGenerationCommand } from "./run-generation-command.ts";
11
13
 
12
- import type { ConfigFlags } from '@ts-for-gir/lib'
14
+ const command = "doc [modules..]";
13
15
 
14
- const command = 'doc [modules..]'
16
+ const description = "Generates HTML documentation from GIR files using TypeDoc";
15
17
 
16
- const description = 'The HTML documentation generator is not yet implemented, but feel free to implement it 🤗'
18
+ const examples: ReadonlyArray<[string, string?]> = [
19
+ [`${APP_NAME} doc Gtk-4.0 --outdir ./docs`, "Generate HTML documentation for Gtk-4.0"],
20
+ [`${APP_NAME} doc '*' --outdir ./docs`, "Generate documentation for all locally installed GIR modules"],
21
+ [
22
+ `${APP_NAME} doc --merge --jsonDir ./json-output --outdir ./docs`,
23
+ "Generate HTML from pre-generated JSON files (low memory)",
24
+ ],
25
+ ];
17
26
 
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- const builder: BuilderCallback<any, ConfigFlags> = (yargs: Argv<any>) => {
20
- const optionNames = Object.keys(Config.docOptions)
21
- for (const optionName of optionNames) {
22
- yargs = yargs.option(optionName, Config.docOptions[optionName])
23
- }
24
- return yargs.example(examples) as Argv<ConfigFlags>
25
- }
27
+ const builder = createBuilder<DocCommandArgs>(docOptions, examples);
26
28
 
27
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
29
  const handler = async (args: ConfigFlags) => {
29
- const config = await Config.load(args)
30
-
31
- const generateConfig = Config.getOptionsGeneration(config)
32
- const moduleLoader = new ModuleLoader(generateConfig)
33
- const { keep } = await moduleLoader.getModulesResolved(
34
- config.modules,
35
- config.ignore || [],
36
- config.ignoreVersionConflicts,
37
- )
38
- if (keep.length === 0) {
39
- return Logger.error(ERROR_NO_MODULES_FOUND(config.girDirectories))
40
- }
41
- const tsForGir = new GenerationHandler(generateConfig, GeneratorType.HTML_DOC)
42
- const registry = moduleLoader.dependencyManager
43
-
44
- await tsForGir.start(
45
- Array.from(keep).map((girModuleResolvedBy) => girModuleResolvedBy.module),
46
- registry,
47
- )
48
- }
49
-
50
- const examples: ReadonlyArray<[string, string?]> = []
30
+ const config = getOptionsGeneration(await load(args));
31
+ if (config.merge) {
32
+ if (!config.jsonDir) {
33
+ throw new Error("--jsonDir is required when using --merge mode");
34
+ }
35
+ const generator = new HtmlDocGenerator(config, new NSRegistry());
36
+ await generator.generateFromJson(config.jsonDir);
37
+ return;
38
+ }
39
+
40
+ await runGenerationCommand(args, {
41
+ generatorType: GeneratorType.HTML_DOC,
42
+ loggerName: "DocCommand",
43
+ configureRegistry: (registry) => {
44
+ registry.registerFormatter("dts", new TypeScriptFormatter());
45
+ },
46
+ });
47
+ };
51
48
 
52
49
  export const doc = {
53
- command,
54
- description,
55
- builder,
56
- handler,
57
- examples,
58
- }
50
+ command,
51
+ description,
52
+ builder,
53
+ handler,
54
+ examples,
55
+ };
@@ -2,89 +2,45 @@
2
2
  * Everything you need for the `ts-for-gir generate` command is located here
3
3
  */
4
4
 
5
- import { Argv, BuilderCallback } from 'yargs'
6
- import { ERROR_NO_MODULES_FOUND, Logger } from '@ts-for-gir/lib'
7
- import { GeneratorType } from '@ts-for-gir/generator-base'
8
- import { GenerationHandler } from '../generation-handler.js'
9
- import { Config } from '../config.js'
10
- import { ModuleLoader } from '../module-loader.js'
11
- import prettier from 'prettier'
5
+ import { GeneratorType } from "@ts-for-gir/generator-base";
6
+ import { APP_NAME, type ConfigFlags } from "@ts-for-gir/lib";
7
+ import { generateOptions } from "../config.ts";
8
+ import { TypeScriptFormatter } from "../formatters/typescript-formatter.ts";
9
+ import type { GenerateCommandArgs } from "../types/index.ts";
10
+ import { createBuilder } from "./command-builder.ts";
11
+ import { runGenerationCommand } from "./run-generation-command.ts";
12
12
 
13
- import type { ConfigFlags } from '@ts-for-gir/lib'
14
- import { Formatter } from '@ts-for-gir/lib'
13
+ const command = "generate [modules..]";
15
14
 
16
- const command = 'generate [modules..]'
17
-
18
- const description = 'Generates Typescript type definition .d.ts files from GIR for GJS'
19
-
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- const builder: BuilderCallback<any, ConfigFlags> = (yargs: Argv<any>) => {
22
- const optionNames = Object.keys(Config.generateOptions)
23
- for (const optionName of optionNames) {
24
- yargs = yargs.option(optionName, Config.generateOptions[optionName])
25
- }
26
- return yargs.example(examples) as Argv<ConfigFlags>
27
- }
28
-
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- const handler = async (args: ConfigFlags) => {
31
- const config = await Config.load(args)
32
-
33
- const generateConfig = Config.getOptionsGeneration(config)
34
- const moduleLoader = new ModuleLoader(generateConfig)
35
- const { keep } = await moduleLoader.getModulesResolved(
36
- config.modules,
37
- config.ignore || [],
38
- config.ignoreVersionConflicts,
39
- )
40
-
41
- if (keep.length === 0) {
42
- return Logger.error(ERROR_NO_MODULES_FOUND(config.girDirectories))
43
- }
44
-
45
- moduleLoader.parse(keep)
46
-
47
- const tsForGir = new GenerationHandler(generateConfig, GeneratorType.TYPES)
48
-
49
- const girModules = Array.from(keep).map((girModuleResolvedBy) => girModuleResolvedBy.module)
50
-
51
- moduleLoader.dependencyManager.registerFormatter('dts', new TypeScriptFormatter())
52
- await tsForGir.start(girModules, moduleLoader.dependencyManager)
53
- }
15
+ const description = "Generates Typescript type definition .d.ts files from GIR for GJS";
54
16
 
55
17
  const examples: ReadonlyArray<[string, string?]> = [
56
- [
57
- `${Config.appName} generate`,
58
- `Run '${Config.appName} generate' in your gjs project to generate typings for your project, pass the gir modules you need for your project`,
59
- ],
60
- [`${Config.appName} generate Gtk*`, 'You can also use wild cards'],
61
- [`${Config.appName} generate '*'`, 'If you want to parse all of your locally installed gir modules run'],
62
- [`${Config.appName} generate --configName='.ts-for-gir.gtk4.rc.js`, 'Use a special config file'],
63
- [
64
- `${Config.appName} generate --ignore=Gtk-4.0 xrandr-1.3`,
65
- 'Generate .d.ts. files but not for Gtk-4.0 and xrandr-1.3',
66
- ],
67
- ]
18
+ [
19
+ `${APP_NAME} generate`,
20
+ `Run '${APP_NAME} generate' in your gjs project to generate typings for your project, pass the gir modules you need for your project`,
21
+ ],
22
+ [`${APP_NAME} generate 'Gtk*'`, "You can also use wild cards"],
23
+ [`${APP_NAME} generate '*'`, "If you want to parse all of your locally installed gir modules run"],
24
+ [`${APP_NAME} generate --configName='.ts-for-gir.gtk4.rc.js`, "Use a special config file"],
25
+ [`${APP_NAME} generate --ignore=Gtk-4.0 xrandr-1.3`, "Generate .d.ts. files but not for Gtk-4.0 and xrandr-1.3"],
26
+ ];
27
+
28
+ const builder = createBuilder<GenerateCommandArgs>(generateOptions, examples);
68
29
 
69
- class TypeScriptFormatter extends Formatter {
70
- format(input: string): Promise<string> {
71
- try {
72
- return prettier.format(input, {
73
- singleQuote: true,
74
- parser: 'typescript',
75
- printWidth: 120,
76
- tabWidth: 4,
77
- })
78
- } catch (error) {
79
- return Promise.resolve(input)
80
- }
81
- }
82
- }
30
+ const handler = async (args: ConfigFlags) => {
31
+ await runGenerationCommand(args, {
32
+ generatorType: GeneratorType.TYPES,
33
+ loggerName: "GenerateCommand",
34
+ configureRegistry: (registry) => {
35
+ registry.registerFormatter("dts", new TypeScriptFormatter());
36
+ },
37
+ });
38
+ };
83
39
 
84
40
  export const generate = {
85
- command,
86
- description,
87
- builder,
88
- handler,
89
- examples,
90
- }
41
+ command,
42
+ description,
43
+ builder,
44
+ handler,
45
+ examples,
46
+ };
@@ -1,4 +1,8 @@
1
- export * from './copy.js'
2
- export * from './doc.js'
3
- export * from './generate.js'
4
- export * from './list.js'
1
+ export * from "./analyze.ts";
2
+ export * from "./copy.ts";
3
+ export * from "./create.ts";
4
+ export * from "./doc.ts";
5
+ export * from "./generate.ts";
6
+ export * from "./json.ts";
7
+ export * from "./list.ts";
8
+ export * from "./self-update.ts";
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Everything you need for the `ts-for-gir json` command is located here
3
+ */
4
+
5
+ import { GeneratorType } from "@ts-for-gir/generator-base";
6
+ import { APP_NAME, type ConfigFlags } from "@ts-for-gir/lib";
7
+ import { generateOptions } from "../config.ts";
8
+ import { TypeScriptFormatter } from "../formatters/typescript-formatter.ts";
9
+ import type { GenerateCommandArgs } from "../types/index.ts";
10
+ import { createBuilder } from "./command-builder.ts";
11
+ import { runGenerationCommand } from "./run-generation-command.ts";
12
+
13
+ const command = "json [modules..]";
14
+
15
+ const description = "Generates JSON representation from GIR files for analysis and tooling";
16
+
17
+ const examples: ReadonlyArray<[string, string?]> = [
18
+ [`${APP_NAME} json`, `Run '${APP_NAME} json' in your gjs project to generate JSON files for your project`],
19
+ [`${APP_NAME} json 'Gtk*'`, "You can also use wild cards"],
20
+ [`${APP_NAME} json '*'`, "If you want to parse all of your locally installed gir modules run"],
21
+ [`${APP_NAME} json --configName='.ts-for-gir.gtk4.rc.js`, "Use a special config file"],
22
+ [`${APP_NAME} json --ignore=Gtk-4.0 xrandr-1.3`, "Generate JSON files but not for Gtk-4.0 and xrandr-1.3"],
23
+ ];
24
+
25
+ const builder = createBuilder<GenerateCommandArgs>(generateOptions, examples);
26
+
27
+ const handler = async (args: ConfigFlags) => {
28
+ await runGenerationCommand(args, {
29
+ generatorType: GeneratorType.JSON,
30
+ loggerName: "JsonCommand",
31
+ configureRegistry: (registry) => {
32
+ registry.registerFormatter("dts", new TypeScriptFormatter());
33
+ },
34
+ });
35
+ };
36
+
37
+ export const json = {
38
+ command,
39
+ description,
40
+ builder,
41
+ handler,
42
+ examples,
43
+ };