@contember/create 2.1.0-rc.3 → 2.2.0-alpha.10
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/CLAUDE.md +22 -0
- package/dist/development/run.cjs +7 -7
- package/dist/development/run.cjs.map +1 -1
- package/dist/development/run.js +8 -8
- package/dist/development/run.js.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs +28 -14
- package/dist/development/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/development/src/commands/WorkspaceCreateCommand.js +28 -14
- package/dist/development/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/development/src/lib/FileSystem.cjs +1 -2
- package/dist/development/src/lib/FileSystem.cjs.map +1 -1
- package/dist/development/src/lib/FileSystem.js +1 -2
- package/dist/development/src/lib/FileSystem.js.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.cjs +79 -67
- package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.js +72 -60
- package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/development/src/lib/packageManagerDetector.cjs +6 -6
- package/dist/development/src/lib/packageManagerDetector.cjs.map +1 -1
- package/dist/development/src/lib/version.cjs +2 -2
- package/dist/development/src/lib/version.cjs.map +1 -1
- package/dist/development/src/lib/version.js.map +1 -1
- package/dist/development/src/paths.cjs +3 -3
- package/dist/development/src/paths.cjs.map +1 -1
- package/dist/production/run.cjs +7 -7
- package/dist/production/run.cjs.map +1 -1
- package/dist/production/run.js +8 -8
- package/dist/production/run.js.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs +28 -14
- package/dist/production/src/commands/WorkspaceCreateCommand.cjs.map +1 -1
- package/dist/production/src/commands/WorkspaceCreateCommand.js +28 -14
- package/dist/production/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/production/src/lib/FileSystem.cjs +1 -2
- package/dist/production/src/lib/FileSystem.cjs.map +1 -1
- package/dist/production/src/lib/FileSystem.js +1 -2
- package/dist/production/src/lib/FileSystem.js.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.cjs +79 -67
- package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.js +72 -60
- package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/production/src/lib/packageManagerDetector.cjs +6 -6
- package/dist/production/src/lib/packageManagerDetector.cjs.map +1 -1
- package/dist/production/src/lib/version.cjs +2 -2
- package/dist/production/src/lib/version.cjs.map +1 -1
- package/dist/production/src/lib/version.js.map +1 -1
- package/dist/production/src/paths.cjs +3 -3
- package/dist/production/src/paths.cjs.map +1 -1
- package/dist/types/commands/WorkspaceCreateCommand.d.ts +16 -4
- package/dist/types/commands/WorkspaceCreateCommand.d.ts.map +1 -1
- package/dist/types/commands/index.d.ts +1 -1
- package/dist/types/commands/index.d.ts.map +1 -1
- package/dist/types/lib/FileSystem.d.ts +3 -2
- package/dist/types/lib/FileSystem.d.ts.map +1 -1
- package/dist/types/lib/TemplateInstaller.d.ts +10 -2
- package/dist/types/lib/TemplateInstaller.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/resources/templates/default/README.md +3 -1
- package/resources/templates/default/admin/app/components/navigation.tsx +95 -8
- package/resources/templates/default/admin/app/pages/tenant.tsx +328 -77
- package/resources/templates/default/admin/entrypoint/components/login.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/magicLink.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/magicLinkSent.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/passwordReset.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/resetRequest.tsx +1 -1
- package/resources/templates/default/admin/entrypoint/pages/resetRequestSuccess.tsx +1 -1
- package/resources/templates/default/admin/lib/binding/binding.tsx +19 -4
- package/resources/templates/default/admin/lib/binding/delete.tsx +37 -3
- package/resources/templates/default/admin/lib/binding/hooks.tsx +65 -3
- package/resources/templates/default/admin/lib/binding/identity.tsx +17 -4
- package/resources/templates/default/admin/lib/binding/index.ts +5 -5
- package/resources/templates/default/admin/lib/binding/navigation-guard-dialog.tsx +15 -3
- package/resources/templates/default/admin/lib/binding/persist.tsx +27 -5
- package/resources/templates/default/admin/lib/block-repeater/block-repeater.tsx +15 -11
- package/resources/templates/default/admin/lib/block-repeater/index.ts +1 -1
- package/resources/templates/default/admin/lib/board/board.tsx +2 -2
- package/resources/templates/default/admin/lib/board/index.ts +1 -1
- package/resources/templates/default/admin/lib/buttons/back-button.tsx +22 -2
- package/resources/templates/default/admin/lib/buttons/index.ts +2 -2
- package/resources/templates/default/admin/lib/buttons/link-back-button.tsx +11 -2
- package/resources/templates/default/admin/lib/datagrid/cells.tsx +3 -3
- package/resources/templates/default/admin/lib/datagrid/column-header.tsx +4 -4
- package/resources/templates/default/admin/lib/datagrid/columns.tsx +28 -14
- package/resources/templates/default/admin/lib/datagrid/elements.tsx +2 -2
- package/resources/templates/default/admin/lib/datagrid/empty.tsx +1 -1
- package/resources/templates/default/admin/lib/datagrid/export.tsx +2 -2
- package/resources/templates/default/admin/lib/datagrid/filters/boolean.tsx +13 -13
- package/resources/templates/default/admin/lib/datagrid/filters/common.tsx +2 -2
- package/resources/templates/default/admin/lib/datagrid/filters/date.tsx +37 -16
- package/resources/templates/default/admin/lib/datagrid/filters/defined.tsx +13 -12
- package/resources/templates/default/admin/lib/datagrid/filters/enum.tsx +56 -22
- package/resources/templates/default/admin/lib/datagrid/filters/index.ts +7 -7
- package/resources/templates/default/admin/lib/datagrid/filters/mobile.tsx +18 -0
- package/resources/templates/default/admin/lib/datagrid/filters/number.tsx +10 -13
- package/resources/templates/default/admin/lib/datagrid/filters/relation.tsx +8 -8
- package/resources/templates/default/admin/lib/datagrid/filters/text.tsx +9 -9
- package/resources/templates/default/admin/lib/datagrid/grid.tsx +31 -23
- package/resources/templates/default/admin/lib/datagrid/index.ts +12 -12
- package/resources/templates/default/admin/lib/datagrid/labels.tsx +22 -4
- package/resources/templates/default/admin/lib/datagrid/layout-switcher.tsx +10 -4
- package/resources/templates/default/admin/lib/datagrid/loader.tsx +4 -4
- package/resources/templates/default/admin/lib/datagrid/pagination.tsx +16 -6
- package/resources/templates/default/admin/lib/datagrid/table.tsx +8 -6
- package/resources/templates/default/admin/lib/datagrid/tiles.tsx +6 -5
- package/resources/templates/default/admin/lib/datagrid/toolbar.tsx +15 -19
- package/resources/templates/default/admin/lib/datagrid/ui.tsx +3 -3
- package/resources/templates/default/admin/lib/dev/index.ts +2 -2
- package/resources/templates/default/admin/lib/dev/login-panel.tsx +12 -3
- package/resources/templates/default/admin/lib/dev/todo.tsx +12 -0
- package/resources/templates/default/admin/lib/dict.ts +0 -261
- package/resources/templates/default/admin/lib/dimensions/dimensions.tsx +85 -4
- package/resources/templates/default/admin/lib/dimensions/index.ts +1 -1
- package/resources/templates/default/admin/lib/editor/block-editor.tsx +72 -3
- package/resources/templates/default/admin/lib/editor/common/baseEditorPlugins.tsx +54 -11
- package/resources/templates/default/admin/lib/editor/common/buttons.tsx +1 -1
- package/resources/templates/default/admin/lib/editor/common/editor-block-toolbar.tsx +1 -1
- package/resources/templates/default/admin/lib/editor/common/elements/HeadingRenderer.tsx +1 -1
- package/resources/templates/default/admin/lib/editor/common/elements/HorizontalRuleRenderer.tsx +1 -1
- package/resources/templates/default/admin/lib/editor/common/elements/ListItemRenderer.tsx +1 -1
- package/resources/templates/default/admin/lib/editor/common/elements/OrderedListRenderer.tsx +1 -1
- package/resources/templates/default/admin/lib/editor/common/elements/TableElementRenderer.tsx +1 -1
- package/resources/templates/default/admin/lib/editor/common/elements/UnorderedListRenderer.tsx +1 -1
- package/resources/templates/default/admin/lib/editor/common/index.ts +6 -6
- package/resources/templates/default/admin/lib/editor/editor-block.tsx +54 -3
- package/resources/templates/default/admin/lib/editor/index.ts +6 -6
- package/resources/templates/default/admin/lib/editor/plugins.tsx +46 -2
- package/resources/templates/default/admin/lib/editor/rich-text-view.tsx +44 -0
- package/resources/templates/default/admin/lib/editor/rich-text.tsx +31 -3
- package/resources/templates/default/admin/lib/editor/sortable-block.tsx +34 -2
- package/resources/templates/default/admin/lib/errors/index.ts +1 -1
- package/resources/templates/default/admin/lib/errors/use-error-formatter.ts +22 -1
- package/resources/templates/default/admin/lib/field/formatted-field.tsx +16 -1
- package/resources/templates/default/admin/lib/field/index.ts +2 -1
- package/resources/templates/default/admin/lib/field/list-field.tsx +56 -0
- package/resources/templates/default/admin/lib/form/container.tsx +33 -3
- package/resources/templates/default/admin/lib/form/index.ts +6 -5
- package/resources/templates/default/admin/lib/form/inputs.tsx +105 -6
- package/resources/templates/default/admin/lib/form/labels.tsx +1 -1
- package/resources/templates/default/admin/lib/form/select.tsx +162 -5
- package/resources/templates/default/admin/lib/form/ui.tsx +2 -2
- package/resources/templates/default/admin/lib/form/upload-repeaters.tsx +159 -5
- package/resources/templates/default/admin/lib/form/upload.tsx +116 -3
- package/resources/templates/default/admin/lib/formatting/formatting.ts +106 -1
- package/resources/templates/default/admin/lib/formatting/index.ts +1 -1
- package/resources/templates/default/admin/lib/images/formatImageResizeUrl.ts +19 -0
- package/resources/templates/default/admin/lib/images/index.ts +1 -1
- package/resources/templates/default/admin/lib/index.ts +54 -0
- package/resources/templates/default/admin/lib/labels/index.ts +2 -2
- package/resources/templates/default/admin/lib/layout/index.ts +3 -3
- package/resources/templates/default/admin/lib/layout/layout-boxed.tsx +5 -5
- package/resources/templates/default/admin/lib/layout/layout.tsx +3 -3
- package/resources/templates/default/admin/lib/outdated-application-dialog/index.ts +1 -1
- package/resources/templates/default/admin/lib/outdated-application-dialog/outdated-application-dialog.tsx +2 -2
- package/resources/templates/default/admin/lib/repeater/index.ts +1 -1
- package/resources/templates/default/admin/lib/repeater/repeater.tsx +26 -9
- package/resources/templates/default/admin/lib/select/create-new.tsx +19 -3
- package/resources/templates/default/admin/lib/select/filter.tsx +8 -2
- package/resources/templates/default/admin/lib/select/highlight.tsx +16 -0
- package/resources/templates/default/admin/lib/select/index.ts +6 -6
- package/resources/templates/default/admin/lib/select/list.tsx +30 -6
- package/resources/templates/default/admin/lib/select/multi-select.tsx +41 -4
- package/resources/templates/default/admin/lib/select/select.tsx +44 -6
- package/resources/templates/default/admin/lib/select/sortable-select.tsx +15 -6
- package/resources/templates/default/admin/lib/select/ui.tsx +100 -4
- package/resources/templates/default/admin/lib/tenant/config/auth-policy-list.tsx +86 -0
- package/resources/templates/default/admin/lib/tenant/config/common.tsx +71 -0
- package/resources/templates/default/admin/lib/tenant/config/identity-provider-list.tsx +113 -0
- package/resources/templates/default/admin/lib/tenant/config/index.ts +5 -0
- package/resources/templates/default/admin/lib/tenant/config/mail-template-list.tsx +108 -0
- package/resources/templates/default/admin/lib/tenant/config/tenant-config-view.tsx +182 -0
- package/resources/templates/default/admin/lib/tenant/dict.ts +770 -0
- package/resources/templates/default/admin/lib/tenant/errors.ts +10 -0
- package/resources/templates/default/admin/lib/tenant/forms/add-project-member.tsx +57 -0
- package/resources/templates/default/admin/lib/tenant/forms/change-my-password.tsx +4 -4
- package/resources/templates/default/admin/lib/tenant/forms/change-my-profile.tsx +40 -0
- package/resources/templates/default/admin/lib/tenant/forms/change-profile.tsx +55 -0
- package/resources/templates/default/admin/lib/tenant/forms/common.tsx +12 -5
- package/resources/templates/default/admin/lib/tenant/forms/confirm-email-change.tsx +38 -0
- package/resources/templates/default/admin/lib/tenant/forms/create-api-key.tsx +5 -5
- package/resources/templates/default/admin/lib/tenant/forms/create-global-api-key.tsx +69 -0
- package/resources/templates/default/admin/lib/tenant/forms/global-roles-control.tsx +113 -0
- package/resources/templates/default/admin/lib/tenant/forms/index.ts +23 -8
- package/resources/templates/default/admin/lib/tenant/forms/invite.tsx +46 -8
- package/resources/templates/default/admin/lib/tenant/forms/login.tsx +8 -14
- package/resources/templates/default/admin/lib/tenant/forms/memberships-control.tsx +7 -5
- package/resources/templates/default/admin/lib/tenant/forms/mfa-code-fields.tsx +81 -0
- package/resources/templates/default/admin/lib/tenant/forms/password-reset-request.tsx +4 -4
- package/resources/templates/default/admin/lib/tenant/forms/password-reset.tsx +4 -4
- package/resources/templates/default/admin/lib/tenant/forms/passwordless-signin-init.tsx +4 -4
- package/resources/templates/default/admin/lib/tenant/forms/passwordless-signin.tsx +8 -14
- package/resources/templates/default/admin/lib/tenant/forms/request-email-verification.tsx +35 -0
- package/resources/templates/default/admin/lib/tenant/forms/set-person-password.tsx +58 -0
- package/resources/templates/default/admin/lib/tenant/forms/set-project-secret.tsx +59 -0
- package/resources/templates/default/admin/lib/tenant/forms/sign-up.tsx +73 -0
- package/resources/templates/default/admin/lib/tenant/forms/update-project-member.tsx +14 -5
- package/resources/templates/default/admin/lib/tenant/forms/verify-email.tsx +38 -0
- package/resources/templates/default/admin/lib/tenant/hooks/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/hooks/useInvite.ts +41 -0
- package/resources/templates/default/admin/lib/tenant/hooks/useInviteUser.tsx +32 -3
- package/resources/templates/default/admin/lib/tenant/idp/identity-provider-connections.tsx +124 -0
- package/resources/templates/default/admin/lib/tenant/idp/index.ts +1 -0
- package/resources/templates/default/admin/lib/tenant/index.ts +10 -3
- package/resources/templates/default/admin/lib/tenant/listing/api-key-list.tsx +161 -23
- package/resources/templates/default/admin/lib/tenant/listing/auth-log-list.tsx +179 -0
- package/resources/templates/default/admin/lib/tenant/listing/global-api-key-list.tsx +149 -0
- package/resources/templates/default/admin/lib/tenant/listing/index.ts +11 -4
- package/resources/templates/default/admin/lib/tenant/listing/member-delete-dialog.tsx +4 -4
- package/resources/templates/default/admin/lib/tenant/listing/member-list.tsx +28 -19
- package/resources/templates/default/admin/lib/tenant/listing/mfa.tsx +29 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-actions.tsx +179 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-detail.tsx +141 -0
- package/resources/templates/default/admin/lib/tenant/listing/person-list.tsx +17 -6
- package/resources/templates/default/admin/lib/tenant/listing/persons-list.tsx +128 -0
- package/resources/templates/default/admin/lib/tenant/listing/project-secret-list.tsx +82 -0
- package/resources/templates/default/admin/lib/tenant/otp/backup-codes.tsx +81 -0
- package/resources/templates/default/admin/lib/tenant/otp/email-otp-setup.tsx +133 -0
- package/resources/templates/default/admin/lib/tenant/otp/index.ts +3 -1
- package/resources/templates/default/admin/lib/tenant/otp/otp-setup.tsx +6 -6
- package/resources/templates/default/admin/lib/tenant/security/index.ts +2 -0
- package/resources/templates/default/admin/lib/tenant/security/passwordless-toggle.tsx +63 -0
- package/resources/templates/default/admin/lib/tenant/security/session-list.tsx +143 -0
- package/resources/templates/default/admin/lib/toast/index.ts +2 -2
- package/resources/templates/default/admin/lib/toast/toast.tsx +3 -3
- package/resources/templates/default/admin/lib/ui/alert-dialog.tsx +114 -3
- package/resources/templates/default/admin/lib/ui/avatar.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/button.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/card.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/collapsible.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/dialog.tsx +2 -2
- package/resources/templates/default/admin/lib/ui/dimension.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/divider.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/dropdown.tsx +3 -3
- package/resources/templates/default/admin/lib/ui/input.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/label.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/loader.tsx +2 -2
- package/resources/templates/default/admin/lib/ui/menu.tsx +2 -2
- package/resources/templates/default/admin/lib/ui/overlay.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/popover.tsx +2 -2
- package/resources/templates/default/admin/lib/ui/progress.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/property-list.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/scroll-area.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/select.tsx +44 -2
- package/resources/templates/default/admin/lib/ui/separator.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/sheet.tsx +2 -2
- package/resources/templates/default/admin/lib/ui/sidebar.tsx +8 -8
- package/resources/templates/default/admin/lib/ui/skeleton.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/sortable.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/switch.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/table.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/textarea.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/toggle-group.tsx +2 -2
- package/resources/templates/default/admin/lib/ui/toggle.tsx +1 -1
- package/resources/templates/default/admin/lib/ui/tooltip.tsx +2 -2
- package/resources/templates/default/admin/lib/upload/dropzone.tsx +20 -3
- package/resources/templates/default/admin/lib/upload/index.ts +3 -3
- package/resources/templates/default/admin/lib/upload/repeater.tsx +5 -1
- package/resources/templates/default/admin/lib/upload/ui.tsx +2 -2
- package/resources/templates/default/admin/lib/upload/upload-progress.tsx +6 -6
- package/resources/templates/default/admin/lib/upload/view.tsx +4 -4
- package/resources/templates/default/admin/lib/utils/cn.ts +18 -0
- package/resources/templates/default/admin/lib/utils/createComponentOpenHooks.tsx +33 -0
- package/resources/templates/default/admin/lib/utils/index.ts +2 -2
- package/resources/templates/default/admin/lib/utils/uic.tsx +59 -0
- package/resources/templates/default/admin/lib/utils/use-mobile.ts +19 -0
- package/resources/templates/default/admin/package.json +1 -0
- package/resources/templates/default/docker/object-storage/README.md +13 -0
- package/resources/templates/default/docker/object-storage/identities.json +13 -0
- package/resources/templates/default/docker-compose.yaml +29 -7
- package/resources/templates/default/scripts/assemble-ui-lib.mjs +132 -0
- package/resources/templates/default/scripts/update-ui-lib.sh +101 -185
- package/src/commands/WorkspaceCreateCommand.ts +45 -17
- package/src/commands/index.ts +1 -1
- package/src/lib/FileSystem.ts +2 -2
- package/src/lib/TemplateInstaller.ts +87 -69
- package/src/lib/version.ts +1 -1
- package/src/run.ts +11 -10
- package/tests/cases/unit/create-process.test.ts +66 -0
- package/tests/cases/unit/template-installer-cleanup.test.ts +150 -0
- package/tests/cases/unit/workspace-create.test.ts +81 -0
|
@@ -1,44 +1,58 @@
|
|
|
1
|
-
import { Command } from "@contember/cli-common";
|
|
1
|
+
import { Command, escapeTerminalText } from "@contember/cli-common";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { getPackageVersion } from "../lib/version.js";
|
|
5
5
|
import { detectPackageManager } from "../lib/packageManagerDetector.js";
|
|
6
|
+
const defaultRuntime = {
|
|
7
|
+
cwd: () => process.cwd(),
|
|
8
|
+
getPackageVersion,
|
|
9
|
+
detectPackageManager
|
|
10
|
+
};
|
|
6
11
|
class WorkspaceCreateCommand extends Command {
|
|
7
|
-
constructor(templateInstaller) {
|
|
12
|
+
constructor(templateInstaller, runtime = defaultRuntime) {
|
|
8
13
|
super();
|
|
9
14
|
this.templateInstaller = templateInstaller;
|
|
15
|
+
this.runtime = runtime;
|
|
10
16
|
}
|
|
11
17
|
configure(configuration) {
|
|
12
18
|
configuration.description("Creates a new Contember project");
|
|
13
19
|
configuration.argument("projectName");
|
|
14
20
|
configuration.option("template").shortcut("t").valueRequired().description("Template name or remote source");
|
|
15
21
|
}
|
|
16
|
-
async execute(input) {
|
|
22
|
+
async execute(input, output) {
|
|
17
23
|
const projectName = input.getArgument("projectName");
|
|
18
|
-
const projectDirectory = join(
|
|
19
|
-
const packageManager = detectPackageManager();
|
|
24
|
+
const projectDirectory = join(this.runtime.cwd(), projectName);
|
|
25
|
+
const packageManager = this.runtime.detectPackageManager();
|
|
20
26
|
const template = input.getOption("template") ?? "default";
|
|
21
27
|
await this.templateInstaller.installTemplate(template, projectDirectory, {
|
|
22
|
-
version: await getPackageVersion(),
|
|
28
|
+
version: await this.runtime.getPackageVersion(),
|
|
23
29
|
projectName,
|
|
24
30
|
packageManager
|
|
25
31
|
});
|
|
26
|
-
|
|
32
|
+
const result = { projectName, projectDirectory, template, packageManager };
|
|
33
|
+
output.data(result, {
|
|
34
|
+
human: (value) => createDocs(value),
|
|
35
|
+
quiet: (value) => value.projectDirectory
|
|
36
|
+
});
|
|
27
37
|
}
|
|
28
38
|
}
|
|
29
|
-
const createDocs = (projectDirectory, projectName, packageManager) =>
|
|
30
|
-
|
|
39
|
+
const createDocs = ({ projectDirectory, projectName, packageManager }) => {
|
|
40
|
+
const safeProjectDirectory = escapeTerminalText(projectDirectory);
|
|
41
|
+
const safeProjectName = escapeTerminalText(projectName);
|
|
42
|
+
const safePackageManager = escapeTerminalText(packageManager);
|
|
43
|
+
return `
|
|
44
|
+
Contember project successfully created in ${safeProjectDirectory}
|
|
31
45
|
|
|
32
46
|
Next steps:
|
|
33
47
|
|
|
34
48
|
1. Navigate to the project directory:
|
|
35
|
-
$ ${chalk.green(`cd ${
|
|
49
|
+
$ ${chalk.green(`cd ${safeProjectName}`)}
|
|
36
50
|
|
|
37
51
|
2. Install dependencies:
|
|
38
|
-
$ ${chalk.green(`${
|
|
52
|
+
$ ${chalk.green(`${safePackageManager} install`)}
|
|
39
53
|
|
|
40
54
|
3. Start the Contember stack:
|
|
41
|
-
$ ${chalk.green(`${
|
|
55
|
+
$ ${chalk.green(`${safePackageManager} start`)}
|
|
42
56
|
|
|
43
57
|
Available services:
|
|
44
58
|
|
|
@@ -51,13 +65,13 @@ ${chalk.bold("API & Backend")}
|
|
|
51
65
|
|
|
52
66
|
${chalk.bold("Development Tools")}
|
|
53
67
|
- PostgreSQL database ${chalk.blue("http://localhost:1482")} ${chalk.grey("credentials: contember / contember")}
|
|
54
|
-
-
|
|
68
|
+
- S3 object storage ${chalk.blue("http://localhost:1483")} ${chalk.grey("credentials: contember / contember")}
|
|
55
69
|
- Mailpit SMTP testing ${chalk.blue("http://localhost:1484")}
|
|
56
70
|
- Adminer DB manager ${chalk.blue("http://localhost:1485")}
|
|
57
|
-
- Minio Dashboard ${chalk.blue("http://localhost:1486")} ${chalk.grey("credentials: contember / contember")}
|
|
58
71
|
|
|
59
72
|
${chalk.bold("Need help?")} Ask the community: https://github.com/orgs/contember/discussions
|
|
60
73
|
`;
|
|
74
|
+
};
|
|
61
75
|
export {
|
|
62
76
|
WorkspaceCreateCommand
|
|
63
77
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceCreateCommand.js","sources":["../../../../../packages/create/src/commands/WorkspaceCreateCommand.ts"],"sourcesContent":["import { Command, CommandConfiguration, Input } from '@contember/cli-common'\nimport { join } from 'node:path'\nimport chalk from 'chalk'\nimport { TemplateInstaller } from '../lib/TemplateInstaller'\nimport { getPackageVersion } from '../lib/version'\nimport { detectPackageManager } from '../lib/packageManagerDetector'\n\ntype Args = {\n\tprojectName: string\n}\n\ntype Options = {\n\ttemplate: string\n}\n\nexport class WorkspaceCreateCommand extends Command<Args, Options> {\n\tconstructor(\n\t\tprivate readonly templateInstaller: TemplateInstaller,\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
|
|
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 chalk from 'chalk'\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 $ ${chalk.green(`cd ${safeProjectName}`)}\n\n2. Install dependencies:\n $ ${chalk.green(`${safePackageManager} install`)}\n\n3. Start the Contember stack:\n $ ${chalk.green(`${safePackageManager} start`)}\n\nAvailable services:\n\n${chalk.bold('UI & Admin')}\n- Contember Admin ${chalk.blue('http://localhost:1480')}\n\n${chalk.bold('API & Backend')}\n- Contember Engine API ${chalk.blue('http://localhost:1481')}\n Auth token: 0000000000000000000000000000000000000000\n\n${chalk.bold('Development Tools')}\n- PostgreSQL database ${chalk.blue('http://localhost:1482')} ${chalk.grey('credentials: contember / contember')}\n- S3 object storage ${chalk.blue('http://localhost:1483')} ${chalk.grey('credentials: contember / contember')}\n- Mailpit SMTP testing ${chalk.blue('http://localhost:1484')}\n- Adminer DB manager ${chalk.blue('http://localhost:1485')}\n\n${chalk.bold('Need help?')} Ask the community: https://github.com/orgs/contember/discussions\n`\n}\n"],"names":[],"mappings":";;;;;AA4BA,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,gCAAgC;AAAA,EAC5G;AAAA,EAEA,MAAgB,QAAQ,OAA6B,QAA+B;AACnF,UAAM,cAAc,MAAM,YAAY,aAAa;AACnD,UAAM,mBAAmB,KAAK,KAAK,QAAQ,IAAA,GAAO,WAAW;AAC7D,UAAM,iBAAiB,KAAK,QAAQ,qBAAA;AACpC,UAAM,WAAW,MAAM,UAAU,UAAU,KAAK;AAEhD,UAAM,KAAK,kBAAkB,gBAAgB,UAAU,kBAAkB;AAAA,MACxE,SAAS,MAAM,KAAK,QAAQ,kBAAA;AAAA,MAC5B;AAAA,MACA;AAAA,IAAA,CACA;AAED,UAAM,SAAgC,EAAE,aAAa,kBAAkB,UAAU,eAAA;AACjF,WAAO,KAAK,QAAQ;AAAA,MACnB,OAAO,CAAA,UAAS,WAAW,KAAK;AAAA,MAChC,OAAO,WAAS,MAAM;AAAA,IAAA,CACtB;AAAA,EACF;AACD;AAEA,MAAM,aAAa,CAAC,EAAE,kBAAkB,aAAa,qBAA4C;AAChG,QAAM,uBAAuB,mBAAmB,gBAAgB;AAChE,QAAM,kBAAkB,mBAAmB,WAAW;AACtD,QAAM,qBAAqB,mBAAmB,cAAc;AAC5D,SAAO;AAAA,4CACoC,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,OAKzD,MAAM,MAAM,MAAM,eAAe,EAAE,CAAC;AAAA;AAAA;AAAA,OAGpC,MAAM,MAAM,GAAG,kBAAkB,UAAU,CAAC;AAAA;AAAA;AAAA,OAG5C,MAAM,MAAM,GAAG,kBAAkB,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA,EAI/C,MAAM,KAAK,YAAY,CAAC;AAAA,4BACE,MAAM,KAAK,uBAAuB,CAAC;AAAA;AAAA,EAE7D,MAAM,KAAK,eAAe,CAAC;AAAA,4BACD,MAAM,KAAK,uBAAuB,CAAC;AAAA;AAAA;AAAA,EAG7D,MAAM,KAAK,mBAAmB,CAAC;AAAA,4BACL,MAAM,KAAK,uBAAuB,CAAC,OAAO,MAAM,KAAK,oCAAoC,CAAC;AAAA,4BAC1F,MAAM,KAAK,uBAAuB,CAAC,OAAO,MAAM,KAAK,oCAAoC,CAAC;AAAA,4BAC1F,MAAM,KAAK,uBAAuB,CAAC;AAAA,4BACnC,MAAM,KAAK,uBAAuB,CAAC;AAAA;AAAA,EAE7D,MAAM,KAAK,YAAY,CAAC;AAAA;AAE1B;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fs = require("node:fs/promises");
|
|
4
|
-
const fsExtra = require("fs-extra");
|
|
5
4
|
const os = require("node:os");
|
|
6
5
|
function _interopNamespaceDefault(e) {
|
|
7
6
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -29,7 +28,7 @@ class FileSystem {
|
|
|
29
28
|
__publicField(this, "writeFile", fs__namespace.writeFile);
|
|
30
29
|
__publicField(this, "rename", fs__namespace.rename);
|
|
31
30
|
__publicField(this, "readDir", fs__namespace.readdir);
|
|
32
|
-
__publicField(this, "copy",
|
|
31
|
+
__publicField(this, "copy", (source, destination, options) => fs__namespace.cp(source, destination, { recursive: true, ...options }));
|
|
33
32
|
__publicField(this, "unlink", fs__namespace.unlink);
|
|
34
33
|
__publicField(this, "remove", fs__namespace.rm);
|
|
35
34
|
__publicField(this, "pathExists", async (path) => {
|
|
@@ -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 {
|
|
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":";;;;;;;;;;;;;;;;;;;;;;;;AAIO,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,WAAUA,cAAG,OAAA;AACb,kBAAA,MAAA,QAAO,CAAC,QAAgB,aAAqB,YAC5CA,cAAG,GAAG,QAAQ,aAAa,EAAE,WAAW,MAAM,GAAG,SAAS,CAAA;AAC3D,kBAAA,MAAA,UAASA,cAAG,MAAA;AACZ,kBAAA,MAAA,UAASA,cAAG,EAAA;AACZ,kBAAA,MAAA,cAAa,OAAO,SAAiB;AACpC,UAAI;AACH,cAAMC,GAAAA,OAAO,IAAI;AACjB,eAAO;AAAA,MACR,QAAQ;AACP,eAAO;AAAA,MACR;AAAA,IACD,CAAA;AACA,kBAAA,MAAA,iBAAgB,YAAY;AAC3B,aAAO,MAAMD,cAAG,QAAQE,GAAAA,QAAQ;AAAA,IACjC,CAAA;AAAA,EAAA;AACD;;"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as fs from "node:fs/promises";
|
|
2
2
|
import { access } from "node:fs/promises";
|
|
3
|
-
import { copy } from "fs-extra";
|
|
4
3
|
import { tmpdir } from "node:os";
|
|
5
4
|
var __defProp = Object.defineProperty;
|
|
6
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -11,7 +10,7 @@ class FileSystem {
|
|
|
11
10
|
__publicField(this, "writeFile", fs.writeFile);
|
|
12
11
|
__publicField(this, "rename", fs.rename);
|
|
13
12
|
__publicField(this, "readDir", fs.readdir);
|
|
14
|
-
__publicField(this, "copy",
|
|
13
|
+
__publicField(this, "copy", (source, destination, options) => fs.cp(source, destination, { recursive: true, ...options }));
|
|
15
14
|
__publicField(this, "unlink", fs.unlink);
|
|
16
15
|
__publicField(this, "remove", fs.rm);
|
|
17
16
|
__publicField(this, "pathExists", async (path) => {
|
|
@@ -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 {
|
|
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":";;;;;;AAIO,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,WAAU,GAAG,OAAA;AACb,kBAAA,MAAA,QAAO,CAAC,QAAgB,aAAqB,YAC5C,GAAG,GAAG,QAAQ,aAAa,EAAE,WAAW,MAAM,GAAG,SAAS,CAAA;AAC3D,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;AAC3B,aAAO,MAAM,GAAG,QAAQ,QAAQ;AAAA,IACjC,CAAA;AAAA,EAAA;AACD;"}
|
|
@@ -1,94 +1,106 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const jsyaml = require("js-yaml");
|
|
3
|
+
const path = require("node:path");
|
|
5
4
|
const degit = require("degit");
|
|
5
|
+
const jsyaml = require("js-yaml");
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
7
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
8
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
+
const cloneTemplate = async (source, target) => {
|
|
10
|
+
const emitter = degit(source, { cache: false, force: true, verbose: true });
|
|
11
|
+
await emitter.clone(target);
|
|
12
|
+
};
|
|
9
13
|
class TemplateInstaller {
|
|
10
|
-
constructor(resourceDir, fs) {
|
|
14
|
+
constructor(resourceDir, fs, output, clone = cloneTemplate) {
|
|
11
15
|
this.resourceDir = resourceDir;
|
|
12
16
|
this.fs = fs;
|
|
17
|
+
this.output = output;
|
|
18
|
+
this.clone = clone;
|
|
13
19
|
__publicField(this, "localTemplates");
|
|
14
20
|
__publicField(this, "installTemplate", async (template, targetDir, variables = {}) => {
|
|
15
|
-
let
|
|
16
|
-
|
|
21
|
+
let temporaryTemplateDir;
|
|
22
|
+
let remoteTemplate;
|
|
17
23
|
if (this.localTemplates[template]) {
|
|
18
24
|
template = this.localTemplates[template];
|
|
19
25
|
} else {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
await emitter.clone(tmpDir);
|
|
24
|
-
removeTemplate = () => {
|
|
25
|
-
try {
|
|
26
|
-
this.fs.remove(tmpDir, { recursive: true, force: true });
|
|
27
|
-
} catch (error) {
|
|
28
|
-
console.error(`Failed to clean up template: ${error}`);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
template = tmpDir;
|
|
32
|
-
} catch (error) {
|
|
33
|
-
throw new Error(`Failed to clone template from repository: ${error}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const templateConfigFile = node_path.join(template, "contember.template.yaml");
|
|
37
|
-
if (!await this.fs.pathExists(templateConfigFile)) {
|
|
38
|
-
removeTemplate();
|
|
39
|
-
throw new Error(`${template} is not a Contember template`);
|
|
40
|
-
}
|
|
41
|
-
const config = await this.readYaml(templateConfigFile);
|
|
42
|
-
const nodeModulesDir = node_path.join(template, "node_modules");
|
|
43
|
-
const skippedFiles = /* @__PURE__ */ new Set([...(config.remove || []).map((it) => node_path.join(template, it)), templateConfigFile]);
|
|
44
|
-
if (await this.fs.pathExists(targetDir)) {
|
|
45
|
-
throw `${targetDir} already exists`;
|
|
26
|
+
remoteTemplate = template;
|
|
27
|
+
temporaryTemplateDir = await this.fs.createTempDir();
|
|
28
|
+
template = temporaryTemplateDir;
|
|
46
29
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
30
|
+
try {
|
|
31
|
+
if (remoteTemplate !== void 0) {
|
|
32
|
+
try {
|
|
33
|
+
await this.clone(remoteTemplate, template);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new Error(`Failed to clone template from repository: ${error}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const templateConfigFile = path.join(template, "contember.template.yaml");
|
|
39
|
+
if (!await this.fs.pathExists(templateConfigFile)) {
|
|
40
|
+
throw new Error(`${template} is not a Contember template`);
|
|
41
|
+
}
|
|
42
|
+
const config = await this.readYaml(templateConfigFile);
|
|
43
|
+
const nodeModulesDir = path.join(template, "node_modules");
|
|
44
|
+
const skippedFiles = /* @__PURE__ */ new Set([...(config.remove || []).map((it) => path.join(template, it)), templateConfigFile]);
|
|
45
|
+
if (await this.fs.pathExists(targetDir)) {
|
|
46
|
+
throw `${targetDir} already exists`;
|
|
47
|
+
}
|
|
48
|
+
await this.fs.copy(template, targetDir, {
|
|
49
|
+
filter: (src) => !src.startsWith(nodeModulesDir) && !skippedFiles.has(src)
|
|
62
50
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
51
|
+
if (config.patchPackageJson) {
|
|
52
|
+
await this.replaceFileContent(path.join(targetDir, "package.json"), (content) => {
|
|
53
|
+
const {
|
|
54
|
+
name,
|
|
55
|
+
version,
|
|
56
|
+
"scripts-template": scripts,
|
|
57
|
+
scripts: _nullScripts,
|
|
58
|
+
license,
|
|
59
|
+
...json
|
|
60
|
+
} = JSON.parse(content);
|
|
61
|
+
return JSON.stringify({ scripts, ...json }, null, " ");
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
for (const [source, target] of Object.entries(config.rename || {})) {
|
|
65
|
+
await this.fs.rename(path.join(targetDir, source), path.join(targetDir, target));
|
|
66
|
+
}
|
|
67
|
+
for (const [source, target] of Object.entries(config.copy || {})) {
|
|
68
|
+
await this.fs.copy(path.join(targetDir, source), path.join(targetDir, target));
|
|
74
69
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
for (const file of config.replaceVariables || []) {
|
|
71
|
+
const path$1 = path.join(targetDir, file);
|
|
72
|
+
if (!await this.fs.pathExists(path$1)) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
await this.replaceFileContent(path$1, (content) => Object.entries(variables).reduce(
|
|
76
|
+
(content2, [key, value]) => content2.replace(new RegExp(`{${key}}`, "g"), value),
|
|
77
|
+
content
|
|
78
|
+
));
|
|
79
|
+
}
|
|
80
|
+
} finally {
|
|
81
|
+
if (temporaryTemplateDir !== void 0) {
|
|
82
|
+
await this.cleanupTemporaryTemplate(temporaryTemplateDir);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
__publicField(this, "cleanupTemporaryTemplate", async (path2) => {
|
|
87
|
+
try {
|
|
88
|
+
await this.fs.remove(path2, { recursive: true, force: true });
|
|
89
|
+
} catch {
|
|
90
|
+
this.output.warn("Failed to clean up the temporary template directory.");
|
|
79
91
|
}
|
|
80
92
|
});
|
|
81
|
-
__publicField(this, "replaceFileContent", async (
|
|
82
|
-
const content = await this.fs.readFile(
|
|
93
|
+
__publicField(this, "replaceFileContent", async (path2, replacer) => {
|
|
94
|
+
const content = await this.fs.readFile(path2, { encoding: "utf8" });
|
|
83
95
|
const newContent = replacer(content);
|
|
84
|
-
await this.fs.writeFile(
|
|
96
|
+
await this.fs.writeFile(path2, newContent, { encoding: "utf8" });
|
|
85
97
|
});
|
|
86
|
-
__publicField(this, "readYaml", async (
|
|
87
|
-
const content = await this.fs.readFile(
|
|
98
|
+
__publicField(this, "readYaml", async (path2) => {
|
|
99
|
+
const content = await this.fs.readFile(path2, { encoding: "utf8" });
|
|
88
100
|
return jsyaml.load(content);
|
|
89
101
|
});
|
|
90
102
|
this.localTemplates = {
|
|
91
|
-
["default"]:
|
|
103
|
+
["default"]: path.join(this.resourceDir, "templates/default")
|
|
92
104
|
};
|
|
93
105
|
}
|
|
94
106
|
}
|
|
@@ -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 degit from 'degit'\nimport jsyaml from 'js-yaml'\nimport { FileSystem } from './FileSystem.js'\n\ninterface TemplateInstallerOutput {\n\twarn(message: string): void\n}\n\ntype CloneTemplate = (source: string, target: string) => Promise<void>\n\nconst cloneTemplate: CloneTemplate = async (source, target) => {\n\tconst emitter = degit(source, { cache: false, force: true, verbose: true })\n\tawait emitter.clone(target)\n}\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\tfor (const [source, target] of Object.entries(config.rename || {})) {\n\t\t\t\tawait this.fs.rename(join(targetDir, source), join(targetDir, 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(join(targetDir, source), join(targetDir, target))\n\t\t\t}\n\n\t\t\tfor (const file of config.replaceVariables || []) {\n\t\t\t\tconst path = join(targetDir, 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":["join","path","content"],"mappings":";;;;;;;;AAWA,MAAM,gBAA+B,OAAO,QAAQ,WAAW;AAC9D,QAAM,UAAU,MAAM,QAAQ,EAAE,OAAO,OAAO,OAAO,MAAM,SAAS,MAAM;AAC1E,QAAM,QAAQ,MAAM,MAAM;AAC3B;AAEO,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,qBAAqBA,KAAAA,KAAK,UAAU,yBAAyB;AACnE,YAAI,CAAE,MAAM,KAAK,GAAG,WAAW,kBAAk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
1
1
|
import { join } from "node:path";
|
|
2
|
-
import jsyaml__default from "js-yaml";
|
|
3
2
|
import degit from "degit";
|
|
3
|
+
import jsyaml__default from "js-yaml";
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
6
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
+
const cloneTemplate = async (source, target) => {
|
|
8
|
+
const emitter = degit(source, { cache: false, force: true, verbose: true });
|
|
9
|
+
await emitter.clone(target);
|
|
10
|
+
};
|
|
7
11
|
class TemplateInstaller {
|
|
8
|
-
constructor(resourceDir, fs) {
|
|
12
|
+
constructor(resourceDir, fs, output, clone = cloneTemplate) {
|
|
9
13
|
this.resourceDir = resourceDir;
|
|
10
14
|
this.fs = fs;
|
|
15
|
+
this.output = output;
|
|
16
|
+
this.clone = clone;
|
|
11
17
|
__publicField(this, "localTemplates");
|
|
12
18
|
__publicField(this, "installTemplate", async (template, targetDir, variables = {}) => {
|
|
13
|
-
let
|
|
14
|
-
|
|
19
|
+
let temporaryTemplateDir;
|
|
20
|
+
let remoteTemplate;
|
|
15
21
|
if (this.localTemplates[template]) {
|
|
16
22
|
template = this.localTemplates[template];
|
|
17
23
|
} else {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
await emitter.clone(tmpDir);
|
|
22
|
-
removeTemplate = () => {
|
|
23
|
-
try {
|
|
24
|
-
this.fs.remove(tmpDir, { recursive: true, force: true });
|
|
25
|
-
} catch (error) {
|
|
26
|
-
console.error(`Failed to clean up template: ${error}`);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
template = tmpDir;
|
|
30
|
-
} catch (error) {
|
|
31
|
-
throw new Error(`Failed to clone template from repository: ${error}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
const templateConfigFile = join(template, "contember.template.yaml");
|
|
35
|
-
if (!await this.fs.pathExists(templateConfigFile)) {
|
|
36
|
-
removeTemplate();
|
|
37
|
-
throw new Error(`${template} is not a Contember template`);
|
|
24
|
+
remoteTemplate = template;
|
|
25
|
+
temporaryTemplateDir = await this.fs.createTempDir();
|
|
26
|
+
template = temporaryTemplateDir;
|
|
38
27
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return JSON.stringify({ scripts, ...json }, null, " ");
|
|
28
|
+
try {
|
|
29
|
+
if (remoteTemplate !== void 0) {
|
|
30
|
+
try {
|
|
31
|
+
await this.clone(remoteTemplate, template);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw new Error(`Failed to clone template from repository: ${error}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const templateConfigFile = join(template, "contember.template.yaml");
|
|
37
|
+
if (!await this.fs.pathExists(templateConfigFile)) {
|
|
38
|
+
throw new Error(`${template} is not a Contember template`);
|
|
39
|
+
}
|
|
40
|
+
const config = await this.readYaml(templateConfigFile);
|
|
41
|
+
const nodeModulesDir = join(template, "node_modules");
|
|
42
|
+
const skippedFiles = /* @__PURE__ */ new Set([...(config.remove || []).map((it) => join(template, it)), templateConfigFile]);
|
|
43
|
+
if (await this.fs.pathExists(targetDir)) {
|
|
44
|
+
throw `${targetDir} already exists`;
|
|
45
|
+
}
|
|
46
|
+
await this.fs.copy(template, targetDir, {
|
|
47
|
+
filter: (src) => !src.startsWith(nodeModulesDir) && !skippedFiles.has(src)
|
|
60
48
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
49
|
+
if (config.patchPackageJson) {
|
|
50
|
+
await this.replaceFileContent(join(targetDir, "package.json"), (content) => {
|
|
51
|
+
const {
|
|
52
|
+
name,
|
|
53
|
+
version,
|
|
54
|
+
"scripts-template": scripts,
|
|
55
|
+
scripts: _nullScripts,
|
|
56
|
+
license,
|
|
57
|
+
...json
|
|
58
|
+
} = JSON.parse(content);
|
|
59
|
+
return JSON.stringify({ scripts, ...json }, null, " ");
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
for (const [source, target] of Object.entries(config.rename || {})) {
|
|
63
|
+
await this.fs.rename(join(targetDir, source), join(targetDir, target));
|
|
64
|
+
}
|
|
65
|
+
for (const [source, target] of Object.entries(config.copy || {})) {
|
|
66
|
+
await this.fs.copy(join(targetDir, source), join(targetDir, target));
|
|
72
67
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
for (const file of config.replaceVariables || []) {
|
|
69
|
+
const path = join(targetDir, file);
|
|
70
|
+
if (!await this.fs.pathExists(path)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
await this.replaceFileContent(path, (content) => Object.entries(variables).reduce(
|
|
74
|
+
(content2, [key, value]) => content2.replace(new RegExp(`{${key}}`, "g"), value),
|
|
75
|
+
content
|
|
76
|
+
));
|
|
77
|
+
}
|
|
78
|
+
} finally {
|
|
79
|
+
if (temporaryTemplateDir !== void 0) {
|
|
80
|
+
await this.cleanupTemporaryTemplate(temporaryTemplateDir);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
__publicField(this, "cleanupTemporaryTemplate", async (path) => {
|
|
85
|
+
try {
|
|
86
|
+
await this.fs.remove(path, { recursive: true, force: true });
|
|
87
|
+
} catch {
|
|
88
|
+
this.output.warn("Failed to clean up the temporary template directory.");
|
|
77
89
|
}
|
|
78
90
|
});
|
|
79
91
|
__publicField(this, "replaceFileContent", async (path, replacer) => {
|
|
@@ -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 degit from 'degit'\nimport jsyaml from 'js-yaml'\nimport { FileSystem } from './FileSystem.js'\n\ninterface TemplateInstallerOutput {\n\twarn(message: string): void\n}\n\ntype CloneTemplate = (source: string, target: string) => Promise<void>\n\nconst cloneTemplate: CloneTemplate = async (source, target) => {\n\tconst emitter = degit(source, { cache: false, force: true, verbose: true })\n\tawait emitter.clone(target)\n}\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\tfor (const [source, target] of Object.entries(config.rename || {})) {\n\t\t\t\tawait this.fs.rename(join(targetDir, source), join(targetDir, 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(join(targetDir, source), join(targetDir, target))\n\t\t\t}\n\n\t\t\tfor (const file of config.replaceVariables || []) {\n\t\t\t\tconst path = join(targetDir, 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":";;;;;;AAWA,MAAM,gBAA+B,OAAO,QAAQ,WAAW;AAC9D,QAAM,UAAU,MAAM,QAAQ,EAAE,OAAO,OAAO,OAAO,MAAM,SAAS,MAAM;AAC1E,QAAM,QAAQ,MAAM,MAAM;AAC3B;AAEO,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,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C/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;AA1GC,SAAK,iBAAiB;AAAA,MACrB,CAAC,SAAS,GAAG,KAAK,KAAK,aAAa,mBAAmB;AAAA,IAAA;AAAA,EAEzD;AAwGD;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const node_fs = require("node:fs");
|
|
4
|
-
const
|
|
4
|
+
const path = require("node:path");
|
|
5
5
|
const detectPackageManager = () => {
|
|
6
6
|
const userAgent = process.env.npm_config_user_agent;
|
|
7
7
|
if (userAgent) {
|
|
@@ -11,11 +11,11 @@ const detectPackageManager = () => {
|
|
|
11
11
|
if (userAgent.startsWith("bun/")) return "bun";
|
|
12
12
|
}
|
|
13
13
|
const cwd = process.cwd();
|
|
14
|
-
if (node_fs.existsSync(
|
|
15
|
-
if (node_fs.existsSync(
|
|
16
|
-
if (node_fs.existsSync(
|
|
17
|
-
if (node_fs.existsSync(
|
|
18
|
-
if (node_fs.existsSync(
|
|
14
|
+
if (node_fs.existsSync(path.join(cwd, "yarn.lock"))) return "yarn";
|
|
15
|
+
if (node_fs.existsSync(path.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
16
|
+
if (node_fs.existsSync(path.join(cwd, "package-lock.json"))) return "npm";
|
|
17
|
+
if (node_fs.existsSync(path.join(cwd, "bun.lockb"))) return "bun";
|
|
18
|
+
if (node_fs.existsSync(path.join(cwd, "bun.lock"))) return "bun";
|
|
19
19
|
return "npm";
|
|
20
20
|
};
|
|
21
21
|
exports.detectPackageManager = detectPackageManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageManagerDetector.cjs","sources":["../../../../../packages/create/src/lib/packageManagerDetector.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { join } from 'node:path'\n\nexport type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun'\n\nexport const detectPackageManager = (): PackageManager => {\n\tconst userAgent = process.env.npm_config_user_agent\n\n\tif (userAgent) {\n\t\tif (userAgent.startsWith('yarn/')) return 'yarn'\n\t\tif (userAgent.startsWith('pnpm/')) return 'pnpm'\n\t\tif (userAgent.startsWith('npm/')) return 'npm'\n\t\tif (userAgent.startsWith('bun/')) return 'bun'\n\t}\n\n\tconst cwd = process.cwd()\n\tif (existsSync(join(cwd, 'yarn.lock'))) return 'yarn'\n\tif (existsSync(join(cwd, 'pnpm-lock.yaml'))) return 'pnpm'\n\tif (existsSync(join(cwd, 'package-lock.json'))) return 'npm'\n\tif (existsSync(join(cwd, 'bun.lockb'))) return 'bun'\n\tif (existsSync(join(cwd, 'bun.lock'))) return 'bun'\n\n\treturn 'npm'\n}\n"],"names":["existsSync","join"],"mappings":";;;;AAKO,MAAM,uBAAuB,MAAsB;AACzD,QAAM,YAAY,QAAQ,IAAI;AAE9B,MAAI,WAAW;AACd,QAAI,UAAU,WAAW,OAAO,EAAG,QAAO;AAC1C,QAAI,UAAU,WAAW,OAAO,EAAG,QAAO;AAC1C,QAAI,UAAU,WAAW,MAAM,EAAG,QAAO;AACzC,QAAI,UAAU,WAAW,MAAM,EAAG,QAAO;AAAA,EAC1C;AAEA,QAAM,MAAM,QAAQ,IAAA;AACpB,MAAIA,QAAAA,WAAWC,
|
|
1
|
+
{"version":3,"file":"packageManagerDetector.cjs","sources":["../../../../../packages/create/src/lib/packageManagerDetector.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { join } from 'node:path'\n\nexport type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun'\n\nexport const detectPackageManager = (): PackageManager => {\n\tconst userAgent = process.env.npm_config_user_agent\n\n\tif (userAgent) {\n\t\tif (userAgent.startsWith('yarn/')) return 'yarn'\n\t\tif (userAgent.startsWith('pnpm/')) return 'pnpm'\n\t\tif (userAgent.startsWith('npm/')) return 'npm'\n\t\tif (userAgent.startsWith('bun/')) return 'bun'\n\t}\n\n\tconst cwd = process.cwd()\n\tif (existsSync(join(cwd, 'yarn.lock'))) return 'yarn'\n\tif (existsSync(join(cwd, 'pnpm-lock.yaml'))) return 'pnpm'\n\tif (existsSync(join(cwd, 'package-lock.json'))) return 'npm'\n\tif (existsSync(join(cwd, 'bun.lockb'))) return 'bun'\n\tif (existsSync(join(cwd, 'bun.lock'))) return 'bun'\n\n\treturn 'npm'\n}\n"],"names":["existsSync","join"],"mappings":";;;;AAKO,MAAM,uBAAuB,MAAsB;AACzD,QAAM,YAAY,QAAQ,IAAI;AAE9B,MAAI,WAAW;AACd,QAAI,UAAU,WAAW,OAAO,EAAG,QAAO;AAC1C,QAAI,UAAU,WAAW,OAAO,EAAG,QAAO;AAC1C,QAAI,UAAU,WAAW,MAAM,EAAG,QAAO;AACzC,QAAI,UAAU,WAAW,MAAM,EAAG,QAAO;AAAA,EAC1C;AAEA,QAAM,MAAM,QAAQ,IAAA;AACpB,MAAIA,QAAAA,WAAWC,KAAAA,KAAK,KAAK,WAAW,CAAC,EAAG,QAAO;AAC/C,MAAID,QAAAA,WAAWC,KAAAA,KAAK,KAAK,gBAAgB,CAAC,EAAG,QAAO;AACpD,MAAID,QAAAA,WAAWC,KAAAA,KAAK,KAAK,mBAAmB,CAAC,EAAG,QAAO;AACvD,MAAID,QAAAA,WAAWC,KAAAA,KAAK,KAAK,WAAW,CAAC,EAAG,QAAO;AAC/C,MAAID,QAAAA,WAAWC,KAAAA,KAAK,KAAK,UAAU,CAAC,EAAG,QAAO;AAE9C,SAAO;AACR;;"}
|