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

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 (40) hide show
  1. package/README.md +8 -166
  2. package/dist/build-allowance.d.ts.map +1 -1
  3. package/dist/build-allowance.js +6 -5
  4. package/dist/build-allowance.js.map +1 -1
  5. package/dist/cli.js +1 -1
  6. package/dist/cli.js.map +1 -1
  7. package/dist/command.d.ts +3 -2
  8. package/dist/command.d.ts.map +1 -1
  9. package/dist/command.js +93 -90
  10. package/dist/command.js.map +1 -1
  11. package/dist/errors.d.ts.map +1 -1
  12. package/dist/manifest.d.ts.map +1 -1
  13. package/dist/manifest.js +2 -10
  14. package/dist/manifest.js.map +1 -1
  15. package/dist/package-managers.d.ts +0 -3
  16. package/dist/package-managers.d.ts.map +1 -1
  17. package/dist/package-managers.js +0 -3
  18. package/dist/package-managers.js.map +1 -1
  19. package/dist/project-name.d.ts.map +1 -1
  20. package/dist/scaffolder.d.ts.map +1 -1
  21. package/dist/scaffolder.js +51 -158
  22. package/dist/scaffolder.js.map +1 -1
  23. package/dist/templates/gtkx.config.ts.ejs +2 -2
  24. package/dist/templates/package.json.ejs +4 -1
  25. package/dist/templates.d.ts.map +1 -1
  26. package/dist/templates.js.map +1 -1
  27. package/package.json +16 -39
  28. package/src/build-allowance.ts +6 -7
  29. package/src/cli.ts +1 -1
  30. package/src/command.ts +114 -110
  31. package/src/manifest.ts +2 -10
  32. package/src/package-managers.ts +0 -3
  33. package/src/scaffolder.ts +83 -255
  34. package/src/templates/gtkx.config.ts.ejs +2 -2
  35. package/src/templates/package.json.ejs +4 -1
  36. package/dist/install-hints.d.ts +0 -3
  37. package/dist/install-hints.d.ts.map +0 -1
  38. package/dist/install-hints.js +0 -35
  39. package/dist/install-hints.js.map +0 -1
  40. package/src/install-hints.ts +0 -54
package/src/scaffolder.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  import * as p from "@clack/prompts";
2
2
  import { APPLICATION_ID_MAX_LENGTH, isValidApplicationId } from "@gtkx/config/internal";
3
- import { errorMessage, tryResolveExecutable, upperFirst } from "@gtkx/utils";
3
+ import { errorMessage, HEADLESS_DISPLAY_TOOLS, missingToolLines, tryResolveExecutable, upperFirst } from "@gtkx/utils";
4
4
  import { execFileSync } from "node:child_process";
