@silexlabs/silex 3.0.0-alpha.49 → 3.0.0-alpha.51

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 (119) hide show
  1. package/dist/client/client/config.d.ts +14 -1
  2. package/dist/client/client/grapesjs/PublicationManager.d.ts +2 -7
  3. package/dist/client/client/publication-transformers.d.ts +41 -0
  4. package/dist/client/css/admin.css +4 -1
  5. package/dist/client/js/main.js +3 -3
  6. package/dist/client/types.d.ts +18 -16
  7. package/dist/plugins/client/client/api.d.ts +83 -0
  8. package/dist/plugins/client/client/api.js +105 -0
  9. package/dist/plugins/client/client/api.js.map +1 -0
  10. package/dist/plugins/client/client/config.d.ts +58 -0
  11. package/dist/plugins/client/client/config.js +80 -0
  12. package/dist/plugins/client/client/config.js.map +1 -0
  13. package/dist/plugins/client/client/events.js +2 -0
  14. package/dist/plugins/client/client/events.js.map +1 -1
  15. package/dist/plugins/client/client/grapesjs/LoginDialog.d.ts +15 -0
  16. package/dist/plugins/client/client/grapesjs/LoginDialog.js +193 -0
  17. package/dist/plugins/client/client/grapesjs/LoginDialog.js.map +1 -0
  18. package/dist/plugins/client/client/grapesjs/PublicationManager.d.ts +70 -0
  19. package/dist/plugins/client/client/grapesjs/PublicationManager.js +310 -0
  20. package/dist/plugins/client/client/grapesjs/PublicationManager.js.map +1 -0
  21. package/dist/plugins/client/client/grapesjs/PublicationUi.d.ts +61 -0
  22. package/dist/plugins/client/client/grapesjs/PublicationUi.js +324 -0
  23. package/dist/plugins/client/client/grapesjs/PublicationUi.js.map +1 -0
  24. package/dist/plugins/client/client/grapesjs/blocks.d.ts +1 -0
  25. package/dist/plugins/client/client/grapesjs/blocks.js +37 -0
  26. package/dist/plugins/client/client/grapesjs/blocks.js.map +1 -0
  27. package/dist/plugins/client/client/grapesjs/index.d.ts +5 -0
  28. package/dist/plugins/client/client/grapesjs/index.js +264 -0
  29. package/dist/plugins/client/client/grapesjs/index.js.map +1 -0
  30. package/dist/plugins/client/client/grapesjs/internal-links.d.ts +1 -0
  31. package/dist/plugins/client/client/grapesjs/internal-links.js +220 -0
  32. package/dist/plugins/client/client/grapesjs/internal-links.js.map +1 -0
  33. package/dist/plugins/client/client/grapesjs/new-page-dialog.d.ts +2 -0
  34. package/dist/plugins/client/client/grapesjs/new-page-dialog.js +83 -0
  35. package/dist/plugins/client/client/grapesjs/new-page-dialog.js.map +1 -0
  36. package/dist/plugins/client/client/grapesjs/openImport.d.ts +9 -0
  37. package/dist/plugins/client/client/grapesjs/openImport.js +74 -0
  38. package/dist/plugins/client/client/grapesjs/openImport.js.map +1 -0
  39. package/dist/plugins/client/client/grapesjs/page-panel.d.ts +3 -0
  40. package/dist/plugins/client/client/grapesjs/page-panel.js +113 -0
  41. package/dist/plugins/client/client/grapesjs/page-panel.js.map +1 -0
  42. package/dist/plugins/client/client/grapesjs/project-bar.d.ts +1 -0
  43. package/dist/plugins/client/client/grapesjs/project-bar.js +106 -0
  44. package/dist/plugins/client/client/grapesjs/project-bar.js.map +1 -0
  45. package/dist/plugins/client/client/grapesjs/rich-text.d.ts +1 -0
  46. package/dist/plugins/client/client/grapesjs/rich-text.js +31 -0
  47. package/dist/plugins/client/client/grapesjs/rich-text.js.map +1 -0
  48. package/dist/plugins/client/client/grapesjs/semantic.d.ts +1 -0
  49. package/dist/plugins/client/client/grapesjs/semantic.js +110 -0
  50. package/dist/plugins/client/client/grapesjs/semantic.js.map +1 -0
  51. package/dist/plugins/client/client/grapesjs/settings.d.ts +2 -0
  52. package/dist/plugins/client/client/grapesjs/settings.js +197 -0
  53. package/dist/plugins/client/client/grapesjs/settings.js.map +1 -0
  54. package/dist/plugins/client/client/grapesjs/storage.d.ts +1 -0
  55. package/dist/plugins/client/client/grapesjs/storage.js +124 -0
  56. package/dist/plugins/client/client/grapesjs/storage.js.map +1 -0
  57. package/dist/plugins/client/client/grapesjs/symbolDialogs.d.ts +3 -0
  58. package/dist/plugins/client/client/grapesjs/symbolDialogs.js +36 -0
  59. package/dist/plugins/client/client/grapesjs/symbolDialogs.js.map +1 -0
  60. package/dist/plugins/client/client/publication-transformers.d.ts +41 -0
  61. package/dist/plugins/client/client/publication-transformers.js +165 -0
  62. package/dist/plugins/client/client/publication-transformers.js.map +1 -0
  63. package/dist/plugins/client/constants.d.ts +29 -0
  64. package/dist/plugins/client/constants.js +46 -0
  65. package/dist/plugins/client/constants.js.map +1 -0
  66. package/dist/plugins/client/plugins/client/11ty.d.ts +17 -0
  67. package/dist/plugins/client/plugins/client/11ty.js +70 -0
  68. package/dist/plugins/client/plugins/client/11ty.js.map +1 -0
  69. package/dist/plugins/client/plugins/client/publicationRenderer.js +59 -21
  70. package/dist/plugins/client/plugins/client/publicationRenderer.js.map +1 -1
  71. package/dist/plugins/client/plugins/client/website-info.js +1 -1
  72. package/dist/plugins/client/plugins/client/website-info.js.map +1 -1
  73. package/dist/plugins/client/types.d.ts +18 -16
  74. package/dist/plugins/client/types.js.map +1 -1
  75. package/dist/plugins/server/plugins/server/FtpConnector.d.ts +2 -1
  76. package/dist/plugins/server/plugins/server/FtpConnector.js +5 -6
  77. package/dist/plugins/server/plugins/server/FtpConnector.js.map +1 -1
  78. package/dist/plugins/server/plugins/server/GitlabConnector.d.ts +1 -7
  79. package/dist/plugins/server/plugins/server/GitlabConnector.js +124 -112
  80. package/dist/plugins/server/plugins/server/GitlabConnector.js.map +1 -1
  81. package/dist/plugins/server/server/connectors/FsHosting.d.ts +2 -1
  82. package/dist/plugins/server/server/connectors/FsHosting.js +4 -5
  83. package/dist/plugins/server/server/connectors/FsHosting.js.map +1 -1
  84. package/dist/plugins/server/server/connectors/FsStorage.js +1 -0
  85. package/dist/plugins/server/server/connectors/FsStorage.js.map +1 -1
  86. package/dist/plugins/server/server/connectors/connectors.d.ts +2 -1
  87. package/dist/plugins/server/server/connectors/connectors.js.map +1 -1
  88. package/dist/plugins/server/server/jobs.d.ts +6 -0
  89. package/dist/plugins/server/server/jobs.js +3 -1
  90. package/dist/plugins/server/server/jobs.js.map +1 -1
  91. package/dist/plugins/server/types.d.ts +18 -16
  92. package/dist/plugins/server/types.js.map +1 -1
  93. package/dist/server/server/api/publicationApi.js +14 -20
  94. package/dist/server/server/connectors/FsHosting.js +4 -5
  95. package/dist/server/server/connectors/FsStorage.js +1 -0
  96. package/dist/server/server/jobs.js +2 -1
  97. package/package.json +1 -1
  98. package/public/silex.js +23 -0
  99. package/src/css/website-info.scss +4 -1
  100. package/src/ts/client/config.ts +22 -2
  101. package/src/ts/client/events.ts +3 -0
  102. package/src/ts/client/grapesjs/PublicationManager.ts +23 -3
  103. package/src/ts/client/grapesjs/internal-links.ts +0 -2
  104. package/src/ts/client/grapesjs/storage.ts +1 -1
  105. package/src/ts/client/index.ts +4 -0
  106. package/src/ts/client/publication-transformers.test.ts +146 -0
  107. package/src/ts/client/publication-transformers.ts +188 -0
  108. package/src/ts/plugins/client/11ty.ts +89 -0
  109. package/src/ts/plugins/client/publicationRenderer.ts +64 -22
  110. package/src/ts/plugins/client/website-info.ts +1 -1
  111. package/src/ts/plugins/server/FtpConnector.ts +3 -3
  112. package/src/ts/plugins/server/GitlabConnector.ts +128 -109
  113. package/src/ts/server/api/publicationApi.ts +16 -23
  114. package/src/ts/server/connectors/FsHosting.ts +2 -2
  115. package/src/ts/server/connectors/FsStorage.ts +1 -0
  116. package/src/ts/server/connectors/connectors.ts +3 -1
  117. package/src/ts/server/jobs.ts +10 -0
  118. package/src/ts/server/utils/BackwardCompat.ts +530 -529
  119. package/src/ts/types.ts +20 -17
