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.
- package/README.md +3 -3
- package/dependency-ranges.json +7 -0
- package/dist/build-allowance.d.ts +43 -2
- package/dist/build-allowance.d.ts.map +1 -1
- package/dist/build-allowance.js +360 -10
- package/dist/build-allowance.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/package-managers.d.ts +6 -0
- package/dist/package-managers.d.ts.map +1 -1
- package/dist/package-managers.js +6 -0
- package/dist/package-managers.js.map +1 -1
- package/dist/project-name.d.ts +4 -2
- package/dist/project-name.d.ts.map +1 -1
- package/dist/project-name.js +12 -2
- package/dist/project-name.js.map +1 -1
- package/dist/scaffolder.d.ts.map +1 -1
- package/dist/scaffolder.js +171 -64
- package/dist/scaffolder.js.map +1 -1
- package/dist/templates/.claude/settings.json.ejs +4 -3
- package/dist/templates/.gitignore.ejs +4 -0
- package/dist/templates/.mcp.json.ejs +1 -1
- package/dist/templates/src/app.tsx.ejs +1 -1
- package/dist/templates/src/gtkx-env.d.ts.ejs +0 -1
- package/dist/templates/tsconfig.json.ejs +4 -2
- package/dist/templates.d.ts +3 -0
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +10 -6
- package/dist/templates.js.map +1 -1
- package/dist/workspace-mcp.d.ts +33 -0
- package/dist/workspace-mcp.d.ts.map +1 -0
- package/dist/workspace-mcp.js +75 -0
- package/dist/workspace-mcp.js.map +1 -0
- package/package.json +11 -7
- package/src/build-allowance.ts +488 -10
- package/src/index.ts +1 -0
- package/src/package-managers.ts +6 -0
- package/src/project-name.ts +19 -2
- package/src/scaffolder.ts +250 -70
- package/src/templates/.claude/settings.json.ejs +4 -3
- package/src/templates/.gitignore.ejs +4 -0
- package/src/templates/.mcp.json.ejs +1 -1
- package/src/templates/src/app.tsx.ejs +1 -1
- package/src/templates/src/gtkx-env.d.ts.ejs +0 -1
- package/src/templates/tsconfig.json.ejs +4 -2
- package/src/templates.ts +17 -8
- package/src/workspace-mcp.ts +111 -0
package/dist/package-managers.js
CHANGED
|
@@ -4,6 +4,8 @@ const PACKAGE_MANAGERS = [
|
|
|
4
4
|
label: "pnpm",
|
|
5
5
|
devCommand: "pnpm dev",
|
|
6
6
|
installCommand: "pnpm install",
|
|
7
|
+
runCommand: "pnpm",
|
|
8
|
+
testCommand: "pnpm test",
|
|
7
9
|
isRecommended: true,
|
|
8
10
|
},
|
|
9
11
|
{
|
|
@@ -11,6 +13,8 @@ const PACKAGE_MANAGERS = [
|
|
|
11
13
|
label: "npm",
|
|
12
14
|
devCommand: "npm run dev",
|
|
13
15
|
installCommand: "npm install",
|
|
16
|
+
runCommand: "npm run",
|
|
17
|
+
testCommand: "npm test",
|
|
14
18
|
isRecommended: false,
|
|
15
19
|
},
|
|
16
20
|
{
|
|
@@ -18,6 +22,8 @@ const PACKAGE_MANAGERS = [
|
|
|
18
22
|
label: "yarn",
|
|
19
23
|
devCommand: "yarn dev",
|
|
20
24
|
installCommand: "yarn install",
|
|
25
|
+
runCommand: "yarn",
|
|
26
|
+
testCommand: "yarn test",
|
|
21
27
|
isRecommended: false,
|
|
22
28
|
},
|
|
23
29
|
];
|
|
@@ -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,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
|
+
{"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,UAAU,EAAE,MAAM;QAClB,WAAW,EAAE,WAAW;QACxB,aAAa,EAAE,IAAI;KACtB;IACD;QACI,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,UAAU,EAAE,aAAa;QACzB,cAAc,EAAE,aAAa;QAC7B,UAAU,EAAE,SAAS;QACrB,WAAW,EAAE,UAAU;QACvB,aAAa,EAAE,KAAK;KACvB;IACD;QACI,KAAK,EAAE,MAAM;QACb,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,UAAU;QACtB,cAAc,EAAE,cAAc;QAC9B,UAAU,EAAE,MAAM;QAClB,WAAW,EAAE,WAAW;QACxB,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 runCommand: \"pnpm\",\n testCommand: \"pnpm test\",\n isRecommended: true,\n },\n {\n value: \"npm\",\n label: \"npm\",\n devCommand: \"npm run dev\",\n installCommand: \"npm install\",\n runCommand: \"npm run\",\n testCommand: \"npm test\",\n isRecommended: false,\n },\n {\n value: \"yarn\",\n label: \"yarn\",\n devCommand: \"yarn dev\",\n installCommand: \"yarn install\",\n runCommand: \"yarn\",\n testCommand: \"yarn test\",\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"]}
|
package/dist/project-name.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
|
|
1
|
+
declare const withoutAccents: (name: string) => string;
|
|
2
|
+
declare const isValidPackageName: (name: string) => boolean;
|
|
3
|
+
declare const packageNameFromDirectory: (directoryName: string) => string;
|
|
4
|
+
export { isValidPackageName, packageNameFromDirectory, withoutAccents };
|
|
3
5
|
//# sourceMappingURL=project-name.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-name.d.ts","sourceRoot":"","sources":["../src/project-name.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"project-name.d.ts","sourceRoot":"","sources":["../src/project-name.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,cAAc,SAAU,MAAM,KAAG,MAA0D,CAAC;AAElG,QAAA,MAAM,kBAAkB,SAAU,MAAM,KAAG,OACkC,CAAC;AAU9E,QAAA,MAAM,wBAAwB,kBAAmB,MAAM,KAAG,MAC+B,CAAC;AAE1F,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/project-name.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const PACKAGE_NAME_MAX_LENGTH = 214;
|
|
2
|
+
const PACKAGE_NAME_PATTERN = /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/;
|
|
3
|
+
const withoutAccents = (name) => name.normalize("NFKD").replaceAll(/\p{M}/gu, "");
|
|
4
|
+
const isValidPackageName = (name) => name.length <= PACKAGE_NAME_MAX_LENGTH && PACKAGE_NAME_PATTERN.test(name);
|
|
5
|
+
const toValidPackageName = (name) => withoutAccents(name)
|
|
6
|
+
.toLowerCase()
|
|
7
|
+
.replaceAll(/[^a-z0-9]+/g, "-")
|
|
8
|
+
.replaceAll(/^-+|-+$/g, "")
|
|
9
|
+
.slice(0, PACKAGE_NAME_MAX_LENGTH)
|
|
10
|
+
.replace(/-+$/, "");
|
|
11
|
+
const packageNameFromDirectory = (directoryName) => isValidPackageName(directoryName) ? directoryName : toValidPackageName(directoryName);
|
|
12
|
+
export { isValidPackageName, packageNameFromDirectory, withoutAccents };
|
|
3
13
|
//# sourceMappingURL=project-name.js.map
|
package/dist/project-name.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-name.js","sourceRoot":"","sources":["../src/project-name.ts"],"names":[],"mappings":"AAAA,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"project-name.js","sourceRoot":"","sources":["../src/project-name.ts"],"names":[],"mappings":"AAAA,MAAM,uBAAuB,GAAG,GAAG,CAAC;AACpC,MAAM,oBAAoB,GAAG,4DAA4D,CAAC;AAE1F,MAAM,cAAc,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AAElG,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAW,EAAE,CACjD,IAAI,CAAC,MAAM,IAAI,uBAAuB,IAAI,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAE9E,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAU,EAAE,CAChD,cAAc,CAAC,IAAI,CAAC;KACf,WAAW,EAAE;KACb,UAAU,CAAC,aAAa,EAAE,GAAG,CAAC;KAC9B,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC;KAC1B,KAAK,CAAC,CAAC,EAAE,uBAAuB,CAAC;KACjC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAE5B,MAAM,wBAAwB,GAAG,CAAC,aAAqB,EAAU,EAAE,CAC/D,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC;AAE1F,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,cAAc,EAAE,CAAC","sourcesContent":["const PACKAGE_NAME_MAX_LENGTH = 214;\nconst PACKAGE_NAME_PATTERN = /^(?:@[a-z\\d\\-*~][a-z\\d\\-*._~]*\\/)?[a-z\\d\\-~][a-z\\d\\-._~]*$/;\n\nconst withoutAccents = (name: string): string => name.normalize(\"NFKD\").replaceAll(/\\p{M}/gu, \"\");\n\nconst isValidPackageName = (name: string): boolean =>\n name.length <= PACKAGE_NAME_MAX_LENGTH && PACKAGE_NAME_PATTERN.test(name);\n\nconst toValidPackageName = (name: string): string =>\n withoutAccents(name)\n .toLowerCase()\n .replaceAll(/[^a-z0-9]+/g, \"-\")\n .replaceAll(/^-+|-+$/g, \"\")\n .slice(0, PACKAGE_NAME_MAX_LENGTH)\n .replace(/-+$/, \"\");\n\nconst packageNameFromDirectory = (directoryName: string): string =>\n isValidPackageName(directoryName) ? directoryName : toValidPackageName(directoryName);\n\nexport { isValidPackageName, packageNameFromDirectory, withoutAccents };\n"]}
|
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":"AA6BA,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;AA41BF,QAAA,MAAM,QAAQ,aAAmB,aAAa,KAAQ,OAAO,CAAC,IAAI,CAoBjE,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/scaffolder.js
CHANGED
|
@@ -2,35 +2,46 @@ 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 {
|
|
11
|
+
import { PACKAGE_MANAGER_CONFIG_FILES, enclosingWorkspace, packageManagerPin, writePackageManagerSettings, } from "./build-allowance.js";
|
|
11
12
|
import { OperationCanceledError, ScaffoldAbortedError } from "./errors.js";
|
|
12
13
|
import { updateManifest } from "./manifest.js";
|
|
13
14
|
import { isKnownPackageManager, PACKAGE_MANAGER_VALUES, PACKAGE_MANAGERS, } from "./package-managers.js";
|
|
14
|
-
import {
|
|
15
|
+
import { isValidPackageName, packageNameFromDirectory, withoutAccents } from "./project-name.js";
|
|
15
16
|
import { listTemplates, renderFile } from "./templates.js";
|
|
17
|
+
import { addWorkspaceMcpServer } from "./workspace-mcp.js";
|
|
16
18
|
const selfVersion = packageManifest.version;
|
|
17
19
|
const ICON_TEMPLATE_NAME = "icon.svg";
|
|
18
20
|
const TYPESCRIPT_VERSION = "^6.0.3";
|
|
21
|
+
const DEPENDENCY_RANGES = {
|
|
22
|
+
...JSON.parse(readFileSync(new URL("../dependency-ranges.json", import.meta.url), "utf8")),
|
|
23
|
+
typescript: TYPESCRIPT_VERSION,
|
|
24
|
+
};
|
|
19
25
|
const DEPENDENCIES = ["@gtkx/cairo", "@gtkx/css", "@gtkx/runtime", "@gtkx/react", "react"];
|
|
20
|
-
const DEV_DEPENDENCIES = ["@gtkx/cli", "@gtkx/config", "@gtkx/mcp", "vite"];
|
|
21
|
-
const TYPESCRIPT_DEV_DEPENDENCIES = ["@types/node", "
|
|
22
|
-
const TESTING_DEV_DEPENDENCIES = ["
|
|
26
|
+
const DEV_DEPENDENCIES = ["@gtkx/cli", "@gtkx/config", "@gtkx/mcp", "@gtkx/testing", "@types/react", "vite"];
|
|
27
|
+
const TYPESCRIPT_DEV_DEPENDENCIES = ["@types/node", "typescript"];
|
|
28
|
+
const TESTING_DEV_DEPENDENCIES = ["vitest"];
|
|
23
29
|
const DEV_COMMAND = Object.fromEntries(PACKAGE_MANAGERS.map((manager) => [manager.value, manager.devCommand]));
|
|
24
30
|
const INSTALL_COMMAND = Object.fromEntries(PACKAGE_MANAGERS.map((manager) => [manager.value, manager.installCommand]));
|
|
31
|
+
const RUN_COMMAND = Object.fromEntries(PACKAGE_MANAGERS.map((manager) => [manager.value, manager.runCommand]));
|
|
32
|
+
const TEST_COMMAND = Object.fromEntries(PACKAGE_MANAGERS.map((manager) => [manager.value, manager.testCommand]));
|
|
25
33
|
const INHERITED_SCRIPT_POLICY_VARS = ["npm_config_allow_scripts", "npm_config_allow-scripts"];
|
|
34
|
+
const LENIENT_PNPM_BUILDS_ENV = { pnpm_config_strict_dep_builds: "false" };
|
|
26
35
|
const TESTING_TEMPLATES = new Set(["vitest.config.ts", "tests/app.test.tsx"]);
|
|
27
36
|
const TYPESCRIPT_TEMPLATES = new Set(["tsconfig.json", "src/gtkx-env.d.ts"]);
|
|
28
37
|
const APPLICATION_ID_FORMAT_ERROR = "Application ID must be reverse domain notation (e.g., com.example.myapp)";
|
|
38
|
+
const PACKAGE_NAME_FORMAT_ERROR = "Package name must be a valid npm package name: lowercase, no spaces (e.g., my-app)";
|
|
29
39
|
const APPLICATION_ID_PREFIX = "com.";
|
|
30
40
|
const APPLICATION_ID_SUFFIX = ".app";
|
|
31
41
|
const APPLICATION_ID_SEGMENT_LIMIT = APPLICATION_ID_MAX_LENGTH - APPLICATION_ID_PREFIX.length - APPLICATION_ID_SUFFIX.length;
|
|
32
|
-
const
|
|
33
|
-
.split(
|
|
42
|
+
const displayNameFromDirectory = (directoryName) => directoryName
|
|
43
|
+
.split(/[\s._-]+/)
|
|
44
|
+
.filter((part) => part.length > 0)
|
|
34
45
|
.map((part) => upperFirst(part))
|
|
35
46
|
.join(" ");
|
|
36
47
|
const gitConfigValue = (key) => {
|
|
@@ -45,13 +56,16 @@ const gitConfigValue = (key) => {
|
|
|
45
56
|
return null;
|
|
46
57
|
}
|
|
47
58
|
};
|
|
48
|
-
const
|
|
49
|
-
|
|
59
|
+
const compactIdentifier = (name) => withoutAccents(name).replaceAll(/[^A-Za-z0-9_]/g, "");
|
|
60
|
+
const applicationIdSegment = (directoryName, name) => {
|
|
61
|
+
const compact = compactIdentifier(directoryName) || compactIdentifier(name);
|
|
50
62
|
const segment = /^[A-Za-z_]/.test(compact) ? compact : `_${compact}`;
|
|
51
63
|
return segment.slice(0, APPLICATION_ID_SEGMENT_LIMIT);
|
|
52
64
|
};
|
|
53
|
-
const suggestApplicationId = (name) => `${APPLICATION_ID_PREFIX}${applicationIdSegment(name)}${APPLICATION_ID_SUFFIX}`;
|
|
54
|
-
const
|
|
65
|
+
const suggestApplicationId = (directoryName, name) => `${APPLICATION_ID_PREFIX}${applicationIdSegment(directoryName, name)}${APPLICATION_ID_SUFFIX}`;
|
|
66
|
+
const HOME_PREFIX = /^~(?=$|\/)/;
|
|
67
|
+
const expandHome = (target) => target.replace(HOME_PREFIX, () => homedir());
|
|
68
|
+
const directoryNameOf = (target) => basename(resolve(process.cwd(), target));
|
|
55
69
|
const isDirEmpty = (dir) => {
|
|
56
70
|
const entries = readdirSync(dir);
|
|
57
71
|
return entries.length === 0 || (entries.length === 1 && entries[0] === ".git");
|
|
@@ -78,15 +92,9 @@ const guardCancellation = (value) => {
|
|
|
78
92
|
}
|
|
79
93
|
return value;
|
|
80
94
|
};
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
if (!isValidProjectName(value)) {
|
|
86
|
-
return "Project name must be lowercase letters, numbers, and hyphens only";
|
|
87
|
-
}
|
|
88
|
-
return undefined;
|
|
89
|
-
};
|
|
95
|
+
const validatePackageNameFormat = (value) => isValidPackageName(value) ? undefined : PACKAGE_NAME_FORMAT_ERROR;
|
|
96
|
+
const validatePackageNameInput = (value) => value ? validatePackageNameFormat(value) : "Package name is required";
|
|
97
|
+
const validatePackageNameAnswer = (value) => value ? validatePackageNameFormat(value) : undefined;
|
|
90
98
|
const validateApplicationIdFormat = (value) => isValidApplicationId(value) ? undefined : APPLICATION_ID_FORMAT_ERROR;
|
|
91
99
|
const validateApplicationIdInput = (value) => value ? validateApplicationIdFormat(value) : "Application ID is required";
|
|
92
100
|
const validateApplicationIdAnswer = (value) => value ? validateApplicationIdFormat(value) : undefined;
|
|
@@ -110,20 +118,20 @@ const requestedPackageManager = (value) => {
|
|
|
110
118
|
}
|
|
111
119
|
return value;
|
|
112
120
|
};
|
|
113
|
-
const validateTargetDir = (target) =>
|
|
114
|
-
|
|
115
|
-
return "Project directory is required";
|
|
116
|
-
}
|
|
117
|
-
return validateProjectName(deriveProjectName(target));
|
|
118
|
-
};
|
|
119
|
-
const validateTargetAnswer = (value) => validateTargetDir(value ?? "");
|
|
121
|
+
const validateTargetDir = (target) => target ? undefined : "Project directory is required";
|
|
122
|
+
const validateTargetAnswer = (value) => validateTargetDir(expandHome(value ?? ""));
|
|
120
123
|
const promptTarget = async () => guardCancellation(await p.text({
|
|
121
124
|
message: "Project directory",
|
|
122
125
|
placeholder: "my-app",
|
|
123
126
|
validate: validateTargetAnswer,
|
|
124
127
|
}));
|
|
125
|
-
const
|
|
126
|
-
|
|
128
|
+
const promptPackageName = async (derived) => guardCancellation(await p.text({
|
|
129
|
+
message: "Package name",
|
|
130
|
+
...(derived === "" ? {} : { placeholder: derived, defaultValue: derived }),
|
|
131
|
+
validate: derived === "" ? validatePackageNameInput : validatePackageNameAnswer,
|
|
132
|
+
}));
|
|
133
|
+
const promptApplicationId = async (directoryName, name) => {
|
|
134
|
+
const defaultApplicationId = suggestApplicationId(directoryName, name);
|
|
127
135
|
return guardCancellation(await p.text({
|
|
128
136
|
message: "Application ID",
|
|
129
137
|
placeholder: defaultApplicationId,
|
|
@@ -131,8 +139,8 @@ const promptApplicationId = async (name) => {
|
|
|
131
139
|
validate: validateApplicationIdAnswer,
|
|
132
140
|
}));
|
|
133
141
|
};
|
|
134
|
-
const promptDisplayName = async (
|
|
135
|
-
const defaultDisplayName =
|
|
142
|
+
const promptDisplayName = async (directoryName) => {
|
|
143
|
+
const defaultDisplayName = displayNameFromDirectory(directoryName);
|
|
136
144
|
return guardCancellation(await p.text({
|
|
137
145
|
message: "Display name",
|
|
138
146
|
placeholder: defaultDisplayName,
|
|
@@ -228,20 +236,36 @@ const validateTargetAvailability = async (root, target, options, changes) => {
|
|
|
228
236
|
};
|
|
229
237
|
const resolveTarget = async (options) => {
|
|
230
238
|
if (options.name === undefined && options.isInteractive) {
|
|
231
|
-
return promptTarget();
|
|
239
|
+
return expandHome(await promptTarget());
|
|
232
240
|
}
|
|
233
|
-
const target = options.name ?? "";
|
|
241
|
+
const target = expandHome(options.name ?? "");
|
|
234
242
|
const error = validateTargetDir(target);
|
|
235
243
|
return error === undefined ? target : fail(error);
|
|
236
244
|
};
|
|
237
|
-
const
|
|
238
|
-
const
|
|
245
|
+
const resolvePackageName = async (options, directoryName) => {
|
|
246
|
+
const derived = packageNameFromDirectory(directoryName);
|
|
247
|
+
if (derived === directoryName) {
|
|
248
|
+
return derived;
|
|
249
|
+
}
|
|
250
|
+
if (options.isInteractive) {
|
|
251
|
+
return promptPackageName(derived);
|
|
252
|
+
}
|
|
253
|
+
return derived === ""
|
|
254
|
+
? fail(`Directory name "${directoryName}" has no Latin letters or numbers to derive a package name from. ` +
|
|
255
|
+
"Rename it, or run interactively to enter a package name")
|
|
256
|
+
: derived;
|
|
257
|
+
};
|
|
258
|
+
const resolveApplicationId = async (options, directoryName, name) => {
|
|
259
|
+
const applicationId = options.applicationId ??
|
|
260
|
+
(options.isInteractive
|
|
261
|
+
? await promptApplicationId(directoryName, name)
|
|
262
|
+
: suggestApplicationId(directoryName, name));
|
|
239
263
|
const error = validateApplicationIdInput(applicationId);
|
|
240
264
|
return error === undefined ? applicationId : fail(error);
|
|
241
265
|
};
|
|
242
|
-
const resolveDisplayName = async (options,
|
|
266
|
+
const resolveDisplayName = async (options, directoryName) => {
|
|
243
267
|
const value = options.displayName ??
|
|
244
|
-
(options.isInteractive ? await promptDisplayName(
|
|
268
|
+
(options.isInteractive ? await promptDisplayName(directoryName) : displayNameFromDirectory(directoryName));
|
|
245
269
|
const error = validateDisplayName(value);
|
|
246
270
|
return error === undefined ? value.trim() : fail(error);
|
|
247
271
|
};
|
|
@@ -257,9 +281,10 @@ const resolvePackageManager = async (requested, options) => {
|
|
|
257
281
|
const resolveOptions = async (options) => {
|
|
258
282
|
const requested = requestedPackageManager(options.packageManager);
|
|
259
283
|
const target = await resolveTarget(options);
|
|
260
|
-
const
|
|
261
|
-
const
|
|
262
|
-
const
|
|
284
|
+
const directoryName = directoryNameOf(target);
|
|
285
|
+
const name = await resolvePackageName(options, directoryName);
|
|
286
|
+
const displayName = await resolveDisplayName(options, directoryName);
|
|
287
|
+
const applicationId = await resolveApplicationId(options, directoryName, name);
|
|
263
288
|
const root = resolve(process.cwd(), target);
|
|
264
289
|
const shouldInitialize = shouldInitializeGit(root);
|
|
265
290
|
const packageManager = await resolvePackageManager(requested, options);
|
|
@@ -272,6 +297,7 @@ const resolveOptions = async (options) => {
|
|
|
272
297
|
displayName,
|
|
273
298
|
applicationId,
|
|
274
299
|
packageManager,
|
|
300
|
+
workspace: enclosingWorkspace(root, packageManager),
|
|
275
301
|
isTypescript,
|
|
276
302
|
shouldIncludeTesting,
|
|
277
303
|
shouldInitializeGit: shouldInitialize,
|
|
@@ -293,6 +319,10 @@ const destinationPath = (template, resolved) => {
|
|
|
293
319
|
? `${scriptPath.slice(0, -ICON_TEMPLATE_NAME.length)}${resolved.applicationId}.svg`
|
|
294
320
|
: scriptPath;
|
|
295
321
|
};
|
|
322
|
+
const scriptCommands = ({ packageManager, isTypescript, shouldIncludeTesting, }) => [
|
|
323
|
+
...["dev", "build", "codegen", ...(isTypescript ? ["typecheck"] : [])].map((script) => `${RUN_COMMAND[packageManager]} ${script}`),
|
|
324
|
+
...(shouldIncludeTesting ? [TEST_COMMAND[packageManager]] : []),
|
|
325
|
+
];
|
|
296
326
|
const templateContext = (resolved) => ({
|
|
297
327
|
name: resolved.name,
|
|
298
328
|
applicationId: resolved.applicationId,
|
|
@@ -302,6 +332,8 @@ const templateContext = (resolved) => ({
|
|
|
302
332
|
importExtension: resolved.isTypescript ? ".js" : ".jsx",
|
|
303
333
|
developerName: gitConfigValue("user.name") ?? resolved.displayName,
|
|
304
334
|
developerEmail: gitConfigValue("user.email"),
|
|
335
|
+
packageManager: resolved.packageManager,
|
|
336
|
+
scriptCommands: scriptCommands(resolved),
|
|
305
337
|
});
|
|
306
338
|
const assertSafeAncestor = (ancestor) => {
|
|
307
339
|
const entry = lstatSync(ancestor, { throwIfNoEntry: false });
|
|
@@ -346,18 +378,25 @@ const plannedScaffoldFiles = async (root, resolved) => {
|
|
|
346
378
|
}
|
|
347
379
|
return files;
|
|
348
380
|
};
|
|
349
|
-
const
|
|
381
|
+
const configDestinations = (root, resolved) => resolved.workspace === null
|
|
382
|
+
? PACKAGE_MANAGER_CONFIG_FILES[resolved.packageManager].map((file) => join(root, file))
|
|
383
|
+
: [];
|
|
350
384
|
const planScaffoldProject = async (root, resolved) => {
|
|
351
385
|
const files = await plannedScaffoldFiles(root, resolved);
|
|
352
|
-
|
|
353
|
-
|
|
386
|
+
for (const destination of configDestinations(root, resolved)) {
|
|
387
|
+
hasExistingDestination(root, destination);
|
|
388
|
+
}
|
|
389
|
+
const replaceDestinations = files
|
|
390
|
+
.map((file) => file.destination)
|
|
391
|
+
.filter((destination) => hasExistingDestination(root, destination));
|
|
354
392
|
return {
|
|
355
393
|
files,
|
|
356
394
|
replaceDestinations,
|
|
357
395
|
changes: replaceDestinations.map((destination) => relative(root, destination)),
|
|
396
|
+
packageManagerPin: packageManagerPin(root, resolved.packageManager, resolved.workspace !== null),
|
|
358
397
|
};
|
|
359
398
|
};
|
|
360
|
-
const scaffoldProject = (plan) => {
|
|
399
|
+
const scaffoldProject = (root, plan) => {
|
|
361
400
|
for (const destination of plan.replaceDestinations) {
|
|
362
401
|
rmSync(destination);
|
|
363
402
|
}
|
|
@@ -365,6 +404,12 @@ const scaffoldProject = (plan) => {
|
|
|
365
404
|
mkdirSync(dirname(file.destination), { recursive: true });
|
|
366
405
|
writeFileSync(file.destination, file.contents);
|
|
367
406
|
}
|
|
407
|
+
const pin = plan.packageManagerPin;
|
|
408
|
+
if (pin !== null) {
|
|
409
|
+
updateManifest(root, (manifest) => {
|
|
410
|
+
manifest.packageManager = pin;
|
|
411
|
+
});
|
|
412
|
+
}
|
|
368
413
|
};
|
|
369
414
|
const withoutInheritedScriptPolicy = async (run) => {
|
|
370
415
|
const saved = INHERITED_SCRIPT_POLICY_VARS.map((key) => [key, process.env[key]]);
|
|
@@ -386,44 +431,83 @@ const dependencyVersions = (names) => Object.fromEntries(names.map((dependency)
|
|
|
386
431
|
if (dependency.startsWith("@gtkx/")) {
|
|
387
432
|
return [dependency, `^${selfVersion}`];
|
|
388
433
|
}
|
|
389
|
-
|
|
434
|
+
const range = DEPENDENCY_RANGES[dependency];
|
|
435
|
+
if (range === undefined) {
|
|
436
|
+
throw new Error(`No supported version range for ${dependency}`);
|
|
437
|
+
}
|
|
438
|
+
return [dependency, range];
|
|
390
439
|
}));
|
|
391
|
-
const dependencyArguments = (names) => Object.entries(dependencyVersions(names)).map(([name, version]) =>
|
|
440
|
+
const dependencyArguments = (names) => Object.entries(dependencyVersions(names)).map(([name, version]) => `${name}@${version}`);
|
|
441
|
+
const declaredDependencies = (value) => typeof value === "object" && value !== null ? { ...value } : {};
|
|
392
442
|
const writeDependencies = (root, devDependencies) => {
|
|
393
443
|
updateManifest(root, (manifest) => {
|
|
394
|
-
manifest.dependencies =
|
|
395
|
-
|
|
444
|
+
manifest.dependencies = {
|
|
445
|
+
...dependencyVersions(DEPENDENCIES),
|
|
446
|
+
...declaredDependencies(manifest.dependencies),
|
|
447
|
+
};
|
|
448
|
+
manifest.devDependencies = {
|
|
449
|
+
...dependencyVersions(devDependencies),
|
|
450
|
+
...declaredDependencies(manifest.devDependencies),
|
|
451
|
+
};
|
|
396
452
|
});
|
|
397
453
|
};
|
|
398
454
|
const formatRecovery = (resolved) => `To finish setup, run ${INSTALL_COMMAND[resolved.packageManager]} in ${resolved.root}.`;
|
|
455
|
+
const startProgress = (message) => {
|
|
456
|
+
if (process.stdout.isTTY) {
|
|
457
|
+
const spinner = p.spinner();
|
|
458
|
+
spinner.start(message);
|
|
459
|
+
return spinner;
|
|
460
|
+
}
|
|
461
|
+
p.log.step(message);
|
|
462
|
+
return { stop: (done) => p.log.step(done), error: (failed) => p.log.error(failed) };
|
|
463
|
+
};
|
|
399
464
|
const runWithSpinner = async (step) => {
|
|
400
|
-
const
|
|
401
|
-
spinner.start(step.pending);
|
|
465
|
+
const progress = startProgress(step.pending);
|
|
402
466
|
try {
|
|
403
467
|
await step.run();
|
|
404
|
-
|
|
468
|
+
progress.stop(step.done);
|
|
405
469
|
}
|
|
406
470
|
catch (error) {
|
|
407
|
-
|
|
471
|
+
progress.error(step.failed);
|
|
408
472
|
p.log.error(errorMessage(error));
|
|
409
473
|
step.explain?.();
|
|
410
474
|
throw new ScaffoldAbortedError(step.failed);
|
|
411
475
|
}
|
|
412
476
|
};
|
|
477
|
+
const printWorkspaceAllowances = ({ root, packageManager, workspace }) => {
|
|
478
|
+
const installed = workspace === null ? null : enclosingWorkspace(root, packageManager);
|
|
479
|
+
if (installed === null || installed.missingSettings.length === 0) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
p.log.warn(`The ${installed.packageManager} workspace lacks settings this app needs. ` +
|
|
483
|
+
`Set these entries, then run ${INSTALL_COMMAND[installed.packageManager]}:\n\n` +
|
|
484
|
+
installed.missingSettings
|
|
485
|
+
.map(({ file, section, entries }) => `${section === null ? file : `${file} (under ${section})`}:\n${entries}`)
|
|
486
|
+
.join("\n\n"));
|
|
487
|
+
};
|
|
488
|
+
const hasMissingAllowances = (resolved) => resolved.workspace?.packageManager === "pnpm" && resolved.workspace.missingSettings.length > 0;
|
|
413
489
|
const installAllDependencies = async (resolved, devDependencies) => {
|
|
414
490
|
const { root, packageManager } = resolved;
|
|
491
|
+
const env = hasMissingAllowances(resolved) ? LENIENT_PNPM_BUILDS_ENV : {};
|
|
415
492
|
await runWithSpinner({
|
|
416
493
|
pending: "Installing dependencies...",
|
|
417
494
|
done: "Dependencies installed",
|
|
418
495
|
failed: "Failed to install dependencies",
|
|
419
496
|
run: async () => {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
497
|
+
try {
|
|
498
|
+
await withoutInheritedScriptPolicy(async () => {
|
|
499
|
+
const options = { cwd: root, packageManager, env, silent: true };
|
|
500
|
+
await addDependency(dependencyArguments(DEPENDENCIES), options);
|
|
501
|
+
await addDependency(dependencyArguments(devDependencies), { ...options, dev: true });
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
catch (error) {
|
|
505
|
+
writeDependencies(root, devDependencies);
|
|
506
|
+
throw error;
|
|
507
|
+
}
|
|
425
508
|
},
|
|
426
509
|
explain: () => {
|
|
510
|
+
printWorkspaceAllowances(resolved);
|
|
427
511
|
p.log.info(formatRecovery(resolved));
|
|
428
512
|
},
|
|
429
513
|
});
|
|
@@ -445,17 +529,16 @@ const initializeGitRepo = async (root, shouldInitialize) => {
|
|
|
445
529
|
if (!shouldInitialize || isInsideGitRepository(root)) {
|
|
446
530
|
return;
|
|
447
531
|
}
|
|
448
|
-
const
|
|
449
|
-
spinner.start("Initializing git repository...");
|
|
532
|
+
const progress = startProgress("Initializing git repository...");
|
|
450
533
|
try {
|
|
451
534
|
const opts = { nodeOptions: { cwd: root }, throwOnError: true };
|
|
452
535
|
await x("git", ["init"], opts);
|
|
453
536
|
await x("git", ["add", "-A"], opts);
|
|
454
537
|
await x("git", ["commit", "-m", "Initial commit"], opts);
|
|
455
|
-
|
|
538
|
+
progress.stop("Git repository initialized");
|
|
456
539
|
}
|
|
457
540
|
catch {
|
|
458
|
-
|
|
541
|
+
progress.error("Failed to initialize git repository");
|
|
459
542
|
}
|
|
460
543
|
};
|
|
461
544
|
const missingHeadlessToolsNote = () => {
|
|
@@ -464,6 +547,26 @@ const missingHeadlessToolsNote = () => {
|
|
|
464
547
|
? ""
|
|
465
548
|
: ["", "", "To run tests, install these tools:", ...missingToolLines(missing)].join("\n");
|
|
466
549
|
};
|
|
550
|
+
const addRootMcpServer = ({ workspace, name, root }) => {
|
|
551
|
+
if (workspace === null) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
const result = addWorkspaceMcpServer(workspace, name);
|
|
555
|
+
if (result.kind === "added") {
|
|
556
|
+
p.log.info(`Added the MCP server "${result.key}" to ${result.path}, so an AI client opened at the workspace ` +
|
|
557
|
+
"root reaches this app.");
|
|
558
|
+
}
|
|
559
|
+
else if (result.kind === "shared") {
|
|
560
|
+
p.log.info(`The MCP server "${result.key}" in ${result.path} drives every running GTKX app, including this one, ` +
|
|
561
|
+
`so no server was added for it. To look up this app's bindings, pass projectRoot "${root}" to its ` +
|
|
562
|
+
"reference tools.");
|
|
563
|
+
}
|
|
564
|
+
else if (result.kind === "unreadable") {
|
|
565
|
+
p.log.warn(`Could not add this app's MCP server to ${result.path}: ${result.reason}. For an AI client opened ` +
|
|
566
|
+
`at the workspace root, add this entry under "mcpServers":\n\n` +
|
|
567
|
+
JSON.stringify({ [result.key]: result.server }, null, 4));
|
|
568
|
+
}
|
|
569
|
+
};
|
|
467
570
|
const printNextSteps = (resolved) => {
|
|
468
571
|
const devCmd = DEV_COMMAND[resolved.packageManager];
|
|
469
572
|
const installStep = resolved.shouldInstallDependencies ? "" : `${INSTALL_COMMAND[resolved.packageManager]}\n`;
|
|
@@ -477,8 +580,10 @@ const createProjectStructure = async (root, resolved, plan) => {
|
|
|
477
580
|
failed: "Failed to create the project structure",
|
|
478
581
|
run: () => {
|
|
479
582
|
mkdirSync(root, { recursive: true });
|
|
480
|
-
scaffoldProject(plan);
|
|
481
|
-
|
|
583
|
+
scaffoldProject(root, plan);
|
|
584
|
+
if (resolved.workspace === null) {
|
|
585
|
+
writePackageManagerSettings(root, resolved.packageManager);
|
|
586
|
+
}
|
|
482
587
|
},
|
|
483
588
|
});
|
|
484
589
|
};
|
|
@@ -493,10 +598,12 @@ const scaffold = async (options = {}) => {
|
|
|
493
598
|
await createProjectStructure(root, resolved, plan);
|
|
494
599
|
writeDependencies(root, devDeps);
|
|
495
600
|
reportCompletedChanges(plan.changes);
|
|
601
|
+
addRootMcpServer(resolved);
|
|
496
602
|
if (resolved.shouldInstallDependencies) {
|
|
497
603
|
await installAllDependencies(resolved, devDeps);
|
|
498
604
|
}
|
|
499
605
|
await initializeGitRepo(root, resolved.shouldInitializeGit);
|
|
606
|
+
printWorkspaceAllowances(resolved);
|
|
500
607
|
printNextSteps(resolved);
|
|
501
608
|
};
|
|
502
609
|
export { scaffold };
|