@contember/create 2.2.0-alpha.17 → 2.2.0-alpha.19
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/dist/development/src/commands/WorkspaceCreateCommand.cjs +13 -14
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.js +14 -15
- package/dist/development/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/development/src/lib/FileSystem.cjs +10 -4
- package/dist/development/src/lib/FileSystem.cjs.map +1 -1
- package/dist/development/src/lib/FileSystem.js +8 -2
- package/dist/development/src/lib/FileSystem.js.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.cjs +13 -14
- package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.js +7 -8
- package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/development/src/lib/fsErrors.cjs +7 -0
- package/dist/development/src/lib/fsErrors.cjs.map +1 -0
- package/dist/development/src/lib/fsErrors.js +7 -0
- package/dist/development/src/lib/fsErrors.js.map +1 -0
- package/dist/development/src/lib/projectPath.cjs +66 -0
- package/dist/development/src/lib/projectPath.cjs.map +1 -0
- package/dist/development/src/lib/projectPath.js +66 -0
- package/dist/development/src/lib/projectPath.js.map +1 -0
- package/dist/development/src/lib/remoteTemplate.cjs +108 -0
- package/dist/development/src/lib/remoteTemplate.cjs.map +1 -0
- package/dist/development/src/lib/remoteTemplate.js +108 -0
- package/dist/development/src/lib/remoteTemplate.js.map +1 -0
- package/dist/development/src/lib/tar.cjs +243 -0
- package/dist/development/src/lib/tar.cjs.map +1 -0
- package/dist/development/src/lib/tar.js +243 -0
- package/dist/development/src/lib/tar.js.map +1 -0
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs +13 -14
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.js +14 -15
- package/dist/production/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/production/src/lib/FileSystem.cjs +10 -4
- package/dist/production/src/lib/FileSystem.cjs.map +1 -1
- package/dist/production/src/lib/FileSystem.js +8 -2
- package/dist/production/src/lib/FileSystem.js.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.cjs +13 -14
- package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.js +7 -8
- package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/production/src/lib/fsErrors.cjs +7 -0
- package/dist/production/src/lib/fsErrors.cjs.map +1 -0
- package/dist/production/src/lib/fsErrors.js +7 -0
- package/dist/production/src/lib/fsErrors.js.map +1 -0
- package/dist/production/src/lib/projectPath.cjs +66 -0
- package/dist/production/src/lib/projectPath.cjs.map +1 -0
- package/dist/production/src/lib/projectPath.js +66 -0
- package/dist/production/src/lib/projectPath.js.map +1 -0
- package/dist/production/src/lib/remoteTemplate.cjs +108 -0
- package/dist/production/src/lib/remoteTemplate.cjs.map +1 -0
- package/dist/production/src/lib/remoteTemplate.js +108 -0
- package/dist/production/src/lib/remoteTemplate.js.map +1 -0
- package/dist/production/src/lib/tar.cjs +243 -0
- package/dist/production/src/lib/tar.cjs.map +1 -0
- package/dist/production/src/lib/tar.js +243 -0
- package/dist/production/src/lib/tar.js.map +1 -0
- package/dist/types/commands/WorkspaceCreateCommand.d.ts.map +1 -1
- package/dist/types/lib/FileSystem.d.ts +2 -0
- package/dist/types/lib/FileSystem.d.ts.map +1 -1
- package/dist/types/lib/TemplateInstaller.d.ts.map +1 -1
- package/dist/types/lib/fsErrors.d.ts +3 -0
- package/dist/types/lib/fsErrors.d.ts.map +1 -0
- package/dist/types/lib/projectPath.d.ts +12 -0
- package/dist/types/lib/projectPath.d.ts.map +1 -0
- package/dist/types/lib/remoteTemplate.d.ts +15 -0
- package/dist/types/lib/remoteTemplate.d.ts.map +1 -0
- package/dist/types/lib/tar.d.ts +28 -0
- package/dist/types/lib/tar.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -7
- package/resources/templates/default/admin/lib/editor/sortable-block.tsx +5 -4
- package/resources/templates/default/admin/lib/tenant/dict.ts +3 -0
- package/resources/templates/default/admin/lib/ui/label.tsx +25 -2
- package/resources/templates/default/admin/lib/ui/menu.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/progress.tsx +75 -11
- package/resources/templates/default/admin/lib/ui/separator.tsx +27 -3
- package/resources/templates/default/admin/lib/ui/sidebar.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/toggle.tsx +41 -2
- package/resources/templates/default/admin/lib/utils/classNames.ts +107 -0
- package/resources/templates/default/admin/lib/utils/cn.ts +3 -3
- package/resources/templates/default/admin/lib/utils/index.ts +1 -0
- package/resources/templates/default/admin/lib/utils/uic.tsx +2 -3
- package/resources/templates/default/admin/package.json +0 -7
- package/src/commands/WorkspaceCreateCommand.ts +14 -15
- package/src/lib/FileSystem.ts +7 -2
- package/src/lib/TemplateInstaller.ts +8 -8
- package/src/lib/fsErrors.ts +2 -0
- package/src/lib/projectPath.ts +79 -0
- package/src/lib/remoteTemplate.ts +130 -0
- package/src/lib/tar.ts +283 -0
- package/tests/cases/unit/fileSystem.test.ts +14 -0
- package/tests/cases/unit/fixtures/template.tar.gz +0 -0
- package/tests/cases/unit/remoteTemplate.test.ts +277 -0
- package/tests/cases/unit/template-installer-containment.test.ts +133 -0
- package/tests/cases/unit/template-installer-symlinks.test.ts +37 -0
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const cliCommon = require("@contember/cli-common");
|
|
4
4
|
const path = require("node:path");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
5
|
const version = require("../lib/version.cjs");
|
|
7
6
|
const packageManagerDetector = require("../lib/packageManagerDetector.cjs");
|
|
8
7
|
const defaultRuntime = {
|
|
@@ -48,30 +47,30 @@ Contember project successfully created in ${safeProjectDirectory}
|
|
|
48
47
|
Next steps:
|
|
49
48
|
|
|
50
49
|
1. Navigate to the project directory:
|
|
51
|
-
$ ${
|
|
50
|
+
$ ${cliCommon.style("green", `cd ${safeProjectName}`)}
|
|
52
51
|
|
|
53
52
|
2. Install dependencies:
|
|
54
|
-
$ ${
|
|
53
|
+
$ ${cliCommon.style("green", `${safePackageManager} install`)}
|
|
55
54
|
|
|
56
55
|
3. Start the Contember stack:
|
|
57
|
-
$ ${
|
|
56
|
+
$ ${cliCommon.style("green", `${safePackageManager} start`)}
|
|
58
57
|
|
|
59
58
|
Available services:
|
|
60
59
|
|
|
61
|
-
${
|
|
62
|
-
- Contember Admin ${
|
|
60
|
+
${cliCommon.style("bold", "UI & Admin")}
|
|
61
|
+
- Contember Admin ${cliCommon.style("blue", "http://localhost:1480")}
|
|
63
62
|
|
|
64
|
-
${
|
|
65
|
-
- Contember Engine API ${
|
|
63
|
+
${cliCommon.style("bold", "API & Backend")}
|
|
64
|
+
- Contember Engine API ${cliCommon.style("blue", "http://localhost:1481")}
|
|
66
65
|
Auth token: 0000000000000000000000000000000000000000
|
|
67
66
|
|
|
68
|
-
${
|
|
69
|
-
- PostgreSQL database ${
|
|
70
|
-
- S3 object storage ${
|
|
71
|
-
- Mailpit SMTP testing ${
|
|
72
|
-
- Adminer DB manager ${
|
|
67
|
+
${cliCommon.style("bold", "Development Tools")}
|
|
68
|
+
- PostgreSQL database ${cliCommon.style("blue", "http://localhost:1482")} ${cliCommon.style("grey", "credentials: contember / contember")}
|
|
69
|
+
- S3 object storage ${cliCommon.style("blue", "http://localhost:1483")} ${cliCommon.style("grey", "credentials: contember / contember")}
|
|
70
|
+
- Mailpit SMTP testing ${cliCommon.style("blue", "http://localhost:1484")}
|
|
71
|
+
- Adminer DB manager ${cliCommon.style("blue", "http://localhost:1485")}
|
|
73
72
|
|
|
74
|
-
${
|
|
73
|
+
${cliCommon.style("bold", "Need help?")} Ask the community: https://github.com/orgs/contember/discussions
|
|
75
74
|
`;
|
|
76
75
|
};
|
|
77
76
|
exports.WorkspaceCreateCommand = WorkspaceCreateCommand;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceCreateCommand.cjs","sources":["../../../../../packages/create/src/commands/WorkspaceCreateCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, escapeTerminalText, Input, Output } from '@contember/cli-common'\nimport { join } from 'node:path'\nimport
|
|
1
|
+
{"version":3,"file":"WorkspaceCreateCommand.cjs","sources":["../../../../../packages/create/src/commands/WorkspaceCreateCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, escapeTerminalText, Input, Output, style } from '@contember/cli-common'\nimport { join } from 'node:path'\nimport { TemplateInstaller } from '../lib/TemplateInstaller.js'\nimport { getPackageVersion } from '../lib/version.js'\nimport { detectPackageManager } from '../lib/packageManagerDetector.js'\n\ntype Args = {\n\tprojectName: string\n}\n\ntype Options = {\n\ttemplate: string\n}\n\nexport interface WorkspaceCreateResult {\n\tprojectName: string\n\tprojectDirectory: string\n\ttemplate: string\n\tpackageManager: string\n}\n\nexport interface WorkspaceCreateRuntime {\n\tcwd(): string\n\tgetPackageVersion(): Promise<string>\n\tdetectPackageManager(): string\n}\n\nconst defaultRuntime: WorkspaceCreateRuntime = {\n\tcwd: () => process.cwd(),\n\tgetPackageVersion,\n\tdetectPackageManager,\n}\n\nexport class WorkspaceCreateCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly templateInstaller: Pick<TemplateInstaller, 'installTemplate'>,\n\t\tprivate readonly runtime: WorkspaceCreateRuntime = defaultRuntime,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Creates a new Contember project')\n\t\tconfiguration.argument('projectName')\n\t\tconfiguration.option('template').shortcut('t').valueRequired().description('Template name or remote source')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>, output: Output): Promise<void> {\n\t\tconst projectName = input.getArgument('projectName')\n\t\tconst projectDirectory = join(this.runtime.cwd(), projectName)\n\t\tconst packageManager = this.runtime.detectPackageManager()\n\t\tconst template = input.getOption('template') ?? 'default'\n\n\t\tawait this.templateInstaller.installTemplate(template, projectDirectory, {\n\t\t\tversion: await this.runtime.getPackageVersion(),\n\t\t\tprojectName: projectName,\n\t\t\tpackageManager: packageManager,\n\t\t})\n\n\t\tconst result: WorkspaceCreateResult = { projectName, projectDirectory, template, packageManager }\n\t\toutput.data(result, {\n\t\t\thuman: value => createDocs(value),\n\t\t\tquiet: value => value.projectDirectory,\n\t\t})\n\t}\n}\n\nconst createDocs = ({ projectDirectory, projectName, packageManager }: WorkspaceCreateResult) => {\n\tconst safeProjectDirectory = escapeTerminalText(projectDirectory)\n\tconst safeProjectName = escapeTerminalText(projectName)\n\tconst safePackageManager = escapeTerminalText(packageManager)\n\treturn `\nContember project successfully created in ${safeProjectDirectory}\n\nNext steps:\n\n1. Navigate to the project directory:\n $ ${style('green', `cd ${safeProjectName}`)}\n\n2. Install dependencies:\n $ ${style('green', `${safePackageManager} install`)}\n\n3. Start the Contember stack:\n $ ${style('green', `${safePackageManager} start`)}\n\nAvailable services:\n\n${style('bold', 'UI & Admin')}\n- Contember Admin ${style('blue', 'http://localhost:1480')}\n\n${style('bold', 'API & Backend')}\n- Contember Engine API ${style('blue', 'http://localhost:1481')}\n Auth token: 0000000000000000000000000000000000000000\n\n${style('bold', 'Development Tools')}\n- PostgreSQL database ${style('blue', 'http://localhost:1482')} ${style('grey', 'credentials: contember / contember')}\n- S3 object storage ${style('blue', 'http://localhost:1483')} ${style('grey', 'credentials: contember / contember')}\n- Mailpit SMTP testing ${style('blue', 'http://localhost:1484')}\n- Adminer DB manager ${style('blue', 'http://localhost:1485')}\n\n${style('bold', 'Need help?')} Ask the community: https://github.com/orgs/contember/discussions\n`\n}\n"],"names":["getPackageVersion","detectPackageManager","Command","join","escapeTerminalText","style"],"mappings":";;;;;;AA2BA,MAAM,iBAAyC;A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M,eAAe,EAAE,CAAC;AAAA;AAAA;AAAA,OAGvCA,UAAAA,MAAM,SAAS,GAAG,kBAAkB,UAAU,CAAC;AAAA;AAAA;AAAA,OAG/CA,UAAAA,MAAM,SAAS,GAAG,kBAAkB,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA,EAIlDA,UAAAA,MAAM,QAAQ,YAAY,CAAC;AAAA,4BACDA,UAAAA,MAAM,QAAQ,uBAAuB,CAAC;AAAA;AAAA,EAEhEA,UAAAA,MAAM,QAAQ,eAAe,CAAC;AAAA,4BACJA,UAAAA,MAAM,QAAQ,uBAAuB,CAAC;AAAA;AAAA;AAAA,EAGhEA,UAAAA,MAAM,QAAQ,mBAAmB,CAAC;AAAA,4BACRA,UAAAA,MAAM,QAAQ,uBAAuB,CAAC,OAAOA,UAAAA,MAAM,QAAQ,oCAAoC,CAAC;AAAA,4BAChGA,UAAAA,MAAM,QAAQ,uBAAuB,CAAC,OAAOA,UAAAA,MAAM,QAAQ,oCAAoC,CAAC;AAAA,4BAChGA,UAAAA,MAAM,QAAQ,uBAAuB,CAAC;AAAA,4BACtCA,UAAAA,MAAM,QAAQ,uBAAuB,CAAC;AAAA;AAAA,EAEhEA,gBAAM,QAAQ,YAAY,CAAC;AAAA;AAE7B;;"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Command, escapeTerminalText } from "@contember/cli-common";
|
|
1
|
+
import { Command, escapeTerminalText, style } from "@contember/cli-common";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import chalk from "chalk";
|
|
4
3
|
import { getPackageVersion } from "../lib/version.js";
|
|
5
4
|
import { detectPackageManager } from "../lib/packageManagerDetector.js";
|
|
6
5
|
const defaultRuntime = {
|
|
@@ -46,30 +45,30 @@ Contember project successfully created in ${safeProjectDirectory}
|
|
|
46
45
|
Next steps:
|
|
47
46
|
|
|
48
47
|
1. Navigate to the project directory:
|
|
49
|
-
$ ${
|
|
48
|
+
$ ${style("green", `cd ${safeProjectName}`)}
|
|
50
49
|
|
|
51
50
|
2. Install dependencies:
|
|
52
|
-
$ ${
|
|
51
|
+
$ ${style("green", `${safePackageManager} install`)}
|
|
53
52
|
|
|
54
53
|
3. Start the Contember stack:
|
|
55
|
-
$ ${
|
|
54
|
+
$ ${style("green", `${safePackageManager} start`)}
|
|
56
55
|
|
|
57
56
|
Available services:
|
|
58
57
|
|
|
59
|
-
${
|
|
60
|
-
- Contember Admin ${
|
|
58
|
+
${style("bold", "UI & Admin")}
|
|
59
|
+
- Contember Admin ${style("blue", "http://localhost:1480")}
|
|
61
60
|
|
|
62
|
-
${
|
|
63
|
-
- Contember Engine API ${
|
|
61
|
+
${style("bold", "API & Backend")}
|
|
62
|
+
- Contember Engine API ${style("blue", "http://localhost:1481")}
|
|
64
63
|
Auth token: 0000000000000000000000000000000000000000
|
|
65
64
|
|
|
66
|
-
${
|
|
67
|
-
- PostgreSQL database ${
|
|
68
|
-
- S3 object storage ${
|
|
69
|
-
- Mailpit SMTP testing ${
|
|
70
|
-
- Adminer DB manager ${
|
|
65
|
+
${style("bold", "Development Tools")}
|
|
66
|
+
- PostgreSQL database ${style("blue", "http://localhost:1482")} ${style("grey", "credentials: contember / contember")}
|
|
67
|
+
- S3 object storage ${style("blue", "http://localhost:1483")} ${style("grey", "credentials: contember / contember")}
|
|
68
|
+
- Mailpit SMTP testing ${style("blue", "http://localhost:1484")}
|
|
69
|
+
- Adminer DB manager ${style("blue", "http://localhost:1485")}
|
|
71
70
|
|
|
72
|
-
${
|
|
71
|
+
${style("bold", "Need help?")} Ask the community: https://github.com/orgs/contember/discussions
|
|
73
72
|
`;
|
|
74
73
|
};
|
|
75
74
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceCreateCommand.js","sources":["../../../../../packages/create/src/commands/WorkspaceCreateCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, escapeTerminalText, Input, Output } from '@contember/cli-common'\nimport { join } from 'node:path'\nimport
|
|
1
|
+
{"version":3,"file":"WorkspaceCreateCommand.js","sources":["../../../../../packages/create/src/commands/WorkspaceCreateCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, escapeTerminalText, Input, Output, style } from '@contember/cli-common'\nimport { join } from 'node:path'\nimport { TemplateInstaller } from '../lib/TemplateInstaller.js'\nimport { getPackageVersion } from '../lib/version.js'\nimport { detectPackageManager } from '../lib/packageManagerDetector.js'\n\ntype Args = {\n\tprojectName: string\n}\n\ntype Options = {\n\ttemplate: string\n}\n\nexport interface WorkspaceCreateResult {\n\tprojectName: string\n\tprojectDirectory: string\n\ttemplate: string\n\tpackageManager: string\n}\n\nexport interface WorkspaceCreateRuntime {\n\tcwd(): string\n\tgetPackageVersion(): Promise<string>\n\tdetectPackageManager(): string\n}\n\nconst defaultRuntime: WorkspaceCreateRuntime = {\n\tcwd: () => process.cwd(),\n\tgetPackageVersion,\n\tdetectPackageManager,\n}\n\nexport class WorkspaceCreateCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly templateInstaller: Pick<TemplateInstaller, 'installTemplate'>,\n\t\tprivate readonly runtime: WorkspaceCreateRuntime = defaultRuntime,\n\t) {\n\t\tsuper()\n\t}\n\n\tprotected configure(configuration: CommandConfiguration<Args, Options>): void {\n\t\tconfiguration.description('Creates a new Contember project')\n\t\tconfiguration.argument('projectName')\n\t\tconfiguration.option('template').shortcut('t').valueRequired().description('Template name or remote source')\n\t}\n\n\tprotected async execute(input: Input<Args, Options>, output: Output): Promise<void> {\n\t\tconst projectName = input.getArgument('projectName')\n\t\tconst projectDirectory = join(this.runtime.cwd(), projectName)\n\t\tconst packageManager = this.runtime.detectPackageManager()\n\t\tconst template = input.getOption('template') ?? 'default'\n\n\t\tawait this.templateInstaller.installTemplate(template, projectDirectory, {\n\t\t\tversion: await this.runtime.getPackageVersion(),\n\t\t\tprojectName: projectName,\n\t\t\tpackageManager: packageManager,\n\t\t})\n\n\t\tconst result: WorkspaceCreateResult = { projectName, projectDirectory, template, packageManager }\n\t\toutput.data(result, {\n\t\t\thuman: value => createDocs(value),\n\t\t\tquiet: value => value.projectDirectory,\n\t\t})\n\t}\n}\n\nconst createDocs = ({ projectDirectory, projectName, packageManager }: WorkspaceCreateResult) => {\n\tconst safeProjectDirectory = escapeTerminalText(projectDirectory)\n\tconst safeProjectName = escapeTerminalText(projectName)\n\tconst safePackageManager = escapeTerminalText(packageManager)\n\treturn `\nContember project successfully created in ${safeProjectDirectory}\n\nNext steps:\n\n1. Navigate to the project directory:\n $ ${style('green', `cd ${safeProjectName}`)}\n\n2. Install dependencies:\n $ ${style('green', `${safePackageManager} install`)}\n\n3. Start the Contember stack:\n $ ${style('green', `${safePackageManager} start`)}\n\nAvailable services:\n\n${style('bold', 'UI & Admin')}\n- Contember Admin ${style('blue', 'http://localhost:1480')}\n\n${style('bold', 'API & Backend')}\n- Contember Engine API ${style('blue', 'http://localhost:1481')}\n Auth token: 0000000000000000000000000000000000000000\n\n${style('bold', 'Development Tools')}\n- PostgreSQL database ${style('blue', 'http://localhost:1482')} ${style('grey', 'credentials: contember / contember')}\n- S3 object storage ${style('blue', 'http://localhost:1483')} ${style('grey', 'credentials: contember / contember')}\n- Mailpit SMTP testing ${style('blue', 'http://localhost:1484')}\n- Adminer DB manager ${style('blue', 'http://localhost:1485')}\n\n${style('bold', 'Need help?')} Ask the community: https://github.com/orgs/contember/discussions\n`\n}\n"],"names":[],"mappings":";;;;AA2BA,MAAM,iBAAyC;AAAA,EAC9C,KAAK,MAAM,QAAQ,IAAA;AAAA,EACnB;AAAA,EACA;AACD;AAEO,MAAM,+BAA+B,QAAuB;AAAA,EAClE,YACkB,mBACA,UAAkC,gBAClD;AACD,UAAA;AAHiB,SAAA,oBAAA;AACA,SAAA,UAAA;AAAA,EAGlB;AAAA,EAEU,UAAU,eAA0D;AAC7E,kBAAc,YAAY,iCAAiC;AAC3D,kBAAc,SAAS,aAAa;AACpC,kBAAc,OAAO,UAAU,EAAE,SAAS,GAAG,EAAE,cAAA,EAAgB,YAAY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AAO,MAAM,QAAQ,oCAAoC,CAAC;AAAA,4BAChG,MAAM,QAAQ,uBAAuB,CAAC,OAAO,MAAM,QAAQ,oCAAoC,CAAC;AAAA,4BAChG,MAAM,QAAQ,uBAAuB,CAAC;AAAA,4BACtC,MAAM,QAAQ,uBAAuB,CAAC;AAAA;AAAA,EAEhE,MAAM,QAAQ,YAAY,CAAC;AAAA;AAE7B;"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fs = require("node:fs/promises");
|
|
4
4
|
const os = require("node:os");
|
|
5
|
+
const path = require("node:path");
|
|
5
6
|
function _interopNamespaceDefault(e) {
|
|
6
7
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
8
|
if (e) {
|
|
@@ -27,20 +28,25 @@ class FileSystem {
|
|
|
27
28
|
__publicField(this, "readFile", fs__namespace.readFile);
|
|
28
29
|
__publicField(this, "writeFile", fs__namespace.writeFile);
|
|
29
30
|
__publicField(this, "rename", fs__namespace.rename);
|
|
31
|
+
__publicField(this, "realPath", fs__namespace.realpath);
|
|
32
|
+
__publicField(this, "lstat", fs__namespace.lstat);
|
|
30
33
|
__publicField(this, "readDir", fs__namespace.readdir);
|
|
31
|
-
__publicField(this, "copy", (source, destination, options) =>
|
|
34
|
+
__publicField(this, "copy", (source, destination, options) => (
|
|
35
|
+
// verbatimSymlinks: by default fs.cp rewrites relative links into absolute paths into the source tree
|
|
36
|
+
fs__namespace.cp(source, destination, { recursive: true, verbatimSymlinks: true, ...options })
|
|
37
|
+
));
|
|
32
38
|
__publicField(this, "unlink", fs__namespace.unlink);
|
|
33
39
|
__publicField(this, "remove", fs__namespace.rm);
|
|
34
|
-
__publicField(this, "pathExists", async (
|
|
40
|
+
__publicField(this, "pathExists", async (path2) => {
|
|
35
41
|
try {
|
|
36
|
-
await fs.access(
|
|
42
|
+
await fs.access(path2);
|
|
37
43
|
return true;
|
|
38
44
|
} catch {
|
|
39
45
|
return false;
|
|
40
46
|
}
|
|
41
47
|
});
|
|
42
48
|
__publicField(this, "createTempDir", async () => {
|
|
43
|
-
return await fs__namespace.mkdtemp(os.tmpdir());
|
|
49
|
+
return await fs__namespace.mkdtemp(path.join(os.tmpdir(), "contember-template-"));
|
|
44
50
|
});
|
|
45
51
|
}
|
|
46
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystem.cjs","sources":["../../../../../packages/create/src/lib/FileSystem.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { access } from 'node:fs/promises'\nimport { tmpdir } from 'node:os'\n\nexport class FileSystem {\n\treadFile = fs.readFile\n\twriteFile = fs.writeFile\n\trename = fs.rename\n\treadDir = fs.readdir\n\tcopy = (source: string, destination: string, options?: { filter?: (source: string, destination: string) => boolean }) =>\n\t\tfs.cp(source, destination, { recursive: true, ...options })\n\tunlink = fs.unlink\n\tremove = fs.rm\n\tpathExists = async (path: string) => {\n\t\ttry {\n\t\t\tawait access(path)\n\t\t\treturn true\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t}\n\tcreateTempDir = async () => {\n\t\treturn await fs.mkdtemp(tmpdir())\n\t}\n}\n"],"names":["fs","access","tmpdir"],"mappings":"
|
|
1
|
+
{"version":3,"file":"FileSystem.cjs","sources":["../../../../../packages/create/src/lib/FileSystem.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { access } from 'node:fs/promises'\nimport { tmpdir } from 'node:os'\nimport { join } from 'node:path'\n\nexport class FileSystem {\n\treadFile = fs.readFile\n\twriteFile = fs.writeFile\n\trename = fs.rename\n\trealPath = fs.realpath\n\tlstat = fs.lstat\n\treadDir = fs.readdir\n\tcopy = (source: string, destination: string, options?: { filter?: (source: string, destination: string) => boolean }) =>\n\t\t// verbatimSymlinks: by default fs.cp rewrites relative links into absolute paths into the source tree\n\t\tfs.cp(source, destination, { recursive: true, verbatimSymlinks: true, ...options })\n\tunlink = fs.unlink\n\tremove = fs.rm\n\tpathExists = async (path: string) => {\n\t\ttry {\n\t\t\tawait access(path)\n\t\t\treturn true\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t}\n\tcreateTempDir = async () => {\n\t\t// mkdtemp appends random characters to the prefix, so without a separator it would create `/tmpXXXXXX`\n\t\treturn await fs.mkdtemp(join(tmpdir(), 'contember-template-'))\n\t}\n}\n"],"names":["fs","path","access","join","tmpdir"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAKO,MAAM,WAAW;AAAA,EAAjB,cAAA;AACN,kBAAA,MAAA,YAAWA,cAAG,QAAA;AACd,kBAAA,MAAA,aAAYA,cAAG,SAAA;AACf,kBAAA,MAAA,UAASA,cAAG,MAAA;AACZ,kBAAA,MAAA,YAAWA,cAAG,QAAA;AACd,kBAAA,MAAA,SAAQA,cAAG,KAAA;AACX,kBAAA,MAAA,WAAUA,cAAG,OAAA;AACb,kBAAA,MAAA,QAAO,CAAC,QAAgB,aAAqB;AAAA;AAAA,MAE5CA,cAAG,GAAG,QAAQ,aAAa,EAAE,WAAW,MAAM,kBAAkB,MAAM,GAAG,QAAA,CAAS;AAAA,KAAA;AACnF,kBAAA,MAAA,UAASA,cAAG,MAAA;AACZ,kBAAA,MAAA,UAASA,cAAG,EAAA;AACZ,kBAAA,MAAA,cAAa,OAAOC,UAAiB;AACpC,UAAI;AACH,cAAMC,GAAAA,OAAOD,KAAI;AACjB,eAAO;AAAA,MACR,QAAQ;AACP,eAAO;AAAA,MACR;AAAA,IACD,CAAA;AACA,kBAAA,MAAA,iBAAgB,YAAY;AAE3B,aAAO,MAAMD,cAAG,QAAQG,KAAAA,KAAKC,GAAAA,OAAA,GAAU,qBAAqB,CAAC;AAAA,IAC9D,CAAA;AAAA,EAAA;AACD;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs/promises";
|
|
2
2
|
import { access } from "node:fs/promises";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
7
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -9,8 +10,13 @@ class FileSystem {
|
|
|
9
10
|
__publicField(this, "readFile", fs.readFile);
|
|
10
11
|
__publicField(this, "writeFile", fs.writeFile);
|
|
11
12
|
__publicField(this, "rename", fs.rename);
|
|
13
|
+
__publicField(this, "realPath", fs.realpath);
|
|
14
|
+
__publicField(this, "lstat", fs.lstat);
|
|
12
15
|
__publicField(this, "readDir", fs.readdir);
|
|
13
|
-
__publicField(this, "copy", (source, destination, options) =>
|
|
16
|
+
__publicField(this, "copy", (source, destination, options) => (
|
|
17
|
+
// verbatimSymlinks: by default fs.cp rewrites relative links into absolute paths into the source tree
|
|
18
|
+
fs.cp(source, destination, { recursive: true, verbatimSymlinks: true, ...options })
|
|
19
|
+
));
|
|
14
20
|
__publicField(this, "unlink", fs.unlink);
|
|
15
21
|
__publicField(this, "remove", fs.rm);
|
|
16
22
|
__publicField(this, "pathExists", async (path) => {
|
|
@@ -22,7 +28,7 @@ class FileSystem {
|
|
|
22
28
|
}
|
|
23
29
|
});
|
|
24
30
|
__publicField(this, "createTempDir", async () => {
|
|
25
|
-
return await fs.mkdtemp(tmpdir());
|
|
31
|
+
return await fs.mkdtemp(join(tmpdir(), "contember-template-"));
|
|
26
32
|
});
|
|
27
33
|
}
|
|
28
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystem.js","sources":["../../../../../packages/create/src/lib/FileSystem.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { access } from 'node:fs/promises'\nimport { tmpdir } from 'node:os'\n\nexport class FileSystem {\n\treadFile = fs.readFile\n\twriteFile = fs.writeFile\n\trename = fs.rename\n\treadDir = fs.readdir\n\tcopy = (source: string, destination: string, options?: { filter?: (source: string, destination: string) => boolean }) =>\n\t\tfs.cp(source, destination, { recursive: true, ...options })\n\tunlink = fs.unlink\n\tremove = fs.rm\n\tpathExists = async (path: string) => {\n\t\ttry {\n\t\t\tawait access(path)\n\t\t\treturn true\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t}\n\tcreateTempDir = async () => {\n\t\treturn await fs.mkdtemp(tmpdir())\n\t}\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FileSystem.js","sources":["../../../../../packages/create/src/lib/FileSystem.ts"],"sourcesContent":["import * as fs from 'node:fs/promises'\nimport { access } from 'node:fs/promises'\nimport { tmpdir } from 'node:os'\nimport { join } from 'node:path'\n\nexport class FileSystem {\n\treadFile = fs.readFile\n\twriteFile = fs.writeFile\n\trename = fs.rename\n\trealPath = fs.realpath\n\tlstat = fs.lstat\n\treadDir = fs.readdir\n\tcopy = (source: string, destination: string, options?: { filter?: (source: string, destination: string) => boolean }) =>\n\t\t// verbatimSymlinks: by default fs.cp rewrites relative links into absolute paths into the source tree\n\t\tfs.cp(source, destination, { recursive: true, verbatimSymlinks: true, ...options })\n\tunlink = fs.unlink\n\tremove = fs.rm\n\tpathExists = async (path: string) => {\n\t\ttry {\n\t\t\tawait access(path)\n\t\t\treturn true\n\t\t} catch {\n\t\t\treturn false\n\t\t}\n\t}\n\tcreateTempDir = async () => {\n\t\t// mkdtemp appends random characters to the prefix, so without a separator it would create `/tmpXXXXXX`\n\t\treturn await fs.mkdtemp(join(tmpdir(), 'contember-template-'))\n\t}\n}\n"],"names":[],"mappings":";;;;;;;AAKO,MAAM,WAAW;AAAA,EAAjB,cAAA;AACN,kBAAA,MAAA,YAAW,GAAG,QAAA;AACd,kBAAA,MAAA,aAAY,GAAG,SAAA;AACf,kBAAA,MAAA,UAAS,GAAG,MAAA;AACZ,kBAAA,MAAA,YAAW,GAAG,QAAA;AACd,kBAAA,MAAA,SAAQ,GAAG,KAAA;AACX,kBAAA,MAAA,WAAU,GAAG,OAAA;AACb,kBAAA,MAAA,QAAO,CAAC,QAAgB,aAAqB;AAAA;AAAA,MAE5C,GAAG,GAAG,QAAQ,aAAa,EAAE,WAAW,MAAM,kBAAkB,MAAM,GAAG,QAAA,CAAS;AAAA,KAAA;AACnF,kBAAA,MAAA,UAAS,GAAG,MAAA;AACZ,kBAAA,MAAA,UAAS,GAAG,EAAA;AACZ,kBAAA,MAAA,cAAa,OAAO,SAAiB;AACpC,UAAI;AACH,cAAM,OAAO,IAAI;AACjB,eAAO;AAAA,MACR,QAAQ;AACP,eAAO;AAAA,MACR;AAAA,IACD,CAAA;AACA,kBAAA,MAAA,iBAAgB,YAAY;AAE3B,aAAO,MAAM,GAAG,QAAQ,KAAK,OAAA,GAAU,qBAAqB,CAAC;AAAA,IAC9D,CAAA;AAAA,EAAA;AACD;"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const path = require("node:path");
|
|
4
|
-
const degit = require("degit");
|
|
5
4
|
const jsyaml = require("js-yaml");
|
|
5
|
+
const projectPath = require("./projectPath.cjs");
|
|
6
|
+
const remoteTemplate = require("./remoteTemplate.cjs");
|
|
6
7
|
var __defProp = Object.defineProperty;
|
|
7
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
9
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
-
const cloneTemplate =
|
|
10
|
-
const emitter = degit(source, { cache: false, force: true, verbose: true });
|
|
11
|
-
await emitter.clone(target);
|
|
12
|
-
};
|
|
10
|
+
const cloneTemplate = (source, target) => remoteTemplate.downloadTemplate(source, target);
|
|
13
11
|
class TemplateInstaller {
|
|
14
12
|
constructor(resourceDir, fs, output, clone = cloneTemplate) {
|
|
15
13
|
this.resourceDir = resourceDir;
|
|
@@ -19,18 +17,18 @@ class TemplateInstaller {
|
|
|
19
17
|
__publicField(this, "localTemplates");
|
|
20
18
|
__publicField(this, "installTemplate", async (template, targetDir, variables = {}) => {
|
|
21
19
|
let temporaryTemplateDir;
|
|
22
|
-
let
|
|
20
|
+
let remoteTemplate2;
|
|
23
21
|
if (this.localTemplates[template]) {
|
|
24
22
|
template = this.localTemplates[template];
|
|
25
23
|
} else {
|
|
26
|
-
|
|
24
|
+
remoteTemplate2 = template;
|
|
27
25
|
temporaryTemplateDir = await this.fs.createTempDir();
|
|
28
26
|
template = temporaryTemplateDir;
|
|
29
27
|
}
|
|
30
28
|
try {
|
|
31
|
-
if (
|
|
29
|
+
if (remoteTemplate2 !== void 0) {
|
|
32
30
|
try {
|
|
33
|
-
await this.clone(
|
|
31
|
+
await this.clone(remoteTemplate2, template);
|
|
34
32
|
} catch (error) {
|
|
35
33
|
throw new Error(`Failed to clone template from repository: ${error}`);
|
|
36
34
|
}
|
|
@@ -61,18 +59,19 @@ class TemplateInstaller {
|
|
|
61
59
|
return JSON.stringify({ scripts, ...json }, null, " ");
|
|
62
60
|
});
|
|
63
61
|
}
|
|
62
|
+
const projectPath$1 = (path2) => projectPath.resolveProjectPath(this.fs, targetDir, path2);
|
|
64
63
|
for (const [source, target] of Object.entries(config.rename || {})) {
|
|
65
|
-
await this.fs.rename(
|
|
64
|
+
await this.fs.rename(await projectPath$1(source), await projectPath$1(target));
|
|
66
65
|
}
|
|
67
66
|
for (const [source, target] of Object.entries(config.copy || {})) {
|
|
68
|
-
await this.fs.copy(
|
|
67
|
+
await this.fs.copy(await projectPath$1(source), await projectPath.resolveNewProjectPath(this.fs, targetDir, target));
|
|
69
68
|
}
|
|
70
69
|
for (const file of config.replaceVariables || []) {
|
|
71
|
-
const
|
|
72
|
-
if (!await this.fs.pathExists(
|
|
70
|
+
const path2 = await projectPath$1(file);
|
|
71
|
+
if (!await this.fs.pathExists(path2)) {
|
|
73
72
|
continue;
|
|
74
73
|
}
|
|
75
|
-
await this.replaceFileContent(
|
|
74
|
+
await this.replaceFileContent(path2, (content) => Object.entries(variables).reduce(
|
|
76
75
|
(content2, [key, value]) => content2.replace(new RegExp(`{${key}}`, "g"), value),
|
|
77
76
|
content
|
|
78
77
|
));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateInstaller.cjs","sources":["../../../../../packages/create/src/lib/TemplateInstaller.ts"],"sourcesContent":["import { join } from 'node:path'\nimport
|
|
1
|
+
{"version":3,"file":"TemplateInstaller.cjs","sources":["../../../../../packages/create/src/lib/TemplateInstaller.ts"],"sourcesContent":["import { join } from 'node:path'\nimport jsyaml from 'js-yaml'\nimport { FileSystem } from './FileSystem.js'\nimport { resolveNewProjectPath, resolveProjectPath } from './projectPath.js'\nimport { downloadTemplate } from './remoteTemplate.js'\n\ninterface TemplateInstallerOutput {\n\twarn(message: string): void\n}\n\ntype CloneTemplate = (source: string, target: string) => Promise<void>\n\nconst cloneTemplate: CloneTemplate = (source, target) => downloadTemplate(source, target)\n\nexport class TemplateInstaller {\n\tprivate localTemplates: Record<string, string>\n\n\tconstructor(\n\t\tprivate readonly resourceDir: string,\n\t\tprivate readonly fs: FileSystem,\n\t\tprivate readonly output: TemplateInstallerOutput,\n\t\tprivate readonly clone: CloneTemplate = cloneTemplate,\n\t) {\n\t\tthis.localTemplates = {\n\t\t\t['default']: join(this.resourceDir, 'templates/default'),\n\t\t}\n\t}\n\n\tinstallTemplate = async (\n\t\ttemplate: string,\n\t\ttargetDir: string,\n\t\tvariables: Record<string, string> = {},\n\t) => {\n\t\tlet temporaryTemplateDir: string | undefined\n\t\tlet remoteTemplate: string | undefined\n\n\t\tif (this.localTemplates[template]) {\n\t\t\ttemplate = this.localTemplates[template]\n\t\t} else {\n\t\t\tremoteTemplate = template\n\t\t\ttemporaryTemplateDir = await this.fs.createTempDir()\n\t\t\ttemplate = temporaryTemplateDir\n\t\t}\n\n\t\ttry {\n\t\t\tif (remoteTemplate !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.clone(remoteTemplate, template)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthrow new Error(`Failed to clone template from repository: ${error}`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst templateConfigFile = join(template, 'contember.template.yaml')\n\t\t\tif (!(await this.fs.pathExists(templateConfigFile))) {\n\t\t\t\tthrow new Error(`${template} is not a Contember template`)\n\t\t\t}\n\t\t\tconst config = (await this.readYaml(templateConfigFile)) as {\n\t\t\t\ttype?: string\n\t\t\t\tremove?: string[]\n\t\t\t\tpatchPackageJson?: boolean\n\t\t\t\trename?: Record<string, string>\n\t\t\t\tcopy?: Record<string, string>\n\t\t\t\treplaceVariables?: string[]\n\t\t\t}\n\t\t\tconst nodeModulesDir = join(template, 'node_modules')\n\t\t\tconst skippedFiles = new Set([...(config.remove || []).map(it => join(template, it)), templateConfigFile])\n\t\t\tif (await this.fs.pathExists(targetDir)) {\n\t\t\t\tthrow `${targetDir} already exists`\n\t\t\t}\n\t\t\tawait this.fs.copy(template, targetDir, {\n\t\t\t\tfilter: src => !src.startsWith(nodeModulesDir) && !skippedFiles.has(src),\n\t\t\t})\n\n\t\t\tif (config.patchPackageJson) {\n\t\t\t\tawait this.replaceFileContent(join(targetDir, 'package.json'), content => {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t\t'scripts-template': scripts,\n\t\t\t\t\t\tscripts: _nullScripts,\n\t\t\t\t\t\tlicense,\n\t\t\t\t\t\t...json\n\t\t\t\t\t} = JSON.parse(content)\n\t\t\t\t\treturn JSON.stringify({ scripts, ...json }, null, ' ')\n\t\t\t\t})\n\t\t\t}\n\t\t\t// The template is untrusted input: every directive path must stay inside the new project.\n\t\t\tconst projectPath = (path: string) => resolveProjectPath(this.fs, targetDir, path)\n\t\t\tfor (const [source, target] of Object.entries(config.rename || {})) {\n\t\t\t\tawait this.fs.rename(await projectPath(source), await projectPath(target))\n\t\t\t}\n\t\t\tfor (const [source, target] of Object.entries(config.copy || {})) {\n\t\t\t\tawait this.fs.copy(await projectPath(source), await resolveNewProjectPath(this.fs, targetDir, target))\n\t\t\t}\n\n\t\t\tfor (const file of config.replaceVariables || []) {\n\t\t\t\tconst path = await projectPath(file)\n\t\t\t\tif (!(await this.fs.pathExists(path))) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tawait this.replaceFileContent(path, content =>\n\t\t\t\t\tObject.entries(variables).reduce(\n\t\t\t\t\t\t(content, [key, value]) => content.replace(new RegExp(`{${key}}`, 'g'), value),\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t))\n\t\t\t}\n\t\t} finally {\n\t\t\tif (temporaryTemplateDir !== undefined) {\n\t\t\t\tawait this.cleanupTemporaryTemplate(temporaryTemplateDir)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate cleanupTemporaryTemplate = async (path: string): Promise<void> => {\n\t\ttry {\n\t\t\tawait this.fs.remove(path, { recursive: true, force: true })\n\t\t} catch {\n\t\t\tthis.output.warn('Failed to clean up the temporary template directory.')\n\t\t}\n\t}\n\n\tprivate replaceFileContent = async (path: string, replacer: (content: string) => string): Promise<void> => {\n\t\tconst content = await this.fs.readFile(path, { encoding: 'utf8' })\n\t\tconst newContent = replacer(content)\n\t\tawait this.fs.writeFile(path, newContent, { encoding: 'utf8' })\n\t}\n\n\tprivate readYaml = async <T = unknown>(path: string): Promise<T> => {\n\t\tconst content = await this.fs.readFile(path, { encoding: 'utf8' })\n\t\treturn jsyaml.load(content) as unknown as T\n\t}\n}\n"],"names":["downloadTemplate","remoteTemplate","join","projectPath","path","resolveProjectPath","resolveNewProjectPath","content"],"mappings":";;;;;;;;;AAYA,MAAM,gBAA+B,CAAC,QAAQ,WAAWA,eAAAA,iBAAiB,QAAQ,MAAM;AAEjF,MAAM,kBAAkB;AAAA,EAG9B,YACkB,aACA,IACA,QACA,QAAuB,eACvC;AAJgB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OH,UAAgC;AACzE,UAAI;AACH,cAAM,KAAK,GAAG,OAAOA,OAAM,EAAE,WAAW,MAAM,OAAO,MAAM;AAAA,MAC5D,QAAQ;AACP,aAAK,OAAO,KAAK,sDAAsD;AAAA,MACxE;AAAA,IACD,CAAA;AAEA,kBAAA,MAAQ,sBAAqB,OAAOA,OAAc,aAAyD;AAC1G,YAAM,UAAU,MAAM,KAAK,GAAG,SAASA,OAAM,EAAE,UAAU,QAAQ;AACjE,YAAM,aAAa,SAAS,OAAO;AACnC,YAAM,KAAK,GAAG,UAAUA,OAAM,YAAY,EAAE,UAAU,QAAQ;AAAA,IAC/D,CAAA;AAEA,kBAAA,MAAQ,YAAW,OAAoBA,UAA6B;AACnE,YAAM,UAAU,MAAM,KAAK,GAAG,SAASA,OAAM,EAAE,UAAU,QAAQ;AACjE,aAAO,OAAO,KAAK,OAAO;AAAA,IAC3B,CAAA;AA5GC,SAAK,iBAAiB;AAAA,MACrB,CAAC,SAAS,GAAGF,KAAAA,KAAK,KAAK,aAAa,mBAAmB;AAAA,IAAA;AAAA,EAEzD;AA0GD;;"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import degit from "degit";
|
|
3
2
|
import jsyaml__default from "js-yaml";
|
|
3
|
+
import { resolveProjectPath, resolveNewProjectPath } from "./projectPath.js";
|
|
4
|
+
import { downloadTemplate } from "./remoteTemplate.js";
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
7
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
-
const cloneTemplate =
|
|
8
|
-
const emitter = degit(source, { cache: false, force: true, verbose: true });
|
|
9
|
-
await emitter.clone(target);
|
|
10
|
-
};
|
|
8
|
+
const cloneTemplate = (source, target) => downloadTemplate(source, target);
|
|
11
9
|
class TemplateInstaller {
|
|
12
10
|
constructor(resourceDir, fs, output, clone = cloneTemplate) {
|
|
13
11
|
this.resourceDir = resourceDir;
|
|
@@ -59,14 +57,15 @@ class TemplateInstaller {
|
|
|
59
57
|
return JSON.stringify({ scripts, ...json }, null, " ");
|
|
60
58
|
});
|
|
61
59
|
}
|
|
60
|
+
const projectPath = (path) => resolveProjectPath(this.fs, targetDir, path);
|
|
62
61
|
for (const [source, target] of Object.entries(config.rename || {})) {
|
|
63
|
-
await this.fs.rename(
|
|
62
|
+
await this.fs.rename(await projectPath(source), await projectPath(target));
|
|
64
63
|
}
|
|
65
64
|
for (const [source, target] of Object.entries(config.copy || {})) {
|
|
66
|
-
await this.fs.copy(
|
|
65
|
+
await this.fs.copy(await projectPath(source), await resolveNewProjectPath(this.fs, targetDir, target));
|
|
67
66
|
}
|
|
68
67
|
for (const file of config.replaceVariables || []) {
|
|
69
|
-
const path =
|
|
68
|
+
const path = await projectPath(file);
|
|
70
69
|
if (!await this.fs.pathExists(path)) {
|
|
71
70
|
continue;
|
|
72
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateInstaller.js","sources":["../../../../../packages/create/src/lib/TemplateInstaller.ts"],"sourcesContent":["import { join } from 'node:path'\nimport
|
|
1
|
+
{"version":3,"file":"TemplateInstaller.js","sources":["../../../../../packages/create/src/lib/TemplateInstaller.ts"],"sourcesContent":["import { join } from 'node:path'\nimport jsyaml from 'js-yaml'\nimport { FileSystem } from './FileSystem.js'\nimport { resolveNewProjectPath, resolveProjectPath } from './projectPath.js'\nimport { downloadTemplate } from './remoteTemplate.js'\n\ninterface TemplateInstallerOutput {\n\twarn(message: string): void\n}\n\ntype CloneTemplate = (source: string, target: string) => Promise<void>\n\nconst cloneTemplate: CloneTemplate = (source, target) => downloadTemplate(source, target)\n\nexport class TemplateInstaller {\n\tprivate localTemplates: Record<string, string>\n\n\tconstructor(\n\t\tprivate readonly resourceDir: string,\n\t\tprivate readonly fs: FileSystem,\n\t\tprivate readonly output: TemplateInstallerOutput,\n\t\tprivate readonly clone: CloneTemplate = cloneTemplate,\n\t) {\n\t\tthis.localTemplates = {\n\t\t\t['default']: join(this.resourceDir, 'templates/default'),\n\t\t}\n\t}\n\n\tinstallTemplate = async (\n\t\ttemplate: string,\n\t\ttargetDir: string,\n\t\tvariables: Record<string, string> = {},\n\t) => {\n\t\tlet temporaryTemplateDir: string | undefined\n\t\tlet remoteTemplate: string | undefined\n\n\t\tif (this.localTemplates[template]) {\n\t\t\ttemplate = this.localTemplates[template]\n\t\t} else {\n\t\t\tremoteTemplate = template\n\t\t\ttemporaryTemplateDir = await this.fs.createTempDir()\n\t\t\ttemplate = temporaryTemplateDir\n\t\t}\n\n\t\ttry {\n\t\t\tif (remoteTemplate !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.clone(remoteTemplate, template)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthrow new Error(`Failed to clone template from repository: ${error}`)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst templateConfigFile = join(template, 'contember.template.yaml')\n\t\t\tif (!(await this.fs.pathExists(templateConfigFile))) {\n\t\t\t\tthrow new Error(`${template} is not a Contember template`)\n\t\t\t}\n\t\t\tconst config = (await this.readYaml(templateConfigFile)) as {\n\t\t\t\ttype?: string\n\t\t\t\tremove?: string[]\n\t\t\t\tpatchPackageJson?: boolean\n\t\t\t\trename?: Record<string, string>\n\t\t\t\tcopy?: Record<string, string>\n\t\t\t\treplaceVariables?: string[]\n\t\t\t}\n\t\t\tconst nodeModulesDir = join(template, 'node_modules')\n\t\t\tconst skippedFiles = new Set([...(config.remove || []).map(it => join(template, it)), templateConfigFile])\n\t\t\tif (await this.fs.pathExists(targetDir)) {\n\t\t\t\tthrow `${targetDir} already exists`\n\t\t\t}\n\t\t\tawait this.fs.copy(template, targetDir, {\n\t\t\t\tfilter: src => !src.startsWith(nodeModulesDir) && !skippedFiles.has(src),\n\t\t\t})\n\n\t\t\tif (config.patchPackageJson) {\n\t\t\t\tawait this.replaceFileContent(join(targetDir, 'package.json'), content => {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t\t'scripts-template': scripts,\n\t\t\t\t\t\tscripts: _nullScripts,\n\t\t\t\t\t\tlicense,\n\t\t\t\t\t\t...json\n\t\t\t\t\t} = JSON.parse(content)\n\t\t\t\t\treturn JSON.stringify({ scripts, ...json }, null, ' ')\n\t\t\t\t})\n\t\t\t}\n\t\t\t// The template is untrusted input: every directive path must stay inside the new project.\n\t\t\tconst projectPath = (path: string) => resolveProjectPath(this.fs, targetDir, path)\n\t\t\tfor (const [source, target] of Object.entries(config.rename || {})) {\n\t\t\t\tawait this.fs.rename(await projectPath(source), await projectPath(target))\n\t\t\t}\n\t\t\tfor (const [source, target] of Object.entries(config.copy || {})) {\n\t\t\t\tawait this.fs.copy(await projectPath(source), await resolveNewProjectPath(this.fs, targetDir, target))\n\t\t\t}\n\n\t\t\tfor (const file of config.replaceVariables || []) {\n\t\t\t\tconst path = await projectPath(file)\n\t\t\t\tif (!(await this.fs.pathExists(path))) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tawait this.replaceFileContent(path, content =>\n\t\t\t\t\tObject.entries(variables).reduce(\n\t\t\t\t\t\t(content, [key, value]) => content.replace(new RegExp(`{${key}}`, 'g'), value),\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t))\n\t\t\t}\n\t\t} finally {\n\t\t\tif (temporaryTemplateDir !== undefined) {\n\t\t\t\tawait this.cleanupTemporaryTemplate(temporaryTemplateDir)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate cleanupTemporaryTemplate = async (path: string): Promise<void> => {\n\t\ttry {\n\t\t\tawait this.fs.remove(path, { recursive: true, force: true })\n\t\t} catch {\n\t\t\tthis.output.warn('Failed to clean up the temporary template directory.')\n\t\t}\n\t}\n\n\tprivate replaceFileContent = async (path: string, replacer: (content: string) => string): Promise<void> => {\n\t\tconst content = await this.fs.readFile(path, { encoding: 'utf8' })\n\t\tconst newContent = replacer(content)\n\t\tawait this.fs.writeFile(path, newContent, { encoding: 'utf8' })\n\t}\n\n\tprivate readYaml = async <T = unknown>(path: string): Promise<T> => {\n\t\tconst content = await this.fs.readFile(path, { encoding: 'utf8' })\n\t\treturn jsyaml.load(content) as unknown as T\n\t}\n}\n"],"names":["content","jsyaml"],"mappings":";;;;;;;AAYA,MAAM,gBAA+B,CAAC,QAAQ,WAAW,iBAAiB,QAAQ,MAAM;AAEjF,MAAM,kBAAkB;AAAA,EAG9B,YACkB,aACA,IACA,QACA,QAAuB,eACvC;AAJgB,SAAA,cAAA;AACA,SAAA,KAAA;AACA,SAAA,SAAA;AACA,SAAA,QAAA;AANlB,kBAAA,MAAQ,gBAAA;AAaR,kBAAA,MAAA,mBAAkB,OACjB,UACA,WACA,YAAoC,OAChC;AACJ,UAAI;AACJ,UAAI;AAEJ,UAAI,KAAK,eAAe,QAAQ,GAAG;AAClC,mBAAW,KAAK,eAAe,QAAQ;AAAA,MACxC,OAAO;AACN,yBAAiB;AACjB,+BAAuB,MAAM,KAAK,GAAG,cAAA;AACrC,mBAAW;AAAA,MACZ;AAEA,UAAI;AACH,YAAI,mBAAmB,QAAW;AACjC,cAAI;AACH,kBAAM,KAAK,MAAM,gBAAgB,QAAQ;AAAA,UAC1C,SAAS,OAAO;AACf,kBAAM,IAAI,MAAM,6CAA6C,KAAK,EAAE;AAAA,UACrE;AAAA,QACD;AAEA,cAAM,qBAAqB,KAAK,UAAU,yBAAyB;AACnE,YAAI,CAAE,MAAM,KAAK,GAAG,WAAW,kBAAkB,GAAI;AACpD,gBAAM,IAAI,MAAM,GAAG,QAAQ,8BAA8B;AAAA,QAC1D;AACA,cAAM,SAAU,MAAM,KAAK,SAAS,kBAAkB;AAQtD,cAAM,iBAAiB,KAAK,UAAU,cAAc;AACpD,cAAM,eAAe,oBAAI,IAAI,CAAC,IAAI,OAAO,UAAU,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B,MAAM,aACnC,OAAO,QAAQ,SAAS,EAAE;AAAA,YACzB,CAACA,UAAS,CAAC,KAAK,KAAK,MAAMA,SAAQ,QAAQ,IAAI,OAAO,IAAI,GAAG,KAAK,GAAG,GAAG,KAAK;AAAA,YAC7E;AAAA,UAAA,CACA;AAAA,QACH;AAAA,MACD,UAAA;AACC,YAAI,yBAAyB,QAAW;AACvC,gBAAM,KAAK,yBAAyB,oBAAoB;AAAA,QACzD;AAAA,MACD;AAAA,IACD,CAAA;AAEA,kBAAA,MAAQ,4BAA2B,OAAO,SAAgC;AACzE,UAAI;AACH,cAAM,KAAK,GAAG,OAAO,MAAM,EAAE,WAAW,MAAM,OAAO,MAAM;AAAA,MAC5D,QAAQ;AACP,aAAK,OAAO,KAAK,sDAAsD;AAAA,MACxE;AAAA,IACD,CAAA;AAEA,kBAAA,MAAQ,sBAAqB,OAAO,MAAc,aAAyD;AAC1G,YAAM,UAAU,MAAM,KAAK,GAAG,SAAS,MAAM,EAAE,UAAU,QAAQ;AACjE,YAAM,aAAa,SAAS,OAAO;AACnC,YAAM,KAAK,GAAG,UAAU,MAAM,YAAY,EAAE,UAAU,QAAQ;AAAA,IAC/D,CAAA;AAEA,kBAAA,MAAQ,YAAW,OAAoB,SAA6B;AACnE,YAAM,UAAU,MAAM,KAAK,GAAG,SAAS,MAAM,EAAE,UAAU,QAAQ;AACjE,aAAOC,gBAAO,KAAK,OAAO;AAAA,IAC3B,CAAA;AA5GC,SAAK,iBAAiB;AAAA,MACrB,CAAC,SAAS,GAAG,KAAK,KAAK,aAAa,mBAAmB;AAAA,IAAA;AAAA,EAEzD;AA0GD;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const hasCode = (error, code) => error instanceof Error && "code" in error && error.code === code;
|
|
4
|
+
const isNotFound = (error) => hasCode(error, "ENOENT");
|
|
5
|
+
exports.hasCode = hasCode;
|
|
6
|
+
exports.isNotFound = isNotFound;
|
|
7
|
+
//# sourceMappingURL=fsErrors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsErrors.cjs","sources":["../../../../../packages/create/src/lib/fsErrors.ts"],"sourcesContent":["export const hasCode = (error: unknown, code: string): boolean => error instanceof Error && 'code' in error && error.code === code\nexport const isNotFound = (error: unknown): boolean => hasCode(error, 'ENOENT')\n"],"names":[],"mappings":";;AAAO,MAAM,UAAU,CAAC,OAAgB,SAA0B,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS;AACvH,MAAM,aAAa,CAAC,UAA4B,QAAQ,OAAO,QAAQ;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsErrors.js","sources":["../../../../../packages/create/src/lib/fsErrors.ts"],"sourcesContent":["export const hasCode = (error: unknown, code: string): boolean => error instanceof Error && 'code' in error && error.code === code\nexport const isNotFound = (error: unknown): boolean => hasCode(error, 'ENOENT')\n"],"names":[],"mappings":"AAAO,MAAM,UAAU,CAAC,OAAgB,SAA0B,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS;AACvH,MAAM,aAAa,CAAC,UAA4B,QAAQ,OAAO,QAAQ;"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const fsErrors = require("./fsErrors.cjs");
|
|
5
|
+
const resolveProjectPath = async (fs, root, path$1) => {
|
|
6
|
+
const outside = new Error(`Template path "${path$1}" points outside the project`);
|
|
7
|
+
if (path.isAbsolute(path$1)) {
|
|
8
|
+
throw outside;
|
|
9
|
+
}
|
|
10
|
+
const resolved = path.resolve(root, path$1);
|
|
11
|
+
if (!isStrictlyInside(root, resolved)) {
|
|
12
|
+
throw outside;
|
|
13
|
+
}
|
|
14
|
+
const realRoot = await fs.realPath(root);
|
|
15
|
+
const realPath = await resolveExistingPrefix(fs, resolved);
|
|
16
|
+
if (realPath === void 0) {
|
|
17
|
+
throw new Error(`Template path "${path$1}" passes through a dangling symlink`);
|
|
18
|
+
}
|
|
19
|
+
if (!isStrictlyInside(realRoot, realPath)) {
|
|
20
|
+
throw outside;
|
|
21
|
+
}
|
|
22
|
+
return resolved;
|
|
23
|
+
};
|
|
24
|
+
const resolveNewProjectPath = async (fs, root, path2) => {
|
|
25
|
+
const resolved = await resolveProjectPath(fs, root, path2);
|
|
26
|
+
if (await isPresent(fs, resolved)) {
|
|
27
|
+
throw new Error(`Template path "${path2}" already exists`);
|
|
28
|
+
}
|
|
29
|
+
return resolved;
|
|
30
|
+
};
|
|
31
|
+
const isStrictlyInside = (root, path$1) => {
|
|
32
|
+
const rel = path.relative(root, path$1);
|
|
33
|
+
return rel !== "" && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
|
|
34
|
+
};
|
|
35
|
+
const resolveExistingPrefix = async (fs, path$1) => {
|
|
36
|
+
try {
|
|
37
|
+
return await fs.realPath(path$1);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (!fsErrors.isNotFound(error)) {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (await isPresent(fs, path$1)) {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
const parent = path.dirname(path$1);
|
|
47
|
+
if (parent === path$1) {
|
|
48
|
+
return path$1;
|
|
49
|
+
}
|
|
50
|
+
const realParent = await resolveExistingPrefix(fs, parent);
|
|
51
|
+
return realParent === void 0 ? void 0 : path.join(realParent, path.basename(path$1));
|
|
52
|
+
};
|
|
53
|
+
const isPresent = async (fs, path2) => {
|
|
54
|
+
try {
|
|
55
|
+
await fs.lstat(path2);
|
|
56
|
+
return true;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (fsErrors.isNotFound(error)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.resolveNewProjectPath = resolveNewProjectPath;
|
|
65
|
+
exports.resolveProjectPath = resolveProjectPath;
|
|
66
|
+
//# sourceMappingURL=projectPath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectPath.cjs","sources":["../../../../../packages/create/src/lib/projectPath.ts"],"sourcesContent":["import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'\nimport { FileSystem } from './FileSystem.js'\nimport { isNotFound } from './fsErrors.js'\n\n/**\n * Resolves a path from a template directive against the project root.\n * Refuses absolute paths, the root itself and anything that leaves the root, lexically or through a symlink.\n */\nexport const resolveProjectPath = async (fs: FileSystem, root: string, path: string): Promise<string> => {\n\tconst outside = new Error(`Template path \"${path}\" points outside the project`)\n\tif (isAbsolute(path)) {\n\t\tthrow outside\n\t}\n\tconst resolved = resolve(root, path)\n\tif (!isStrictlyInside(root, resolved)) {\n\t\tthrow outside\n\t}\n\tconst realRoot = await fs.realPath(root)\n\tconst realPath = await resolveExistingPrefix(fs, resolved)\n\tif (realPath === undefined) {\n\t\tthrow new Error(`Template path \"${path}\" passes through a dangling symlink`)\n\t}\n\tif (!isStrictlyInside(realRoot, realPath)) {\n\t\tthrow outside\n\t}\n\treturn resolved\n}\n\n/**\n * Like resolveProjectPath, and the path must not exist yet. fs.cp into an existing directory writes entries the check\n * above never saw, and Bun's fs.cp follows symlinks it finds there.\n */\nexport const resolveNewProjectPath = async (fs: FileSystem, root: string, path: string): Promise<string> => {\n\tconst resolved = await resolveProjectPath(fs, root, path)\n\tif (await isPresent(fs, resolved)) {\n\t\tthrow new Error(`Template path \"${path}\" already exists`)\n\t}\n\treturn resolved\n}\n\nconst isStrictlyInside = (root: string, path: string): boolean => {\n\tconst rel = relative(root, path)\n\treturn rel !== '' && rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)\n}\n\n/**\n * realpath() of the longest existing prefix, with the missing components appended (they cannot be symlinks).\n * Returns undefined for a dangling symlink: writing to it would create its target, wherever that is.\n */\nconst resolveExistingPrefix = async (fs: FileSystem, path: string): Promise<string | undefined> => {\n\ttry {\n\t\treturn await fs.realPath(path)\n\t} catch (error) {\n\t\tif (!isNotFound(error)) {\n\t\t\tthrow error\n\t\t}\n\t}\n\tif (await isPresent(fs, path)) {\n\t\treturn undefined\n\t}\n\tconst parent = dirname(path)\n\tif (parent === path) {\n\t\treturn path\n\t}\n\tconst realParent = await resolveExistingPrefix(fs, parent)\n\treturn realParent === undefined ? undefined : join(realParent, basename(path))\n}\n\nconst isPresent = async (fs: FileSystem, path: string): Promise<boolean> => {\n\ttry {\n\t\tawait fs.lstat(path)\n\t\treturn true\n\t} catch (error) {\n\t\tif (isNotFound(error)) {\n\t\t\treturn false\n\t\t}\n\t\tthrow error\n\t}\n}\n"],"names":["path","isAbsolute","resolve","relative","sep","isNotFound","dirname","join","basename"],"mappings":";;;;AAQO,MAAM,qBAAqB,OAAO,IAAgB,MAAcA,WAAkC;AACxG,QAAM,UAAU,IAAI,MAAM,kBAAkBA,MAAI,8BAA8B;AAC9E,MAAIC,KAAAA,WAAWD,MAAI,GAAG;AACrB,UAAM;AAAA,EACP;AACA,QAAM,WAAWE,KAAAA,QAAQ,MAAMF,MAAI;AACnC,MAAI,CAAC,iBAAiB,MAAM,QAAQ,GAAG;AACtC,UAAM;AAAA,EACP;AACA,QAAM,WAAW,MAAM,GAAG,SAAS,IAAI;AACvC,QAAM,WAAW,MAAM,sBAAsB,IAAI,QAAQ;AACzD,MAAI,aAAa,QAAW;AAC3B,UAAM,IAAI,MAAM,kBAAkBA,MAAI,qCAAqC;AAAA,EAC5E;AACA,MAAI,CAAC,iBAAiB,UAAU,QAAQ,GAAG;AAC1C,UAAM;AAAA,EACP;AACA,SAAO;AACR;AAMO,MAAM,wBAAwB,OAAO,IAAgB,MAAcA,UAAkC;AAC3G,QAAM,WAAW,MAAM,mBAAmB,IAAI,MAAMA,KAAI;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