@ts-for-gir/cli 4.0.0-rc.13 → 4.0.0-rc.14
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/bin/ts-for-gir +40 -16
- package/bin/ts-for-gir-gjs +9789 -15011
- package/dist-templates/types-locally/package.json +1 -1
- package/dist-templates/types-npm/package.json +5 -5
- package/dist-templates/types-workspace/package.json +1 -1
- package/package.json +24 -13
- package/src/commands/create.ts +53 -11
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"typescript": "^6.0.2"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@girs/adw-1": "^1.10.0-4.0.0-rc.
|
|
18
|
-
"@girs/gio-2.0": "^2.88.0-4.0.0-rc.
|
|
19
|
-
"@girs/gjs": "^4.0.0-rc.
|
|
20
|
-
"@girs/glib-2.0": "^2.88.0-4.0.0-rc.
|
|
21
|
-
"@girs/gtk-4.0": "^4.23.0-4.0.0-rc.
|
|
17
|
+
"@girs/adw-1": "^1.10.0-4.0.0-rc.13",
|
|
18
|
+
"@girs/gio-2.0": "^2.88.0-4.0.0-rc.13",
|
|
19
|
+
"@girs/gjs": "^4.0.0-rc.13",
|
|
20
|
+
"@girs/glib-2.0": "^2.88.0-4.0.0-rc.13",
|
|
21
|
+
"@girs/gtk-4.0": "^4.23.0-4.0.0-rc.13"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-for-gir/cli",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.14",
|
|
4
4
|
"description": "TypeScript type definition generator for GObject introspection GIR files",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"module": "src/index.ts",
|
|
@@ -17,8 +17,19 @@
|
|
|
17
17
|
},
|
|
18
18
|
"shebang": true,
|
|
19
19
|
"bundler": {
|
|
20
|
+
"input": "src/start.ts",
|
|
20
21
|
"output": {
|
|
21
22
|
"file": "bin/ts-for-gir-gjs"
|
|
23
|
+
},
|
|
24
|
+
"transform": {
|
|
25
|
+
"define": {
|
|
26
|
+
"__GJS_BUNDLE__": "true"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"defineFromPackageJson": {
|
|
31
|
+
"__TS_FOR_GIR_VERSION__": {
|
|
32
|
+
"field": "version"
|
|
22
33
|
}
|
|
23
34
|
},
|
|
24
35
|
"excludeGlobals": [
|
|
@@ -33,7 +44,7 @@
|
|
|
33
44
|
"start": "node bin/ts-for-gir-dev",
|
|
34
45
|
"start:prod": "node bin/ts-for-gir",
|
|
35
46
|
"build": "node --experimental-specifier-resolution=node --experimental-strip-types --experimental-transform-types --no-warnings esbuild.ts && chmod +x bin/ts-for-gir-dev && chmod +x bin/ts-for-gir",
|
|
36
|
-
"build:gjs": "
|
|
47
|
+
"build:gjs": "gjsify build",
|
|
37
48
|
"build:templates": "node scripts/process-templates.mjs",
|
|
38
49
|
"prepack": "node scripts/process-templates.mjs",
|
|
39
50
|
"check:types": "tsc --noEmit",
|
|
@@ -72,18 +83,18 @@
|
|
|
72
83
|
".": "./src/index.ts"
|
|
73
84
|
},
|
|
74
85
|
"devDependencies": {
|
|
75
|
-
"@gi.ts/parser": "^4.0.0-rc.
|
|
76
|
-
"@gjsify/cli": "^0.3.
|
|
77
|
-
"@ts-for-gir/generator-base": "^4.0.0-rc.
|
|
78
|
-
"@ts-for-gir/generator-html-doc": "^4.0.0-rc.
|
|
79
|
-
"@ts-for-gir/generator-json": "^4.0.0-rc.
|
|
80
|
-
"@ts-for-gir/generator-typescript": "^4.0.0-rc.
|
|
81
|
-
"@ts-for-gir/lib": "^4.0.0-rc.
|
|
82
|
-
"@ts-for-gir/reporter": "^4.0.0-rc.
|
|
83
|
-
"@ts-for-gir/tsconfig": "^4.0.0-rc.
|
|
86
|
+
"@gi.ts/parser": "^4.0.0-rc.14",
|
|
87
|
+
"@gjsify/cli": "^0.3.16",
|
|
88
|
+
"@ts-for-gir/generator-base": "^4.0.0-rc.14",
|
|
89
|
+
"@ts-for-gir/generator-html-doc": "^4.0.0-rc.14",
|
|
90
|
+
"@ts-for-gir/generator-json": "^4.0.0-rc.14",
|
|
91
|
+
"@ts-for-gir/generator-typescript": "^4.0.0-rc.14",
|
|
92
|
+
"@ts-for-gir/lib": "^4.0.0-rc.14",
|
|
93
|
+
"@ts-for-gir/reporter": "^4.0.0-rc.14",
|
|
94
|
+
"@ts-for-gir/tsconfig": "^4.0.0-rc.14",
|
|
84
95
|
"@types/ejs": "^3.1.5",
|
|
85
96
|
"@types/inquirer": "^9.0.9",
|
|
86
|
-
"@types/node": "^25.6.
|
|
97
|
+
"@types/node": "^25.6.2",
|
|
87
98
|
"@types/yargs": "^17.0.35",
|
|
88
99
|
"esbuild": "^0.28.0",
|
|
89
100
|
"source-map-support": "^0.5.21",
|
|
@@ -91,7 +102,7 @@
|
|
|
91
102
|
},
|
|
92
103
|
"dependencies": {
|
|
93
104
|
"@inquirer/prompts": "^8.4.2",
|
|
94
|
-
"@ts-for-gir/templates": "^4.0.0-rc.
|
|
105
|
+
"@ts-for-gir/templates": "^4.0.0-rc.14",
|
|
95
106
|
"colorette": "^2.0.20",
|
|
96
107
|
"cosmiconfig": "^9.0.1",
|
|
97
108
|
"ejs": "^5.0.2",
|
package/src/commands/create.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
6
|
-
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { dirname, join, resolve } from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
|
|
@@ -55,18 +55,44 @@ const builder = createBuilder<CreateCommandArgs>(createOptions, examples);
|
|
|
55
55
|
function findTemplatesRoot(): string {
|
|
56
56
|
const __filename = fileURLToPath(import.meta.url);
|
|
57
57
|
const __dirname = dirname(__filename);
|
|
58
|
+
// Resolve symlinks too. When the CLI is installed via `npm i -g`,
|
|
59
|
+
// `gjsify install -g`, or any tool that lands a symlink in the user's PATH
|
|
60
|
+
// (Yarn Berry's bin links, asdf shims, ...), `import.meta.url` resolves to
|
|
61
|
+
// the symlink path — `<dir>/../dist-templates` would then look for the
|
|
62
|
+
// templates next to the symlink (e.g. `~/.local/bin/../dist-templates`)
|
|
63
|
+
// instead of next to the real package. Resolving via realpath first lets
|
|
64
|
+
// the same `<dir>/../dist-templates` candidate hit the actual install dir.
|
|
65
|
+
let realDirname = __dirname;
|
|
66
|
+
try {
|
|
67
|
+
realDirname = dirname(realpathSync(__filename));
|
|
68
|
+
} catch {
|
|
69
|
+
// `realpathSync` can throw on bundled paths that don't exist on disk
|
|
70
|
+
// (e.g. virtual entries in a single-file binary). Fall through to the
|
|
71
|
+
// direct __dirname — the candidate list below is a superset and will
|
|
72
|
+
// still find templates when they live alongside the bundle.
|
|
73
|
+
}
|
|
58
74
|
const candidates = [
|
|
59
|
-
//
|
|
75
|
+
// Symlink-resolved binary (`npm i -g` / `gjsify install -g`): the
|
|
76
|
+
// realpath-aware candidate is required when the CLI is launched via a
|
|
77
|
+
// `~/.local/bin/<name>` symlink that points at the real package's
|
|
78
|
+
// `bin/<name>`. Try it first so the success path is symmetric across
|
|
79
|
+
// install modes.
|
|
80
|
+
resolve(realDirname, "..", "dist-templates"),
|
|
81
|
+
// Bundled production binary invoked at its real path (no symlink),
|
|
82
|
+
// or a tarball extracted into a flat `bin/` + `dist-templates/` layout.
|
|
60
83
|
resolve(__dirname, "..", "dist-templates"),
|
|
61
84
|
// Source layout (src/commands/create.ts): ../../dist-templates then ../../templates
|
|
62
85
|
resolve(__dirname, "..", "..", "dist-templates"),
|
|
63
86
|
resolve(__dirname, "..", "..", "templates"),
|
|
64
87
|
];
|
|
88
|
+
const seen = new Set<string>();
|
|
65
89
|
for (const path of candidates) {
|
|
90
|
+
if (seen.has(path)) continue;
|
|
91
|
+
seen.add(path);
|
|
66
92
|
if (existsSync(path)) return path;
|
|
67
93
|
}
|
|
68
94
|
throw new Error(
|
|
69
|
-
`Could not locate templates directory. Looked in:\n ${
|
|
95
|
+
`Could not locate templates directory. Looked in:\n ${[...seen].join("\n ")}\n` +
|
|
70
96
|
"If you are running from source, make sure packages/cli/templates/ exists. " +
|
|
71
97
|
"If you are running the published CLI, make sure dist-templates/ was packed.",
|
|
72
98
|
);
|
|
@@ -122,17 +148,33 @@ function walkAndSubstitute(rootDir: string, projectName: string): void {
|
|
|
122
148
|
declare const __GJS_BUNDLE__: boolean | undefined;
|
|
123
149
|
|
|
124
150
|
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
151
|
const opts = args as unknown as CreateCommandArgs;
|
|
133
152
|
const log = new Logger(opts.verbose ?? false, "CreateCommand");
|
|
134
153
|
|
|
135
|
-
|
|
154
|
+
let templatesRoot: string;
|
|
155
|
+
try {
|
|
156
|
+
templatesRoot = findTemplatesRoot();
|
|
157
|
+
} catch (err) {
|
|
158
|
+
// `dist-templates/` not next to the running file. Two known scenarios:
|
|
159
|
+
// 1. `install.js` (or any flow) deployed only the single-file GJS
|
|
160
|
+
// binary without the package tree. We can't scaffold without
|
|
161
|
+
// templates — point the user at the working install path.
|
|
162
|
+
// 2. Source-mode mis-checkout (no `packages/cli/templates/`). Surface
|
|
163
|
+
// the original error so the developer can fix their layout.
|
|
164
|
+
// The `__GJS_BUNDLE__` define lets us discriminate at build time.
|
|
165
|
+
if (typeof __GJS_BUNDLE__ !== "undefined") {
|
|
166
|
+
process.stderr.write(
|
|
167
|
+
"The 'create' command needs templates that aren't shipped alongside this binary.\n" +
|
|
168
|
+
"Install the full package instead so `dist-templates/` lives next to the bin:\n" +
|
|
169
|
+
" gjsify install -g @ts-for-gir/cli\n" +
|
|
170
|
+
" npm install -g @ts-for-gir/cli\n" +
|
|
171
|
+
" npx @ts-for-gir/cli create ... # one-shot, no install\n",
|
|
172
|
+
);
|
|
173
|
+
process.exitCode = 1;
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
136
178
|
const available = listTemplates(templatesRoot);
|
|
137
179
|
if (available.length === 0) {
|
|
138
180
|
throw new Error(`No templates found in ${templatesRoot}`);
|