create-gtkx 2.0.0-beta.9 → 2.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.
Files changed (71) hide show
  1. package/README.md +8 -166
  2. package/dependency-ranges.json +7 -0
  3. package/dist/build-allowance.d.ts +43 -2
  4. package/dist/build-allowance.d.ts.map +1 -1
  5. package/dist/build-allowance.js +360 -9
  6. package/dist/build-allowance.js.map +1 -1
  7. package/dist/cli.js +1 -1
  8. package/dist/cli.js.map +1 -1
  9. package/dist/command.d.ts +3 -2
  10. package/dist/command.d.ts.map +1 -1
  11. package/dist/command.js +93 -90
  12. package/dist/command.js.map +1 -1
  13. package/dist/errors.d.ts.map +1 -1
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/manifest.d.ts.map +1 -1
  19. package/dist/manifest.js +2 -10
  20. package/dist/manifest.js.map +1 -1
  21. package/dist/package-managers.d.ts +6 -3
  22. package/dist/package-managers.d.ts.map +1 -1
  23. package/dist/package-managers.js +6 -3
  24. package/dist/package-managers.js.map +1 -1
  25. package/dist/project-name.d.ts +4 -2
  26. package/dist/project-name.d.ts.map +1 -1
  27. package/dist/project-name.js +12 -2
  28. package/dist/project-name.js.map +1 -1
  29. package/dist/scaffolder.d.ts.map +1 -1
  30. package/dist/scaffolder.js +199 -199
  31. package/dist/scaffolder.js.map +1 -1
  32. package/dist/templates/.claude/settings.json.ejs +4 -3
  33. package/dist/templates/.gitignore.ejs +4 -0
  34. package/dist/templates/.mcp.json.ejs +1 -1
  35. package/dist/templates/gtkx.config.ts.ejs +2 -2
  36. package/dist/templates/package.json.ejs +4 -1
  37. package/dist/templates/src/app.tsx.ejs +1 -1
  38. package/dist/templates/src/gtkx-env.d.ts.ejs +0 -1
  39. package/dist/templates/tsconfig.json.ejs +4 -2
  40. package/dist/templates.d.ts +3 -0
  41. package/dist/templates.d.ts.map +1 -1
  42. package/dist/templates.js +10 -6
  43. package/dist/templates.js.map +1 -1
  44. package/dist/workspace-mcp.d.ts +33 -0
  45. package/dist/workspace-mcp.d.ts.map +1 -0
  46. package/dist/workspace-mcp.js +75 -0
  47. package/dist/workspace-mcp.js.map +1 -0
  48. package/package.json +20 -39
  49. package/src/build-allowance.ts +486 -9
  50. package/src/cli.ts +1 -1
  51. package/src/command.ts +114 -110
  52. package/src/index.ts +1 -0
  53. package/src/manifest.ts +2 -10
  54. package/src/package-managers.ts +6 -3
  55. package/src/project-name.ts +19 -2
  56. package/src/scaffolder.ts +294 -286
  57. package/src/templates/.claude/settings.json.ejs +4 -3
  58. package/src/templates/.gitignore.ejs +4 -0
  59. package/src/templates/.mcp.json.ejs +1 -1
  60. package/src/templates/gtkx.config.ts.ejs +2 -2
  61. package/src/templates/package.json.ejs +4 -1
  62. package/src/templates/src/app.tsx.ejs +1 -1
  63. package/src/templates/src/gtkx-env.d.ts.ejs +0 -1
  64. package/src/templates/tsconfig.json.ejs +4 -2
  65. package/src/templates.ts +17 -8
  66. package/src/workspace-mcp.ts +111 -0
  67. package/dist/install-hints.d.ts +0 -3
  68. package/dist/install-hints.d.ts.map +0 -1
  69. package/dist/install-hints.js +0 -35
  70. package/dist/install-hints.js.map +0 -1
  71. 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
- type CreateCommandArgs = {
11
- name?: string | undefined;
12
- "application-id"?: string | undefined;
13
- "display-name"?: string | undefined;
14
- "package-manager"?: string | undefined;
15
- typescript?: boolean | undefined;
16
- vitest?: boolean | undefined;
17
- yes?: boolean | undefined;
18
- "no-interactive"?: boolean | undefined;
19
- overwrite?: boolean | undefined;
20
- "skip-install"?: boolean | undefined;
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
- const STRICT_OPTIONS: ParseArgsOptionsConfig = {
24
- "application-id": { type: "string" },
25
- applicationId: { type: "string" },
26
- "display-name": { type: "string" },
27
- displayName: { type: "string" },
28
- "package-manager": { type: "string", short: "p" },
29
- packageManager: { type: "string" },
30
- typescript: { type: "boolean" },
31
- vitest: { type: "boolean" },
32
- yes: { type: "boolean", short: "y" },
33
- "no-interactive": { type: "boolean" },
34
- noInteractive: { type: "boolean" },
35
- overwrite: { type: "boolean", short: "f" },
36
- "skip-install": { type: "boolean" },
37
- skipInstall: { type: "boolean" },
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 BOOLEAN_OPTIONS: ReadonlySet<string> = new Set([
41
- "--typescript",
42
- "--vitest",
43
- "--yes",
44
- "--overwrite",
45
- "--skip-install",
46
- "--skipInstall",
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 isKnownOption = (name: string, rawName: string): boolean =>
64
- Object.hasOwn(STRICT_OPTIONS, name) || Object.hasOwn(STRICT_OPTIONS, rawName.replace(/^--/, ""));
65
-
66
- const unknownOptions = (args: string[]): string[] => {
67
- const { tokens } = parseArgs({
68
- args,
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: false,
130
+ strict: true,
73
131
  tokens: true,
74
132
  });
75
133
 
76
- return tokens.flatMap((token) =>
77
- token.kind === "option" && !isKnownOption(token.name, token.rawName) ? [token.rawName] : []);
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
- parseArgs({ args, options: STRICT_OPTIONS, allowPositionals: true, allowNegative: true, strict: true });
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 new Adwaita-first GNOME application with GTKX",
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
- run: ({ args, rawArgs }) => runCreate(args, rawArgs),
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 (args: CreateCommandArgs, rawArgs: string[]): Promise<void> => {
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
- assertKnownArguments(rawArgs);
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
@@ -1 +1,2 @@
1
+ export { writeReleaseAgeExemptions } from "./build-allowance.js";
1
2
  export { scaffoldCommand } from "./command.js";
package/src/manifest.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { randomUUID } from "node:crypto";
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
- const pendingPath = join(root, `.package-${randomUUID()}.json`);
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 };
@@ -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;
@@ -1,3 +1,20 @@
1
- const isValidProjectName = (name: string): boolean => /^[a-z0-9-]+$/.test(name);
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
- export { isValidProjectName };
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 };