create-gtkx 2.0.0-beta.12 → 2.0.0-beta.14

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 (49) hide show
  1. package/README.md +3 -3
  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 -10
  6. package/dist/build-allowance.js.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/package-managers.d.ts +6 -0
  12. package/dist/package-managers.d.ts.map +1 -1
  13. package/dist/package-managers.js +6 -0
  14. package/dist/package-managers.js.map +1 -1
  15. package/dist/project-name.d.ts +4 -2
  16. package/dist/project-name.d.ts.map +1 -1
  17. package/dist/project-name.js +12 -2
  18. package/dist/project-name.js.map +1 -1
  19. package/dist/scaffolder.d.ts.map +1 -1
  20. package/dist/scaffolder.js +171 -64
  21. package/dist/scaffolder.js.map +1 -1
  22. package/dist/templates/.claude/settings.json.ejs +4 -3
  23. package/dist/templates/.gitignore.ejs +4 -0
  24. package/dist/templates/.mcp.json.ejs +1 -1
  25. package/dist/templates/src/app.tsx.ejs +1 -1
  26. package/dist/templates/src/gtkx-env.d.ts.ejs +0 -1
  27. package/dist/templates/tsconfig.json.ejs +4 -2
  28. package/dist/templates.d.ts +3 -0
  29. package/dist/templates.d.ts.map +1 -1
  30. package/dist/templates.js +10 -6
  31. package/dist/templates.js.map +1 -1
  32. package/dist/workspace-mcp.d.ts +33 -0
  33. package/dist/workspace-mcp.d.ts.map +1 -0
  34. package/dist/workspace-mcp.js +75 -0
  35. package/dist/workspace-mcp.js.map +1 -0
  36. package/package.json +11 -7
  37. package/src/build-allowance.ts +488 -10
  38. package/src/index.ts +1 -0
  39. package/src/package-managers.ts +6 -0
  40. package/src/project-name.ts +19 -2
  41. package/src/scaffolder.ts +250 -70
  42. package/src/templates/.claude/settings.json.ejs +4 -3
  43. package/src/templates/.gitignore.ejs +4 -0
  44. package/src/templates/.mcp.json.ejs +1 -1
  45. package/src/templates/src/app.tsx.ejs +1 -1
  46. package/src/templates/src/gtkx-env.d.ts.ejs +0 -1
  47. package/src/templates/tsconfig.json.ejs +4 -2
  48. package/src/templates.ts +17 -8
  49. package/src/workspace-mcp.ts +111 -0
package/src/scaffolder.ts CHANGED
@@ -2,12 +2,19 @@ import * as p from "@clack/prompts";
2
2
  import { APPLICATION_ID_MAX_LENGTH, isValidApplicationId } from "@gtkx/config/internal";
3
3
  import { errorMessage, HEADLESS_DISPLAY_TOOLS, missingToolLines, tryResolveExecutable, upperFirst } from "@gtkx/utils";
4
4
  import { execFileSync } from "node:child_process";
