@contember/create 1.4.0-rc.4 → 1.4.0-rc.6

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.
Files changed (223) hide show
  1. package/dist/src/commands/WorkspaceCreateCommand.d.ts +4 -3
  2. package/dist/src/commands/WorkspaceCreateCommand.d.ts.map +1 -1
  3. package/dist/src/commands/WorkspaceCreateCommand.js +10 -4
  4. package/dist/src/commands/WorkspaceCreateCommand.js.map +1 -1
  5. package/dist/src/lib/FileSystem.d.ts +14 -0
  6. package/dist/src/lib/FileSystem.d.ts.map +1 -0
  7. package/dist/src/lib/FileSystem.js +54 -0
  8. package/dist/src/lib/FileSystem.js.map +1 -0
  9. package/dist/src/lib/PackageDownloader.d.ts +7 -0
  10. package/dist/src/lib/PackageDownloader.d.ts.map +1 -0
  11. package/dist/src/lib/PackageDownloader.js +32 -0
  12. package/dist/src/lib/PackageDownloader.js.map +1 -0
  13. package/dist/src/lib/TemplateInstaller.d.ts +13 -0
  14. package/dist/src/lib/TemplateInstaller.d.ts.map +1 -0
  15. package/dist/src/lib/TemplateInstaller.js +75 -0
  16. package/dist/src/lib/TemplateInstaller.js.map +1 -0
  17. package/dist/src/lib/pathUtils.d.ts +3 -0
  18. package/dist/src/lib/pathUtils.d.ts.map +1 -0
  19. package/dist/src/lib/pathUtils.js +7 -0
  20. package/dist/src/lib/pathUtils.js.map +1 -0
  21. package/dist/src/run.js +7 -3
  22. package/dist/src/run.js.map +1 -1
  23. package/dist/src/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +9 -3
  25. package/resources/templates/template-workspace/.gitignore.dist +3 -0
  26. package/resources/templates/template-workspace/admin/.env.development +3 -0
  27. package/resources/templates/template-workspace/admin/.env.production +3 -0
  28. package/resources/templates/template-workspace/admin/app/components/layout.tsx +32 -0
  29. package/resources/templates/template-workspace/admin/app/components/logo.tsx +16 -0
  30. package/resources/templates/template-workspace/admin/app/components/navigation.tsx +1 -0
  31. package/resources/templates/template-workspace/admin/app/config.ts +27 -0
  32. package/resources/templates/template-workspace/admin/app/index.html +15 -0
  33. package/resources/templates/template-workspace/admin/app/index.tsx +40 -0
  34. package/resources/templates/template-workspace/admin/app/pages/index.tsx +5 -0
  35. package/resources/templates/template-workspace/admin/index.css +53 -0
  36. package/resources/templates/template-workspace/admin/index.html +13 -0
  37. package/resources/templates/template-workspace/admin/index.tsx +268 -0
  38. package/resources/templates/template-workspace/admin/lib/binding/binding.tsx +45 -0
  39. package/resources/templates/template-workspace/admin/lib/binding/delete.tsx +43 -0
  40. package/resources/templates/template-workspace/admin/lib/binding/hooks.tsx +71 -0
  41. package/resources/templates/template-workspace/admin/lib/binding/identity.tsx +19 -0
  42. package/resources/templates/template-workspace/admin/lib/binding/index.ts +5 -0
  43. package/resources/templates/template-workspace/admin/lib/binding/persist.tsx +70 -0
  44. package/resources/templates/template-workspace/admin/lib/block-repeater/block-repeater.tsx +224 -0
  45. package/resources/templates/template-workspace/admin/lib/block-repeater/index.ts +1 -0
  46. package/resources/templates/template-workspace/admin/lib/board/board.tsx +240 -0
  47. package/resources/templates/template-workspace/admin/lib/board/index.ts +1 -0
  48. package/resources/templates/template-workspace/admin/lib/buttons/back-button.tsx +20 -0
  49. package/resources/templates/template-workspace/admin/lib/buttons/index.ts +2 -0
  50. package/resources/templates/template-workspace/admin/lib/buttons/link-back-button.tsx +21 -0
  51. package/resources/templates/template-workspace/admin/lib/datagrid/cells.tsx +64 -0
  52. package/resources/templates/template-workspace/admin/lib/datagrid/column-header.tsx +65 -0
  53. package/resources/templates/template-workspace/admin/lib/datagrid/columns.tsx +166 -0
  54. package/resources/templates/template-workspace/admin/lib/datagrid/elements.tsx +42 -0
  55. package/resources/templates/template-workspace/admin/lib/datagrid/empty.tsx +8 -0
  56. package/resources/templates/template-workspace/admin/lib/datagrid/export.tsx +17 -0
  57. package/resources/templates/template-workspace/admin/lib/datagrid/filters/boolean.tsx +76 -0
  58. package/resources/templates/template-workspace/admin/lib/datagrid/filters/common.tsx +29 -0
  59. package/resources/templates/template-workspace/admin/lib/datagrid/filters/date.tsx +153 -0
  60. package/resources/templates/template-workspace/admin/lib/datagrid/filters/enum.tsx +115 -0
  61. package/resources/templates/template-workspace/admin/lib/datagrid/filters/index.ts +7 -0
  62. package/resources/templates/template-workspace/admin/lib/datagrid/filters/mobile.tsx +19 -0
  63. package/resources/templates/template-workspace/admin/lib/datagrid/filters/number.tsx +100 -0
  64. package/resources/templates/template-workspace/admin/lib/datagrid/filters/relation.tsx +180 -0
  65. package/resources/templates/template-workspace/admin/lib/datagrid/filters/text.tsx +121 -0
  66. package/resources/templates/template-workspace/admin/lib/datagrid/grid.tsx +61 -0
  67. package/resources/templates/template-workspace/admin/lib/datagrid/index.ts +16 -0
  68. package/resources/templates/template-workspace/admin/lib/datagrid/layout-switcher.tsx +32 -0
  69. package/resources/templates/template-workspace/admin/lib/datagrid/loader.tsx +10 -0
  70. package/resources/templates/template-workspace/admin/lib/datagrid/pagination.tsx +103 -0
  71. package/resources/templates/template-workspace/admin/lib/datagrid/table.tsx +69 -0
  72. package/resources/templates/template-workspace/admin/lib/datagrid/tiles.tsx +24 -0
  73. package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +66 -0
  74. package/resources/templates/template-workspace/admin/lib/datagrid/ui.tsx +153 -0
  75. package/resources/templates/template-workspace/admin/lib/dev/index.ts +2 -0
  76. package/resources/templates/template-workspace/admin/lib/dev/login-panel.tsx +56 -0
  77. package/resources/templates/template-workspace/admin/lib/dev/todo.tsx +14 -0
  78. package/resources/templates/template-workspace/admin/lib/dict.ts +324 -0
  79. package/resources/templates/template-workspace/admin/lib/dimensions/dimensions.tsx +135 -0
  80. package/resources/templates/template-workspace/admin/lib/dimensions/index.ts +1 -0
  81. package/resources/templates/template-workspace/admin/lib/editor/block-editor.tsx +111 -0
  82. package/resources/templates/template-workspace/admin/lib/editor/common/baseEditorPlugins.tsx +66 -0
  83. package/resources/templates/template-workspace/admin/lib/editor/common/buttons.tsx +83 -0
  84. package/resources/templates/template-workspace/admin/lib/editor/common/editor-block-toolbar.tsx +17 -0
  85. package/resources/templates/template-workspace/admin/lib/editor/common/editor-canvas.tsx +30 -0
  86. package/resources/templates/template-workspace/admin/lib/editor/common/editor-editable-canvas.tsx +50 -0
  87. package/resources/templates/template-workspace/admin/lib/editor/common/editor-inline-toolbar.tsx +63 -0
  88. package/resources/templates/template-workspace/admin/lib/editor/common/elements/AnchorRenderer.tsx +36 -0
  89. package/resources/templates/template-workspace/admin/lib/editor/common/elements/BlockElement.tsx +48 -0
  90. package/resources/templates/template-workspace/admin/lib/editor/common/elements/HeadingRenderer.tsx +48 -0
  91. package/resources/templates/template-workspace/admin/lib/editor/common/elements/HorizontalRuleRenderer.tsx +28 -0
  92. package/resources/templates/template-workspace/admin/lib/editor/common/elements/ListItemRenderer.tsx +13 -0
  93. package/resources/templates/template-workspace/admin/lib/editor/common/elements/OrderedListRenderer.tsx +13 -0
  94. package/resources/templates/template-workspace/admin/lib/editor/common/elements/ParagraphRenderer.tsx +15 -0
  95. package/resources/templates/template-workspace/admin/lib/editor/common/elements/ScrollTargetRenderer.tsx +30 -0
  96. package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableCellElementRenderer.tsx +20 -0
  97. package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableElementRenderer.tsx +96 -0
  98. package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableRowElementRenderer.tsx +15 -0
  99. package/resources/templates/template-workspace/admin/lib/editor/common/elements/UnorderedListRenderer.tsx +13 -0
  100. package/resources/templates/template-workspace/admin/lib/editor/common/index.ts +6 -0
  101. package/resources/templates/template-workspace/admin/lib/editor/editor-block.tsx +96 -0
  102. package/resources/templates/template-workspace/admin/lib/editor/index.ts +5 -0
  103. package/resources/templates/template-workspace/admin/lib/editor/plugins.tsx +36 -0
  104. package/resources/templates/template-workspace/admin/lib/editor/rich-text.tsx +54 -0
  105. package/resources/templates/template-workspace/admin/lib/editor/sortable-block.tsx +51 -0
  106. package/resources/templates/template-workspace/admin/lib/errors/index.ts +1 -0
  107. package/resources/templates/template-workspace/admin/lib/errors/use-error-formatter.ts +26 -0
  108. package/resources/templates/template-workspace/admin/lib/form/container.tsx +63 -0
  109. package/resources/templates/template-workspace/admin/lib/form/index.ts +5 -0
  110. package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +99 -0
  111. package/resources/templates/template-workspace/admin/lib/form/select.tsx +123 -0
  112. package/resources/templates/template-workspace/admin/lib/form/ui.tsx +29 -0
  113. package/resources/templates/template-workspace/admin/lib/form/upload.tsx +243 -0
  114. package/resources/templates/template-workspace/admin/lib/formatting/formatting.ts +62 -0
  115. package/resources/templates/template-workspace/admin/lib/formatting/index.ts +1 -0
  116. package/resources/templates/template-workspace/admin/lib/images/formatImageResizeUrl.ts +23 -0
  117. package/resources/templates/template-workspace/admin/lib/images/index.ts +1 -0
  118. package/resources/templates/template-workspace/admin/lib/layout/index.ts +2 -0
  119. package/resources/templates/template-workspace/admin/lib/layout/layout.tsx +167 -0
  120. package/resources/templates/template-workspace/admin/lib/layout/slots.tsx +24 -0
  121. package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/index.ts +1 -0
  122. package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/outdated-application-dialog.tsx +41 -0
  123. package/resources/templates/template-workspace/admin/lib/repeater/index.ts +1 -0
  124. package/resources/templates/template-workspace/admin/lib/repeater/repeater.tsx +142 -0
  125. package/resources/templates/template-workspace/admin/lib/select/create-new.tsx +34 -0
  126. package/resources/templates/template-workspace/admin/lib/select/filter.tsx +13 -0
  127. package/resources/templates/template-workspace/admin/lib/select/highlight.tsx +16 -0
  128. package/resources/templates/template-workspace/admin/lib/select/index.ts +7 -0
  129. package/resources/templates/template-workspace/admin/lib/select/list.tsx +49 -0
  130. package/resources/templates/template-workspace/admin/lib/select/multi-select.tsx +95 -0
  131. package/resources/templates/template-workspace/admin/lib/select/pagination.tsx +48 -0
  132. package/resources/templates/template-workspace/admin/lib/select/select.tsx +87 -0
  133. package/resources/templates/template-workspace/admin/lib/select/sortable-select.tsx +129 -0
  134. package/resources/templates/template-workspace/admin/lib/select/ui.tsx +80 -0
  135. package/resources/templates/template-workspace/admin/lib/tenant/forms/change-my-password.tsx +40 -0
  136. package/resources/templates/template-workspace/admin/lib/tenant/forms/common.tsx +94 -0
  137. package/resources/templates/template-workspace/admin/lib/tenant/forms/create-api-key.tsx +39 -0
  138. package/resources/templates/template-workspace/admin/lib/tenant/forms/index.ts +8 -0
  139. package/resources/templates/template-workspace/admin/lib/tenant/forms/invite.tsx +46 -0
  140. package/resources/templates/template-workspace/admin/lib/tenant/forms/login.tsx +52 -0
  141. package/resources/templates/template-workspace/admin/lib/tenant/forms/memberships-control.tsx +128 -0
  142. package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset-request.tsx +31 -0
  143. package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset.tsx +44 -0
  144. package/resources/templates/template-workspace/admin/lib/tenant/forms/update-project-member.tsx +32 -0
  145. package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInvite.ts +28 -0
  146. package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInviteUser.tsx +45 -0
  147. package/resources/templates/template-workspace/admin/lib/tenant/index.ts +3 -0
  148. package/resources/templates/template-workspace/admin/lib/tenant/listing/api-key-list.tsx +25 -0
  149. package/resources/templates/template-workspace/admin/lib/tenant/listing/index.ts +4 -0
  150. package/resources/templates/template-workspace/admin/lib/tenant/listing/member-delete-dialog.tsx +38 -0
  151. package/resources/templates/template-workspace/admin/lib/tenant/listing/member-list.tsx +147 -0
  152. package/resources/templates/template-workspace/admin/lib/tenant/listing/person-list.tsx +25 -0
  153. package/resources/templates/template-workspace/admin/lib/tenant/otp/index.ts +1 -0
  154. package/resources/templates/template-workspace/admin/lib/tenant/otp/otp-setup.tsx +146 -0
  155. package/resources/templates/template-workspace/admin/lib/toast/index.ts +2 -0
  156. package/resources/templates/template-workspace/admin/lib/toast/toast.tsx +112 -0
  157. package/resources/templates/template-workspace/admin/lib/toast/toaster.tsx +104 -0
  158. package/resources/templates/template-workspace/admin/lib/ui/alert-dialog.tsx +59 -0
  159. package/resources/templates/template-workspace/admin/lib/ui/button.tsx +29 -0
  160. package/resources/templates/template-workspace/admin/lib/ui/card.tsx +25 -0
  161. package/resources/templates/template-workspace/admin/lib/ui/dialog.tsx +51 -0
  162. package/resources/templates/template-workspace/admin/lib/ui/divider.tsx +11 -0
  163. package/resources/templates/template-workspace/admin/lib/ui/dropdown.tsx +108 -0
  164. package/resources/templates/template-workspace/admin/lib/ui/input.tsx +62 -0
  165. package/resources/templates/template-workspace/admin/lib/ui/label.tsx +7 -0
  166. package/resources/templates/template-workspace/admin/lib/ui/loader.tsx +30 -0
  167. package/resources/templates/template-workspace/admin/lib/ui/menu.tsx +103 -0
  168. package/resources/templates/template-workspace/admin/lib/ui/overlay.tsx +33 -0
  169. package/resources/templates/template-workspace/admin/lib/ui/popover.tsx +31 -0
  170. package/resources/templates/template-workspace/admin/lib/ui/progress.tsx +25 -0
  171. package/resources/templates/template-workspace/admin/lib/ui/scroll-area.tsx +45 -0
  172. package/resources/templates/template-workspace/admin/lib/ui/sheet.tsx +67 -0
  173. package/resources/templates/template-workspace/admin/lib/ui/sortable.tsx +13 -0
  174. package/resources/templates/template-workspace/admin/lib/ui/switch.tsx +10 -0
  175. package/resources/templates/template-workspace/admin/lib/ui/table.tsx +46 -0
  176. package/resources/templates/template-workspace/admin/lib/ui/textarea.tsx +18 -0
  177. package/resources/templates/template-workspace/admin/lib/ui/toggle-group.tsx +44 -0
  178. package/resources/templates/template-workspace/admin/lib/ui/toggle.tsx +29 -0
  179. package/resources/templates/template-workspace/admin/lib/ui/tooltip.tsx +24 -0
  180. package/resources/templates/template-workspace/admin/lib/upload/dropzone.tsx +21 -0
  181. package/resources/templates/template-workspace/admin/lib/upload/index.ts +3 -0
  182. package/resources/templates/template-workspace/admin/lib/upload/repeater.tsx +12 -0
  183. package/resources/templates/template-workspace/admin/lib/upload/ui.tsx +57 -0
  184. package/resources/templates/template-workspace/admin/lib/upload/upload-progress.tsx +130 -0
  185. package/resources/templates/template-workspace/admin/lib/upload/view.tsx +219 -0
  186. package/resources/templates/template-workspace/admin/lib/utils/cn.ts +4 -0
  187. package/resources/templates/template-workspace/admin/lib/utils/dict-format.tsx +3 -0
  188. package/resources/templates/template-workspace/admin/lib/utils/format-image-resize-url.ts +17 -0
  189. package/resources/templates/template-workspace/admin/lib/utils/formatting.ts +60 -0
  190. package/resources/templates/template-workspace/admin/lib/utils/index.ts +2 -0
  191. package/resources/templates/template-workspace/admin/lib/utils/uic.tsx +79 -0
  192. package/resources/templates/template-workspace/admin/package.json +63 -0
  193. package/resources/templates/template-workspace/admin/postcss.config.js +6 -0
  194. package/resources/templates/template-workspace/admin/public/favicon.png +0 -0
  195. package/resources/templates/template-workspace/admin/tailwind.config.js +73 -0
  196. package/resources/templates/template-workspace/admin/tsconfig.json +23 -0
  197. package/resources/templates/template-workspace/admin/vite-env.d.ts +7 -0
  198. package/resources/templates/template-workspace/admin/vite.config.ts +39 -0
  199. package/resources/templates/template-workspace/api/index.ts +7 -0
  200. package/resources/templates/template-workspace/api/migrations/.gitkeep +1 -0
  201. package/resources/templates/template-workspace/api/model/index.ts +1 -0
  202. package/resources/templates/template-workspace/api/package.json +16 -0
  203. package/resources/templates/template-workspace/api/tsconfig.json +10 -0
  204. package/resources/templates/template-workspace/biome.json +45 -0
  205. package/resources/templates/template-workspace/client/package.json +16 -0
  206. package/resources/templates/template-workspace/client/src/index.ts +1 -0
  207. package/resources/templates/template-workspace/client/tsconfig.json +9 -0
  208. package/resources/templates/template-workspace/contember.template.yaml +7 -0
  209. package/resources/templates/template-workspace/docker-compose.yaml +124 -0
  210. package/resources/templates/template-workspace/package.json +32 -0
  211. package/resources/templates/template-workspace/scripts/generate-client.sh +8 -0
  212. package/resources/templates/template-workspace/tsconfig.json +9 -0
  213. package/resources/templates/template-workspace/tsconfig.settings.json +15 -0
  214. package/src/commands/WorkspaceCreateCommand.ts +15 -6
  215. package/src/lib/FileSystem.ts +24 -0
  216. package/src/lib/PackageDownloader.ts +33 -0
  217. package/src/lib/TemplateInstaller.ts +102 -0
  218. package/src/lib/pathUtils.ts +4 -0
  219. package/src/run.ts +14 -5
  220. package/tsconfig.settings.json +5 -1
  221. package/types/download-tarball/index.d.ts +7 -0
  222. package/types/get-package-json-from-registry/index.d.ts +3 -0
  223. package/types/registry-info/index.d.ts +7 -0
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "isolatedModules": true,
5
+ "lib": [
6
+ "esnext"
7
+ ],
8
+ "module": "esnext",
9
+ "moduleResolution": "Bundler",
10
+ "noEmit": true,
11
+ "skipLibCheck": true,
12
+ "strict": true,
13
+ "target": "esnext"
14
+ }
15
+ }
@@ -1,15 +1,22 @@
1
- import { createWorkspace, Command, CommandConfiguration, Input } from '@contember/cli-common'
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
- const template = input.getOption('template')
22
- await createWorkspace({ workspaceDirectory, workspaceName, template })
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(`npm install`)}
44
+ $ ${chalk.greenBright(`yarn install`)}
36
45
 