@@ -15,7 +15,7 @@
15
15
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
- import { API_CONNECTOR_LOGIN_CALLBACK, API_CONNECTOR_PATH, API_PATH, WEBSITE_DATA_FILE, WEBSITE_META_DATA_FILE } from '../../constants'
18
+ import { API_CONNECTOR_LOGIN_CALLBACK, API_CONNECTOR_PATH, API_PATH, WEBSITE_DATA_FILE } from '../../constants'
19
19
  import { ServerConfig } from '../../server/config'
20
20
  import { ConnectorFile, ConnectorFileContent, StatusCallback, StorageConnector, contentToBuffer, contentToString, toConnectorData } from '../../server/connectors/connectors'
21
21
  import { ApiError, ConnectorType, ConnectorUser, WebsiteData, WebsiteId, WebsiteMeta, WebsiteMetaFileContent } from '../../types'
@@ -33,8 +33,9 @@ export interface GitlabOptions {
33
33
  clientSecret: string
34
34
  branch: string
35
35
  assetsFolder: string
36
- metaRepo: string
37
- metaRepoFile: string
36
+ //metaRepo: string
37
+ //metaRepoFile: string
38
+ repoPrefix: string
38
39
  }
39
40
 
40
41
  interface GitlabToken {
@@ -120,8 +121,9 @@ export default class GitlabConnector implements StorageConnector {
120
121
  this.options = {
121
122
  branch: 'main',
122
123
  assetsFolder: 'assets',
123
- metaRepo: 'silex-meta',
124
- metaRepoFile: 'websites.json',
124
+ //metaRepo: 'silex-meta',
125
+ //metaRepoFile: 'websites.json',
126
+ repoPrefix: 'silex_',
125
127
  ...opts,
126
128
  } as GitlabOptions
127
129
  if(!this.options.clientId) throw new Error('Missing Gitlab client ID')
@@ -162,28 +164,28 @@ export default class GitlabConnector implements StorageConnector {
162
164
  * Get the meta repo path for the current user
163
165
  * The meta repo contains a JSON file which contains the list of websites
164
166
  */
165
- private getMetaRepoPath(session: GitlabSession): string {
166
- if(!session.gitlab?.username) throw new ApiError('Missing Gitlab user ID. User not logged in?', 401)
167
- return encodeURIComponent(`${session.gitlab.username}/${this.options.metaRepo}`)
168
- }
169
-
170
- /**
171
- * Initialize the storage with a meta repo
172
- */
173
- private async initStorage(session: GitlabSession): Promise<void> {
174
- // Create the meta repo
175
- try {
176
- const project = await this.callApi(session, 'api/v4/projects/', 'POST', {
177
- name: this.options.metaRepo,
178
- }) as any
179
- return this.createFile(session, this.getMetaRepoPath(session), this.options.metaRepoFile, JSON.stringify({
180
- websites: {}
181
- } as MetaRepoFileContent))
182
- } catch (e) {
183
- console.error('Could not init storage', e.statusCode, e.httpStatusCode, e)
184
- throw e
185
- }
186
- }
167
+ //private getMetaRepoPath(session: GitlabSession): string {
168
+ // if(!session.gitlab?.username) throw new ApiError('Missing Gitlab user ID. User not logged in?', 401)
169
+ // return encodeURIComponent(`${session.gitlab.username}/${this.options.metaRepo}`)
170
+ //}
171
+
172
+ ///**
173
+ // * Initialize the storage with a meta repo
174
+ // */
175
+ //private async initStorage(session: GitlabSession): Promise<void> {
176
+ // // Create the meta repo
177
+ // try {
178
+ // const project = await this.callApi(session, 'api/v4/projects/', 'POST', {
179
+ // name: this.options.metaRepo,
180
+ // }) as any
181
+ // return this.createFile(session, this.getMetaRepoPath(session), this.options.metaRepoFile, JSON.stringify({
182
+ // websites: {}
183
+ // } as MetaRepoFileContent))
184
+ // } catch (e) {
185
+ // console.error('Could not init storage', e.statusCode, e.httpStatusCode, e)
186
+ // throw e
187
+ // }
188
+ //}
187
189
 
188
190
  /**
189
191
  * Call the Gitlab API with the user's token and handle errors
@@ -368,36 +370,38 @@ export default class GitlabConnector implements StorageConnector {
368
370
  }
369
371
 
370
372
  async listWebsites(session: GitlabSession): Promise<WebsiteMeta[]> {
371
- try {
372
- const result = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
373
- ref: this.options.branch,
374
- })
375
- const { content } = result
376
- const contentDecoded = Buffer.from(content, 'base64').toString('utf8')
377
- const websites = (JSON.parse(contentDecoded) as MetaRepoFileContent).websites
378
- return Object.entries(websites).map(([websiteId, {meta, createdAt, updatedAt}]) => ({
379
- websiteId,
380
- createdAt: new Date(createdAt),
381
- updatedAt: new Date(updatedAt),
382
- ...meta,
373
+ //try {
374
+ // const result = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
375
+ // ref: this.options.branch,
376
+ // })
377
+ // const { content } = result
378
+ // const contentDecoded = Buffer.from(content, 'base64').toString('utf8')
379
+ // const websites = (JSON.parse(contentDecoded) as MetaRepoFileContent).websites
380
+ // return Object.entries(websites).map(([websiteId, {meta, createdAt, updatedAt}]) => ({
381
+ // websiteId,
382
+ // createdAt: new Date(createdAt),
383
+ // updatedAt: new Date(updatedAt),
384
+ // ...meta,
385
+ // }))
386
+ //} catch (e) {
387
+ // console.error('Could not list websites', e.statusCode, e.httpStatusCode, e.code)
388
+ // if (e.statusCode === 404 || e.httpStatusCode === 404) {
389
+ // await this.initStorage(session)
390
+ // return []
391
+ // } else {
392
+ // throw e
393
+ // }
394
+ //}
395
+ const projects = await this.callApi(session, `api/v4/users/${session.gitlab?.userId}/projects`) as any[]
396
+ return projects
397
+ .filter(p => p.name.startsWith(this.options.repoPrefix))
398
+ .map(p => ({
399
+ websiteId: p.id,
400
+ name: p.name.replace(this.options.repoPrefix, ''),
401
+ createdAt: p.created_at,
402
+ updatedAt: p.last_activity_at,
403
+ connectorUserSettings: {},
383
404
  }))
384
- } catch (e) {
385
- console.error('Could not list websites', e.statusCode, e.httpStatusCode, e.code)
386
- if (e.statusCode === 404 || e.httpStatusCode === 404) {
387
- await this.initStorage(session)
388
- return []
389
- } else {
390
- throw e
391
- }
392
- }
393
- //const projects = await this.callApi(session, `api/v4/users/${session.gitlab?.user?.id}/projects`) as any[]
394
- //return projects.map(p => ({
395
- // websiteId: p.id,
396
- // name: p.name,
397
- // createdAt: p.created_at,
398
- // updatedAt: p.last_activity_at,
399
- // connectorUserSettings: {},
400
- //}))
401
405
  }
402
406
 
403
407
  async readWebsite(session: GitlabSession, websiteId: string): Promise<WebsiteData> {
@@ -412,12 +416,12 @@ export default class GitlabConnector implements StorageConnector {
412
416
 
413
417
  async createWebsite(session: GitlabSession, websiteMeta: WebsiteMetaFileContent): Promise<WebsiteId> {
414
418
  const project = await this.callApi(session, 'api/v4/projects/', 'POST', {
415
- name: websiteMeta.name,
419
+ name: this.options.repoPrefix + websiteMeta.name,
416
420
  }) as any
417
421
  await this.createFile(session, project.id, WEBSITE_DATA_FILE, JSON.stringify({} as WebsiteData))
418
422
  //await this.createFile(session, project.id, WEBSITE_META_DATA_FILE, JSON.stringify(websiteMeta))
419
423
  //await this.updateWebsite(session, project.id, {} as WebsiteData)
420
- await this.setWebsiteMeta(session, project.id, websiteMeta)
424
+ //await this.setWebsiteMeta(session, project.id, websiteMeta)
421
425
  return project.id
422
426
  }
423
427
 
@@ -434,67 +438,82 @@ export default class GitlabConnector implements StorageConnector {
434
438
  async deleteWebsite(session: GitlabSession, websiteId: WebsiteId): Promise<void> {
435
439
  // Delete repo
436
440
  await this.callApi(session, `api/v4/projects/${websiteId}`, 'DELETE')
437
- // Load the meta repo data
438
- const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
439
- ref: this.options.branch,
440
- })
441
- const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
442
- const data = metaRepo.websites[websiteId]
443
- if(!data) throw new ApiError(`Website ${websiteId} not found`, 404)
444
- // Update or create the website meta data
445
- delete metaRepo.websites[websiteId]
446
- // Save the meta repo data
447
- const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
448
- branch: this.options.branch,
449
- commit_message: `Delete meta data of ${data.meta.name} (${websiteId}) from Silex`,
450
- content: JSON.stringify(metaRepo),
451
- file_path: this.options.metaRepoFile,
452
- })
441
+ //// Load the meta repo data
442
+ //const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
443
+ // ref: this.options.branch,
444
+ //})
445
+ //const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
446
+ //const data = metaRepo.websites[websiteId]
447
+ //if(!data) throw new ApiError(`Website ${websiteId} not found`, 404)
448
+ //// Update or create the website meta data
449
+ //delete metaRepo.websites[websiteId]
450
+ //// Save the meta repo data
451
+ //const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
452
+ // branch: this.options.branch,
453
+ // commit_message: `Delete meta data of ${data.meta.name} (${websiteId}) from Silex`,
454
+ // content: JSON.stringify(metaRepo),
455
+ // file_path: this.options.metaRepoFile,
456
+ //})
453
457
  }
454
458
 
455
459
  async getWebsiteMeta(session: GitlabSession, websiteId: WebsiteId): Promise<WebsiteMeta> {
456
- const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
457
- ref: this.options.branch,
458
- })
459
- const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
460
- if(!metaRepo.websites[websiteId]) throw new ApiError(`Website ${websiteId} not found`, 404)
460
+ //const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
461
+ // ref: this.options.branch,
462
+ //})
463
+ //const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
464
+ //if(!metaRepo.websites[websiteId]) throw new ApiError(`Website ${websiteId} not found`, 404)
465
+ //return {
466
+ // websiteId,
467
+ // createdAt: new Date(metaRepo.websites[websiteId].createdAt),
468
+ // updatedAt: new Date(metaRepo.websites[websiteId].updatedAt),
469
+ // ...metaRepo.websites[websiteId].meta,
470
+ //}
471
+ // const response = await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${WEBSITE_META_DATA_FILE}`, 'GET', null, {
472
+ // ref: this.options.branch,
473
+ // }) as any
474
+ // Base64 to string to JSON
475
+ // const contentDecoded = Buffer.from(response.content, 'base64').toString('utf8')
476
+ // const websiteMeta = JSON.parse(contentDecoded) as WebsiteMetaFileContent
477
+ const project = await this.callApi(session, `api/v4/projects/${websiteId}`)
461
478
  return {
462
479
  websiteId,
463
- createdAt: new Date(metaRepo.websites[websiteId].createdAt),
464
- updatedAt: new Date(metaRepo.websites[websiteId].updatedAt),
465
- ...metaRepo.websites[websiteId].meta,
480
+ name: project.name.replace(this.options.repoPrefix, ''),
481
+ imageUrl: project.avatar_url,
482
+ createdAt: project.created_at,
483
+ updatedAt: project.last_activity_at,
484
+ connectorUserSettings: {},
466
485
  }
467
- //const project = await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${WEBSITE_META_DATA_FILE}`) as any
468
- //return {
469
- // websiteId: project.id,
470
- // name: project.name,
471
- // createdAt: project.created_at,
472
- // updatedAt: project.last_activity_at,
473
- // connectorUserSettings: {},
474
- //}
475
486
  }
476
487
 
477
488
  async setWebsiteMeta(session: GitlabSession, websiteId: WebsiteId, websiteMeta: WebsiteMetaFileContent): Promise<void> {
478
- // Load the meta repo data
479
- const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
480
- ref: this.options.branch,
481
- })
482
- const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
483
- // Update or create the website meta data
484
- metaRepo.websites[websiteId] = {
485
- updatedAt: new Date().toISOString(),
486
- createdAt: metaRepo.websites[websiteId]?.createdAt ?? new Date().toISOString(),
487
- meta: websiteMeta,
488
- }
489
- // Save the meta repo data
490
- const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
491
- branch: this.options.branch,
492
- commit_message: `Update website meta data of ${websiteMeta.name} (${websiteId}) from Silex`,
493
- content: JSON.stringify(metaRepo),
494
- file_path: this.options.metaRepoFile,
495
- })
489
+ //// Load the meta repo data
490
+ //const file = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'GET', null, {
491
+ // ref: this.options.branch,
492
+ //})
493
+ //const metaRepo = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8')) as MetaRepoFileContent
494
+ //// Update or create the website meta data
495
+ //metaRepo.websites[websiteId] = {
496
+ // updatedAt: new Date().toISOString(),
497
+ // createdAt: metaRepo.websites[websiteId]?.createdAt ?? new Date().toISOString(),
498
+ // meta: websiteMeta,
499
+ //}
500
+ //// Save the meta repo data
501
+ //const project = await this.callApi(session, `api/v4/projects/${this.getMetaRepoPath(session)}/repository/files/${this.options.metaRepoFile}`, 'PUT', {
502
+ // branch: this.options.branch,
503
+ // commit_message: `Update website meta data of ${websiteMeta.name} (${websiteId}) from Silex`,
504
+ // content: JSON.stringify(metaRepo),
505
+ // file_path: this.options.metaRepoFile,
506
+ //})
496
507
 
497
- //const project = await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${WEBSITE_META_DATA_FILE}`, 'PUT', {
508
+ // Rename the repo if needed
509
+ const oldMeta = await this.getWebsiteMeta(session, websiteId)
510
+ if(websiteMeta.name !== oldMeta.name) {
511
+ await this.callApi(session, `api/v4/projects/${websiteId}`, 'PUT', {
512
+ name: this.options.repoPrefix + websiteMeta.name,
513
+ })
514
+ }
515
+ //// Update the metadata file
516
+ //await this.callApi(session, `api/v4/projects/${websiteId}/repository/files/${WEBSITE_META_DATA_FILE}`, 'PUT', {
498
517
  // branch: this.options.branch,
499
518
  // commit_message: 'Update website meta data from Silex',
500
519
  // content: JSON.stringify(websiteMeta),
@@ -17,13 +17,12 @@
17
17
 
18
18
  import { Router } from 'express'
19
19
  import { API_PUBLICATION_PUBLISH, API_PUBLICATION_STATUS, API_WEBSITE_ASSET_READ } from '../../constants'
20
- import { getJob } from '../jobs'
21
- import { ApiPublicationPublishBody, ApiPublicationPublishQuery, ApiPublicationPublishResponse, ApiPublicationStatusQuery, ApiPublicationStatusResponse, JobId, PublicationSettings, PublicationData as PublicationData, ConnectorType, ConnectorId, WebsiteId} from '../../types'
20
+ import { ApiPublicationPublishBody, ApiPublicationPublishQuery, ApiPublicationPublishResponse, ApiPublicationStatusQuery, ApiPublicationStatusResponse, JobId, PublicationData, ConnectorType, ConnectorId, WebsiteId, ClientSideFile, ClientSideFileWithContent, ClientSideFileWithSrc} from '../../types'
22
21
  import { ConnectorFile, HostingConnector, StorageConnector, getConnector } from '../connectors/connectors'
23
22
  import { ServerConfig } from '../config'
24
23
  import { requiredParam } from '../utils/validation'
25
- import { join } from 'path'
26
24
  import { PublishEndEventType, PublishStartEventType, ServerEvent } from '../events'
25
+ import { getJob, jobManager } from '../jobs'
27
26
 
28
27
  /**
29
28
  * @fileoverview Publication plugin for Silex
@@ -109,9 +108,9 @@ export default function (config: ServerConfig): Router {
109
108
 
110
109
  // Check params
111
110
  const data = body as PublicationData
112
- const { files, publication, assets } = data
113
- if(!files || !publication || !assets) {
114
- throw new PublicationError('Missing data from request: files, publication or assets', 400)
111
+ const { files } = data
112
+ if(!files) {
113
+ throw new PublicationError('Missing files in body', 400)
115
114
  }
116
115
 
117
116
  // Hook for plugins
@@ -123,29 +122,23 @@ export default function (config: ServerConfig): Router {
123
122
  // Get storage connector which holds the assets
124
123
  const storage = await getStorageConnector(session, config, storageId)
125
124
 
126
- // Publication
127
- const assetsFiles: ConnectorFile[] = await Promise.all(assets.map(async asset => {
128
- if(!asset.path) throw new PublicationError('Missing path in asset', 400)
129
- if(!asset.src) throw new PublicationError('Missing src in asset', 400)
130
- // Remove the / from the asset root if it starts with one
125
+ // Load the content if necessary
126
+ const filesList: ConnectorFile[] = await Promise.all(files.map(async (file: ClientSideFile) => {
131
127
  const prefix = API_WEBSITE_ASSET_READ.replace(/^\//, '')
132
- // Get the asset url relative to the asset root
133
- const src = asset.src.startsWith(prefix) ? asset.src.substring(prefix.length) : asset.src
128
+ const fileWithContent = file as ClientSideFileWithContent
129
+ const fileWithSrc = file as ClientSideFileWithSrc
130
+ if(!fileWithContent.content && !fileWithSrc.src) throw new PublicationError('Missing content or src in file', 400)
131
+ const src = fileWithSrc.src?.startsWith(prefix) ? fileWithSrc.src.substring(prefix.length) : fileWithSrc.src
134
132
  return {
135
- path: asset.path,
136
- content: await storage.readAsset(session, websiteId, src),
133
+ path: file.path,
134
+ content: fileWithContent.content ??
135
+ await storage.readAsset(session, websiteId, src),
137
136
  }
138
137
  }))
139
- const filesList: ConnectorFile[] = files.flatMap<ConnectorFile>(file => ([{
140
- path: file.htmlPath,
141
- content: file.html,
142
- }, {
143
- path: file.cssPath,
144
- content: file.css,
145
- }])).concat(assetsFiles)
138
+
146
139
  res.json({
147
140
  url: await hostingConnector.getUrl(session, websiteId),
148
- job: await hostingConnector.publish(session, websiteId, filesList),
141
+ job: await hostingConnector.publish(session, websiteId, filesList, jobManager),
149
142
  } as ApiPublicationPublishResponse)
150
143
  } catch (err) {
151
144
  console.error('Error publishing the website', err)
@@ -17,9 +17,9 @@
17
17
 
18
18
  import { ConnectorFile, StorageConnector, HostingConnector, StatusCallback, ConnectorSession, contentToString, toConnectorData, ConnectorFileContent} from './connectors'
19
19
  import { join } from 'path'
20
- import { jobError, jobSuccess, startJob } from '../jobs'
21
20
  import { FsStorage } from './FsStorage'
22
21
  import { ConnectorType, JobData, JobStatus, PublicationJobData, WebsiteId } from '../../types'
22
+ import { JobManager } from '../jobs'
23
23
 
24
24
  type FsSession = ConnectorSession
25
25
 
@@ -33,7 +33,7 @@ export class FsHosting extends FsStorage implements HostingConnector<FsSession>
33
33
  icon = 'data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22currentColor%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M6%202L6%2022%2018%2022%2018%207%2012%202%206%202Z%22%3E%3C%2Fpath%3E%3Cpath%20d%3D%22M18%202L12%202%2012%208%2018%208%2018%202Z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E'
34
34
  connectorType = ConnectorType.HOSTING
35
35
 
36
- async publish(session: FsSession, id: WebsiteId, files: ConnectorFile[]): Promise<JobData> {
36
+ async publish(session: FsSession, id: WebsiteId, files: ConnectorFile[], {startJob, jobSuccess, jobError}: JobManager): Promise<JobData> {
37
37
  const job = startJob(`Publishing to ${this.displayName}`) as PublicationJobData
38
38
  job.logs = [[`Publishing to ${this.displayName}`]]
39
39
  job.errors = [[]]
@@ -201,6 +201,7 @@ export class FsStorage implements StorageConnector<FsSession> {
201
201
  let error: Error | null = null
202
202
  for (const fileStatus of filesStatuses) {
203
203
  const {file} = fileStatus
204
+ console.log('writeAssets', file, this.options.path, id, this.options.assetsFolder, file.path)
204
205
  const path = join(this.options.path, id, this.options.assetsFolder, file.path)
205
206
  if (typeof file.content === 'string' || Buffer.isBuffer(file.content)) {
206
207
  fileStatus.message = 'Writing'
@@ -18,6 +18,7 @@
18
18
  import { Readable } from 'stream'
19
19
  import { ServerConfig } from '../config'
20
20
  import { JobStatus, JobData, ConnectorData, ConnectorId, WebsiteId, ConnectorType, ConnectorUser, WebsiteMeta, WebsiteMetaFileContent, WebsiteData, ConnectorOptions } from '../../types'
21
+ import { JobManager } from '../jobs'
21
22
 
22
23
  /**
23
24
  * @fileoverview define types for Silex connectors
@@ -99,8 +100,9 @@ export interface StorageConnector<Session extends ConnectorSession = ConnectorSe
99
100
  * Hosting connectors are used to publish the website
100
101
  */
101
102
  export interface HostingConnector<Session extends ConnectorSession = ConnectorSession> extends Connector<Session> {
102
- publish(session: Session, websiteId: WebsiteId, files: ConnectorFile[]): Promise<JobData>
103
+ publish(session: Session, websiteId: WebsiteId, files: ConnectorFile[], jobManager: JobManager): Promise<JobData> // Pass the jobManager as plugins do not neccessarily share the same module instance
103
104
  getUrl(session: Session, websiteId: WebsiteId): Promise<string>
105
+
104
106
  }
105
107
 
106
108
  export function toConnectorEnum(type: string | ConnectorType): ConnectorType {
@@ -75,3 +75,13 @@ function end(id: JobId, status: JobStatus, message = ''): boolean {
75
75
  }
76
76
  return false
77
77
  }
78
+
79
+ // Type definition of the job manager
80
+ export interface JobManager {
81
+ startJob: typeof startJob
82
+ jobSuccess: typeof jobSuccess
83
+ jobError: typeof jobError
84
+ }
85
+
86
+ // Export the job manager
87
+ export const jobManager: JobManager = { startJob, jobSuccess, jobError }