@contember/create 1.4.0-rc.3 → 1.4.0-rc.5
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/src/commands/WorkspaceCreateCommand.d.ts +4 -3
- package/dist/src/commands/WorkspaceCreateCommand.d.ts.map +1 -1
- package/dist/src/commands/WorkspaceCreateCommand.js +10 -4
- package/dist/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/src/lib/FileSystem.d.ts +14 -0
- package/dist/src/lib/FileSystem.d.ts.map +1 -0
- package/dist/src/lib/FileSystem.js +54 -0
- package/dist/src/lib/FileSystem.js.map +1 -0
- package/dist/src/lib/PackageDownloader.d.ts +7 -0
- package/dist/src/lib/PackageDownloader.d.ts.map +1 -0
- package/dist/src/lib/PackageDownloader.js +32 -0
- package/dist/src/lib/PackageDownloader.js.map +1 -0
- package/dist/src/lib/TemplateInstaller.d.ts +13 -0
- package/dist/src/lib/TemplateInstaller.d.ts.map +1 -0
- package/dist/src/lib/TemplateInstaller.js +75 -0
- package/dist/src/lib/TemplateInstaller.js.map +1 -0
- package/dist/src/lib/pathUtils.d.ts +3 -0
- package/dist/src/lib/pathUtils.d.ts.map +1 -0
- package/dist/src/lib/pathUtils.js +7 -0
- package/dist/src/lib/pathUtils.js.map +1 -0
- package/dist/src/run.js +7 -3
- package/dist/src/run.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -3
- package/resources/templates/template-workspace/.gitignore.dist +3 -0
- package/resources/templates/template-workspace/admin/.env.development +3 -0
- package/resources/templates/template-workspace/admin/.env.production +3 -0
- package/resources/templates/template-workspace/admin/app/components/layout.tsx +32 -0
- package/resources/templates/template-workspace/admin/app/components/logo.tsx +16 -0
- package/resources/templates/template-workspace/admin/app/components/navigation.tsx +1 -0
- package/resources/templates/template-workspace/admin/app/config.ts +27 -0
- package/resources/templates/template-workspace/admin/app/index.html +15 -0
- package/resources/templates/template-workspace/admin/app/index.tsx +40 -0
- package/resources/templates/template-workspace/admin/app/pages/index.tsx +5 -0
- package/resources/templates/template-workspace/admin/index.css +53 -0
- package/resources/templates/template-workspace/admin/index.html +13 -0
- package/resources/templates/template-workspace/admin/index.tsx +268 -0
- package/resources/templates/template-workspace/admin/lib/binding/binding.tsx +45 -0
- package/resources/templates/template-workspace/admin/lib/binding/delete.tsx +43 -0
- package/resources/templates/template-workspace/admin/lib/binding/hooks.tsx +71 -0
- package/resources/templates/template-workspace/admin/lib/binding/identity.tsx +19 -0
- package/resources/templates/template-workspace/admin/lib/binding/index.ts +5 -0
- package/resources/templates/template-workspace/admin/lib/binding/persist.tsx +70 -0
- package/resources/templates/template-workspace/admin/lib/block-repeater/block-repeater.tsx +224 -0
- package/resources/templates/template-workspace/admin/lib/block-repeater/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/board/board.tsx +240 -0
- package/resources/templates/template-workspace/admin/lib/board/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/buttons/back-button.tsx +20 -0
- package/resources/templates/template-workspace/admin/lib/buttons/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/buttons/link-back-button.tsx +21 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/cells.tsx +64 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/column-header.tsx +65 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/columns.tsx +166 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/elements.tsx +42 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/empty.tsx +8 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/export.tsx +17 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/boolean.tsx +76 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/common.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/date.tsx +153 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/enum.tsx +115 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/index.ts +7 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/mobile.tsx +19 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/number.tsx +100 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/relation.tsx +180 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/text.tsx +121 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/grid.tsx +61 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/index.ts +16 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/layout-switcher.tsx +32 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/loader.tsx +10 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/pagination.tsx +103 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/table.tsx +69 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/tiles.tsx +24 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +66 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/ui.tsx +153 -0
- package/resources/templates/template-workspace/admin/lib/dev/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/dev/login-panel.tsx +56 -0
- package/resources/templates/template-workspace/admin/lib/dev/todo.tsx +14 -0
- package/resources/templates/template-workspace/admin/lib/dict.ts +324 -0
- package/resources/templates/template-workspace/admin/lib/dimensions/dimensions.tsx +135 -0
- package/resources/templates/template-workspace/admin/lib/dimensions/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/editor/block-editor.tsx +111 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/baseEditorPlugins.tsx +66 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/buttons.tsx +83 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-block-toolbar.tsx +17 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-canvas.tsx +30 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-editable-canvas.tsx +50 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-inline-toolbar.tsx +63 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/AnchorRenderer.tsx +36 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/BlockElement.tsx +48 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/HeadingRenderer.tsx +48 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/HorizontalRuleRenderer.tsx +28 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/ListItemRenderer.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/OrderedListRenderer.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/ParagraphRenderer.tsx +15 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/ScrollTargetRenderer.tsx +30 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableCellElementRenderer.tsx +20 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableElementRenderer.tsx +96 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableRowElementRenderer.tsx +15 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/UnorderedListRenderer.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/index.ts +6 -0
- package/resources/templates/template-workspace/admin/lib/editor/editor-block.tsx +96 -0
- package/resources/templates/template-workspace/admin/lib/editor/index.ts +5 -0
- package/resources/templates/template-workspace/admin/lib/editor/plugins.tsx +36 -0
- package/resources/templates/template-workspace/admin/lib/editor/rich-text.tsx +54 -0
- package/resources/templates/template-workspace/admin/lib/editor/sortable-block.tsx +51 -0
- package/resources/templates/template-workspace/admin/lib/errors/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/errors/use-error-formatter.ts +26 -0
- package/resources/templates/template-workspace/admin/lib/form/container.tsx +63 -0
- package/resources/templates/template-workspace/admin/lib/form/index.ts +5 -0
- package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +99 -0
- package/resources/templates/template-workspace/admin/lib/form/select.tsx +123 -0
- package/resources/templates/template-workspace/admin/lib/form/ui.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/form/upload.tsx +243 -0
- package/resources/templates/template-workspace/admin/lib/formatting/formatting.ts +62 -0
- package/resources/templates/template-workspace/admin/lib/formatting/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/images/formatImageResizeUrl.ts +23 -0
- package/resources/templates/template-workspace/admin/lib/images/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/layout/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/layout/layout.tsx +167 -0
- package/resources/templates/template-workspace/admin/lib/layout/slots.tsx +24 -0
- package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/outdated-application-dialog.tsx +41 -0
- package/resources/templates/template-workspace/admin/lib/repeater/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/repeater/repeater.tsx +142 -0
- package/resources/templates/template-workspace/admin/lib/select/create-new.tsx +34 -0
- package/resources/templates/template-workspace/admin/lib/select/filter.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/select/highlight.tsx +16 -0
- package/resources/templates/template-workspace/admin/lib/select/index.ts +7 -0
- package/resources/templates/template-workspace/admin/lib/select/list.tsx +49 -0
- package/resources/templates/template-workspace/admin/lib/select/multi-select.tsx +95 -0
- package/resources/templates/template-workspace/admin/lib/select/pagination.tsx +48 -0
- package/resources/templates/template-workspace/admin/lib/select/select.tsx +87 -0
- package/resources/templates/template-workspace/admin/lib/select/sortable-select.tsx +129 -0
- package/resources/templates/template-workspace/admin/lib/select/ui.tsx +80 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/change-my-password.tsx +40 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/common.tsx +94 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/create-api-key.tsx +39 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/index.ts +8 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/invite.tsx +46 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/login.tsx +52 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/memberships-control.tsx +128 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset-request.tsx +31 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset.tsx +44 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/update-project-member.tsx +32 -0
- package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInvite.ts +28 -0
- package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInviteUser.tsx +45 -0
- package/resources/templates/template-workspace/admin/lib/tenant/index.ts +3 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/api-key-list.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/index.ts +4 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/member-delete-dialog.tsx +38 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/member-list.tsx +147 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/person-list.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/tenant/otp/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/tenant/otp/otp-setup.tsx +146 -0
- package/resources/templates/template-workspace/admin/lib/toast/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/toast/toast.tsx +112 -0
- package/resources/templates/template-workspace/admin/lib/toast/toaster.tsx +104 -0
- package/resources/templates/template-workspace/admin/lib/ui/alert-dialog.tsx +59 -0
- package/resources/templates/template-workspace/admin/lib/ui/button.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/ui/card.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/ui/dialog.tsx +51 -0
- package/resources/templates/template-workspace/admin/lib/ui/divider.tsx +11 -0
- package/resources/templates/template-workspace/admin/lib/ui/dropdown.tsx +108 -0
- package/resources/templates/template-workspace/admin/lib/ui/input.tsx +62 -0
- package/resources/templates/template-workspace/admin/lib/ui/label.tsx +7 -0
- package/resources/templates/template-workspace/admin/lib/ui/loader.tsx +30 -0
- package/resources/templates/template-workspace/admin/lib/ui/menu.tsx +103 -0
- package/resources/templates/template-workspace/admin/lib/ui/overlay.tsx +33 -0
- package/resources/templates/template-workspace/admin/lib/ui/popover.tsx +31 -0
- package/resources/templates/template-workspace/admin/lib/ui/progress.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/ui/scroll-area.tsx +45 -0
- package/resources/templates/template-workspace/admin/lib/ui/sheet.tsx +67 -0
- package/resources/templates/template-workspace/admin/lib/ui/sortable.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/ui/switch.tsx +10 -0
- package/resources/templates/template-workspace/admin/lib/ui/table.tsx +46 -0
- package/resources/templates/template-workspace/admin/lib/ui/textarea.tsx +18 -0
- package/resources/templates/template-workspace/admin/lib/ui/toggle-group.tsx +44 -0
- package/resources/templates/template-workspace/admin/lib/ui/toggle.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/ui/tooltip.tsx +24 -0
- package/resources/templates/template-workspace/admin/lib/upload/dropzone.tsx +21 -0
- package/resources/templates/template-workspace/admin/lib/upload/index.ts +3 -0
- package/resources/templates/template-workspace/admin/lib/upload/repeater.tsx +12 -0
- package/resources/templates/template-workspace/admin/lib/upload/ui.tsx +57 -0
- package/resources/templates/template-workspace/admin/lib/upload/upload-progress.tsx +130 -0
- package/resources/templates/template-workspace/admin/lib/upload/view.tsx +219 -0
- package/resources/templates/template-workspace/admin/lib/utils/cn.ts +4 -0
- package/resources/templates/template-workspace/admin/lib/utils/dict-format.tsx +3 -0
- package/resources/templates/template-workspace/admin/lib/utils/format-image-resize-url.ts +17 -0
- package/resources/templates/template-workspace/admin/lib/utils/formatting.ts +60 -0
- package/resources/templates/template-workspace/admin/lib/utils/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/utils/uic.tsx +79 -0
- package/resources/templates/template-workspace/admin/package.json +63 -0
- package/resources/templates/template-workspace/admin/postcss.config.js +6 -0
- package/resources/templates/template-workspace/admin/public/favicon.png +0 -0
- package/resources/templates/template-workspace/admin/tailwind.config.js +73 -0
- package/resources/templates/template-workspace/admin/tsconfig.json +23 -0
- package/resources/templates/template-workspace/admin/vite-env.d.ts +7 -0
- package/resources/templates/template-workspace/admin/vite.config.ts +39 -0
- package/resources/templates/template-workspace/api/index.ts +7 -0
- package/resources/templates/template-workspace/api/migrations/.gitkeep +1 -0
- package/resources/templates/template-workspace/api/model/index.ts +1 -0
- package/resources/templates/template-workspace/api/package.json +16 -0
- package/resources/templates/template-workspace/api/tsconfig.json +10 -0
- package/resources/templates/template-workspace/biome.json +45 -0
- package/resources/templates/template-workspace/client/package.json +16 -0
- package/resources/templates/template-workspace/client/src/index.ts +1 -0
- package/resources/templates/template-workspace/client/tsconfig.json +9 -0
- package/resources/templates/template-workspace/contember.template.yaml +7 -0
- package/resources/templates/template-workspace/docker-compose.yaml +124 -0
- package/resources/templates/template-workspace/package.json +32 -0
- package/resources/templates/template-workspace/scripts/generate-client.sh +8 -0
- package/resources/templates/template-workspace/tsconfig.json +9 -0
- package/resources/templates/template-workspace/tsconfig.settings.json +15 -0
- package/src/commands/WorkspaceCreateCommand.ts +15 -6
- package/src/lib/FileSystem.ts +24 -0
- package/src/lib/PackageDownloader.ts +33 -0
- package/src/lib/TemplateInstaller.ts +102 -0
- package/src/lib/pathUtils.ts +4 -0
- package/src/run.ts +14 -5
- package/tsconfig.settings.json +5 -1
- package/types/download-tarball/index.d.ts +7 -0
- package/types/get-package-json-from-registry/index.d.ts +3 -0
- package/types/registry-info/index.d.ts +7 -0
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Command, CommandConfiguration, getPackageVersion, Input } from '@contember/cli-common'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
|
+
import { TemplateInstaller } from '../lib/TemplateInstaller'
|
|
5
|
+
|
|
4
6
|
type Args = {
|
|
5
7
|
workspaceName: string
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
type Options = {
|
|
9
|
-
template?: string
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export class WorkspaceCreateCommand extends Command<Args, Options> {
|
|
14
|
+
constructor(
|
|
15
|
+
private readonly templateInstaller: TemplateInstaller,
|
|
16
|
+
) {
|
|
17
|
+
super()
|
|
18
|
+
}
|
|
19
|
+
|
|
13
20
|
protected configure(configuration: CommandConfiguration<Args, Options>): void {
|
|
14
21
|
configuration.description('Creates a new Contember workspace')
|
|
15
22
|
configuration.argument('workspaceName')
|
|
@@ -18,8 +25,10 @@ export class WorkspaceCreateCommand extends Command<Args, Options> {
|
|
|
18
25
|
protected async execute(input: Input<Args, Options>): Promise<void> {
|
|
19
26
|
const workspaceName = input.getArgument('workspaceName')
|
|
20
27
|
const workspaceDirectory = join(process.cwd(), workspaceName)
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
await this.templateInstaller.installTemplate('@contember/template-workspace', workspaceDirectory, {
|
|
29
|
+
version: getPackageVersion(),
|
|
30
|
+
projectName: workspaceName,
|
|
31
|
+
})
|
|
23
32
|
// eslint-disable-next-line no-console
|
|
24
33
|
console.log(createDocs(workspaceDirectory, workspaceName))
|
|
25
34
|
}
|
|
@@ -32,10 +41,10 @@ You can now enter this directory:
|
|
|
32
41
|
$ ${chalk.greenBright(`cd ${workspaceName}`)}
|
|
33
42
|
|
|
34
43
|
Install NPM dependencies:
|
|
35
|
-
$ ${chalk.greenBright(`
|
|
44
|
+
$ ${chalk.greenBright(`yarn install`)}
|
|
36
45
|
|
|
37
46
|
And start the Contember stack:
|
|
38
|
-
$ ${chalk.greenBright('
|
|
47
|
+
$ ${chalk.greenBright('yarn start')}
|
|
39
48
|
|
|
40
49
|
The following services will be accessible:
|
|
41
50
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises'
|
|
2
|
+
import { access } from 'node:fs/promises'
|
|
3
|
+
import { copy } from 'fs-extra'
|
|
4
|
+
import { tmpdir } from 'node:os'
|
|
5
|
+
|
|
6
|
+
export class FileSystem {
|
|
7
|
+
readFile = fs.readFile
|
|
8
|
+
writeFile = fs.writeFile
|
|
9
|
+
rename = fs.rename
|
|
10
|
+
readDir = fs.readdir
|
|
11
|
+
copy = copy
|
|
12
|
+
unlink = fs.unlink
|
|
13
|
+
pathExists = async (path: string) => {
|
|
14
|
+
try {
|
|
15
|
+
await access(path)
|
|
16
|
+
return true
|
|
17
|
+
} catch {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
createTempDir = async () => {
|
|
22
|
+
return await fs.mkdtemp(tmpdir())
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import npa from 'npm-package-arg'
|
|
2
|
+
import getRegistryInfo from 'registry-info'
|
|
3
|
+
import getPackageJson from 'get-package-json-from-registry'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import downloadTarball from 'download-tarball'
|
|
6
|
+
import { FileSystem } from './FileSystem'
|
|
7
|
+
|
|
8
|
+
export class PackageDownloader {
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
private readonly fs: FileSystem,
|
|
12
|
+
) {
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
downloadPackage = async (pkgName: string): Promise<string> => {
|
|
16
|
+
const { scope } = npa(pkgName)
|
|
17
|
+
const { authorization } = getRegistryInfo(scope)
|
|
18
|
+
const headers = authorization ? { authorization } : {}
|
|
19
|
+
|
|
20
|
+
const pkg = await getPackageJson(pkgName)
|
|
21
|
+
const {
|
|
22
|
+
dist: { tarball },
|
|
23
|
+
} = pkg
|
|
24
|
+
|
|
25
|
+
const tmpDir = await this.fs.createTempDir()
|
|
26
|
+
await downloadTarball({ url: tarball, gotOpts: { headers }, dir: tmpDir })
|
|
27
|
+
const dirContent = await this.fs.readDir(tmpDir)
|
|
28
|
+
if (dirContent.length !== 1 || dirContent[0] !== 'package') {
|
|
29
|
+
throw 'Invalid NPM package'
|
|
30
|
+
}
|
|
31
|
+
return join(tmpDir, 'package')
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { isAbsolute, join } from 'node:path'
|
|
2
|
+
import { PackageDownloader } from './PackageDownloader'
|
|
3
|
+
import { FileSystem } from './FileSystem'
|
|
4
|
+
import jsyaml from 'js-yaml'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export class TemplateInstaller {
|
|
8
|
+
|
|
9
|
+
private localTemplates: Record<string, string> = {
|
|
10
|
+
['@contember/template-workspace']: join(this.resourceDir, 'templates/template-workspace'),
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
private readonly resourceDir: string,
|
|
15
|
+
private readonly packageDownloader: PackageDownloader,
|
|
16
|
+
private readonly fs: FileSystem,
|
|
17
|
+
) {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
installTemplate = async (
|
|
21
|
+
template: string,
|
|
22
|
+
targetDir: string,
|
|
23
|
+
variables: Record<string, string> = {},
|
|
24
|
+
) => {
|
|
25
|
+
let removeTemplate = () => {
|
|
26
|
+
}
|
|
27
|
+
if (this.localTemplates[template]) {
|
|
28
|
+
template = this.localTemplates[template]
|
|
29
|
+
}
|
|
30
|
+
if (!isAbsolute(template)) {
|
|
31
|
+
template = await this.packageDownloader.downloadPackage(template)
|
|
32
|
+
removeTemplate = async () => {
|
|
33
|
+
await this.fs.unlink(template)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const templateConfigFile = join(template, 'contember.template.yaml')
|
|
37
|
+
if (!(await this.fs.pathExists(templateConfigFile))) {
|
|
38
|
+
throw `${template} is not a Contember template`
|
|
39
|
+
}
|
|
40
|
+
const config = (await this.readYaml(templateConfigFile)) as {
|
|
41
|
+
type?: string
|
|
42
|
+
remove?: string[]
|
|
43
|
+
patchPackageJson?: boolean
|
|
44
|
+
rename?: Record<string, string>
|
|
45
|
+
copy?: Record<string, string>
|
|
46
|
+
replaceVariables?: string[]
|
|
47
|
+
}
|
|
48
|
+
const nodeModulesDir = join(template, 'node_modules')
|
|
49
|
+
const skippedFiles = new Set([...(config.remove || []).map(it => join(template, it)), templateConfigFile])
|
|
50
|
+
if (await this.fs.pathExists(targetDir)) {
|
|
51
|
+
throw `${targetDir} already exists`
|
|
52
|
+
}
|
|
53
|
+
await this.fs.copy(template, targetDir, {
|
|
54
|
+
filter: src => !src.startsWith(nodeModulesDir) && !skippedFiles.has(src),
|
|
55
|
+
})
|
|
56
|
+
await removeTemplate()
|
|
57
|
+
|
|
58
|
+
if (config.patchPackageJson) {
|
|
59
|
+
await this.replaceFileContent(join(targetDir, 'package.json'), content => {
|
|
60
|
+
const {
|
|
61
|
+
name,
|
|
62
|
+
version,
|
|
63
|
+
'scripts-template': scripts,
|
|
64
|
+
scripts: _nullScripts,
|
|
65
|
+
license,
|
|
66
|
+
...json
|
|
67
|
+
} = JSON.parse(content)
|
|
68
|
+
return JSON.stringify({ scripts, ...json }, null, ' ')
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
for (const [source, target] of Object.entries(config.rename || {})) {
|
|
72
|
+
await this.fs.rename(join(targetDir, source), join(targetDir, target))
|
|
73
|
+
}
|
|
74
|
+
for (const [source, target] of Object.entries(config.copy || {})) {
|
|
75
|
+
await this.fs.copy(join(targetDir, source), join(targetDir, target))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (const file of config.replaceVariables || []) {
|
|
79
|
+
const path = join(targetDir, file)
|
|
80
|
+
if (!(await this.fs.pathExists(path))) {
|
|
81
|
+
continue
|
|
82
|
+
}
|
|
83
|
+
await this.replaceFileContent(path, content =>
|
|
84
|
+
Object.entries(variables).reduce(
|
|
85
|
+
(content, [key, value]) => content.replace(new RegExp(`\{${key}\}`, 'g'), value),
|
|
86
|
+
content,
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private replaceFileContent = async (path: string, replacer: (content: string) => string): Promise<void> => {
|
|
93
|
+
const content = await this.fs.readFile(path, { encoding: 'utf8' })
|
|
94
|
+
const newContent = replacer(content)
|
|
95
|
+
await this.fs.writeFile(path, newContent, { encoding: 'utf8' })
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private readYaml = async <T = unknown>(path: string): Promise<T> => {
|
|
99
|
+
const content = await this.fs.readFile(path, { encoding: 'utf8' })
|
|
100
|
+
return jsyaml.load(content) as unknown as T
|
|
101
|
+
}
|
|
102
|
+
}
|
package/src/run.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { Application, CommandManager } from '@contember/cli-common'
|
|
3
3
|
import { WorkspaceCreateCommand } from './commands'
|
|
4
|
-
|
|
4
|
+
import { TemplateInstaller } from './lib/TemplateInstaller'
|
|
5
|
+
import { resourcesDir } from './lib/pathUtils'
|
|
6
|
+
import { PackageDownloader } from './lib/PackageDownloader'
|
|
7
|
+
import { FileSystem } from './lib/FileSystem'
|
|
8
|
+
|
|
9
|
+
(async () => {
|
|
5
10
|
const commandManager = new CommandManager({
|
|
6
|
-
['workspace']: () => new WorkspaceCreateCommand(
|
|
11
|
+
['workspace']: () => new WorkspaceCreateCommand(new TemplateInstaller(
|
|
12
|
+
resourcesDir,
|
|
13
|
+
new PackageDownloader(new FileSystem()),
|
|
14
|
+
new FileSystem(),
|
|
15
|
+
)),
|
|
7
16
|
})
|
|
8
17
|
|
|
9
18
|
const nodeVersion = process.version.match(/^v?(\d+)\..+$/)
|
|
10
|
-
if (nodeVersion && Number(nodeVersion[1]) <
|
|
11
|
-
throw `Node >=
|
|
19
|
+
if (nodeVersion && Number(nodeVersion[1]) < 18) {
|
|
20
|
+
throw `Node >= 18 is required`
|
|
12
21
|
}
|
|
13
22
|
const app = new Application(commandManager, `Contember installer`)
|
|
14
23
|
await app.runCommand('workspace', process.argv.slice(2))
|
package/tsconfig.settings.json
CHANGED