37
46
  And start the Contember stack:
38
- $ ${chalk.greenBright('npm start')}
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
+ }
@@ -0,0 +1,4 @@
1
+ import { join } from 'node:path'
2
+
3
+ export const packageRoot = process.env.CONTEMBER_CLI_PACKAGE_ROOT || join(__dirname, '../../')
4
+ export const resourcesDir = join(packageRoot, './resources')
package/src/run.ts CHANGED
@@ -1,14 +1,23 @@
1
1
  #!/usr/bin/env node
2
- import { CommandManager, Application } from '@contember/cli-common'
2
+ import { Application, CommandManager } from '@contember/cli-common'
3
3
  import { WorkspaceCreateCommand } from './commands'
4
- ;(async () => {
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]) < 12) {
11
- throw `Node >= 12 is required`
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))
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "esModuleInterop": true
3
+ "esModuleInterop": true,
4
+ "typeRoots": [
5
+ "./types",
6
+ "./node_modules/@types"
7
+ ]
4
8
  },
5
9
  "extends": "../../tsconfig.settings.json"
6
10
  }
@@ -0,0 +1,7 @@
1
+ declare module 'download-tarball' {
2
+ export default function downloadTarball(args: {
3
+ url: string
4
+ dir: string
5
+ gotOpts?: { headers?: Record<string, any> }
6
+ }): Promise<void>
7
+ }
@@ -0,0 +1,3 @@
1
+ declare module 'get-package-json-from-registry' {
2
+ export default function getPackageJson(packageName: string): any
3
+ }
@@ -0,0 +1,7 @@
1
+ declare module 'registry-info' {
2
+ export default function getRegistryInfo(scope: string | null): {
3
+ registryUrl: string
4
+ authToken: string
5
+ authorization: string
6
+ }
7
+ }