create-gtkx 2.0.0-beta.1 → 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 -163
- 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 +12 -3
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +111 -45
- package/dist/command.js.map +1 -1
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +2 -4
- package/dist/manifest.js.map +1 -1
- package/dist/package-managers.d.ts +3 -3
- package/dist/package-managers.d.ts.map +1 -1
- package/dist/package-managers.js +21 -3
- package/dist/package-managers.js.map +1 -1
- package/dist/scaffolder.d.ts +2 -0
- package/dist/scaffolder.d.ts.map +1 -1
- package/dist/scaffolder.js +200 -112
- package/dist/scaffolder.js.map +1 -1
- package/dist/templates/gtkx.config.ts.ejs +3 -4
- package/dist/templates/package.json.ejs +4 -1
- package/dist/templates/src/app.tsx.ejs +27 -24
- package/dist/templates.d.ts +1 -1
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js.map +1 -1
- package/package.json +26 -12
- package/src/build-allowance.ts +6 -7
- package/src/cli.ts +1 -1
- package/src/command.ts +140 -57
- package/src/manifest.ts +2 -4
- package/src/package-managers.ts +21 -3
- package/src/scaffolder.ts +282 -153
- package/src/templates/gtkx.config.ts.ejs +3 -4
- package/src/templates/package.json.ejs +4 -1
- package/src/templates/src/app.tsx.ejs +27 -24
- package/src/templates.ts +1 -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,68 +1,148 @@
|
|
|
1
1
|
import * as p from "@clack/prompts";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { assertSupportedNodeVersion } from "@gtkx/config/internal";
|
|
3
|
+
import { camelCase, errorMessage, kebabCase } from "@gtkx/utils";
|
|
4
|
+
import { type ArgsDef, defineCommand, type ParsedArgs } from "citty";
|
|
5
|
+
import { parseArgs, type ParseArgsOptionsConfig } from "node:util";
|
|
4
6
|
import { OperationCanceledError, ScaffoldAbortedError } from "./errors.js";
|
|
5
7
|
import { PACKAGE_MANAGER_FLAG_DESCRIPTION } from "./package-managers.js";
|
|
6
8
|
import { scaffold } from "./scaffolder.js";
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
name
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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" }>;
|
|
68
|
+
|
|
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;
|
|
90
|
+
};
|
|
91
|
+
|
|
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
|
+
);
|
|
97
|
+
|
|
98
|
+
const normalizeBooleanArgument = (argument: string): string => {
|
|
99
|
+
const [option, value, ...rest] = argument.split("=");
|
|
100
|
+
|
|
101
|
+
if (option === undefined || rest.length > 0 || !BOOLEAN_OPTIONS.has(option)) {
|
|
102
|
+
return argument;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (value === "true") {
|
|
106
|
+
return option;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return value === "false" ? `--no-${option.slice(2)}` : argument;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const canonicalOption = (token: OptionToken): [string, string | boolean] =>
|
|
113
|
+
[kebabCase(token.name), token.value ?? !token.rawName.startsWith("--no-")];
|
|
114
|
+
|
|
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)),
|
|
122
|
+
options: STRICT_OPTIONS,
|
|
123
|
+
allowPositionals: true,
|
|
124
|
+
allowNegative: true,
|
|
125
|
+
strict: true,
|
|
126
|
+
tokens: true,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (positionals.length > 1) {
|
|
130
|
+
throw new TypeError("Expected one project directory");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
...Object.fromEntries(tokens.filter((token) => token.kind === "option").map((token) => canonicalOption(token))),
|
|
135
|
+
name: positionals[0],
|
|
136
|
+
} as CreateCommandArgs;
|
|
17
137
|
};
|
|
18
138
|
|
|
19
139
|
const scaffoldCommand = defineCommand({
|
|
20
140
|
meta: {
|
|
21
141
|
name: "create",
|
|
22
|
-
description: "Create a
|
|
142
|
+
description: "Create a Linux application with GTKX",
|
|
23
143
|
},
|
|
24
|
-
args:
|
|
25
|
-
|
|
26
|
-
type: "positional",
|
|
27
|
-
description: "Target directory or project name (e.g. my-app, ., apps/my-app)",
|
|
28
|
-
required: false,
|
|
29
|
-
},
|
|
30
|
-
"application-id": {
|
|
31
|
-
type: "string",
|
|
32
|
-
description: "Application ID (e.g., com.example.myapp)",
|
|
33
|
-
},
|
|
34
|
-
"package-manager": {
|
|
35
|
-
type: "string",
|
|
36
|
-
alias: "p",
|
|
37
|
-
description: PACKAGE_MANAGER_FLAG_DESCRIPTION,
|
|
38
|
-
},
|
|
39
|
-
typescript: {
|
|
40
|
-
type: "boolean",
|
|
41
|
-
negativeDescription: "Scaffold the application in JavaScript instead of TypeScript",
|
|
42
|
-
description: "Scaffold the application in TypeScript",
|
|
43
|
-
},
|
|
44
|
-
vitest: {
|
|
45
|
-
type: "boolean",
|
|
46
|
-
description: "Include a Vitest testing setup",
|
|
47
|
-
},
|
|
48
|
-
yes: {
|
|
49
|
-
type: "boolean",
|
|
50
|
-
alias: "y",
|
|
51
|
-
description: "Skip prompts and accept defaults for unspecified options",
|
|
52
|
-
},
|
|
53
|
-
"no-interactive": {
|
|
54
|
-
type: "boolean",
|
|
55
|
-
description:
|
|
56
|
-
"Run without prompts, using the default for every option not passed on the command line " +
|
|
57
|
-
"(same as --yes)",
|
|
58
|
-
},
|
|
59
|
-
overwrite: {
|
|
60
|
-
type: "boolean",
|
|
61
|
-
alias: "f",
|
|
62
|
-
description: "Overwrite the contents of a non-empty target directory when running without prompts",
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
run: ({ args }) => runCreate(args),
|
|
144
|
+
args: CREATE_ARGS,
|
|
145
|
+
run: ({ rawArgs }) => runCreate(rawArgs),
|
|
66
146
|
});
|
|
67
147
|
|
|
68
148
|
const settleScaffoldFailure = (error: unknown): void => {
|
|
@@ -77,18 +157,21 @@ const settleScaffoldFailure = (error: unknown): void => {
|
|
|
77
157
|
process.exitCode = 1;
|
|
78
158
|
};
|
|
79
159
|
|
|
80
|
-
const runCreate = async (
|
|
81
|
-
const isInteractive = args["no-interactive"] || args.yes ? false : process.stdin.isTTY;
|
|
82
|
-
|
|
160
|
+
const runCreate = async (rawArgs: string[]): Promise<void> => {
|
|
83
161
|
try {
|
|
162
|
+
const args = parseCreateArguments(rawArgs);
|
|
163
|
+
const isInteractive = args.interactive !== false && !args.yes && process.stdin.isTTY;
|
|
164
|
+
assertSupportedNodeVersion();
|
|
84
165
|
await scaffold({
|
|
85
166
|
name: args.name,
|
|
86
167
|
applicationId: args["application-id"],
|
|
168
|
+
displayName: args["display-name"],
|
|
87
169
|
packageManager: args["package-manager"],
|
|
88
170
|
isTypescript: args.typescript,
|
|
89
171
|
shouldIncludeTesting: args.vitest,
|
|
90
172
|
isInteractive,
|
|
91
173
|
shouldOverwrite: args.overwrite,
|
|
174
|
+
shouldInstallDependencies: args["skip-install"] !== true,
|
|
92
175
|
});
|
|
93
176
|
} catch (error) {
|
|
94
177
|
settleScaffoldFailure(error);
|
package/src/manifest.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync,
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
|
|
4
4
|
const PACKAGE_JSON_FILE = "package.json";
|
|
@@ -7,9 +7,7 @@ const updateManifest = (root: string, mutate: (manifest: Record<string, unknown>
|
|
|
7
7
|
const manifestPath = join(root, PACKAGE_JSON_FILE);
|
|
8
8
|
const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as Record<string, unknown>;
|
|
9
9
|
mutate(manifest);
|
|
10
|
-
|
|
11
|
-
writeFileSync(pendingPath, `${JSON.stringify(manifest, null, 4)}\n`);
|
|
12
|
-
renameSync(pendingPath, manifestPath);
|
|
10
|
+
writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 4)}\n`);
|
|
13
11
|
};
|
|
14
12
|
|
|
15
13
|
export { updateManifest };
|
package/src/package-managers.ts
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
type PackageManager = (typeof PACKAGE_MANAGERS)[number]["value"];
|
|
2
2
|
|
|
3
3
|
const PACKAGE_MANAGERS = [
|
|
4
|
-
{
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
{
|
|
5
|
+
value: "pnpm",
|
|
6
|
+
label: "pnpm",
|
|
7
|
+
devCommand: "pnpm dev",
|
|
8
|
+
installCommand: "pnpm install",
|
|
9
|
+
isRecommended: true,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
value: "npm",
|
|
13
|
+
label: "npm",
|
|
14
|
+
devCommand: "npm run dev",
|
|
15
|
+
installCommand: "npm install",
|
|
16
|
+
isRecommended: false,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
value: "yarn",
|
|
20
|
+
label: "yarn",
|
|
21
|
+
devCommand: "yarn dev",
|
|
22
|
+
installCommand: "yarn install",
|
|
23
|
+
isRecommended: false,
|
|
24
|
+
},
|
|
7
25
|
] as const;
|
|
8
26
|
|
|
9
27
|
const PACKAGE_MANAGER_VALUES: PackageManager[] = PACKAGE_MANAGERS.map((manager) => manager.value);
|