@ts-for-gir/cli 4.0.0-beta.9 → 4.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +295 -84
- package/bin/ts-for-gir +26644 -0
- package/bin/ts-for-gir-dev +43 -0
- package/package.json +39 -38
- package/src/commands/analyze.ts +344 -0
- package/src/commands/command-builder.ts +30 -0
- package/src/commands/copy.ts +71 -76
- package/src/commands/doc.ts +44 -47
- package/src/commands/generate.ts +35 -79
- package/src/commands/index.ts +6 -4
- package/src/commands/json.ts +43 -0
- package/src/commands/list.ts +71 -90
- package/src/commands/run-generation-command.ts +70 -0
- package/src/config/config-loader.ts +190 -0
- package/src/config/config-writer.ts +52 -0
- package/src/config/defaults.ts +66 -0
- package/src/config/index.ts +8 -0
- package/src/config/options.ts +315 -0
- package/src/config.ts +3 -456
- package/src/formatters/typescript-formatter.ts +24 -0
- package/src/generation-handler.ts +122 -67
- package/src/index.ts +4 -4
- package/src/module-loader/dependency-resolver.ts +100 -0
- package/src/module-loader/file-finder.ts +65 -0
- package/src/module-loader/index.ts +8 -0
- package/src/module-loader/module-grouper.ts +77 -0
- package/src/module-loader/prompt-handler.ts +111 -0
- package/src/module-loader.ts +289 -578
- package/src/start.ts +17 -14
- package/src/types/command-args.ts +118 -0
- package/src/types/command-definition.ts +17 -0
- package/src/types/commands.ts +30 -0
- package/src/types/index.ts +15 -0
- package/src/types/report-types.ts +34 -0
- package/lib/commands/copy.d.ts +0 -12
- package/lib/commands/copy.js +0 -80
- package/lib/commands/copy.js.map +0 -1
- package/lib/commands/doc.d.ts +0 -12
- package/lib/commands/doc.js +0 -40
- package/lib/commands/doc.js.map +0 -1
- package/lib/commands/generate.d.ts +0 -12
- package/lib/commands/generate.js +0 -71
- package/lib/commands/generate.js.map +0 -1
- package/lib/commands/index.d.ts +0 -4
- package/lib/commands/index.js +0 -5
- package/lib/commands/index.js.map +0 -1
- package/lib/commands/list.d.ts +0 -12
- package/lib/commands/list.js +0 -81
- package/lib/commands/list.js.map +0 -1
- package/lib/config.d.ts +0 -108
- package/lib/config.js +0 -410
- package/lib/config.js.map +0 -1
- package/lib/generation-handler.d.ts +0 -10
- package/lib/generation-handler.js +0 -48
- package/lib/generation-handler.js.map +0 -1
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -5
- package/lib/index.js.map +0 -1
- package/lib/module-loader.d.ts +0 -148
- package/lib/module-loader.js +0 -468
- package/lib/module-loader.js.map +0 -1
- package/lib/start.d.ts +0 -2
- package/lib/start.js +0 -16
- package/lib/start.js.map +0 -1
package/src/commands/copy.ts
CHANGED
|
@@ -2,93 +2,88 @@
|
|
|
2
2
|
* Everything you need for the `ts-for-gir copy` command is located here
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
5
|
+
import { copyFile, mkdir } from "node:fs/promises";
|
|
6
|
+
import { basename, join } from "node:path";
|
|
7
|
+
import type { ConfigFlags, GirModuleResolvedBy, UserConfig } from "@ts-for-gir/lib";
|
|
8
|
+
import { APP_NAME, ERROR_NO_MODULES_FOUND, Logger, NSRegistry } from "@ts-for-gir/lib";
|
|
9
|
+
import { copyOptions, getOptionsGeneration, load } from "../config.ts";
|
|
10
|
+
import { ModuleLoader } from "../module-loader.ts";
|
|
11
|
+
import type { CopyCommandArgs } from "../types/index.ts";
|
|
12
|
+
import { createBuilder } from "./command-builder.ts";
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
const command = "copy [modules..]";
|
|
13
15
|
|
|
14
|
-
const
|
|
16
|
+
const description = "Scan for *.gir files and copy them to a new directory";
|
|
15
17
|
|
|
16
|
-
const
|
|
18
|
+
const logger = new Logger(true, "CopyCommand");
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const examples: ReadonlyArray<[string, string?]> = [
|
|
21
|
+
[`${APP_NAME} copy -o ./gir`, "Copy found *.gir files to ./gir"],
|
|
22
|
+
[
|
|
23
|
+
`${APP_NAME} copy -g /usr/share/gir-1.0 --ignore=Gtk-3.0 xrandr-1.3 -o ./gir`,
|
|
24
|
+
"Copy all found *.gir files in /usr/share/gir-1.0 excluding Gtk-3.0 and xrandr-1.3 to ./gir",
|
|
25
|
+
],
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const builder = createBuilder<CopyCommandArgs>(copyOptions, examples);
|
|
26
29
|
|
|
27
30
|
const copyGirFile = async (config: UserConfig, depModule: GirModuleResolvedBy) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
31
|
+
if (!depModule.path) {
|
|
32
|
+
logger.danger(`- ${depModule.packageName} not found`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!config.outdir) {
|
|
36
|
+
logger.error("outdir not found");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const filename = basename(depModule.path);
|
|
40
|
+
const dest = join(config.outdir, filename);
|
|
41
|
+
if (depModule.path === dest) {
|
|
42
|
+
logger.yellow(`Skip ${depModule.path}`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
logger.success(`Copy ${depModule.path}`);
|
|
46
|
+
await copyFile(depModule.path, dest);
|
|
47
|
+
};
|
|
45
48
|
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
49
|
const handler = async (args: ConfigFlags) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
const config = await load(args);
|
|
51
|
+
const generateConfig = getOptionsGeneration(config);
|
|
52
|
+
const registry = new NSRegistry();
|
|
53
|
+
const moduleLoader = new ModuleLoader(generateConfig, registry);
|
|
54
|
+
const { grouped, failed } = await moduleLoader.getModules(config.modules, config.ignore);
|
|
55
|
+
const moduleGroups = Object.values(grouped);
|
|
56
|
+
if (Object.keys(grouped).length === 0) {
|
|
57
|
+
return logger.error(ERROR_NO_MODULES_FOUND(config.girDirectories));
|
|
58
|
+
}
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
if (!config.outdir) {
|
|
61
|
+
logger.error("outdir not found");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
await mkdir(config.outdir, { recursive: true }).catch((err) => {
|
|
66
|
+
logger.error(`Failed to copy gir files to ${config.outdir}: ${err}`);
|
|
67
|
+
});
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
for (const module of moduleGroups) {
|
|
70
|
+
for (const mod of module.modules) {
|
|
71
|
+
await copyGirFile(config, mod);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const examples: ReadonlyArray<[string, string?]> = [
|
|
81
|
-
[`${Config.appName} copy -o ./gir`, `Copy found *.gir files to ./gir`],
|
|
82
|
-
[
|
|
83
|
-
`${Config.appName} copy -g /usr/share/gir-1.0 --ignore=Gtk-3.0 xrandr-1.3 -o ./gir`,
|
|
84
|
-
'Copy all found *.gir files in /usr/share/gir-1.0 excluding Gtk-3.0 and xrandr-1.3 to ./gir',
|
|
85
|
-
],
|
|
86
|
-
]
|
|
75
|
+
if (failed.length > 0) {
|
|
76
|
+
logger.danger("\nDependencies not found:");
|
|
77
|
+
for (const fail of failed) {
|
|
78
|
+
logger.white(`- ${fail}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
87
82
|
|
|
88
83
|
export const copy = {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
84
|
+
command,
|
|
85
|
+
description,
|
|
86
|
+
builder,
|
|
87
|
+
handler,
|
|
88
|
+
examples,
|
|
89
|
+
};
|
package/src/commands/doc.ts
CHANGED
|
@@ -1,58 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Everything you need for the `ts-for-gir
|
|
2
|
+
* Everything you need for the `ts-for-gir doc` command is located here
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
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
|
-
|
|
14
|
+
const command = "doc [modules..]";
|
|
13
15
|
|
|
14
|
-
const
|
|
16
|
+
const description = "Generates HTML documentation from GIR files using TypeDoc";
|
|
15
17
|
|
|
16
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
50
|
+
command,
|
|
51
|
+
description,
|
|
52
|
+
builder,
|
|
53
|
+
handler,
|
|
54
|
+
examples,
|
|
55
|
+
};
|
package/src/commands/generate.ts
CHANGED
|
@@ -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 {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
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
|
-
|
|
14
|
-
import { Formatter } from '@ts-for-gir/lib'
|
|
13
|
+
const command = "generate [modules..]";
|
|
15
14
|
|
|
16
|
-
const
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
41
|
+
command,
|
|
42
|
+
description,
|
|
43
|
+
builder,
|
|
44
|
+
handler,
|
|
45
|
+
examples,
|
|
46
|
+
};
|
package/src/commands/index.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./analyze.ts";
|
|
2
|
+
export * from "./copy.ts";
|
|
3
|
+
export * from "./doc.ts";
|
|
4
|
+
export * from "./generate.ts";
|
|
5
|
+
export * from "./json.ts";
|
|
6
|
+
export * from "./list.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
|
+
};
|
package/src/commands/list.ts
CHANGED
|
@@ -2,101 +2,82 @@
|
|
|
2
2
|
* Everything you need for the `ts-for-gir list` command is located here
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import type { ConfigFlags } from "@ts-for-gir/lib";
|
|
6
|
+
import { APP_NAME, ERROR_NO_MODULES_FOUND, Logger, NSRegistry } from "@ts-for-gir/lib";
|
|
7
|
+
import { getOptionsGeneration, listOptions, load } from "../config.ts";
|
|
8
|
+
import { ModuleLoader } from "../module-loader.ts";
|
|
9
|
+
import type { ListCommandArgs } from "../types/index.ts";
|
|
10
|
+
import { createBuilder } from "./command-builder.ts";
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
const command = "list [modules..]";
|
|
11
13
|
|
|
12
|
-
const
|
|
14
|
+
const description = "Lists all available GIR modules";
|
|
13
15
|
|
|
14
|
-
const
|
|
16
|
+
const logger = new Logger(true, "ListCommand");
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
const handler = async (args: ConfigFlags) => {
|
|
27
|
-
const config = await Config.load(args)
|
|
28
|
-
const generateConfig = Config.getOptionsGeneration(config)
|
|
29
|
-
const moduleLoader = new ModuleLoader(generateConfig)
|
|
30
|
-
const { grouped, failed } = await moduleLoader.getModules(config.modules, config.ignore)
|
|
31
|
-
const moduleGroups = Object.values(grouped)
|
|
32
|
-
if (Object.keys(grouped).length === 0) {
|
|
33
|
-
return Logger.error(ERROR_NO_MODULES_FOUND(config.girDirectories))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const conflictModules = moduleGroups.filter((moduleGroup) => moduleGroup.hasConflict)
|
|
37
|
-
|
|
38
|
-
const byHandModules = moduleGroups.filter(
|
|
39
|
-
(moduleGroup) => moduleGroup.modules[0].resolvedBy === ResolveType.BY_HAND,
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
const depModules = moduleGroups.filter(
|
|
43
|
-
(moduleGroup) => moduleGroup.modules[0].resolvedBy === ResolveType.DEPENDENCE,
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
Logger.info('\nSearch for gir files in:')
|
|
47
|
-
for (const dir of config.girDirectories) {
|
|
48
|
-
Logger.white(`- ${dir}`)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
Logger.info('\nSelected Modules:')
|
|
52
|
-
for (const moduleGroup of byHandModules) {
|
|
53
|
-
for (const depModule of moduleGroup.modules) {
|
|
54
|
-
Logger.white(`- ${depModule.packageName}`)
|
|
55
|
-
Logger.gray(` - ${depModule.path}`)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (depModules.length > 0) {
|
|
60
|
-
Logger.yellow('\nDependencies:')
|
|
61
|
-
for (const moduleGroup of depModules) {
|
|
62
|
-
for (const depModule of moduleGroup.modules) {
|
|
63
|
-
Logger.white(`- ${depModule.packageName}`)
|
|
64
|
-
Logger.gray(`- ${depModule.path}`)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (conflictModules.length > 0) {
|
|
70
|
-
Logger.danger('\nConflicts:')
|
|
71
|
-
for (const moduleGroup of conflictModules) {
|
|
72
|
-
Logger.white(`- ${moduleGroup.namespace}`)
|
|
73
|
-
for (const conflictModule of moduleGroup.modules) {
|
|
74
|
-
Logger.white(` - ${conflictModule.packageName}`)
|
|
75
|
-
Logger.gray(` - ${conflictModule.path}`)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
18
|
+
const examples: ReadonlyArray<[string, string?]> = [
|
|
19
|
+
[`${APP_NAME} list -g ./vala-girs/gir-1.0`, "Lists all available GIR modules in ./vala-girs/gir-1.0"],
|
|
20
|
+
[
|
|
21
|
+
`${APP_NAME} list --ignore=Gtk-3.0 xrandr-1.3`,
|
|
22
|
+
"Lists all available GIR modules in /usr/share/gir-1.0 but not Gtk-3.0 and xrandr-1.3",
|
|
23
|
+
],
|
|
24
|
+
];
|
|
79
25
|
|
|
80
|
-
|
|
81
|
-
Logger.danger('\nDependencies not found:')
|
|
82
|
-
for (const fail of failed) {
|
|
83
|
-
Logger.white(`- ${fail}`)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
26
|
+
const builder = createBuilder<ListCommandArgs>(listOptions, examples);
|
|
87
27
|
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
28
|
+
const handler = async (args: ConfigFlags) => {
|
|
29
|
+
const config = await load(args);
|
|
30
|
+
const generateConfig = getOptionsGeneration(config);
|
|
31
|
+
const registry = new NSRegistry();
|
|
32
|
+
const moduleLoader = new ModuleLoader(generateConfig, registry);
|
|
33
|
+
const { grouped, failed } = await moduleLoader.getModules(config.modules, config.ignore);
|
|
34
|
+
const moduleGroups = Object.values(grouped);
|
|
35
|
+
|
|
36
|
+
if (Object.keys(grouped).length === 0) {
|
|
37
|
+
return logger.error(ERROR_NO_MODULES_FOUND(config.girDirectories));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const conflictModules = moduleGroups.filter((moduleGroup) => moduleGroup.hasConflict);
|
|
41
|
+
const allModules = moduleGroups.filter((moduleGroup) => !moduleGroup.hasConflict);
|
|
42
|
+
|
|
43
|
+
logger.info("\nSearch for gir files in:");
|
|
44
|
+
for (const dir of config.girDirectories) {
|
|
45
|
+
logger.white(`- ${dir}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Show all available modules
|
|
49
|
+
logger.info("\nAvailable Modules:");
|
|
50
|
+
for (const moduleGroup of allModules) {
|
|
51
|
+
for (const module of moduleGroup.modules) {
|
|
52
|
+
logger.white(`- ${module.packageName}`);
|
|
53
|
+
logger.gray(` - ${module.path}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Only show sections if there is actual content
|
|
58
|
+
if (conflictModules.length > 0) {
|
|
59
|
+
logger.danger("\nConflicts:");
|
|
60
|
+
for (const moduleGroup of conflictModules) {
|
|
61
|
+
logger.white(`- ${moduleGroup.namespace}`);
|
|
62
|
+
for (const conflictModule of moduleGroup.modules) {
|
|
63
|
+
logger.white(` - ${conflictModule.packageName}`);
|
|
64
|
+
logger.gray(` - ${conflictModule.path}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (failed.length > 0) {
|
|
70
|
+
logger.danger("\nDependencies not found:");
|
|
71
|
+
for (const fail of failed) {
|
|
72
|
+
logger.white(`- ${fail}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
95
76
|
|
|
96
77
|
export const list = {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
78
|
+
command,
|
|
79
|
+
description,
|
|
80
|
+
builder,
|
|
81
|
+
handler,
|
|
82
|
+
examples,
|
|
83
|
+
};
|