5
- import { lstatSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
5
+ import { lstatSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
6
+ import { homedir } from "node:os";
6
7
  import { basename, dirname, join, relative, resolve, sep } from "node:path";
7
8
  import { addDependency, detectPackageManager as nypmDetectPackageManager } from "nypm";
8
9
  import { x } from "tinyexec";
9
10
  import packageManifest from "../package.json" with { type: "json" };
10
- import { writeBuildAllowance } from "./build-allowance.js";
11
+ import {
12
+ PACKAGE_MANAGER_CONFIG_FILES,
13
+ enclosingWorkspace,
14
+ packageManagerPin,
15
+ type Workspace,
16
+ writePackageManagerSettings,
17
+ } from "./build-allowance.js";
11
18
  import { OperationCanceledError, ScaffoldAbortedError } from "./errors.js";
12
19
  import { updateManifest } from "./manifest.js";
13
20
  import {
@@ -16,8 +23,9 @@ import {
16
23
  PACKAGE_MANAGERS,
17
24
  type PackageManager,
18
25
  } from "./package-managers.js";
19
- import { isValidProjectName } from "./project-name.js";
26
+ import { isValidPackageName, packageNameFromDirectory, withoutAccents } from "./project-name.js";
20
27
  import { listTemplates, renderFile, type TemplateContext } from "./templates.js";
28
+ import { addWorkspaceMcpServer } from "./workspace-mcp.js";
21
29
 
22
30
  type CreateOptions = {
23
31
  name?: string | undefined;
@@ -38,6 +46,7 @@ type ResolvedOptions = {
38
46
  displayName: string;
39
47
  applicationId: string;
40
48
  packageManager: PackageManager;
49
+ workspace: Workspace | null;
41
50
  isTypescript: boolean;
42
51
  shouldIncludeTesting: boolean;
43
52
  shouldInitializeGit: boolean;
@@ -52,6 +61,12 @@ type ScaffoldPlan = {
52
61
  files: ScaffoldFile[];
53
62
  replaceDestinations: string[];
54
63
  changes: ScaffoldChanges;
64
+ packageManagerPin: string | null;
65
+ };
66
+
67
+ type Progress = {
68
+ stop: (message: string) => void;
69
+ error: (message: string) => void;
55
70
  };
56
71
 
57
72
  type SpinnerStep = {
@@ -65,11 +80,18 @@ type SpinnerStep = {
65
80
  const selfVersion = packageManifest.version;
66
81
  const ICON_TEMPLATE_NAME = "icon.svg";
67
82
  const TYPESCRIPT_VERSION = "^6.0.3";
83
+ const DEPENDENCY_RANGES: Record<string, string | undefined> = {
84
+ ...(JSON.parse(readFileSync(new URL("../dependency-ranges.json", import.meta.url), "utf8")) as Record<
85
+ string,
86
+ string
87
+ >),
88
+ typescript: TYPESCRIPT_VERSION,
89
+ };
68
90
 
69
91
  const DEPENDENCIES = ["@gtkx/cairo", "@gtkx/css", "@gtkx/runtime", "@gtkx/react", "react"];
70
- const DEV_DEPENDENCIES = ["@gtkx/cli", "@gtkx/config", "@gtkx/mcp", "vite"];
71
- const TYPESCRIPT_DEV_DEPENDENCIES = ["@types/node", "@types/react", "typescript"];
72
- const TESTING_DEV_DEPENDENCIES = ["@gtkx/testing", "vitest"];
92
+ const DEV_DEPENDENCIES = ["@gtkx/cli", "@gtkx/config", "@gtkx/mcp", "@gtkx/testing", "@types/react", "vite"];
93
+ const TYPESCRIPT_DEV_DEPENDENCIES = ["@types/node", "typescript"];
94
+ const TESTING_DEV_DEPENDENCIES = ["vitest"];
73
95
 
74
96
  const DEV_COMMAND: Record<PackageManager, string> = Object.fromEntries(
75
97
  PACKAGE_MANAGERS.map((manager) => [manager.value, manager.devCommand]),
@@ -79,20 +101,31 @@ const INSTALL_COMMAND: Record<PackageManager, string> = Object.fromEntries(
79
101
  PACKAGE_MANAGERS.map((manager) => [manager.value, manager.installCommand]),
80
102
  ) as Record<PackageManager, string>;
81
103
 
104
+ const RUN_COMMAND: Record<PackageManager, string> = Object.fromEntries(
105
+ PACKAGE_MANAGERS.map((manager) => [manager.value, manager.runCommand]),
106
+ ) as Record<PackageManager, string>;
107
+
108
+ const TEST_COMMAND: Record<PackageManager, string> = Object.fromEntries(
109
+ PACKAGE_MANAGERS.map((manager) => [manager.value, manager.testCommand]),
110
+ ) as Record<PackageManager, string>;
111
+
82
112
  const INHERITED_SCRIPT_POLICY_VARS = ["npm_config_allow_scripts", "npm_config_allow-scripts"];
113
+ const LENIENT_PNPM_BUILDS_ENV = { pnpm_config_strict_dep_builds: "false" };
83
114
  const TESTING_TEMPLATES = new Set(["vitest.config.ts", "tests/app.test.tsx"]);
84
115
  const TYPESCRIPT_TEMPLATES = new Set(["tsconfig.json", "src/gtkx-env.d.ts"]);
85
116
 
86
117
  const APPLICATION_ID_FORMAT_ERROR = "Application ID must be reverse domain notation (e.g., com.example.myapp)";
118
+ const PACKAGE_NAME_FORMAT_ERROR = "Package name must be a valid npm package name: lowercase, no spaces (e.g., my-app)";
87
119
  const APPLICATION_ID_PREFIX = "com.";
88
120
  const APPLICATION_ID_SUFFIX = ".app";
89
121
 
90
122
  const APPLICATION_ID_SEGMENT_LIMIT =
91
123
  APPLICATION_ID_MAX_LENGTH - APPLICATION_ID_PREFIX.length - APPLICATION_ID_SUFFIX.length;
92
124
 
93
- const displayNameFromProjectName = (name: string): string =>
94
- name
95
- .split("-")
125
+ const displayNameFromDirectory = (directoryName: string): string =>
126
+ directoryName
127
+ .split(/[\s._-]+/)
128
+ .filter((part) => part.length > 0)
96
129
  .map((part) => upperFirst(part))
97
130
  .join(" ");
98
131
 
@@ -110,17 +143,23 @@ const gitConfigValue = (key: string): string | null => {
110
143
  }
111
144
  };
112
145
 
113
- const applicationIdSegment = (name: string): string => {
114
- const compact = name.replaceAll("-", "");
146
+ const compactIdentifier = (name: string): string => withoutAccents(name).replaceAll(/[^A-Za-z0-9_]/g, "");
147
+
148
+ const applicationIdSegment = (directoryName: string, name: string): string => {
149
+ const compact = compactIdentifier(directoryName) || compactIdentifier(name);
115
150
  const segment = /^[A-Za-z_]/.test(compact) ? compact : `_${compact}`;
116
151
 
117
152
  return segment.slice(0, APPLICATION_ID_SEGMENT_LIMIT);
118
153
  };
119
154
 
120
- const suggestApplicationId = (name: string): string =>
121
- `${APPLICATION_ID_PREFIX}${applicationIdSegment(name)}${APPLICATION_ID_SUFFIX}`;
155
+ const suggestApplicationId = (directoryName: string, name: string): string =>
156
+ `${APPLICATION_ID_PREFIX}${applicationIdSegment(directoryName, name)}${APPLICATION_ID_SUFFIX}`;
122
157
 
123
- const deriveProjectName = (target: string): string => basename(resolve(process.cwd(), target));
158
+ const HOME_PREFIX = /^~(?=$|\/)/;
159
+
160
+ const expandHome = (target: string): string => target.replace(HOME_PREFIX, () => homedir());
161
+
162
+ const directoryNameOf = (target: string): string => basename(resolve(process.cwd(), target));
124
163
 
125
164
  const isDirEmpty = (dir: string): boolean => {
126
165
  const entries = readdirSync(dir);
@@ -162,17 +201,14 @@ const guardCancellation = <T>(value: T | typeof p.CANCEL_SYMBOL): T => {
162
201
  return value;
163
202
  };
164
203
 
165
- const validateProjectName = (value: string | undefined): string | undefined => {
166
- if (!value) {
167
- return "Project name is required";
168
- }
204
+ const validatePackageNameFormat = (value: string): string | undefined =>
205
+ isValidPackageName(value) ? undefined : PACKAGE_NAME_FORMAT_ERROR;
169
206
 
170
- if (!isValidProjectName(value)) {
171
- return "Project name must be lowercase letters, numbers, and hyphens only";
172
- }
207
+ const validatePackageNameInput = (value: string | undefined): string | undefined =>
208
+ value ? validatePackageNameFormat(value) : "Package name is required";
173
209
 
174
- return undefined;
175
- };
210
+ const validatePackageNameAnswer = (value: string | undefined): string | undefined =>
211
+ value ? validatePackageNameFormat(value) : undefined;
176
212
 
177
213
  const validateApplicationIdFormat = (value: string): string | undefined =>
178
214
  isValidApplicationId(value) ? undefined : APPLICATION_ID_FORMAT_ERROR;
@@ -211,15 +247,11 @@ const requestedPackageManager = (value: string | undefined): PackageManager | un
211
247
  return value;
212
248
  };
213
249
 
214
- const validateTargetDir = (target: string): string | undefined => {
215
- if (!target) {
216
- return "Project directory is required";
217
- }
218
-
219
- return validateProjectName(deriveProjectName(target));
220
- };
250
+ const validateTargetDir = (target: string): string | undefined =>
251
+ target ? undefined : "Project directory is required";
221
252
 
222
- const validateTargetAnswer = (value: string | undefined): string | undefined => validateTargetDir(value ?? "");
253
+ const validateTargetAnswer = (value: string | undefined): string | undefined =>
254
+ validateTargetDir(expandHome(value ?? ""));
223
255
 
224
256
  const promptTarget = async (): Promise<string> =>
225
257
  guardCancellation(
@@ -230,8 +262,17 @@ const promptTarget = async (): Promise<string> =>
230
262
  }),
231
263
  );
232
264
 
233
- const promptApplicationId = async (name: string): Promise<string> => {
234
- const defaultApplicationId = suggestApplicationId(name);
265
+ const promptPackageName = async (derived: string): Promise<string> =>
266
+ guardCancellation(
267
+ await p.text({
268
+ message: "Package name",
269
+ ...(derived === "" ? {} : { placeholder: derived, defaultValue: derived }),
270
+ validate: derived === "" ? validatePackageNameInput : validatePackageNameAnswer,
271
+ }),
272
+ );
273
+
274
+ const promptApplicationId = async (directoryName: string, name: string): Promise<string> => {
275
+ const defaultApplicationId = suggestApplicationId(directoryName, name);
235
276
 
236
277
  return guardCancellation(
237
278
  await p.text({
@@ -243,8 +284,8 @@ const promptApplicationId = async (name: string): Promise<string> => {
243
284
  );
244
285
  };
245
286
 
246
- const promptDisplayName = async (name: string): Promise<string> => {
247
- const defaultDisplayName = displayNameFromProjectName(name);
287
+ const promptDisplayName = async (directoryName: string): Promise<string> => {
288
+ const defaultDisplayName = displayNameFromDirectory(directoryName);
248
289
 
249
290
  return guardCancellation(
250
291
  await p.text({
@@ -389,28 +430,50 @@ const validateTargetAvailability = async (
389
430
 
390
431
  const resolveTarget = async (options: CreateOptions): Promise<string> => {
391
432
  if (options.name === undefined && options.isInteractive) {
392
- return promptTarget();
433
+ return expandHome(await promptTarget());
393
434
  }
394
435
 
395
- const target = options.name ?? "";
436
+ const target = expandHome(options.name ?? "");
396
437
  const error = validateTargetDir(target);
397
438
 
398
439
  return error === undefined ? target : fail(error);
399
440
  };
400
441
 
401
- const resolveApplicationId = async (options: CreateOptions, name: string): Promise<string> => {
442
+ const resolvePackageName = async (options: CreateOptions, directoryName: string): Promise<string> => {
443
+ const derived = packageNameFromDirectory(directoryName);
444
+
445
+ if (derived === directoryName) {
446
+ return derived;
447
+ }
448
+
449
+ if (options.isInteractive) {
450
+ return promptPackageName(derived);
451
+ }
452
+
453
+ return derived === ""
454
+ ? fail(
455
+ `Directory name "${directoryName}" has no Latin letters or numbers to derive a package name from. ` +
456
+ "Rename it, or run interactively to enter a package name",
457
+ )
458
+ : derived;
459
+ };
460
+
461
+ const resolveApplicationId = async (options: CreateOptions, directoryName: string, name: string): Promise<string> => {
402
462
  const applicationId =
403
- options.applicationId ?? (options.isInteractive ? await promptApplicationId(name) : suggestApplicationId(name));
463
+ options.applicationId ??
464
+ (options.isInteractive
465
+ ? await promptApplicationId(directoryName, name)
466
+ : suggestApplicationId(directoryName, name));
404
467
 
405
468
  const error = validateApplicationIdInput(applicationId);
406
469
 
407
470
  return error === undefined ? applicationId : fail(error);
408
471
  };
409
472
 
410
- const resolveDisplayName = async (options: CreateOptions, name: string): Promise<string> => {
473
+ const resolveDisplayName = async (options: CreateOptions, directoryName: string): Promise<string> => {
411
474
  const value =
412
475
  options.displayName ??
413
- (options.isInteractive ? await promptDisplayName(name) : displayNameFromProjectName(name));
476
+ (options.isInteractive ? await promptDisplayName(directoryName) : displayNameFromDirectory(directoryName));
414
477
  const error = validateDisplayName(value);
415
478
 
416
479
  return error === undefined ? value.trim() : fail(error);
@@ -434,9 +497,10 @@ const resolvePackageManager = async (
434
497
  const resolveOptions = async (options: CreateOptions): Promise<ResolvedOptions> => {
435
498
  const requested = requestedPackageManager(options.packageManager);
436
499
  const target = await resolveTarget(options);
437
- const name = deriveProjectName(target);
438
- const displayName = await resolveDisplayName(options, name);
439
- const applicationId = await resolveApplicationId(options, name);
500
+ const directoryName = directoryNameOf(target);
501
+ const name = await resolvePackageName(options, directoryName);
502
+ const displayName = await resolveDisplayName(options, directoryName);
503
+ const applicationId = await resolveApplicationId(options, directoryName, name);
440
504
  const root = resolve(process.cwd(), target);
441
505
  const shouldInitialize = shouldInitializeGit(root);
442
506
  const packageManager = await resolvePackageManager(requested, options);
@@ -455,6 +519,7 @@ const resolveOptions = async (options: CreateOptions): Promise<ResolvedOptions>
455
519
  displayName,
456
520
  applicationId,
457
521
  packageManager,
522
+ workspace: enclosingWorkspace(root, packageManager),
458
523
  isTypescript,
459
524
  shouldIncludeTesting,
460
525
  shouldInitializeGit: shouldInitialize,
@@ -482,6 +547,17 @@ const destinationPath = (template: string, resolved: ResolvedOptions): string =>
482
547
  : scriptPath;
483
548
  };
484
549
 
550
+ const scriptCommands = ({
551
+ packageManager,
552
+ isTypescript,
553
+ shouldIncludeTesting,
554
+ }: Pick<ResolvedOptions, "packageManager" | "isTypescript" | "shouldIncludeTesting">): string[] => [
555
+ ...["dev", "build", "codegen", ...(isTypescript ? ["typecheck"] : [])].map(
556
+ (script) => `${RUN_COMMAND[packageManager]} ${script}`,
557
+ ),
558
+ ...(shouldIncludeTesting ? [TEST_COMMAND[packageManager]] : []),
559
+ ];
560
+
485
561
  const templateContext = (resolved: ResolvedOptions): TemplateContext => ({
486
562
  name: resolved.name,
487
563
  applicationId: resolved.applicationId,
@@ -491,6 +567,8 @@ const templateContext = (resolved: ResolvedOptions): TemplateContext => ({
491
567
  importExtension: resolved.isTypescript ? ".js" : ".jsx",
492
568
  developerName: gitConfigValue("user.name") ?? resolved.displayName,
493
569
  developerEmail: gitConfigValue("user.email"),
570
+ packageManager: resolved.packageManager,
571
+ scriptCommands: scriptCommands(resolved),
494
572
  });
495
573
 
496
574
  const assertSafeAncestor = (ancestor: string): void => {
@@ -549,22 +627,31 @@ const plannedScaffoldFiles = async (root: string, resolved: ResolvedOptions): Pr
549
627
  return files;
550
628
  };
551
629
 
552
- const auxiliaryDestinations = (root: string, resolved: ResolvedOptions): string[] =>
553
- resolved.packageManager === "pnpm" ? [join(root, "pnpm-workspace.yaml")] : [];
630
+ const configDestinations = (root: string, resolved: ResolvedOptions): string[] =>
631
+ resolved.workspace === null
632
+ ? PACKAGE_MANAGER_CONFIG_FILES[resolved.packageManager].map((file) => join(root, file))
633
+ : [];
554
634
 
555
635
  const planScaffoldProject = async (root: string, resolved: ResolvedOptions): Promise<ScaffoldPlan> => {
556
636
  const files = await plannedScaffoldFiles(root, resolved);
557
- const destinations = [...files.map((file) => file.destination), ...auxiliaryDestinations(root, resolved)];
558
- const replaceDestinations = destinations.filter((destination) => hasExistingDestination(root, destination));
637
+
638
+ for (const destination of configDestinations(root, resolved)) {
639
+ hasExistingDestination(root, destination);
640
+ }
641
+
642
+ const replaceDestinations = files
643
+ .map((file) => file.destination)
644
+ .filter((destination) => hasExistingDestination(root, destination));
559
645
 
560
646
  return {
561
647
  files,
562
648
  replaceDestinations,
563
649
  changes: replaceDestinations.map((destination) => relative(root, destination)),
650
+ packageManagerPin: packageManagerPin(root, resolved.packageManager, resolved.workspace !== null),
564
651
  };
565
652
  };
566
653
 
567
- const scaffoldProject = (plan: ScaffoldPlan): void => {
654
+ const scaffoldProject = (root: string, plan: ScaffoldPlan): void => {
568
655
  for (const destination of plan.replaceDestinations) {
569
656
  rmSync(destination);
570
657
  }
@@ -573,6 +660,14 @@ const scaffoldProject = (plan: ScaffoldPlan): void => {
573
660
  mkdirSync(dirname(file.destination), { recursive: true });
574
661
  writeFileSync(file.destination, file.contents);
575
662
  }
663
+
664
+ const pin = plan.packageManagerPin;
665
+
666
+ if (pin !== null) {
667
+ updateManifest(root, (manifest) => {
668
+ manifest.packageManager = pin;
669
+ });
670
+ }
576
671
  };
577
672
 
578
673
  const withoutInheritedScriptPolicy = async (run: () => Promise<void>): Promise<void> => {
@@ -600,55 +695,109 @@ const dependencyVersions = (names: string[]): Record<string, string> =>
600
695
  return [dependency, `^${selfVersion}`];
601
696
  }
602
697
 
603
- return [dependency, dependency === "typescript" ? TYPESCRIPT_VERSION : "latest"];
698
+ const range = DEPENDENCY_RANGES[dependency];
699
+
700
+ if (range === undefined) {
701
+ throw new Error(`No supported version range for ${dependency}`);
702
+ }
703
+
704
+ return [dependency, range];
604
705
  }),
605
706
  );
606
707
 
607
708
  const dependencyArguments = (names: string[]): string[] =>
608
- Object.entries(dependencyVersions(names)).map(([name, version]) =>
609
- version === "latest" ? name : `${name}@${version}`,
610
- );
709
+ Object.entries(dependencyVersions(names)).map(([name, version]) => `${name}@${version}`);
710
+
711
+ const declaredDependencies = (value: unknown): Record<string, unknown> =>
712
+ typeof value === "object" && value !== null ? { ...value } : {};
611
713
 
612
714
  const writeDependencies = (root: string, devDependencies: string[]): void => {
613
715
  updateManifest(root, (manifest) => {
614
- manifest.dependencies = dependencyVersions(DEPENDENCIES);
615
- manifest.devDependencies = dependencyVersions(devDependencies);
716
+ manifest.dependencies = {
717
+ ...dependencyVersions(DEPENDENCIES),
718
+ ...declaredDependencies(manifest.dependencies),
719
+ };
720
+ manifest.devDependencies = {
721
+ ...dependencyVersions(devDependencies),
722
+ ...declaredDependencies(manifest.devDependencies),
723
+ };
616
724
  });
617
725
  };
618
726
 
619
727
  const formatRecovery = (resolved: ResolvedOptions): string =>
620
728
  `To finish setup, run ${INSTALL_COMMAND[resolved.packageManager]} in ${resolved.root}.`;
621
729
 
730
+ const startProgress = (message: string): Progress => {
731
+ if (process.stdout.isTTY) {
732
+ const spinner = p.spinner();
733
+ spinner.start(message);
734
+
735
+ return spinner;
736
+ }
737
+
738
+ p.log.step(message);
739
+
740
+ return { stop: (done) => p.log.step(done), error: (failed) => p.log.error(failed) };
741
+ };
742
+
622
743
  const runWithSpinner = async (step: SpinnerStep): Promise<void> => {
623
- const spinner = p.spinner();
624
- spinner.start(step.pending);
744
+ const progress = startProgress(step.pending);
625
745
 
626
746
  try {
627
747
  await step.run();
628
- spinner.stop(step.done);
748
+ progress.stop(step.done);
629
749
  } catch (error) {
630
- spinner.error(step.failed);
750
+ progress.error(step.failed);
631
751
  p.log.error(errorMessage(error));
632
752
  step.explain?.();
633
753
  throw new ScaffoldAbortedError(step.failed);
634
754
  }
635
755
  };
636
756
 
757
+ const printWorkspaceAllowances = ({ root, packageManager, workspace }: ResolvedOptions): void => {
758
+ const installed = workspace === null ? null : enclosingWorkspace(root, packageManager);
759
+
760
+ if (installed === null || installed.missingSettings.length === 0) {
761
+ return;
762
+ }
763
+
764
+ p.log.warn(
765
+ `The ${installed.packageManager} workspace lacks settings this app needs. ` +
766
+ `Set these entries, then run ${INSTALL_COMMAND[installed.packageManager]}:\n\n` +
767
+ installed.missingSettings
768
+ .map(
769
+ ({ file, section, entries }) =>
770
+ `${section === null ? file : `${file} (under ${section})`}:\n${entries}`,
771
+ )
772
+ .join("\n\n"),
773
+ );
774
+ };
775
+
776
+ const hasMissingAllowances = (resolved: ResolvedOptions): boolean =>
777
+ resolved.workspace?.packageManager === "pnpm" && resolved.workspace.missingSettings.length > 0;
778
+
637
779
  const installAllDependencies = async (resolved: ResolvedOptions, devDependencies: string[]): Promise<void> => {
638
780
  const { root, packageManager } = resolved;
781
+ const env = hasMissingAllowances(resolved) ? LENIENT_PNPM_BUILDS_ENV : {};
639
782
 
640
783
  await runWithSpinner({
641
784
  pending: "Installing dependencies...",
642
785
  done: "Dependencies installed",
643
786
  failed: "Failed to install dependencies",
644
787
  run: async () => {
645
- await withoutInheritedScriptPolicy(async () => {
646
- const options = { cwd: root, packageManager, silent: true };
647
- await addDependency(dependencyArguments(DEPENDENCIES), options);
648
- await addDependency(dependencyArguments(devDependencies), { ...options, dev: true });
649
- });
788
+ try {
789
+ await withoutInheritedScriptPolicy(async () => {
790
+ const options = { cwd: root, packageManager, env, silent: true };
791
+ await addDependency(dependencyArguments(DEPENDENCIES), options);
792
+ await addDependency(dependencyArguments(devDependencies), { ...options, dev: true });
793
+ });
794
+ } catch (error) {
795
+ writeDependencies(root, devDependencies);
796
+ throw error;
797
+ }
650
798
  },
651
799
  explain: () => {
800
+ printWorkspaceAllowances(resolved);
652
801
  p.log.info(formatRecovery(resolved));
653
802
  },
654
803
  });
@@ -675,17 +824,16 @@ const initializeGitRepo = async (root: string, shouldInitialize: boolean): Promi
675
824
  return;
676
825
  }
677
826
 
678
- const spinner = p.spinner();
679
- spinner.start("Initializing git repository...");
827
+ const progress = startProgress("Initializing git repository...");
680
828
 
681
829
  try {
682
830
  const opts = { nodeOptions: { cwd: root }, throwOnError: true } as const;
683
831
  await x("git", ["init"], opts);
684
832
  await x("git", ["add", "-A"], opts);
685
833
  await x("git", ["commit", "-m", "Initial commit"], opts);
686
- spinner.stop("Git repository initialized");
834
+ progress.stop("Git repository initialized");
687
835
  } catch {
688
- spinner.error("Failed to initialize git repository");
836
+ progress.error("Failed to initialize git repository");
689
837
  }
690
838
  };
691
839
 
@@ -699,6 +847,33 @@ const missingHeadlessToolsNote = (): string => {
699
847
  : ["", "", "To run tests, install these tools:", ...missingToolLines(missing)].join("\n");
700
848
  };
701
849
 
850
+ const addRootMcpServer = ({ workspace, name, root }: ResolvedOptions): void => {
851
+ if (workspace === null) {
852
+ return;
853
+ }
854
+
855
+ const result = addWorkspaceMcpServer(workspace, name);
856
+
857
+ if (result.kind === "added") {
858
+ p.log.info(
859
+ `Added the MCP server "${result.key}" to ${result.path}, so an AI client opened at the workspace ` +
860
+ "root reaches this app.",
861
+ );
862
+ } else if (result.kind === "shared") {
863
+ p.log.info(
864
+ `The MCP server "${result.key}" in ${result.path} drives every running GTKX app, including this one, ` +
865
+ `so no server was added for it. To look up this app's bindings, pass projectRoot "${root}" to its ` +
866
+ "reference tools.",
867
+ );
868
+ } else if (result.kind === "unreadable") {
869
+ p.log.warn(
870
+ `Could not add this app's MCP server to ${result.path}: ${result.reason}. For an AI client opened ` +
871
+ `at the workspace root, add this entry under "mcpServers":\n\n` +
872
+ JSON.stringify({ [result.key]: result.server }, null, 4),
873
+ );
874
+ }
875
+ };
876
+
702
877
  const printNextSteps = (resolved: ResolvedOptions): void => {
703
878
  const devCmd = DEV_COMMAND[resolved.packageManager];
704
879
  const installStep = resolved.shouldInstallDependencies ? "" : `${INSTALL_COMMAND[resolved.packageManager]}\n`;
@@ -713,8 +888,11 @@ const createProjectStructure = async (root: string, resolved: ResolvedOptions, p
713
888
  failed: "Failed to create the project structure",
714
889
  run: () => {
715
890
  mkdirSync(root, { recursive: true });
716
- scaffoldProject(plan);
717
- writeBuildAllowance(root, resolved.packageManager);
891
+ scaffoldProject(root, plan);
892
+
893
+ if (resolved.workspace === null) {
894
+ writePackageManagerSettings(root, resolved.packageManager);
895
+ }
718
896
  },
719
897
  });
720
898
  };
@@ -730,12 +908,14 @@ const scaffold = async (options: CreateOptions = {}): Promise<void> => {
730
908
  await createProjectStructure(root, resolved, plan);
731
909
  writeDependencies(root, devDeps);
732
910
  reportCompletedChanges(plan.changes);
911
+ addRootMcpServer(resolved);
733
912
 
734
913
  if (resolved.shouldInstallDependencies) {
735
914
  await installAllDependencies(resolved, devDeps);
736
915
  }
737
916
 
738
917
  await initializeGitRepo(root, resolved.shouldInitializeGit);
918
+ printWorkspaceAllowances(resolved);
739
919
  printNextSteps(resolved);
740
920
  };
741
921
 
@@ -3,9 +3,10 @@
3
3
  "allow": [
4
4
  "Bash(npx gtkx codegen:*)",
5
5
  "Bash(npx gtkx dev:*)",
6
- "Bash(npx gtkx build:*)",
7
- "Bash(npx tsc --noEmit)"<% if (shouldIncludeTesting) { %>,
8
- "Bash(npx vitest run:*)"<% } %>
6
+ "Bash(npx gtkx build:*)"<% if (isTypescript) { %>,
7
+ "Bash(npx tsc --noEmit)"<% } %><% if (shouldIncludeTesting) { %>,
8
+ "Bash(npx vitest run:*)"<% } %><% for (const command of scriptCommands) { %>,
9
+ "Bash(<%= command %>:*)"<% } %>
9
10
  ],
10
11
  "deny": [],
11
12
  "ask": []
@@ -2,4 +2,8 @@ node_modules/
2
2
  dist/
3
3
  build/
4
4
  .gtkx/
5
+ *.d.xml.ts
5
6
  *.log
7
+ <% if (packageManager === "yarn") { -%>
8
+ .yarn/install-state.gz
9
+ <% } -%>
@@ -2,7 +2,7 @@
2
2
  "mcpServers": {
3
3
  "gtkx": {
4
4
  "command": "npx",
5
- "args": ["gtkx", "mcp"]
5
+ "args": ["--no", "gtkx", "mcp"]
6
6
  }
7
7
  }
8
8
  }
@@ -14,7 +14,7 @@ const MainWindow = () => {
14
14
  defaultHeight={300}
15
15
  onCloseRequest={quit}
16
16
  >
17
- <AdwToolbarView topBar={<AdwHeaderBar />}>
17
+ <AdwToolbarView top={<AdwHeaderBar />}>
18
18
  <GtkBox
19
19
  orientation={Gtk.Orientation.VERTICAL}
20
20
  spacing={20}
@@ -1,2 +1 @@
1
1
  /// <reference types="@gtkx/cli/env" />
2
- /// <reference path="../node_modules/.gtkx/env.d.ts" />
@@ -7,6 +7,7 @@
7
7
  "strict": true,
8
8
  "skipLibCheck": true,
9
9
  "resolveJsonModule": true,
10
+ "allowArbitraryExtensions": true,
10
11
  "lib": ["esnext"],
11
12
  "types": ["node", "react"],
12
13
  "noEmit": true,
@@ -15,9 +16,10 @@
15
16
  "@gtkx/jsx/*": ["./node_modules/.gtkx/jsx/*/index.d.ts", "./node_modules/.gtkx/jsx/*.d.ts"]
16
17
  }
17
18
  },
19
+ "files": ["node_modules/.gtkx/env.d.ts"],
18
20
  <% if (shouldIncludeTesting) { -%>
19
- "include": ["src/**/*", "tests/**/*"]
21
+ "include": ["src/**/*", "tests/**/*", "gtkx.config.ts", "vitest.config.ts"]
20
22
  <% } else { -%>
21
- "include": ["src/**/*"]
23
+ "include": ["src/**/*", "gtkx.config.ts"]
22
24
  <% } -%>
23
25
  }