@ts-for-gir/cli 4.0.0-rc.9 → 4.0.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.
- package/README.md +43 -3
- package/bin/ts-for-gir +454 -129
- package/bin/ts-for-gir-gjs +1213 -0
- package/package.json +194 -83
- package/src/commands/create.ts +84 -12
- package/src/commands/index.ts +1 -0
- package/src/commands/self-update.ts +142 -0
- package/src/config/config-loader.ts +6 -2
- package/src/config/defaults.ts +14 -0
- package/src/config/options.ts +2 -2
- package/src/start.ts +20 -6
- package/src/types/command-args.ts +8 -1
- package/dist-templates/types-locally/.ts-for-girrc.js +0 -6
- package/dist-templates/types-locally/README.md +0 -15
- package/dist-templates/types-locally/esbuild.ts +0 -10
- package/dist-templates/types-locally/main.ts +0 -21
- package/dist-templates/types-locally/package.json +0 -18
- package/dist-templates/types-locally/tsconfig.json +0 -17
- package/dist-templates/types-npm/README.md +0 -14
- package/dist-templates/types-npm/esbuild.ts +0 -10
- package/dist-templates/types-npm/main.ts +0 -19
- package/dist-templates/types-npm/package.json +0 -23
- package/dist-templates/types-npm/tsconfig.json +0 -15
- package/dist-templates/types-workspace/.ts-for-girrc.js +0 -12
- package/dist-templates/types-workspace/README.md +0 -26
- package/dist-templates/types-workspace/package.json +0 -22
- package/dist-templates/types-workspace/packages/app/esbuild.ts +0 -10
- package/dist-templates/types-workspace/packages/app/main.ts +0 -19
- package/dist-templates/types-workspace/packages/app/package.json +0 -23
- package/dist-templates/types-workspace/packages/app/tsconfig.json +0 -15
- package/dist-templates/types-workspace/tsconfig.json +0 -11
package/src/start.ts
CHANGED
|
@@ -2,18 +2,30 @@ import { APP_NAME, APP_USAGE, APP_VERSION } from "@ts-for-gir/lib";
|
|
|
2
2
|
import yargs, { type CommandModule } from "yargs";
|
|
3
3
|
import { hideBin } from "yargs/helpers";
|
|
4
4
|
|
|
5
|
-
import { analyze, copy, create, doc, generate, json, list } from "./commands/index.ts";
|
|
5
|
+
import { analyze, copy, create, doc, generate, json, list, selfUpdate } from "./commands/index.ts";
|
|
6
6
|
|
|
7
7
|
try {
|
|
8
|
-
|
|
8
|
+
const cli = yargs(hideBin(process.argv));
|
|
9
|
+
await cli
|
|
9
10
|
.scriptName(APP_NAME)
|
|
10
11
|
.strict()
|
|
11
12
|
.usage(APP_USAGE)
|
|
12
13
|
.version(APP_VERSION)
|
|
14
|
+
// Use the full terminal width for help. yargs's default caps at 80
|
|
15
|
+
// (`Math.min(80, process.stdout.columns)`); we explicitly opt into
|
|
16
|
+
// the real terminal width so long option/description lines wrap at
|
|
17
|
+
// the actual terminal edge instead of an arbitrary 80-col limit.
|
|
18
|
+
// Under GJS, `process.stdout.columns` is backed by
|
|
19
|
+
// `@gjsify/terminal-native` (ioctl TIOCGWINSZ) when the typelib is
|
|
20
|
+
// on `GI_TYPELIB_PATH` — the install.js launcher imports those env
|
|
21
|
+
// vars from the gjsify global install when present.
|
|
22
|
+
.wrap(cli.terminalWidth())
|
|
13
23
|
// Disable yargs's internal `process.exit` and route both success
|
|
14
|
-
// and failure through `parseAsync` + `process.
|
|
15
|
-
// command handlers complete and stdout drains before the
|
|
16
|
-
// (Node or the gjsify Node-compat loader on GJS
|
|
24
|
+
// and failure through `parseAsync` + an explicit `process.exit` so
|
|
25
|
+
// async command handlers complete and stdout drains before the
|
|
26
|
+
// runtime (Node or the gjsify Node-compat loader on GJS, which
|
|
27
|
+
// keeps a GLib main loop alive that would otherwise prevent the
|
|
28
|
+
// process from exiting after main() returns) tears down.
|
|
17
29
|
.exitProcess(false)
|
|
18
30
|
.fail(false)
|
|
19
31
|
// TODO: Fix this
|
|
@@ -24,11 +36,13 @@ try {
|
|
|
24
36
|
.command(list as unknown as CommandModule)
|
|
25
37
|
.command(copy as unknown as CommandModule)
|
|
26
38
|
.command(doc as unknown as CommandModule)
|
|
39
|
+
.command(selfUpdate as unknown as CommandModule)
|
|
27
40
|
.demandCommand(1)
|
|
28
41
|
.help()
|
|
29
42
|
.parseAsync();
|
|
43
|
+
process.exit(0);
|
|
30
44
|
} catch (err) {
|
|
31
45
|
const message = err instanceof Error ? err.message : String(err);
|
|
32
46
|
process.stderr.write(`${message}\n`);
|
|
33
|
-
process.
|
|
47
|
+
process.exit(1);
|
|
34
48
|
}
|
|
@@ -94,7 +94,7 @@ export interface DocCommandArgs extends GenerateCommandArgs {
|
|
|
94
94
|
/**
|
|
95
95
|
* Available scaffolding template identifiers for the create command.
|
|
96
96
|
*/
|
|
97
|
-
export type CreateTemplateId = "types-locally" | "types-npm" | "types-workspace";
|
|
97
|
+
export type CreateTemplateId = "types-locally" | "types-npm" | "types-workspace" | "types-gjsify";
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
100
|
* Arguments for the create command
|
|
@@ -145,3 +145,10 @@ export interface AnalyzeCommandArgs {
|
|
|
145
145
|
/** Switch on/off the verbose mode */
|
|
146
146
|
verbose?: boolean;
|
|
147
147
|
}
|
|
148
|
+
|
|
149
|
+
export interface SelfUpdateCommandArgs {
|
|
150
|
+
/** Only check for a newer version, do not install */
|
|
151
|
+
check: boolean;
|
|
152
|
+
/** Force reinstall even if already on the latest version */
|
|
153
|
+
force: boolean;
|
|
154
|
+
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# __PROJECT_NAME__
|
|
2
|
-
|
|
3
|
-
GJS + TypeScript starter that generates GObject Introspection types **locally** into `./@types/`, without using the `@girs/*` NPM packages.
|
|
4
|
-
|
|
5
|
-
## Setup
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm install
|
|
9
|
-
npm run generate # writes types into ./@types/
|
|
10
|
-
npm run check:types # tsc --noEmit
|
|
11
|
-
npm run build # bundles main.ts to dist/ via esbuild
|
|
12
|
-
npm start # runs dist/main.js with gjs
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
`@types/index.d.ts` is regenerated each time you run `npm run generate`. Add or remove modules in `.ts-for-girrc.js`.
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/// <reference path="./@types/index.d.ts" />
|
|
2
|
-
|
|
3
|
-
import Adw from "gi://Adw?version=1";
|
|
4
|
-
import Gio from "gi://Gio?version=2.0";
|
|
5
|
-
import Gtk from "gi://Gtk?version=4.0";
|
|
6
|
-
|
|
7
|
-
const app = new Adw.Application({
|
|
8
|
-
applicationId: "com.example.__PROJECT_NAME__",
|
|
9
|
-
flags: Gio.ApplicationFlags.FLAGS_NONE,
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
app.connect("activate", (app: Adw.Application) => {
|
|
13
|
-
const label = new Gtk.Label({ label: "Hello from __PROJECT_NAME__" });
|
|
14
|
-
const window = new Gtk.ApplicationWindow({ application: app });
|
|
15
|
-
window.set_title("__PROJECT_NAME__");
|
|
16
|
-
window.set_default_size(320, 120);
|
|
17
|
-
window.set_child(label);
|
|
18
|
-
window.present();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
app.run([imports.system.programInvocationName].concat(ARGV));
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "__PROJECT_NAME__",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"private": true,
|
|
6
|
-
"scripts": {
|
|
7
|
-
"generate": "ts-for-gir generate",
|
|
8
|
-
"check:types": "tsc --noEmit",
|
|
9
|
-
"build": "node --experimental-strip-types --experimental-transform-types --no-warnings esbuild.ts",
|
|
10
|
-
"start": "gjs -m dist/main.js",
|
|
11
|
-
"clear": "rm -rf dist @types"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@ts-for-gir/cli": "^4.0.0-rc.9",
|
|
15
|
-
"esbuild": "^0.28.0",
|
|
16
|
-
"typescript": "^6.0.2"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"lib": ["ESNext"],
|
|
6
|
-
"moduleResolution": "bundler",
|
|
7
|
-
"skipLibCheck": false,
|
|
8
|
-
"types": [],
|
|
9
|
-
"strict": true,
|
|
10
|
-
"noImplicitAny": true,
|
|
11
|
-
"strictNullChecks": true,
|
|
12
|
-
"noImplicitThis": true,
|
|
13
|
-
"alwaysStrict": true
|
|
14
|
-
},
|
|
15
|
-
"include": ["main.ts", "@types/index.d.ts"],
|
|
16
|
-
"exclude": []
|
|
17
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# __PROJECT_NAME__
|
|
2
|
-
|
|
3
|
-
GJS + TypeScript starter that consumes pre-generated GObject Introspection types from the [`@girs/*`](https://www.npmjs.com/org/girs) NPM packages.
|
|
4
|
-
|
|
5
|
-
## Setup
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm install
|
|
9
|
-
npm run check # tsc --noEmit
|
|
10
|
-
npm run build # bundles main.ts to dist/ via esbuild
|
|
11
|
-
npm start # runs dist/main.js with gjs
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
To add another GIR module, install the matching `@girs/<name>-<version>` package and add it to `tsconfig.json`'s `types` array.
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import Adw from "gi://Adw?version=1";
|
|
2
|
-
import Gio from "gi://Gio?version=2.0";
|
|
3
|
-
import Gtk from "gi://Gtk?version=4.0";
|
|
4
|
-
|
|
5
|
-
const app = new Adw.Application({
|
|
6
|
-
applicationId: "com.example.__PROJECT_NAME__",
|
|
7
|
-
flags: Gio.ApplicationFlags.FLAGS_NONE,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
app.connect("activate", (app: Adw.Application) => {
|
|
11
|
-
const label = new Gtk.Label({ label: "Hello from __PROJECT_NAME__" });
|
|
12
|
-
const window = new Gtk.ApplicationWindow({ application: app });
|
|
13
|
-
window.set_title("__PROJECT_NAME__");
|
|
14
|
-
window.set_default_size(320, 120);
|
|
15
|
-
window.set_child(label);
|
|
16
|
-
window.present();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
app.run([imports.system.programInvocationName].concat(ARGV));
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "__PROJECT_NAME__",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"private": true,
|
|
6
|
-
"scripts": {
|
|
7
|
-
"check": "tsc --noEmit",
|
|
8
|
-
"build": "node --experimental-strip-types --experimental-transform-types --no-warnings esbuild.ts",
|
|
9
|
-
"start": "gjs -m dist/main.js",
|
|
10
|
-
"clear": "rm -rf dist"
|
|
11
|
-
},
|
|
12
|
-
"devDependencies": {
|
|
13
|
-
"esbuild": "^0.28.0",
|
|
14
|
-
"typescript": "^6.0.2"
|
|
15
|
-
},
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"@girs/adw-1": "^1.10.0-4.0.0-rc.8",
|
|
18
|
-
"@girs/gio-2.0": "^2.88.0-4.0.0-rc.8",
|
|
19
|
-
"@girs/gjs": "^4.0.0-rc.8",
|
|
20
|
-
"@girs/glib-2.0": "^2.88.0-4.0.0-rc.8",
|
|
21
|
-
"@girs/gtk-4.0": "^4.23.0-4.0.0-rc.8"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": ["ESNext"],
|
|
4
|
-
"types": ["@girs/gjs", "@girs/adw-1"],
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"moduleResolution": "bundler",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"noImplicitAny": true,
|
|
10
|
-
"strictNullChecks": true,
|
|
11
|
-
"noImplicitThis": true,
|
|
12
|
-
"alwaysStrict": true
|
|
13
|
-
},
|
|
14
|
-
"files": ["main.ts"]
|
|
15
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
modules: ["Adw-1", "Gtk-4.0"],
|
|
3
|
-
outdir: "./@girs",
|
|
4
|
-
package: true,
|
|
5
|
-
// npm does not support the workspace: protocol. `caret` emits ^<version>
|
|
6
|
-
// which npm, yarn and pnpm all resolve to the local workspace when the ref
|
|
7
|
-
// matches, falling back to the registry otherwise — the most portable
|
|
8
|
-
// default for a generated monorepo. Falls back to "exact" on CLI versions
|
|
9
|
-
// that predate this option, which is also npm-compatible.
|
|
10
|
-
depVersionFormat: "caret",
|
|
11
|
-
ignoreVersionConflicts: true,
|
|
12
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# __PROJECT_NAME__
|
|
2
|
-
|
|
3
|
-
GJS + TypeScript starter that uses an **npm workspace** with the `@girs/*` types generated locally as workspace packages. Useful when you want pinned, hermetic types under version control without depending on the published `@girs/*` packages on NPM.
|
|
4
|
-
|
|
5
|
-
## Setup
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm install
|
|
9
|
-
npm run build:types # generates @girs/* packages into ./@girs/
|
|
10
|
-
npm install # picks up the freshly generated @girs/* workspace packages
|
|
11
|
-
npm run build:app
|
|
12
|
-
npm start
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Or shorthand: `npm run build` runs all three steps in order.
|
|
16
|
-
|
|
17
|
-
The application lives in [`packages/app/`](./packages/app/). Its dependencies on `@girs/*` are written as `"*"` which works across all three package managers — npm, yarn, pnpm all resolve to the locally generated workspace packages in `./@girs/`.
|
|
18
|
-
|
|
19
|
-
### About the dependency version format
|
|
20
|
-
|
|
21
|
-
Two deliberate choices keep the template portable:
|
|
22
|
-
|
|
23
|
-
1. **Generated `@girs/*` packages** reference each other via `^<version>` (not `workspace:^`). Controlled by `depVersionFormat: "caret"` in [`.ts-for-girrc.js`](./.ts-for-girrc.js). npm and yarn/pnpm all prefer the local workspace match; the registry serves as fallback for transitive GIR packages outside your `modules` set.
|
|
24
|
-
2. **Sub-package deps** (`packages/app/package.json`) use `"*"`. Same reasoning — all managers resolve to the local workspace.
|
|
25
|
-
|
|
26
|
-
If you run yarn or pnpm exclusively and want strict workspace-only resolution, switch both: add `workspace: true` and `depVersionFormat: "workspace"` in `.ts-for-girrc.js`, plus `"workspace:^"` specs in `packages/app/package.json`. npm does **not** support the `workspace:` protocol.
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "__PROJECT_NAME__",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"private": true,
|
|
6
|
-
"workspaces": [
|
|
7
|
-
"packages/*",
|
|
8
|
-
"@girs/*"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build:types": "ts-for-gir generate --package --outdir=./@girs",
|
|
12
|
-
"build:app": "npm run --workspace=@__PROJECT_NAME__/app build",
|
|
13
|
-
"build": "npm run build:types && npm install && npm run build:app",
|
|
14
|
-
"check": "npm run --workspaces --if-present check",
|
|
15
|
-
"start": "npm run --workspace=@__PROJECT_NAME__/app start",
|
|
16
|
-
"clear": "rm -rf @girs packages/*/dist"
|
|
17
|
-
},
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"@ts-for-gir/cli": "^4.0.0-rc.9",
|
|
20
|
-
"typescript": "^6.0.2"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import Adw from "gi://Adw?version=1";
|
|
2
|
-
import Gio from "gi://Gio?version=2.0";
|
|
3
|
-
import Gtk from "gi://Gtk?version=4.0";
|
|
4
|
-
|
|
5
|
-
const app = new Adw.Application({
|
|
6
|
-
applicationId: "com.example.__PROJECT_NAME__",
|
|
7
|
-
flags: Gio.ApplicationFlags.FLAGS_NONE,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
app.connect("activate", (app: Adw.Application) => {
|
|
11
|
-
const label = new Gtk.Label({ label: "Hello from __PROJECT_NAME__" });
|
|
12
|
-
const window = new Gtk.ApplicationWindow({ application: app });
|
|
13
|
-
window.set_title("__PROJECT_NAME__");
|
|
14
|
-
window.set_default_size(320, 120);
|
|
15
|
-
window.set_child(label);
|
|
16
|
-
window.present();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
app.run([imports.system.programInvocationName].concat(ARGV));
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@__PROJECT_NAME__/app",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"private": true,
|
|
6
|
-
"scripts": {
|
|
7
|
-
"check": "tsc --noEmit",
|
|
8
|
-
"build": "node --experimental-strip-types --experimental-transform-types --no-warnings esbuild.ts",
|
|
9
|
-
"start": "gjs -m dist/main.js",
|
|
10
|
-
"clear": "rm -rf dist"
|
|
11
|
-
},
|
|
12
|
-
"devDependencies": {
|
|
13
|
-
"esbuild": "^0.28.0",
|
|
14
|
-
"typescript": "^6.0.2"
|
|
15
|
-
},
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"@girs/adw-1": "*",
|
|
18
|
-
"@girs/gio-2.0": "*",
|
|
19
|
-
"@girs/gjs": "*",
|
|
20
|
-
"@girs/glib-2.0": "*",
|
|
21
|
-
"@girs/gtk-4.0": "*"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": ["ESNext"],
|
|
4
|
-
"types": ["@girs/gjs", "@girs/adw-1"],
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"moduleResolution": "bundler",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"noImplicitAny": true,
|
|
10
|
-
"strictNullChecks": true,
|
|
11
|
-
"noImplicitThis": true,
|
|
12
|
-
"alwaysStrict": true
|
|
13
|
-
},
|
|
14
|
-
"files": ["main.ts"]
|
|
15
|
-
}
|