create-gtkx 2.0.0-beta.9 → 2.1.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 +8 -166
- package/dependency-ranges.json +7 -0
- package/dist/build-allowance.d.ts +43 -2
- package/dist/build-allowance.d.ts.map +1 -1
- package/dist/build-allowance.js +360 -9
- 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 +93 -90
- package/dist/command.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.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 +6 -3
- package/dist/package-managers.d.ts.map +1 -1
- package/dist/package-managers.js +6 -3
- package/dist/package-managers.js.map +1 -1
- package/dist/project-name.d.ts +4 -2
- package/dist/project-name.d.ts.map +1 -1
- package/dist/project-name.js +12 -2
- package/dist/project-name.js.map +1 -1
- package/dist/scaffolder.d.ts.map +1 -1
- package/dist/scaffolder.js +199 -199
- package/dist/scaffolder.js.map +1 -1
- package/dist/templates/.claude/settings.json.ejs +4 -3
- package/dist/templates/.gitignore.ejs +4 -0
- package/dist/templates/.mcp.json.ejs +1 -1
- package/dist/templates/gtkx.config.ts.ejs +2 -2
- package/dist/templates/package.json.ejs +4 -1
- package/dist/templates/src/app.tsx.ejs +1 -1
- package/dist/templates/src/gtkx-env.d.ts.ejs +0 -1
- package/dist/templates/tsconfig.json.ejs +4 -2
- package/dist/templates.d.ts +3 -0
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +10 -6
- package/dist/templates.js.map +1 -1
- package/dist/workspace-mcp.d.ts +33 -0
- package/dist/workspace-mcp.d.ts.map +1 -0
- package/dist/workspace-mcp.js +75 -0
- package/dist/workspace-mcp.js.map +1 -0
- package/package.json +20 -39
- package/src/build-allowance.ts +486 -9
- package/src/cli.ts +1 -1
- package/src/command.ts +114 -110
- package/src/index.ts +1 -0
- package/src/manifest.ts +2 -10
- package/src/package-managers.ts +6 -3
- package/src/project-name.ts +19 -2
- package/src/scaffolder.ts +294 -286
- package/src/templates/.claude/settings.json.ejs +4 -3
- package/src/templates/.gitignore.ejs +4 -0
- package/src/templates/.mcp.json.ejs +1 -1
- package/src/templates/gtkx.config.ts.ejs +2 -2
- package/src/templates/package.json.ejs +4 -1
- package/src/templates/src/app.tsx.ejs +1 -1
- package/src/templates/src/gtkx-env.d.ts.ejs +0 -1
- package/src/templates/tsconfig.json.ejs +4 -2
- package/src/templates.ts +17 -8
- package/src/workspace-mcp.ts +111 -0
- 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,101 @@
|
|
|
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;
|
|
22
60
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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;
|
|
38
90
|
};
|
|
39
91
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
]);
|
|
92
|
+
const STRICT_OPTIONS = createStrictOptions();
|
|
93
|
+
|
|
94
|
+
const BOOLEAN_OPTIONS = new Set(
|
|
95
|
+
Object.entries(STRICT_OPTIONS)
|
|
96
|
+
.filter(([, option]) => option.type === "boolean")
|
|
97
|
+
.map(([name]) => `--${name}`),
|
|
98
|
+
);
|
|
48
99
|
|
|
49
100
|
const normalizeBooleanArgument = (argument: string): string => {
|
|
50
101
|
const [option, value, ...rest] = argument.split("=");
|
|
@@ -60,89 +111,43 @@ const normalizeBooleanArgument = (argument: string): string => {
|
|
|
60
111
|
return value === "false" ? `--no-${option.slice(2)}` : argument;
|
|
61
112
|
};
|
|
62
113
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
114
|
+
const canonicalOption = (token: OptionToken): [string, string | boolean] => [
|
|
115
|
+
kebabCase(token.name),
|
|
116
|
+
token.value ?? !token.rawName.startsWith("--no-"),
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
/* TODO: Keep ordered token parsing until Citty respects the order of positive and negated flags.
|
|
120
|
+
* https://github.com/gtkx-org/gtkx/issues/732
|
|
121
|
+
*/
|
|
122
|
+
const parseCreateArguments = (rawArgs: string[]): CreateCommandArgs => {
|
|
123
|
+
const { tokens, positionals } = parseArgs({
|
|
124
|
+
args: rawArgs.map((argument) =>
|
|
125
|
+
normalizeBooleanArgument(argument === "--noInteractive" ? "--no-interactive" : argument),
|
|
126
|
+
),
|
|
69
127
|
options: STRICT_OPTIONS,
|
|
70
128
|
allowPositionals: true,
|
|
71
129
|
allowNegative: true,
|
|
72
|
-
strict:
|
|
130
|
+
strict: true,
|
|
73
131
|
tokens: true,
|
|
74
132
|
});
|
|
75
133
|
|
|
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`);
|
|
134
|
+
if (positionals.length > 1) {
|
|
135
|
+
throw new TypeError("Expected one project directory");
|
|
86
136
|
}
|
|
87
137
|
|
|
88
|
-
|
|
138
|
+
return {
|
|
139
|
+
...Object.fromEntries(tokens.filter((token) => token.kind === "option").map((token) => canonicalOption(token))),
|
|
140
|
+
name: positionals[0],
|
|
141
|
+
} as CreateCommandArgs;
|
|
89
142
|
};
|
|
90
143
|
|
|
91
144
|
const scaffoldCommand = defineCommand({
|
|
92
145
|
meta: {
|
|
93
146
|
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
|
-
},
|
|
147
|
+
description: "Create a Linux application with GTKX",
|
|
144
148
|
},
|
|
145
|
-
|
|
149
|
+
args: CREATE_ARGS,
|
|
150
|
+
run: ({ rawArgs }) => runCreate(rawArgs),
|
|
146
151
|
});
|
|
147
152
|
|
|
148
153
|
const settleScaffoldFailure = (error: unknown): void => {
|
|
@@ -157,11 +162,10 @@ const settleScaffoldFailure = (error: unknown): void => {
|
|
|
157
162
|
process.exitCode = 1;
|
|
158
163
|
};
|
|
159
164
|
|
|
160
|
-
const runCreate = async (
|
|
161
|
-
const isInteractive = args["no-interactive"] || args.yes ? false : process.stdin.isTTY;
|
|
162
|
-
|
|
165
|
+
const runCreate = async (rawArgs: string[]): Promise<void> => {
|
|
163
166
|
try {
|
|
164
|
-
|
|
167
|
+
const args = parseCreateArguments(rawArgs);
|
|
168
|
+
const isInteractive = args.interactive !== false && !args.yes && process.stdin.isTTY;
|
|
165
169
|
assertSupportedNodeVersion();
|
|
166
170
|
await scaffold({
|
|
167
171
|
name: args.name,
|
package/src/index.ts
CHANGED
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,24 +5,27 @@ 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",
|
|
9
|
+
runCommand: "pnpm",
|
|
10
|
+
testCommand: "pnpm test",
|
|
10
11
|
isRecommended: true,
|
|
11
12
|
},
|
|
12
13
|
{
|
|
13
14
|
value: "npm",
|
|
14
15
|
label: "npm",
|
|
15
16
|
devCommand: "npm run dev",
|
|
16
|
-
addCommand: "npm install",
|
|
17
17
|
installCommand: "npm install",
|
|
18
|
+
runCommand: "npm run",
|
|
19
|
+
testCommand: "npm test",
|
|
18
20
|
isRecommended: false,
|
|
19
21
|
},
|
|
20
22
|
{
|
|
21
23
|
value: "yarn",
|
|
22
24
|
label: "yarn",
|
|
23
25
|
devCommand: "yarn dev",
|
|
24
|
-
addCommand: "yarn add",
|
|
25
26
|
installCommand: "yarn install",
|
|
27
|
+
runCommand: "yarn",
|
|
28
|
+
testCommand: "yarn test",
|
|
26
29
|
isRecommended: false,
|
|
27
30
|
},
|
|
28
31
|
] as const;
|
package/src/project-name.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
const
|
|
1
|
+
const PACKAGE_NAME_MAX_LENGTH = 214;
|
|
2
|
+
const PACKAGE_NAME_PATTERN = /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/;
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
const withoutAccents = (name: string): string => name.normalize("NFKD").replaceAll(/\p{M}/gu, "");
|
|
5
|
+
|
|
6
|
+
const isValidPackageName = (name: string): boolean =>
|
|
7
|
+
name.length <= PACKAGE_NAME_MAX_LENGTH && PACKAGE_NAME_PATTERN.test(name);
|
|
8
|
+
|
|
9
|
+
const toValidPackageName = (name: string): string =>
|
|
10
|
+
withoutAccents(name)
|
|
11
|
+
.toLowerCase()
|
|
12
|
+
.replaceAll(/[^a-z0-9]+/g, "-")
|
|
13
|
+
.replaceAll(/^-+|-+$/g, "")
|
|
14
|
+
.slice(0, PACKAGE_NAME_MAX_LENGTH)
|
|
15
|
+
.replace(/-+$/, "");
|
|
16
|
+
|
|
17
|
+
const packageNameFromDirectory = (directoryName: string): string =>
|
|
18
|
+
isValidPackageName(directoryName) ? directoryName : toValidPackageName(directoryName);
|
|
19
|
+
|
|
20
|
+
export { isValidPackageName, packageNameFromDirectory, withoutAccents };
|