5
5
  import { lstatSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
6
- import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
6
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
7
7
  import { addDependency, detectPackageManager as nypmDetectPackageManager } from "nypm";
8
8
  import { x } from "tinyexec";
9
9
  import packageManifest from "../package.json" with { type: "json" };
10
10
  import { writeBuildAllowance } from "./build-allowance.js";
11
11
  import { OperationCanceledError, ScaffoldAbortedError } from "./errors.js";
12
- import { getInstallHint } from "./install-hints.js";
13
12
  import { updateManifest } from "./manifest.js";
14
13
  import {
15
14
  isKnownPackageManager,
@@ -35,7 +34,6 @@ type CreateOptions = {
35
34
  type ResolvedOptions = {
36
35
  target: string;
37
36
  root: string;
38
- isCurrentDirectory: boolean;
39
37
  name: string;
40
38
  displayName: string;
41
39
  applicationId: string;
@@ -56,45 +54,18 @@ type ScaffoldPlan = {
56
54
  changes: ScaffoldChanges;
57
55
  };
58
56
 
59
- type ScaffoldChange = {
60
- destination: string;
61
- relativePath: string;
62
- };
63
-
64
- type InstallDependenciesOptions = {
65
- cwd: string;
66
- packageManager: PackageManager;
67
- dependencies: string[];
68
- isDev: boolean;
69
- };
70
-
71
- type InstallAllOptions = {
72
- resolved: ResolvedOptions;
73
- devDependencies: string[];
74
- };
75
-
76
- type InstallFailureOptions = {
77
- error: unknown;
78
- resolved: ResolvedOptions;
79
- devDependencies: string[];
80
- };
81
-
82
57
  type SpinnerStep = {
83
58
  pending: string;
84
59
  done: string;
85
60
  failed: string;
86
61
  run: () => Promise<void> | void;
87
- explain?: ((error: unknown) => void) | undefined;
62
+ explain?: (() => void) | undefined;
88
63
  };
89
64
 
90
65
  const selfVersion = packageManifest.version;
91
66
  const ICON_TEMPLATE_NAME = "icon.svg";
92
67
  const TYPESCRIPT_VERSION = "^6.0.3";
93
68
 
94
- const GTKX_ENV_MODULE_HEADER = `/**
95
- * Generated by \`gtkx codegen\`, \`gtkx dev\`, and \`gtkx build\`; do not edit.
96
- */`;
97
-
98
69
  const DEPENDENCIES = ["@gtkx/cairo", "@gtkx/css", "@gtkx/runtime", "@gtkx/react", "react"];
99
70
  const DEV_DEPENDENCIES = ["@gtkx/cli", "@gtkx/config", "@gtkx/mcp", "vite"];
100
71
  const TYPESCRIPT_DEV_DEPENDENCIES = ["@types/node", "@types/react", "typescript"];
@@ -104,10 +75,6 @@ const DEV_COMMAND: Record<PackageManager, string> = Object.fromEntries(
104
75
  PACKAGE_MANAGERS.map((manager) => [manager.value, manager.devCommand]),
105
76
  ) as Record<PackageManager, string>;
106
77
 
107
- const ADD_COMMAND: Record<PackageManager, string> = Object.fromEntries(
108
- PACKAGE_MANAGERS.map((manager) => [manager.value, manager.addCommand]),
109
- ) as Record<PackageManager, string>;
110
-
111
78
  const INSTALL_COMMAND: Record<PackageManager, string> = Object.fromEntries(
112
79
  PACKAGE_MANAGERS.map((manager) => [manager.value, manager.installCommand]),
113
80
  ) as Record<PackageManager, string>;
@@ -116,22 +83,18 @@ const INHERITED_SCRIPT_POLICY_VARS = ["npm_config_allow_scripts", "npm_config_al
116
83
  const TESTING_TEMPLATES = new Set(["vitest.config.ts", "tests/app.test.tsx"]);
117
84
  const TYPESCRIPT_TEMPLATES = new Set(["tsconfig.json", "src/gtkx-env.d.ts"]);
118
85
 
119
- const HEADLESS_COMPOSITOR_NOTE = `
120
-
121
- To run tests, you need a headless Wayland compositor installed:
122
- Fedora: sudo dnf install sway
123
- Ubuntu: sudo apt install sway`;
124
-
125
- const RECOVERY_HEADING = "Finish the setup by adding the dependencies again, which is safe to repeat:";
126
86
  const APPLICATION_ID_FORMAT_ERROR = "Application ID must be reverse domain notation (e.g., com.example.myapp)";
127
87
  const APPLICATION_ID_PREFIX = "com.";
128
88
  const APPLICATION_ID_SUFFIX = ".app";
129
89
 
130
- const APPLICATION_ID_SEGMENT_LIMIT = APPLICATION_ID_MAX_LENGTH - APPLICATION_ID_PREFIX.length -
131
- APPLICATION_ID_SUFFIX.length;
90
+ const APPLICATION_ID_SEGMENT_LIMIT =
91
+ APPLICATION_ID_MAX_LENGTH - APPLICATION_ID_PREFIX.length - APPLICATION_ID_SUFFIX.length;
132
92
 
133
93
  const displayNameFromProjectName = (name: string): string =>
134
- name.split("-").map((part) => upperFirst(part)).join(" ");
94
+ name
95
+ .split("-")
96
+ .map((part) => upperFirst(part))
97
+ .join(" ");
135
98
 
136
99
  const gitConfigValue = (key: string): string | null => {
137
100
  const git = tryResolveExecutable("git");
@@ -157,19 +120,6 @@ const applicationIdSegment = (name: string): string => {
157
120
  const suggestApplicationId = (name: string): string =>
158
121
  `${APPLICATION_ID_PREFIX}${applicationIdSegment(name)}${APPLICATION_ID_SUFFIX}`;
159
122
 
160
- const stripTrailingSlashes = (value: string): string => {
161
- let end = value.length;
162
-
163
- while (end > 0 && value[end - 1] === "/") {
164
- end--;
165
- }
166
-
167
- return value.slice(0, end);
168
- };
169
-
170
- const formatTargetDir = (target: string): string =>
171
- stripTrailingSlashes(target.trim().replaceAll(/[<>:"\\|?*]/g, ""));
172
-
173
123
  const deriveProjectName = (target: string): string => basename(resolve(process.cwd(), target));
174
124
 
175
125
  const isDirEmpty = (dir: string): boolean => {
@@ -201,9 +151,9 @@ const getDevDependencies = ({
201
151
  return devDeps;
202
152
  };
203
153
 
204
- const isCancellation = (value: unknown): value is symbol => p.isCancel(value);
154
+ const isCancellation = (value: unknown): value is typeof p.CANCEL_SYMBOL => p.isCancel(value);
205
155
 
206
- const guardCancellation = <T>(value: T | symbol): T => {
156
+ const guardCancellation = <T>(value: T | typeof p.CANCEL_SYMBOL): T => {
207
157
  if (isCancellation(value)) {
208
158
  p.cancel("Operation canceled");
209
159
  throw new OperationCanceledError();
@@ -269,18 +219,15 @@ const validateTargetDir = (target: string): string | undefined => {
269
219
  return validateProjectName(deriveProjectName(target));
270
220
  };
271
221
 
272
- const validateTargetAnswer = (value: string | undefined): string | undefined =>
273
- validateTargetDir(formatTargetDir(value ?? ""));
222
+ const validateTargetAnswer = (value: string | undefined): string | undefined => validateTargetDir(value ?? "");
274
223
 
275
224
  const promptTarget = async (): Promise<string> =>
276
- formatTargetDir(
277
- guardCancellation(
278
- await p.text({
279
- message: "Project directory",
280
- placeholder: "my-app",
281
- validate: validateTargetAnswer,
282
- }),
283
- ),
225
+ guardCancellation(
226
+ await p.text({
227
+ message: "Project directory",
228
+ placeholder: "my-app",
229
+ validate: validateTargetAnswer,
230
+ }),
284
231
  );
285
232
 
286
233
  const promptApplicationId = async (name: string): Promise<string> => {
@@ -348,11 +295,7 @@ const isOptionEnabled = async (
348
295
  value: boolean | undefined,
349
296
  isInteractive: boolean | undefined,
350
297
  message: string,
351
- ): Promise<boolean> =>
352
- value ??
353
- (isInteractive
354
- ? guardCancellation(await p.confirm({ message, initialValue: true }))
355
- : true);
298
+ ): Promise<boolean> => value ?? (!isInteractive || guardCancellation(await p.confirm({ message, initialValue: true })));
356
299
 
357
300
  const formatFileList = (heading: string, files: string[]): string => {
358
301
  const indentedFiles = files.map((file) => ` ${file}`).join("\n");
@@ -418,7 +361,11 @@ const acceptNonEmptyDirectory = async (
418
361
  };
419
362
 
420
363
  const assertTargetIsDirectory = (root: string, target: string): void => {
421
- const stats = statSync(root, { throwIfNoEntry: false });
364
+ const stats = lstatSync(root, { throwIfNoEntry: false });
365
+
366
+ if (stats?.isSymbolicLink()) {
367
+ fail(`Cannot scaffold through a symbolic link: ${root}`);
368
+ }
422
369
 
423
370
  if (stats !== undefined && !stats.isDirectory()) {
424
371
  fail(`Target "${target}" is not a directory`);
@@ -432,7 +379,6 @@ const validateTargetAvailability = async (
432
379
  changes: ScaffoldChanges,
433
380
  ): Promise<void> => {
434
381
  const stats = statSync(root, { throwIfNoEntry: false });
435
- assertTargetIsDirectory(root, target);
436
382
 
437
383
  if (stats === undefined || isDirEmpty(root)) {
438
384
  return;
@@ -446,15 +392,15 @@ const resolveTarget = async (options: CreateOptions): Promise<string> => {
446
392
  return promptTarget();
447
393
  }
448
394
 
449
- const target = formatTargetDir(options.name ?? "");
395
+ const target = options.name ?? "";
450
396
  const error = validateTargetDir(target);
451
397
 
452
398
  return error === undefined ? target : fail(error);
453
399
  };
454
400
 
455
401
  const resolveApplicationId = async (options: CreateOptions, name: string): Promise<string> => {
456
- const applicationId = options.applicationId ??
457
- (options.isInteractive ? await promptApplicationId(name) : suggestApplicationId(name));
402
+ const applicationId =
403
+ options.applicationId ?? (options.isInteractive ? await promptApplicationId(name) : suggestApplicationId(name));
458
404
 
459
405
  const error = validateApplicationIdInput(applicationId);
460
406
 
@@ -462,7 +408,8 @@ const resolveApplicationId = async (options: CreateOptions, name: string): Promi
462
408
  };
463
409
 
464
410
  const resolveDisplayName = async (options: CreateOptions, name: string): Promise<string> => {
465
- const value = options.displayName ??
411
+ const value =
412
+ options.displayName ??
466
413
  (options.isInteractive ? await promptDisplayName(name) : displayNameFromProjectName(name));
467
414
  const error = validateDisplayName(value);
468
415
 
@@ -491,7 +438,6 @@ const resolveOptions = async (options: CreateOptions): Promise<ResolvedOptions>
491
438
  const displayName = await resolveDisplayName(options, name);
492
439
  const applicationId = await resolveApplicationId(options, name);
493
440
  const root = resolve(process.cwd(), target);
494
- const isCurrentDirectory = root === process.cwd();
495
441
  const shouldInitialize = shouldInitializeGit(root);
496
442
  const packageManager = await resolvePackageManager(requested, options);
497
443
  const isTypescript = await isOptionEnabled(options.isTypescript, options.isInteractive, "Use TypeScript?");
@@ -505,7 +451,6 @@ const resolveOptions = async (options: CreateOptions): Promise<ResolvedOptions>
505
451
  return {
506
452
  target,
507
453
  root,
508
- isCurrentDirectory,
509
454
  name,
510
455
  displayName,
511
456
  applicationId,
@@ -548,40 +493,6 @@ const templateContext = (resolved: ResolvedOptions): TemplateContext => ({
548
493
  developerEmail: gitConfigValue("user.email"),
549
494
  });
550
495
 
551
- const replaceTemplateDestination = (destination: string): void => {
552
- const entry = lstatSync(destination, { throwIfNoEntry: false });
553
-
554
- if (entry === undefined) {
555
- return;
556
- }
557
-
558
- if (!entry.isFile() && !entry.isSymbolicLink()) {
559
- fail(`Cannot replace scaffold file because its destination is not a file: ${destination}`);
560
- }
561
-
562
- rmSync(destination, { force: true });
563
- };
564
-
565
- const projectRelativeDestination = (root: string, destination: string): string => {
566
- const relativePath = relative(root, destination);
567
- const isOutsideProject = relativePath.length === 0 || relativePath.startsWith(`..${sep}`) ||
568
- isAbsolute(relativePath);
569
-
570
- if (isOutsideProject) {
571
- fail(`Scaffold destination is outside the project: ${destination}`);
572
- }
573
-
574
- return relativePath;
575
- };
576
-
577
- const assertRootIsNotSymbolicLink = (root: string): void => {
578
- const rootEntry = lstatSync(root, { throwIfNoEntry: false });
579
-
580
- if (rootEntry?.isSymbolicLink()) {
581
- fail(`Cannot scaffold through a symbolic link: ${root}`);
582
- }
583
- };
584
-
585
496
  const assertSafeAncestor = (ancestor: string): void => {
586
497
  const entry = lstatSync(ancestor, { throwIfNoEntry: false });
587
498
 
@@ -605,20 +516,21 @@ const assertSafeAncestors = (root: string, relativePath: string): void => {
605
516
  }
606
517
  };
607
518
 
608
- const assertReplaceableDestination = (destination: string): void => {
519
+ const hasReplaceableDestination = (destination: string): boolean => {
609
520
  const entry = lstatSync(destination, { throwIfNoEntry: false });
610
521
  const isReplaceable = entry === undefined || entry.isFile() || entry.isSymbolicLink();
611
522
 
612
523
  if (!isReplaceable) {
613
524
  fail(`Cannot replace scaffold file because its destination is not a file: ${destination}`);
614
525
  }
526
+
527
+ return entry !== undefined;
615
528
  };
616
529
 
617
- const assertSafeDestination = (root: string, destination: string): void => {
618
- const relativePath = projectRelativeDestination(root, destination);
619
- assertRootIsNotSymbolicLink(root);
620
- assertSafeAncestors(root, relativePath);
621
- assertReplaceableDestination(destination);
530
+ const hasExistingDestination = (root: string, destination: string): boolean => {
531
+ assertSafeAncestors(root, relative(root, destination));
532
+
533
+ return hasReplaceableDestination(destination);
622
534
  };
623
535
 
624
536
  const plannedScaffoldFiles = async (root: string, resolved: ResolvedOptions): Promise<ScaffoldFile[]> => {
@@ -640,75 +552,27 @@ const plannedScaffoldFiles = async (root: string, resolved: ResolvedOptions): Pr
640
552
  const auxiliaryDestinations = (root: string, resolved: ResolvedOptions): string[] =>
641
553
  resolved.packageManager === "pnpm" ? [join(root, "pnpm-workspace.yaml")] : [];
642
554
 
643
- const envModulePath = (root: string): string => join(root, "node_modules", ".gtkx", "env.d.ts");
644
-
645
- const shouldWriteEnvModule = (resolved: ResolvedOptions): boolean =>
646
- resolved.isTypescript && resolved.shouldInstallDependencies;
647
-
648
- const generatedDestinations = (root: string, resolved: ResolvedOptions): string[] =>
649
- shouldWriteEnvModule(resolved) ? [envModulePath(root)] : [];
650
-
651
- const isPresent = (path: string): boolean => lstatSync(path, { throwIfNoEntry: false }) !== undefined;
652
-
653
- const classifyScaffoldChange = (
654
- root: string,
655
- destination: string,
656
- ): ScaffoldChange | undefined => {
657
- const entry = lstatSync(destination, { throwIfNoEntry: false });
658
-
659
- if (entry === undefined) {
660
- return undefined;
661
- }
662
-
663
- return { destination, relativePath: projectRelativeDestination(root, destination) };
664
- };
665
-
666
- const addScaffoldChange = (plan: ScaffoldPlan, change: ScaffoldChange | undefined): void => {
667
- if (change === undefined) {
668
- return;
669
- }
670
-
671
- plan.replaceDestinations.push(change.destination);
672
- plan.changes.push(change.relativePath);
673
- };
674
-
675
555
  const planScaffoldProject = async (root: string, resolved: ResolvedOptions): Promise<ScaffoldPlan> => {
676
556
  const files = await plannedScaffoldFiles(root, resolved);
677
- const reported = [...files.map((file) => file.destination), ...auxiliaryDestinations(root, resolved)];
678
- const generated = generatedDestinations(root, resolved);
679
-
680
- for (const destination of [...reported, ...generated]) {
681
- assertSafeDestination(root, destination);
682
- }
557
+ const destinations = [...files.map((file) => file.destination), ...auxiliaryDestinations(root, resolved)];
558
+ const replaceDestinations = destinations.filter((destination) => hasExistingDestination(root, destination));
683
559
 
684
- const plan: ScaffoldPlan = {
560
+ return {
685
561
  files,
686
- replaceDestinations: generated.filter((destination) => isPresent(destination)),
687
- changes: [],
562
+ replaceDestinations,
563
+ changes: replaceDestinations.map((destination) => relative(root, destination)),
688
564
  };
689
-
690
- for (const destination of reported) {
691
- addScaffoldChange(plan, classifyScaffoldChange(root, destination));
692
- }
693
-
694
- return plan;
695
565
  };
696
566
 
697
- const scaffoldProject = (root: string, resolved: ResolvedOptions, plan: ScaffoldPlan): void => {
567
+ const scaffoldProject = (plan: ScaffoldPlan): void => {
698
568
  for (const destination of plan.replaceDestinations) {
699
- replaceTemplateDestination(destination);
569
+ rmSync(destination);
700
570
  }
701
571
 
702
572
  for (const file of plan.files) {
703
573
  mkdirSync(dirname(file.destination), { recursive: true });
704
574
  writeFileSync(file.destination, file.contents);
705
575
  }
706
-
707
- if (resolved.shouldIncludeTesting) {
708
- updateManifest(root, (manifest) => {
709
- (manifest.scripts as Record<string, string>).test = "vitest run";
710
- });
711
- }
712
576
  };
713
577
 
714
578
  const withoutInheritedScriptPolicy = async (run: () => Promise<void>): Promise<void> => {
@@ -729,32 +593,21 @@ const withoutInheritedScriptPolicy = async (run: () => Promise<void>): Promise<v
729
593
  }
730
594
  };
731
595
 
732
- const installDependencies = async (options: InstallDependenciesOptions): Promise<void> => {
733
- const { cwd, packageManager, dependencies, isDev } = options;
734
-
735
- await withoutInheritedScriptPolicy(async () => {
736
- await addDependency(dependencies, { cwd, packageManager, dev: isDev, silent: true });
737
- });
738
- };
739
-
740
- const pin = (names: string[]): string[] =>
741
- names.map((dependency) => {
742
- if (dependency.startsWith("@gtkx/")) {
743
- return `${dependency}@^${selfVersion}`;
744
- }
745
-
746
- return dependency === "typescript" ? `${dependency}@${TYPESCRIPT_VERSION}` : dependency;
747
- });
596
+ const dependencyVersions = (names: string[]): Record<string, string> =>
597
+ Object.fromEntries(
598
+ names.map((dependency) => {
599
+ if (dependency.startsWith("@gtkx/")) {
600
+ return [dependency, `^${selfVersion}`];
601
+ }
748
602
 
749
- const dependencyVersions = (names: string[]): Record<string, string> => Object.fromEntries(
750
- names.map((dependency) => {
751
- if (dependency.startsWith("@gtkx/")) {
752
- return [dependency, `^${selfVersion}`];
753
- }
603
+ return [dependency, dependency === "typescript" ? TYPESCRIPT_VERSION : "latest"];
604
+ }),
605
+ );
754
606
 
755
- return [dependency, dependency === "typescript" ? TYPESCRIPT_VERSION : "latest"];
756
- }),
757
- );
607
+ const dependencyArguments = (names: string[]): string[] =>
608
+ Object.entries(dependencyVersions(names)).map(([name, version]) =>
609
+ version === "latest" ? name : `${name}@${version}`,
610
+ );
758
611
 
759
612
  const writeDependencies = (root: string, devDependencies: string[]): void => {
760
613
  updateManifest(root, (manifest) => {
@@ -763,29 +616,8 @@ const writeDependencies = (root: string, devDependencies: string[]): void => {
763
616
  });
764
617
  };
765
618
 
766
- const formatRecovery = ({ resolved, devDependencies }: InstallFailureOptions): string => {
767
- const add = ADD_COMMAND[resolved.packageManager];
768
-
769
- const steps = [
770
- ...(resolved.isCurrentDirectory ? [] : [`cd ${resolved.target}`]),
771
- `${add} ${pin(DEPENDENCIES).join(" ")}`,
772
- `${add} -D ${pin(devDependencies).join(" ")}`,
773
- ];
774
-
775
- const indented = steps.map((step) => ` ${step}`).join("\n");
776
-
777
- return `${RECOVERY_HEADING}\n${indented}`;
778
- };
779
-
780
- const explainInstallFailure = (options: InstallFailureOptions): void => {
781
- const hint = getInstallHint(errorMessage(options.error));
782
-
783
- if (hint !== undefined) {
784
- p.log.warn(hint);
785
- }
786
-
787
- p.log.info(formatRecovery(options));
788
- };
619
+ const formatRecovery = (resolved: ResolvedOptions): string =>
620
+ `To finish setup, run ${INSTALL_COMMAND[resolved.packageManager]} in ${resolved.root}.`;
789
621
 
790
622
  const runWithSpinner = async (step: SpinnerStep): Promise<void> => {
791
623
  const spinner = p.spinner();
@@ -797,13 +629,12 @@ const runWithSpinner = async (step: SpinnerStep): Promise<void> => {
797
629
  } catch (error) {
798
630
  spinner.error(step.failed);
799
631
  p.log.error(errorMessage(error));
800
- step.explain?.(error);
632
+ step.explain?.();
801
633
  throw new ScaffoldAbortedError(step.failed);
802
634
  }
803
635
  };
804
636
 
805
- const installAllDependencies = async (options: InstallAllOptions): Promise<void> => {
806
- const { resolved, devDependencies } = options;
637
+ const installAllDependencies = async (resolved: ResolvedOptions, devDependencies: string[]): Promise<void> => {
807
638
  const { root, packageManager } = resolved;
808
639
 
809
640
  await runWithSpinner({
@@ -811,21 +642,18 @@ const installAllDependencies = async (options: InstallAllOptions): Promise<void>
811
642
  done: "Dependencies installed",
812
643
  failed: "Failed to install dependencies",
813
644
  run: async () => {
814
- await installDependencies({ cwd: root, packageManager, dependencies: pin(DEPENDENCIES), isDev: false });
815
- await installDependencies({ cwd: root, packageManager, dependencies: pin(devDependencies), isDev: true });
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
+ });
816
650
  },
817
- explain: (error) => {
818
- explainInstallFailure({ error, resolved, devDependencies });
651
+ explain: () => {
652
+ p.log.info(formatRecovery(resolved));
819
653
  },
820
654
  });
821
655
  };
822
656
 
823
- const writeInitialEnvModule = (root: string): void => {
824
- const path = envModulePath(root);
825
- mkdirSync(dirname(path), { recursive: true });
826
- writeFileSync(path, `${GTKX_ENV_MODULE_HEADER}\n`);
827
- };
828
-
829
657
  const isInsideGitRepository = (root: string): boolean => {
830
658
  const git = tryResolveExecutable("git");
831
659
 
@@ -861,31 +689,32 @@ const initializeGitRepo = async (root: string, shouldInitialize: boolean): Promi
861
689
  }
862
690
  };
863
691
 
692
+ const missingHeadlessToolsNote = (): string => {
693
+ const missing = Object.values(HEADLESS_DISPLAY_TOOLS).filter(
694
+ (tool) => tryResolveExecutable(tool.command) === undefined,
695
+ );
696
+
697
+ return missing.length === 0
698
+ ? ""
699
+ : ["", "", "To run tests, install these tools:", ...missingToolLines(missing)].join("\n");
700
+ };
701
+
864
702
  const printNextSteps = (resolved: ResolvedOptions): void => {
865
703
  const devCmd = DEV_COMMAND[resolved.packageManager];
866
- const cdStep = resolved.isCurrentDirectory ? "" : `cd ${resolved.target}\n`;
867
704
  const installStep = resolved.shouldInstallDependencies ? "" : `${INSTALL_COMMAND[resolved.packageManager]}\n`;
868
- const testingNote = resolved.shouldIncludeTesting ? HEADLESS_COMPOSITOR_NOTE : "";
869
- p.note(`${cdStep}${installStep}${devCmd}${testingNote}`, "Next steps");
705
+ const testingNote = resolved.shouldIncludeTesting ? missingHeadlessToolsNote() : "";
706
+ p.note(`${installStep}${devCmd}${testingNote}`, `Run in ${resolved.root}`);
870
707
  };
871
708
 
872
- const createProjectStructure = async (
873
- root: string,
874
- resolved: ResolvedOptions,
875
- plan: ScaffoldPlan,
876
- ): Promise<void> => {
709
+ const createProjectStructure = async (root: string, resolved: ResolvedOptions, plan: ScaffoldPlan): Promise<void> => {
877
710
  await runWithSpinner({
878
711
  pending: "Creating project structure...",
879
712
  done: "Project structure created",
880
713
  failed: "Failed to create the project structure",
881
714
  run: () => {
882
715
  mkdirSync(root, { recursive: true });
883
- scaffoldProject(root, resolved, plan);
716
+ scaffoldProject(plan);
884
717
  writeBuildAllowance(root, resolved.packageManager);
885
-
886
- if (shouldWriteEnvModule(resolved)) {
887
- writeInitialEnvModule(root);
888
- }
889
718
  },
890
719
  });
891
720
  };
@@ -899,12 +728,11 @@ const scaffold = async (options: CreateOptions = {}): Promise<void> => {
899
728
  const plan = await planScaffoldProject(root, resolved);
900
729
  await validateTargetAvailability(root, resolved.target, options, plan.changes);
901
730
  await createProjectStructure(root, resolved, plan);
731
+ writeDependencies(root, devDeps);
902
732
  reportCompletedChanges(plan.changes);
903
733
 
904
734
  if (resolved.shouldInstallDependencies) {
905
- await installAllDependencies({ resolved, devDependencies: devDeps });
906
- } else {
907
- writeDependencies(root, devDeps);
735
+ await installAllDependencies(resolved, devDeps);
908
736
  }
909
737
 
910
738
  await initializeGitRepo(root, resolved.shouldInitializeGit);
@@ -5,9 +5,9 @@ export default defineConfig({
5
5
  applicationIcon: "data/icons",
6
6
  deploy: {
7
7
  name: <%- sourceStringLiteral(displayName) %>,
8
- summary: "A GNOME application built with GTKX",
8
+ summary: "A Linux application built with GTKX",
9
9
  description: [
10
- <%- sourceStringLiteral(`${displayName} is a GNOME application built with GTKX on Adwaita and GTK4, with native GObject widgets rendered from React. Replace this paragraph with a description of what your application does.`) %>,
10
+ <%- sourceStringLiteral(`${displayName} is built with GTKX. Replace this paragraph with a description of what your application does.`) %>,
11
11
  ],
12
12
  categories: ["Utility"],
13
13
  },
@@ -2,7 +2,7 @@
2
2
  "name": "<%= name %>",
3
3
  "version": "0.0.1",
4
4
  "private": true,
5
- "description": "A GNOME application built with GTKX",
5
+ "description": "A Linux application built with GTKX",
6
6
  "license": "MIT",
7
7
  <% if (developerEmail) { -%>
8
8
  "author": <%- sourceStringLiteral(`${developerName} <${developerEmail}>`) %>,
@@ -17,6 +17,9 @@
17
17
  "dev": "gtkx dev",
18
18
  "build": "gtkx build",
19
19
  "codegen": "gtkx codegen",
20
+ <% if (shouldIncludeTesting) { -%>
21
+ "test": "vitest run",
22
+ <% } -%>
20
23
  <% if (isTypescript) { -%>
21
24
  "typecheck": "gtkx codegen && tsc",
22
25
  <% } -%>
@@ -1,3 +0,0 @@
1
- declare const getInstallHint: (message: string) => string | undefined;
2
- export { getInstallHint };
3
- //# sourceMappingURL=install-hints.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"install-hints.d.ts","sourceRoot":"","sources":["../src/install-hints.ts"],"names":[],"mappings":"AAkDA,QAAA,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,MAAM,GAAG,SAC4B,CAAC;AAEhF,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,35 +0,0 @@
1
- const RELEASE_AGE_PATTERN = /ERR_PNPM_(?:MINIMUM_RELEASE_AGE_VIOLATION|NO_MATURE_MATCHING_VERSION)/;
2
- const BLOCKED_VERSION_PATTERN = /^[ \t]*(\S+) was published at .+ within the minimumReleaseAge cutoff/gm;
3
- const RELEASE_AGE_POLICY = "pnpm refused the install under its minimumReleaseAge policy, which by default holds back every package " +
4
- "published in the last 24 hours so a compromised release has time to be caught and pulled. Nothing is wrong " +
5
- "with these versions other than their age.";
6
- const RELEASE_AGE_REMEDY = "Wait for them to clear that window and install again, or allow the versions pnpm named. They belong at the " +
7
- "top level of pnpm-workspace.yaml, as a sibling of packages: and allowBuilds: rather than nested inside " +
8
- "either of them:";
9
- const RELEASE_AGE_REMEDY_WITHOUT_VERSIONS = "Wait for them to clear that window and install again, or list the versions pnpm reported under a top-level " +
10
- "minimumReleaseAgeExclude key in pnpm-workspace.yaml.";
11
- const RELEASE_AGE_PARTIAL_LIST = "pnpm reports only the versions the command it stopped on had to resolve, so a later install can name more. " +
12
- "Add each one to the same list.";
13
- const RELEASE_AGE_OPT_OUT = 'Listing exact versions keeps the policy on for every other package. Setting "minimumReleaseAge: 0" in the ' +
14
- "same file turns it off for all of them, so prefer the list above. npm and yarn apply no such policy.";
15
- const getBlockedVersions = (message) => {
16
- const matches = Array.from(message.matchAll(BLOCKED_VERSION_PATTERN), (match) => match[1] ?? "");
17
- return [...new Set(matches.filter(Boolean))];
18
- };
19
- const formatExcludeBlock = (versions) => ["minimumReleaseAgeExclude:", ...versions.map((version) => ` - '${version}'`)].join("\n");
20
- const describeReleaseAge = (message) => {
21
- const versions = getBlockedVersions(message);
22
- if (versions.length === 0) {
23
- return [RELEASE_AGE_POLICY, RELEASE_AGE_REMEDY_WITHOUT_VERSIONS].join("\n\n");
24
- }
25
- return [
26
- RELEASE_AGE_POLICY,
27
- RELEASE_AGE_REMEDY,
28
- formatExcludeBlock(versions),
29
- RELEASE_AGE_PARTIAL_LIST,
30
- RELEASE_AGE_OPT_OUT,
31
- ].join("\n\n");
32
- };
33
- const getInstallHint = (message) => RELEASE_AGE_PATTERN.test(message) ? describeReleaseAge(message) : undefined;
34
- export { getInstallHint };
35
- //# sourceMappingURL=install-hints.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"install-hints.js","sourceRoot":"","sources":["../src/install-hints.ts"],"names":[],"mappings":"AAAA,MAAM,mBAAmB,GAAG,uEAAuE,CAAC;AACpG,MAAM,uBAAuB,GAAG,wEAAwE,CAAC;AAEzG,MAAM,kBAAkB,GACpB,yGAAyG;IACzG,6GAA6G;IAC7G,2CAA2C,CAAC;AAEhD,MAAM,kBAAkB,GACpB,6GAA6G;IAC7G,yGAAyG;IACzG,iBAAiB,CAAC;AAEtB,MAAM,mCAAmC,GACrC,6GAA6G;IAC7G,sDAAsD,CAAC;AAE3D,MAAM,wBAAwB,GAC1B,6GAA6G;IAC7G,gCAAgC,CAAC;AAErC,MAAM,mBAAmB,GACrB,4GAA4G;IAC5G,sGAAsG,CAAC;AAE3G,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAY,EAAE;IACrD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAEjG,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,QAAkB,EAAU,EAAE,CACtD,CAAC,2BAA2B,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAE/F,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAU,EAAE;IACnD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAE7C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,kBAAkB,EAAE,mCAAmC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAClF,CAAC;IAED,OAAO;QACH,kBAAkB;QAClB,kBAAkB;QAClB,kBAAkB,CAAC,QAAQ,CAAC;QAC5B,wBAAwB;QACxB,mBAAmB;KACtB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,OAAe,EAAsB,EAAE,CAC3D,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAEhF,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["const RELEASE_AGE_PATTERN = /ERR_PNPM_(?:MINIMUM_RELEASE_AGE_VIOLATION|NO_MATURE_MATCHING_VERSION)/;\nconst BLOCKED_VERSION_PATTERN = /^[ \\t]*(\\S+) was published at .+ within the minimumReleaseAge cutoff/gm;\n\nconst RELEASE_AGE_POLICY =\n \"pnpm refused the install under its minimumReleaseAge policy, which by default holds back every package \" +\n \"published in the last 24 hours so a compromised release has time to be caught and pulled. Nothing is wrong \" +\n \"with these versions other than their age.\";\n\nconst RELEASE_AGE_REMEDY =\n \"Wait for them to clear that window and install again, or allow the versions pnpm named. They belong at the \" +\n \"top level of pnpm-workspace.yaml, as a sibling of packages: and allowBuilds: rather than nested inside \" +\n \"either of them:\";\n\nconst RELEASE_AGE_REMEDY_WITHOUT_VERSIONS =\n \"Wait for them to clear that window and install again, or list the versions pnpm reported under a top-level \" +\n \"minimumReleaseAgeExclude key in pnpm-workspace.yaml.\";\n\nconst RELEASE_AGE_PARTIAL_LIST =\n \"pnpm reports only the versions the command it stopped on had to resolve, so a later install can name more. \" +\n \"Add each one to the same list.\";\n\nconst RELEASE_AGE_OPT_OUT =\n 'Listing exact versions keeps the policy on for every other package. Setting \"minimumReleaseAge: 0\" in the ' +\n \"same file turns it off for all of them, so prefer the list above. npm and yarn apply no such policy.\";\n\nconst getBlockedVersions = (message: string): string[] => {\n const matches = Array.from(message.matchAll(BLOCKED_VERSION_PATTERN), (match) => match[1] ?? \"\");\n\n return [...new Set(matches.filter(Boolean))];\n};\n\nconst formatExcludeBlock = (versions: string[]): string =>\n [\"minimumReleaseAgeExclude:\", ...versions.map((version) => ` - '${version}'`)].join(\"\\n\");\n\nconst describeReleaseAge = (message: string): string => {\n const versions = getBlockedVersions(message);\n\n if (versions.length === 0) {\n return [RELEASE_AGE_POLICY, RELEASE_AGE_REMEDY_WITHOUT_VERSIONS].join(\"\\n\\n\");\n }\n\n return [\n RELEASE_AGE_POLICY,\n RELEASE_AGE_REMEDY,\n formatExcludeBlock(versions),\n RELEASE_AGE_PARTIAL_LIST,\n RELEASE_AGE_OPT_OUT,\n ].join(\"\\n\\n\");\n};\n\nconst getInstallHint = (message: string): string | undefined =>\n RELEASE_AGE_PATTERN.test(message) ? describeReleaseAge(message) : undefined;\n\nexport { getInstallHint };\n"]}