create-gtkx 2.0.0-beta.10 → 2.0.0-beta.11
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 +8 -166
- package/dist/build-allowance.d.ts.map +1 -1
- package/dist/build-allowance.js +6 -5
- package/dist/build-allowance.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/command.d.ts +3 -2
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +88 -90
- package/dist/command.js.map +1 -1
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +2 -10
- package/dist/manifest.js.map +1 -1
- package/dist/package-managers.d.ts +0 -3
- package/dist/package-managers.d.ts.map +1 -1
- package/dist/package-managers.js +0 -3
- package/dist/package-managers.js.map +1 -1
- package/dist/scaffolder.d.ts.map +1 -1
- package/dist/scaffolder.js +37 -146
- package/dist/scaffolder.js.map +1 -1
- package/dist/templates/gtkx.config.ts.ejs +2 -2
- package/dist/templates/package.json.ejs +4 -1
- package/package.json +24 -12
- package/src/build-allowance.ts +6 -7
- package/src/cli.ts +1 -1
- package/src/command.ts +108 -109
- package/src/manifest.ts +2 -10
- package/src/package-managers.ts +0 -3
- package/src/scaffolder.ts +51 -227
- package/src/templates/gtkx.config.ts.ejs +2 -2
- package/src/templates/package.json.ejs +4 -1
- package/dist/install-hints.d.ts +0 -3
- package/dist/install-hints.d.ts.map +0 -1
- package/dist/install-hints.js +0 -35
- package/dist/install-hints.js.map +0 -1
- package/src/install-hints.ts +0 -54
package/src/command.ts
CHANGED
|
@@ -1,50 +1,99 @@
|
|
|
1
1
|
import * as p from "@clack/prompts";
|
|
2
2
|
import { assertSupportedNodeVersion } from "@gtkx/config/internal";
|
|
3
|
-
import { errorMessage } from "@gtkx/utils";
|
|
4
|
-
import { defineCommand } from "citty";
|
|
3
|
+
import { camelCase, errorMessage, kebabCase } from "@gtkx/utils";
|
|
4
|
+
import { type ArgsDef, defineCommand, type ParsedArgs } from "citty";
|
|
5
5
|
import { parseArgs, type ParseArgsOptionsConfig } from "node:util";
|
|
6
6
|
import { OperationCanceledError, ScaffoldAbortedError } from "./errors.js";
|
|
7
7
|
import { PACKAGE_MANAGER_FLAG_DESCRIPTION } from "./package-managers.js";
|
|
8
8
|
import { scaffold } from "./scaffolder.js";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
name
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
10
|
+
const CREATE_ARGS = {
|
|
11
|
+
name: {
|
|
12
|
+
type: "positional",
|
|
13
|
+
description: "Target directory or project name (e.g. my-app, ., apps/my-app)",
|
|
14
|
+
required: false,
|
|
15
|
+
},
|
|
16
|
+
"application-id": {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Application ID (e.g., com.example.myapp)",
|
|
19
|
+
},
|
|
20
|
+
"display-name": {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "Application display name (e.g., My App)",
|
|
23
|
+
},
|
|
24
|
+
"package-manager": {
|
|
25
|
+
type: "string",
|
|
26
|
+
alias: "p",
|
|
27
|
+
description: PACKAGE_MANAGER_FLAG_DESCRIPTION,
|
|
28
|
+
},
|
|
29
|
+
typescript: {
|
|
30
|
+
type: "boolean",
|
|
31
|
+
negativeDescription: "Scaffold the application in JavaScript instead of TypeScript",
|
|
32
|
+
description: "Scaffold the application in TypeScript",
|
|
33
|
+
},
|
|
34
|
+
vitest: {
|
|
35
|
+
type: "boolean",
|
|
36
|
+
description: "Include a Vitest testing setup",
|
|
37
|
+
},
|
|
38
|
+
yes: {
|
|
39
|
+
type: "boolean",
|
|
40
|
+
alias: "y",
|
|
41
|
+
description: "Skip prompts and accept defaults for unspecified options",
|
|
42
|
+
},
|
|
43
|
+
interactive: {
|
|
44
|
+
type: "boolean",
|
|
45
|
+
description: "Prompt for unspecified options when running in a terminal",
|
|
46
|
+
negativeDescription:
|
|
47
|
+
"Run without prompts, using the default for every option not passed on the command line " +
|
|
48
|
+
"(same as --yes)",
|
|
49
|
+
},
|
|
50
|
+
overwrite: {
|
|
51
|
+
type: "boolean",
|
|
52
|
+
alias: "f",
|
|
53
|
+
description: "Replace scaffold files in a non-empty target directory when running without prompts",
|
|
54
|
+
},
|
|
55
|
+
"skip-install": {
|
|
56
|
+
type: "boolean",
|
|
57
|
+
description: "Create the project without installing dependencies",
|
|
58
|
+
},
|
|
59
|
+
} as const satisfies ArgsDef;
|
|
60
|
+
|
|
61
|
+
type OptionToken = Extract<
|
|
62
|
+
ReturnType<typeof parseArgs<{ tokens: true; strict: false }>>["tokens"][number],
|
|
63
|
+
{ kind: "option" }
|
|
64
|
+
>;
|
|
65
|
+
|
|
66
|
+
type CreateCommandArgs = Pick<ParsedArgs<typeof CREATE_ARGS>, keyof typeof CREATE_ARGS>;
|
|
67
|
+
type CreateOption = Exclude<(typeof CREATE_ARGS)[keyof typeof CREATE_ARGS], { type: "positional" }>;
|
|
22
68
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
69
|
+
const strictOption = (definition: CreateOption): ParseArgsOptionsConfig[string] => ({
|
|
70
|
+
type: definition.type,
|
|
71
|
+
...("alias" in definition && { short: definition.alias }),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const createStrictOptions = (): ParseArgsOptionsConfig => {
|
|
75
|
+
const options: ParseArgsOptionsConfig = {};
|
|
76
|
+
|
|
77
|
+
for (const [name, definition] of Object.entries(CREATE_ARGS)) {
|
|
78
|
+
if (definition.type === "positional") {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
options[name] = strictOption(definition);
|
|
83
|
+
|
|
84
|
+
if (camelCase(name) !== name) {
|
|
85
|
+
options[camelCase(name)] = { type: definition.type };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return options;
|
|
38
90
|
};
|
|
39
91
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
"--skip-install",
|
|
46
|
-
"--skipInstall",
|
|
47
|
-
]);
|
|
92
|
+
const STRICT_OPTIONS = createStrictOptions();
|
|
93
|
+
|
|
94
|
+
const BOOLEAN_OPTIONS = new Set(
|
|
95
|
+
Object.entries(STRICT_OPTIONS).filter(([, option]) => option.type === "boolean").map(([name]) => `--${name}`),
|
|
96
|
+
);
|
|
48
97
|
|
|
49
98
|
const normalizeBooleanArgument = (argument: string): string => {
|
|
50
99
|
const [option, value, ...rest] = argument.split("=");
|
|
@@ -60,89 +109,40 @@ const normalizeBooleanArgument = (argument: string): string => {
|
|
|
60
109
|
return value === "false" ? `--no-${option.slice(2)}` : argument;
|
|
61
110
|
};
|
|
62
111
|
|
|
63
|
-
const
|
|
64
|
-
|
|
112
|
+
const canonicalOption = (token: OptionToken): [string, string | boolean] =>
|
|
113
|
+
[kebabCase(token.name), token.value ?? !token.rawName.startsWith("--no-")];
|
|
65
114
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
115
|
+
/* TODO: Keep ordered token parsing until Citty respects the order of positive and negated flags.
|
|
116
|
+
* https://github.com/gtkx-org/gtkx/issues/732
|
|
117
|
+
*/
|
|
118
|
+
const parseCreateArguments = (rawArgs: string[]): CreateCommandArgs => {
|
|
119
|
+
const { tokens, positionals } = parseArgs({
|
|
120
|
+
args: rawArgs.map((argument) =>
|
|
121
|
+
normalizeBooleanArgument(argument === "--noInteractive" ? "--no-interactive" : argument)),
|
|
69
122
|
options: STRICT_OPTIONS,
|
|
70
123
|
allowPositionals: true,
|
|
71
124
|
allowNegative: true,
|
|
72
|
-
strict:
|
|
125
|
+
strict: true,
|
|
73
126
|
tokens: true,
|
|
74
127
|
});
|
|
75
128
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const assertKnownArguments = (rawArgs: string[]): void => {
|
|
81
|
-
const args = rawArgs.map((argument) => normalizeBooleanArgument(argument));
|
|
82
|
-
const [unknown] = unknownOptions(args);
|
|
83
|
-
|
|
84
|
-
if (unknown !== undefined) {
|
|
85
|
-
throw new Error(`Unknown option "${unknown}". Pass --help to list the supported options`);
|
|
129
|
+
if (positionals.length > 1) {
|
|
130
|
+
throw new TypeError("Expected one project directory");
|
|
86
131
|
}
|
|
87
132
|
|
|
88
|
-
|
|
133
|
+
return {
|
|
134
|
+
...Object.fromEntries(tokens.filter((token) => token.kind === "option").map((token) => canonicalOption(token))),
|
|
135
|
+
name: positionals[0],
|
|
136
|
+
} as CreateCommandArgs;
|
|
89
137
|
};
|
|
90
138
|
|
|
91
139
|
const scaffoldCommand = defineCommand({
|
|
92
140
|
meta: {
|
|
93
141
|
name: "create",
|
|
94
|
-
description: "Create a
|
|
95
|
-
},
|
|
96
|
-
args: {
|
|
97
|
-
name: {
|
|
98
|
-
type: "positional",
|
|
99
|
-
description: "Target directory or project name (e.g. my-app, ., apps/my-app)",
|
|
100
|
-
required: false,
|
|
101
|
-
},
|
|
102
|
-
"application-id": {
|
|
103
|
-
type: "string",
|
|
104
|
-
description: "Application ID (e.g., com.example.myapp)",
|
|
105
|
-
},
|
|
106
|
-
"display-name": {
|
|
107
|
-
type: "string",
|
|
108
|
-
description: "Application display name (e.g., My App)",
|
|
109
|
-
},
|
|
110
|
-
"package-manager": {
|
|
111
|
-
type: "string",
|
|
112
|
-
alias: "p",
|
|
113
|
-
description: PACKAGE_MANAGER_FLAG_DESCRIPTION,
|
|
114
|
-
},
|
|
115
|
-
typescript: {
|
|
116
|
-
type: "boolean",
|
|
117
|
-
negativeDescription: "Scaffold the application in JavaScript instead of TypeScript",
|
|
118
|
-
description: "Scaffold the application in TypeScript",
|
|
119
|
-
},
|
|
120
|
-
vitest: {
|
|
121
|
-
type: "boolean",
|
|
122
|
-
description: "Include a Vitest testing setup",
|
|
123
|
-
},
|
|
124
|
-
yes: {
|
|
125
|
-
type: "boolean",
|
|
126
|
-
alias: "y",
|
|
127
|
-
description: "Skip prompts and accept defaults for unspecified options",
|
|
128
|
-
},
|
|
129
|
-
"no-interactive": {
|
|
130
|
-
type: "boolean",
|
|
131
|
-
description:
|
|
132
|
-
"Run without prompts, using the default for every option not passed on the command line " +
|
|
133
|
-
"(same as --yes)",
|
|
134
|
-
},
|
|
135
|
-
overwrite: {
|
|
136
|
-
type: "boolean",
|
|
137
|
-
alias: "f",
|
|
138
|
-
description: "Replace scaffold files in a non-empty target directory when running without prompts",
|
|
139
|
-
},
|
|
140
|
-
"skip-install": {
|
|
141
|
-
type: "boolean",
|
|
142
|
-
description: "Create the project without installing dependencies",
|
|
143
|
-
},
|
|
142
|
+
description: "Create a Linux application with GTKX",
|
|
144
143
|
},
|
|
145
|
-
|
|
144
|
+
args: CREATE_ARGS,
|
|
145
|
+
run: ({ rawArgs }) => runCreate(rawArgs),
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
const settleScaffoldFailure = (error: unknown): void => {
|
|
@@ -157,11 +157,10 @@ const settleScaffoldFailure = (error: unknown): void => {
|
|
|
157
157
|
process.exitCode = 1;
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
-
const runCreate = async (
|
|
161
|
-
const isInteractive = args["no-interactive"] || args.yes ? false : process.stdin.isTTY;
|
|
162
|
-
|
|
160
|
+
const runCreate = async (rawArgs: string[]): Promise<void> => {
|
|
163
161
|
try {
|
|
164
|
-
|
|
162
|
+
const args = parseCreateArguments(rawArgs);
|
|
163
|
+
const isInteractive = args.interactive !== false && !args.yes && process.stdin.isTTY;
|
|
165
164
|
assertSupportedNodeVersion();
|
|
166
165
|
await scaffold({
|
|
167
166
|
name: args.name,
|
package/src/manifest.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
3
2
|
import { join } from "node:path";
|
|
4
3
|
|
|
5
4
|
const PACKAGE_JSON_FILE = "package.json";
|
|
@@ -8,14 +7,7 @@ const updateManifest = (root: string, mutate: (manifest: Record<string, unknown>
|
|
|
8
7
|
const manifestPath = join(root, PACKAGE_JSON_FILE);
|
|
9
8
|
const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as Record<string, unknown>;
|
|
10
9
|
mutate(manifest);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
writeFileSync(pendingPath, `${JSON.stringify(manifest, null, 4)}\n`, { flag: "wx", mode: 0o600 });
|
|
15
|
-
renameSync(pendingPath, manifestPath);
|
|
16
|
-
} finally {
|
|
17
|
-
rmSync(pendingPath, { force: true });
|
|
18
|
-
}
|
|
10
|
+
writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 4)}\n`);
|
|
19
11
|
};
|
|
20
12
|
|
|
21
13
|
export { updateManifest };
|
package/src/package-managers.ts
CHANGED
|
@@ -5,7 +5,6 @@ const PACKAGE_MANAGERS = [
|
|
|
5
5
|
value: "pnpm",
|
|
6
6
|
label: "pnpm",
|
|
7
7
|
devCommand: "pnpm dev",
|
|
8
|
-
addCommand: "pnpm add",
|
|
9
8
|
installCommand: "pnpm install",
|
|
10
9
|
isRecommended: true,
|
|
11
10
|
},
|
|
@@ -13,7 +12,6 @@ const PACKAGE_MANAGERS = [
|
|
|
13
12
|
value: "npm",
|
|
14
13
|
label: "npm",
|
|
15
14
|
devCommand: "npm run dev",
|
|
16
|
-
addCommand: "npm install",
|
|
17
15
|
installCommand: "npm install",
|
|
18
16
|
isRecommended: false,
|
|
19
17
|
},
|
|
@@ -21,7 +19,6 @@ const PACKAGE_MANAGERS = [
|
|
|
21
19
|
value: "yarn",
|
|
22
20
|
label: "yarn",
|
|
23
21
|
devCommand: "yarn dev",
|
|
24
|
-
addCommand: "yarn add",
|
|
25
22
|
installCommand: "yarn install",
|
|
26
23
|
isRecommended: false,
|
|
27
24
|
},
|