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.
- package/README.md +8 -166
- package/dist/build-allowance.d.ts.map +1 -1
- package/dist/build-allowance.js +6 -5
- package/dist/build-allowance.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/command.d.ts +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/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 +0 -3
- package/dist/package-managers.d.ts.map +1 -1
- package/dist/package-managers.js +0 -3
- package/dist/package-managers.js.map +1 -1
- package/dist/project-name.d.ts.map +1 -1
- package/dist/scaffolder.d.ts.map +1 -1
- package/dist/scaffolder.js +51 -158
- package/dist/scaffolder.js.map +1 -1
- package/dist/templates/gtkx.config.ts.ejs +2 -2
- package/dist/templates/package.json.ejs +4 -1
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js.map +1 -1
- package/package.json +16 -39
- package/src/build-allowance.ts +6 -7
- package/src/cli.ts +1 -1
- package/src/command.ts +114 -110
- package/src/manifest.ts +2 -10
- package/src/package-managers.ts +0 -3
- package/src/scaffolder.ts +83 -255
- package/src/templates/gtkx.config.ts.ejs +2 -2
- package/src/templates/package.json.ejs +4 -1
- package/dist/install-hints.d.ts +0 -3
- package/dist/install-hints.d.ts.map +0 -1
- package/dist/install-hints.js +0 -35
- package/dist/install-hints.js.map +0 -1
- package/src/install-hints.ts +0 -54
package/dist/package-managers.js
CHANGED
|
@@ -3,7 +3,6 @@ const PACKAGE_MANAGERS = [
|
|
|
3
3
|
value: "pnpm",
|
|
4
4
|
label: "pnpm",
|
|
5
5
|
devCommand: "pnpm dev",
|
|
6
|
-
addCommand: "pnpm add",
|
|
7
6
|
installCommand: "pnpm install",
|
|
8
7
|
isRecommended: true,
|
|
9
8
|
},
|
|
@@ -11,7 +10,6 @@ const PACKAGE_MANAGERS = [
|
|
|
11
10
|
value: "npm",
|
|
12
11
|
label: "npm",
|
|
13
12
|
devCommand: "npm run dev",
|
|
14
|
-
addCommand: "npm install",
|
|
15
13
|
installCommand: "npm install",
|
|
16
14
|
isRecommended: false,
|
|
17
15
|
},
|
|
@@ -19,7 +17,6 @@ const PACKAGE_MANAGERS = [
|
|
|
19
17
|
value: "yarn",
|
|
20
18
|
label: "yarn",
|
|
21
19
|
devCommand: "yarn dev",
|
|
22
|
-
addCommand: "yarn add",
|
|
23
20
|
installCommand: "yarn install",
|
|
24
21
|
isRecommended: false,
|
|
25
22
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-managers.js","sourceRoot":"","sources":["../src/package-managers.ts"],"names":[],"mappings":"AAEA,MAAM,gBAAgB,GAAG;IACrB;QACI,KAAK,EAAE,MAAM;QACb,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,UAAU;QACtB,
|
|
1
|
+
{"version":3,"file":"package-managers.js","sourceRoot":"","sources":["../src/package-managers.ts"],"names":[],"mappings":"AAEA,MAAM,gBAAgB,GAAG;IACrB;QACI,KAAK,EAAE,MAAM;QACb,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,UAAU;QACtB,cAAc,EAAE,cAAc;QAC9B,aAAa,EAAE,IAAI;KACtB;IACD;QACI,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,UAAU,EAAE,aAAa;QACzB,cAAc,EAAE,aAAa;QAC7B,aAAa,EAAE,KAAK;KACvB;IACD;QACI,KAAK,EAAE,MAAM;QACb,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,UAAU;QACtB,cAAc,EAAE,cAAc;QAC9B,aAAa,EAAE,KAAK;KACvB;CACK,CAAC;AAEX,MAAM,sBAAsB,GAAqB,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAClG,MAAM,gCAAgC,GAAG,oBAAoB,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AAElG,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAA0B,EAAE,CAClE,sBAAmC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAExD,OAAO,EACH,gBAAgB,EAChB,gCAAgC,EAChC,sBAAsB,EACtB,qBAAqB,GAExB,CAAC","sourcesContent":["type PackageManager = (typeof PACKAGE_MANAGERS)[number][\"value\"];\n\nconst PACKAGE_MANAGERS = [\n {\n value: \"pnpm\",\n label: \"pnpm\",\n devCommand: \"pnpm dev\",\n installCommand: \"pnpm install\",\n isRecommended: true,\n },\n {\n value: \"npm\",\n label: \"npm\",\n devCommand: \"npm run dev\",\n installCommand: \"npm install\",\n isRecommended: false,\n },\n {\n value: \"yarn\",\n label: \"yarn\",\n devCommand: \"yarn dev\",\n installCommand: \"yarn install\",\n isRecommended: false,\n },\n] as const;\n\nconst PACKAGE_MANAGER_VALUES: PackageManager[] = PACKAGE_MANAGERS.map((manager) => manager.value);\nconst PACKAGE_MANAGER_FLAG_DESCRIPTION = `Package manager (${PACKAGE_MANAGER_VALUES.join(\", \")})`;\n\nconst isKnownPackageManager = (name: string): name is PackageManager =>\n (PACKAGE_MANAGER_VALUES as string[]).includes(name);\n\nexport {\n PACKAGE_MANAGERS,\n PACKAGE_MANAGER_FLAG_DESCRIPTION,\n PACKAGE_MANAGER_VALUES,\n isKnownPackageManager,\n type PackageManager,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-name.d.ts","sourceRoot":"","sources":["../src/project-name.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"project-name.d.ts","sourceRoot":"","sources":["../src/project-name.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,kBAAkB,SAAU,MAAM,KAAG,OAAoC,CAAC;AAEhF,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/scaffolder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffolder.d.ts","sourceRoot":"","sources":["../src/scaffolder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scaffolder.d.ts","sourceRoot":"","sources":["../src/scaffolder.ts"],"names":[],"mappings":"AAqBA,KAAK,aAAa,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3C,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,yBAAyB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACnD,CAAC;AAkrBF,QAAA,MAAM,QAAQ,aAAmB,aAAa,KAAQ,OAAO,CAAC,IAAI,CAkBjE,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/scaffolder.js
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,
|
|
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 { isKnownPackageManager, PACKAGE_MANAGER_VALUES, PACKAGE_MANAGERS, } from "./package-managers.js";
|
|
15
14
|
import { isValidProjectName } from "./project-name.js";
|
|
@@ -17,31 +16,23 @@ import { listTemplates, renderFile } from "./templates.js";
|
|
|
17
16
|
const selfVersion = packageManifest.version;
|
|
18
17
|
const ICON_TEMPLATE_NAME = "icon.svg";
|
|
19
18
|
const TYPESCRIPT_VERSION = "^6.0.3";
|
|
20
|
-
const GTKX_ENV_MODULE_HEADER = `/**
|
|
21
|
-
* Generated by \`gtkx codegen\`, \`gtkx dev\`, and \`gtkx build\`; do not edit.
|
|
22
|
-
*/`;
|
|
23
19
|
const DEPENDENCIES = ["@gtkx/cairo", "@gtkx/css", "@gtkx/runtime", "@gtkx/react", "react"];
|
|
24
20
|
const DEV_DEPENDENCIES = ["@gtkx/cli", "@gtkx/config", "@gtkx/mcp", "vite"];
|
|
25
21
|
const TYPESCRIPT_DEV_DEPENDENCIES = ["@types/node", "@types/react", "typescript"];
|
|
26
22
|
const TESTING_DEV_DEPENDENCIES = ["@gtkx/testing", "vitest"];
|
|
27
23
|
const DEV_COMMAND = Object.fromEntries(PACKAGE_MANAGERS.map((manager) => [manager.value, manager.devCommand]));
|
|
28
|
-
const ADD_COMMAND = Object.fromEntries(PACKAGE_MANAGERS.map((manager) => [manager.value, manager.addCommand]));
|
|
29
24
|
const INSTALL_COMMAND = Object.fromEntries(PACKAGE_MANAGERS.map((manager) => [manager.value, manager.installCommand]));
|
|
30
25
|
const INHERITED_SCRIPT_POLICY_VARS = ["npm_config_allow_scripts", "npm_config_allow-scripts"];
|
|
31
26
|
const TESTING_TEMPLATES = new Set(["vitest.config.ts", "tests/app.test.tsx"]);
|
|
32
27
|
const TYPESCRIPT_TEMPLATES = new Set(["tsconfig.json", "src/gtkx-env.d.ts"]);
|
|
33
|
-
const HEADLESS_COMPOSITOR_NOTE = `
|
|
34
|
-
|
|
35
|
-
To run tests, you need a headless Wayland compositor installed:
|
|
36
|
-
Fedora: sudo dnf install sway
|
|
37
|
-
Ubuntu: sudo apt install sway`;
|
|
38
|
-
const RECOVERY_HEADING = "Finish the setup by adding the dependencies again, which is safe to repeat:";
|
|
39
28
|
const APPLICATION_ID_FORMAT_ERROR = "Application ID must be reverse domain notation (e.g., com.example.myapp)";
|
|
40
29
|
const APPLICATION_ID_PREFIX = "com.";
|
|
41
30
|
const APPLICATION_ID_SUFFIX = ".app";
|
|
42
|
-
const APPLICATION_ID_SEGMENT_LIMIT = APPLICATION_ID_MAX_LENGTH - APPLICATION_ID_PREFIX.length -
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
const APPLICATION_ID_SEGMENT_LIMIT = APPLICATION_ID_MAX_LENGTH - APPLICATION_ID_PREFIX.length - APPLICATION_ID_SUFFIX.length;
|
|
32
|
+
const displayNameFromProjectName = (name) => name
|
|
33
|
+
.split("-")
|
|
34
|
+
.map((part) => upperFirst(part))
|
|
35
|
+
.join(" ");
|
|
45
36
|
const gitConfigValue = (key) => {
|
|
46
37
|
const git = tryResolveExecutable("git");
|
|
47
38
|
if (git === undefined) {
|
|
@@ -60,14 +51,6 @@ const applicationIdSegment = (name) => {
|
|
|
60
51
|
return segment.slice(0, APPLICATION_ID_SEGMENT_LIMIT);
|
|
61
52
|
};
|
|
62
53
|
const suggestApplicationId = (name) => `${APPLICATION_ID_PREFIX}${applicationIdSegment(name)}${APPLICATION_ID_SUFFIX}`;
|
|
63
|
-
const stripTrailingSlashes = (value) => {
|
|
64
|
-
let end = value.length;
|
|
65
|
-
while (end > 0 && value[end - 1] === "/") {
|
|
66
|
-
end--;
|
|
67
|
-
}
|
|
68
|
-
return value.slice(0, end);
|
|
69
|
-
};
|
|
70
|
-
const formatTargetDir = (target) => stripTrailingSlashes(target.trim().replaceAll(/[<>:"\\|?*]/g, ""));
|
|
71
54
|
const deriveProjectName = (target) => basename(resolve(process.cwd(), target));
|
|
72
55
|
const isDirEmpty = (dir) => {
|
|
73
56
|
const entries = readdirSync(dir);
|
|
@@ -133,12 +116,12 @@ const validateTargetDir = (target) => {
|
|
|
133
116
|
}
|
|
134
117
|
return validateProjectName(deriveProjectName(target));
|
|
135
118
|
};
|
|
136
|
-
const validateTargetAnswer = (value) => validateTargetDir(
|
|
137
|
-
const promptTarget = async () =>
|
|
119
|
+
const validateTargetAnswer = (value) => validateTargetDir(value ?? "");
|
|
120
|
+
const promptTarget = async () => guardCancellation(await p.text({
|
|
138
121
|
message: "Project directory",
|
|
139
122
|
placeholder: "my-app",
|
|
140
123
|
validate: validateTargetAnswer,
|
|
141
|
-
}))
|
|
124
|
+
}));
|
|
142
125
|
const promptApplicationId = async (name) => {
|
|
143
126
|
const defaultApplicationId = suggestApplicationId(name);
|
|
144
127
|
return guardCancellation(await p.text({
|
|
@@ -185,10 +168,7 @@ const promptPackageManager = async () => {
|
|
|
185
168
|
initialValue: initial,
|
|
186
169
|
}));
|
|
187
170
|
};
|
|
188
|
-
const isOptionEnabled = async (value, isInteractive, message) => value ??
|
|
189
|
-
(isInteractive
|
|
190
|
-
? guardCancellation(await p.confirm({ message, initialValue: true }))
|
|
191
|
-
: true);
|
|
171
|
+
const isOptionEnabled = async (value, isInteractive, message) => value ?? (!isInteractive || guardCancellation(await p.confirm({ message, initialValue: true })));
|
|
192
172
|
const formatFileList = (heading, files) => {
|
|
193
173
|
const indentedFiles = files.map((file) => ` ${file}`).join("\n");
|
|
194
174
|
return `${heading}:\n${indentedFiles}`;
|
|
@@ -231,14 +211,16 @@ const acceptNonEmptyDirectory = async (target, options, changes) => {
|
|
|
231
211
|
refuseNonEmptyDirectory(target, changes);
|
|
232
212
|
};
|
|
233
213
|
const assertTargetIsDirectory = (root, target) => {
|
|
234
|
-
const stats =
|
|
214
|
+
const stats = lstatSync(root, { throwIfNoEntry: false });
|
|
215
|
+
if (stats?.isSymbolicLink()) {
|
|
216
|
+
fail(`Cannot scaffold through a symbolic link: ${root}`);
|
|
217
|
+
}
|
|
235
218
|
if (stats !== undefined && !stats.isDirectory()) {
|
|
236
219
|
fail(`Target "${target}" is not a directory`);
|
|
237
220
|
}
|
|
238
221
|
};
|
|
239
222
|
const validateTargetAvailability = async (root, target, options, changes) => {
|
|
240
223
|
const stats = statSync(root, { throwIfNoEntry: false });
|
|
241
|
-
assertTargetIsDirectory(root, target);
|
|
242
224
|
if (stats === undefined || isDirEmpty(root)) {
|
|
243
225
|
return;
|
|
244
226
|
}
|
|
@@ -248,13 +230,12 @@ const resolveTarget = async (options) => {
|
|
|
248
230
|
if (options.name === undefined && options.isInteractive) {
|
|
249
231
|
return promptTarget();
|
|
250
232
|
}
|
|
251
|
-
const target =
|
|
233
|
+
const target = options.name ?? "";
|
|
252
234
|
const error = validateTargetDir(target);
|
|
253
235
|
return error === undefined ? target : fail(error);
|
|
254
236
|
};
|
|
255
237
|
const resolveApplicationId = async (options, name) => {
|
|
256
|
-
const applicationId = options.applicationId ??
|
|
257
|
-
(options.isInteractive ? await promptApplicationId(name) : suggestApplicationId(name));
|
|
238
|
+
const applicationId = options.applicationId ?? (options.isInteractive ? await promptApplicationId(name) : suggestApplicationId(name));
|
|
258
239
|
const error = validateApplicationIdInput(applicationId);
|
|
259
240
|
return error === undefined ? applicationId : fail(error);
|
|
260
241
|
};
|
|
@@ -280,7 +261,6 @@ const resolveOptions = async (options) => {
|
|
|
280
261
|
const displayName = await resolveDisplayName(options, name);
|
|
281
262
|
const applicationId = await resolveApplicationId(options, name);
|
|
282
263
|
const root = resolve(process.cwd(), target);
|
|
283
|
-
const isCurrentDirectory = root === process.cwd();
|
|
284
264
|
const shouldInitialize = shouldInitializeGit(root);
|
|
285
265
|
const packageManager = await resolvePackageManager(requested, options);
|
|
286
266
|
const isTypescript = await isOptionEnabled(options.isTypescript, options.isInteractive, "Use TypeScript?");
|
|
@@ -288,7 +268,6 @@ const resolveOptions = async (options) => {
|
|
|
288
268
|
return {
|
|
289
269
|
target,
|
|
290
270
|
root,
|
|
291
|
-
isCurrentDirectory,
|
|
292
271
|
name,
|
|
293
272
|
displayName,
|
|
294
273
|
applicationId,
|
|
@@ -324,31 +303,6 @@ const templateContext = (resolved) => ({
|
|
|
324
303
|
developerName: gitConfigValue("user.name") ?? resolved.displayName,
|
|
325
304
|
developerEmail: gitConfigValue("user.email"),
|
|
326
305
|
});
|
|
327
|
-
const replaceTemplateDestination = (destination) => {
|
|
328
|
-
const entry = lstatSync(destination, { throwIfNoEntry: false });
|
|
329
|
-
if (entry === undefined) {
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
if (!entry.isFile() && !entry.isSymbolicLink()) {
|
|
333
|
-
fail(`Cannot replace scaffold file because its destination is not a file: ${destination}`);
|
|
334
|
-
}
|
|
335
|
-
rmSync(destination, { force: true });
|
|
336
|
-
};
|
|
337
|
-
const projectRelativeDestination = (root, destination) => {
|
|
338
|
-
const relativePath = relative(root, destination);
|
|
339
|
-
const isOutsideProject = relativePath.length === 0 || relativePath.startsWith(`..${sep}`) ||
|
|
340
|
-
isAbsolute(relativePath);
|
|
341
|
-
if (isOutsideProject) {
|
|
342
|
-
fail(`Scaffold destination is outside the project: ${destination}`);
|
|
343
|
-
}
|
|
344
|
-
return relativePath;
|
|
345
|
-
};
|
|
346
|
-
const assertRootIsNotSymbolicLink = (root) => {
|
|
347
|
-
const rootEntry = lstatSync(root, { throwIfNoEntry: false });
|
|
348
|
-
if (rootEntry?.isSymbolicLink()) {
|
|
349
|
-
fail(`Cannot scaffold through a symbolic link: ${root}`);
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
306
|
const assertSafeAncestor = (ancestor) => {
|
|
353
307
|
const entry = lstatSync(ancestor, { throwIfNoEntry: false });
|
|
354
308
|
if (entry?.isSymbolicLink()) {
|
|
@@ -367,18 +321,17 @@ const assertSafeAncestors = (root, relativePath) => {
|
|
|
367
321
|
assertSafeAncestor(ancestor);
|
|
368
322
|
}
|
|
369
323
|
};
|
|
370
|
-
const
|
|
324
|
+
const hasReplaceableDestination = (destination) => {
|
|
371
325
|
const entry = lstatSync(destination, { throwIfNoEntry: false });
|
|
372
326
|
const isReplaceable = entry === undefined || entry.isFile() || entry.isSymbolicLink();
|
|
373
327
|
if (!isReplaceable) {
|
|
374
328
|
fail(`Cannot replace scaffold file because its destination is not a file: ${destination}`);
|
|
375
329
|
}
|
|
330
|
+
return entry !== undefined;
|
|
376
331
|
};
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
assertSafeAncestors(root, relativePath);
|
|
381
|
-
assertReplaceableDestination(destination);
|
|
332
|
+
const hasExistingDestination = (root, destination) => {
|
|
333
|
+
assertSafeAncestors(root, relative(root, destination));
|
|
334
|
+
return hasReplaceableDestination(destination);
|
|
382
335
|
};
|
|
383
336
|
const plannedScaffoldFiles = async (root, resolved) => {
|
|
384
337
|
const context = templateContext(resolved);
|
|
@@ -394,54 +347,24 @@ const plannedScaffoldFiles = async (root, resolved) => {
|
|
|
394
347
|
return files;
|
|
395
348
|
};
|
|
396
349
|
const auxiliaryDestinations = (root, resolved) => resolved.packageManager === "pnpm" ? [join(root, "pnpm-workspace.yaml")] : [];
|
|
397
|
-
const envModulePath = (root) => join(root, "node_modules", ".gtkx", "env.d.ts");
|
|
398
|
-
const shouldWriteEnvModule = (resolved) => resolved.isTypescript && resolved.shouldInstallDependencies;
|
|
399
|
-
const generatedDestinations = (root, resolved) => shouldWriteEnvModule(resolved) ? [envModulePath(root)] : [];
|
|
400
|
-
const isPresent = (path) => lstatSync(path, { throwIfNoEntry: false }) !== undefined;
|
|
401
|
-
const classifyScaffoldChange = (root, destination) => {
|
|
402
|
-
const entry = lstatSync(destination, { throwIfNoEntry: false });
|
|
403
|
-
if (entry === undefined) {
|
|
404
|
-
return undefined;
|
|
405
|
-
}
|
|
406
|
-
return { destination, relativePath: projectRelativeDestination(root, destination) };
|
|
407
|
-
};
|
|
408
|
-
const addScaffoldChange = (plan, change) => {
|
|
409
|
-
if (change === undefined) {
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
plan.replaceDestinations.push(change.destination);
|
|
413
|
-
plan.changes.push(change.relativePath);
|
|
414
|
-
};
|
|
415
350
|
const planScaffoldProject = async (root, resolved) => {
|
|
416
351
|
const files = await plannedScaffoldFiles(root, resolved);
|
|
417
|
-
const
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
assertSafeDestination(root, destination);
|
|
421
|
-
}
|
|
422
|
-
const plan = {
|
|
352
|
+
const destinations = [...files.map((file) => file.destination), ...auxiliaryDestinations(root, resolved)];
|
|
353
|
+
const replaceDestinations = destinations.filter((destination) => hasExistingDestination(root, destination));
|
|
354
|
+
return {
|
|
423
355
|
files,
|
|
424
|
-
replaceDestinations
|
|
425
|
-
changes:
|
|
356
|
+
replaceDestinations,
|
|
357
|
+
changes: replaceDestinations.map((destination) => relative(root, destination)),
|
|
426
358
|
};
|
|
427
|
-
for (const destination of reported) {
|
|
428
|
-
addScaffoldChange(plan, classifyScaffoldChange(root, destination));
|
|
429
|
-
}
|
|
430
|
-
return plan;
|
|
431
359
|
};
|
|
432
|
-
const scaffoldProject = (
|
|
360
|
+
const scaffoldProject = (plan) => {
|
|
433
361
|
for (const destination of plan.replaceDestinations) {
|
|
434
|
-
|
|
362
|
+
rmSync(destination);
|
|
435
363
|
}
|
|
436
364
|
for (const file of plan.files) {
|
|
437
365
|
mkdirSync(dirname(file.destination), { recursive: true });
|
|
438
366
|
writeFileSync(file.destination, file.contents);
|
|
439
367
|
}
|
|
440
|
-
if (resolved.shouldIncludeTesting) {
|
|
441
|
-
updateManifest(root, (manifest) => {
|
|
442
|
-
manifest.scripts.test = "vitest run";
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
368
|
};
|
|
446
369
|
const withoutInheritedScriptPolicy = async (run) => {
|
|
447
370
|
const saved = INHERITED_SCRIPT_POLICY_VARS.map((key) => [key, process.env[key]]);
|
|
@@ -459,47 +382,20 @@ const withoutInheritedScriptPolicy = async (run) => {
|
|
|
459
382
|
}
|
|
460
383
|
}
|
|
461
384
|
};
|
|
462
|
-
const installDependencies = async (options) => {
|
|
463
|
-
const { cwd, packageManager, dependencies, isDev } = options;
|
|
464
|
-
await withoutInheritedScriptPolicy(async () => {
|
|
465
|
-
await addDependency(dependencies, { cwd, packageManager, dev: isDev, silent: true });
|
|
466
|
-
});
|
|
467
|
-
};
|
|
468
|
-
const pin = (names) => names.map((dependency) => {
|
|
469
|
-
if (dependency.startsWith("@gtkx/")) {
|
|
470
|
-
return `${dependency}@^${selfVersion}`;
|
|
471
|
-
}
|
|
472
|
-
return dependency === "typescript" ? `${dependency}@${TYPESCRIPT_VERSION}` : dependency;
|
|
473
|
-
});
|
|
474
385
|
const dependencyVersions = (names) => Object.fromEntries(names.map((dependency) => {
|
|
475
386
|
if (dependency.startsWith("@gtkx/")) {
|
|
476
387
|
return [dependency, `^${selfVersion}`];
|
|
477
388
|
}
|
|
478
389
|
return [dependency, dependency === "typescript" ? TYPESCRIPT_VERSION : "latest"];
|
|
479
390
|
}));
|
|
391
|
+
const dependencyArguments = (names) => Object.entries(dependencyVersions(names)).map(([name, version]) => version === "latest" ? name : `${name}@${version}`);
|
|
480
392
|
const writeDependencies = (root, devDependencies) => {
|
|
481
393
|
updateManifest(root, (manifest) => {
|
|
482
394
|
manifest.dependencies = dependencyVersions(DEPENDENCIES);
|
|
483
395
|
manifest.devDependencies = dependencyVersions(devDependencies);
|
|
484
396
|
});
|
|
485
397
|
};
|
|
486
|
-
const formatRecovery = (
|
|
487
|
-
const add = ADD_COMMAND[resolved.packageManager];
|
|
488
|
-
const steps = [
|
|
489
|
-
...(resolved.isCurrentDirectory ? [] : [`cd ${resolved.target}`]),
|
|
490
|
-
`${add} ${pin(DEPENDENCIES).join(" ")}`,
|
|
491
|
-
`${add} -D ${pin(devDependencies).join(" ")}`,
|
|
492
|
-
];
|
|
493
|
-
const indented = steps.map((step) => ` ${step}`).join("\n");
|
|
494
|
-
return `${RECOVERY_HEADING}\n${indented}`;
|
|
495
|
-
};
|
|
496
|
-
const explainInstallFailure = (options) => {
|
|
497
|
-
const hint = getInstallHint(errorMessage(options.error));
|
|
498
|
-
if (hint !== undefined) {
|
|
499
|
-
p.log.warn(hint);
|
|
500
|
-
}
|
|
501
|
-
p.log.info(formatRecovery(options));
|
|
502
|
-
};
|
|
398
|
+
const formatRecovery = (resolved) => `To finish setup, run ${INSTALL_COMMAND[resolved.packageManager]} in ${resolved.root}.`;
|
|
503
399
|
const runWithSpinner = async (step) => {
|
|
504
400
|
const spinner = p.spinner();
|
|
505
401
|
spinner.start(step.pending);
|
|
@@ -510,31 +406,28 @@ const runWithSpinner = async (step) => {
|
|
|
510
406
|
catch (error) {
|
|
511
407
|
spinner.error(step.failed);
|
|
512
408
|
p.log.error(errorMessage(error));
|
|
513
|
-
step.explain?.(
|
|
409
|
+
step.explain?.();
|
|
514
410
|
throw new ScaffoldAbortedError(step.failed);
|
|
515
411
|
}
|
|
516
412
|
};
|
|
517
|
-
const installAllDependencies = async (
|
|
518
|
-
const { resolved, devDependencies } = options;
|
|
413
|
+
const installAllDependencies = async (resolved, devDependencies) => {
|
|
519
414
|
const { root, packageManager } = resolved;
|
|
520
415
|
await runWithSpinner({
|
|
521
416
|
pending: "Installing dependencies...",
|
|
522
417
|
done: "Dependencies installed",
|
|
523
418
|
failed: "Failed to install dependencies",
|
|
524
419
|
run: async () => {
|
|
525
|
-
await
|
|
526
|
-
|
|
420
|
+
await withoutInheritedScriptPolicy(async () => {
|
|
421
|
+
const options = { cwd: root, packageManager, silent: true };
|
|
422
|
+
await addDependency(dependencyArguments(DEPENDENCIES), options);
|
|
423
|
+
await addDependency(dependencyArguments(devDependencies), { ...options, dev: true });
|
|
424
|
+
});
|
|
527
425
|
},
|
|
528
|
-
explain: (
|
|
529
|
-
|
|
426
|
+
explain: () => {
|
|
427
|
+
p.log.info(formatRecovery(resolved));
|
|
530
428
|
},
|
|
531
429
|
});
|
|
532
430
|
};
|
|
533
|
-
const writeInitialEnvModule = (root) => {
|
|
534
|
-
const path = envModulePath(root);
|
|
535
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
536
|
-
writeFileSync(path, `${GTKX_ENV_MODULE_HEADER}\n`);
|
|
537
|
-
};
|
|
538
431
|
const isInsideGitRepository = (root) => {
|
|
539
432
|
const git = tryResolveExecutable("git");
|
|
540
433
|
if (git === undefined) {
|
|
@@ -565,12 +458,17 @@ const initializeGitRepo = async (root, shouldInitialize) => {
|
|
|
565
458
|
spinner.error("Failed to initialize git repository");
|
|
566
459
|
}
|
|
567
460
|
};
|
|
461
|
+
const missingHeadlessToolsNote = () => {
|
|
462
|
+
const missing = Object.values(HEADLESS_DISPLAY_TOOLS).filter((tool) => tryResolveExecutable(tool.command) === undefined);
|
|
463
|
+
return missing.length === 0
|
|
464
|
+
? ""
|
|
465
|
+
: ["", "", "To run tests, install these tools:", ...missingToolLines(missing)].join("\n");
|
|
466
|
+
};
|
|
568
467
|
const printNextSteps = (resolved) => {
|
|
569
468
|
const devCmd = DEV_COMMAND[resolved.packageManager];
|
|
570
|
-
const cdStep = resolved.isCurrentDirectory ? "" : `cd ${resolved.target}\n`;
|
|
571
469
|
const installStep = resolved.shouldInstallDependencies ? "" : `${INSTALL_COMMAND[resolved.packageManager]}\n`;
|
|
572
|
-
const testingNote = resolved.shouldIncludeTesting ?
|
|
573
|
-
p.note(`${
|
|
470
|
+
const testingNote = resolved.shouldIncludeTesting ? missingHeadlessToolsNote() : "";
|
|
471
|
+
p.note(`${installStep}${devCmd}${testingNote}`, `Run in ${resolved.root}`);
|
|
574
472
|
};
|
|
575
473
|
const createProjectStructure = async (root, resolved, plan) => {
|
|
576
474
|
await runWithSpinner({
|
|
@@ -579,11 +477,8 @@ const createProjectStructure = async (root, resolved, plan) => {
|
|
|
579
477
|
failed: "Failed to create the project structure",
|
|
580
478
|
run: () => {
|
|
581
479
|
mkdirSync(root, { recursive: true });
|
|
582
|
-
scaffoldProject(
|
|
480
|
+
scaffoldProject(plan);
|
|
583
481
|
writeBuildAllowance(root, resolved.packageManager);
|
|
584
|
-
if (shouldWriteEnvModule(resolved)) {
|
|
585
|
-
writeInitialEnvModule(root);
|
|
586
|
-
}
|
|
587
482
|
},
|
|
588
483
|
});
|
|
589
484
|
};
|
|
@@ -596,12 +491,10 @@ const scaffold = async (options = {}) => {
|
|
|
596
491
|
const plan = await planScaffoldProject(root, resolved);
|
|
597
492
|
await validateTargetAvailability(root, resolved.target, options, plan.changes);
|
|
598
493
|
await createProjectStructure(root, resolved, plan);
|
|
494
|
+
writeDependencies(root, devDeps);
|
|
599
495
|
reportCompletedChanges(plan.changes);
|
|
600
496
|
if (resolved.shouldInstallDependencies) {
|
|
601
|
-
await installAllDependencies(
|
|
602
|
-
}
|
|
603
|
-
else {
|
|
604
|
-
writeDependencies(root, devDeps);
|
|
497
|
+
await installAllDependencies(resolved, devDeps);
|
|
605
498
|
}
|
|
606
499
|
await initializeGitRepo(root, resolved.shouldInitializeGit);
|
|
607
500
|
printNextSteps(resolved);
|