@silexlabs/silex 3.0.0-alpha.100
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/.env.default +19 -0
- package/.silex.js +37 -0
- package/LICENSE +661 -0
- package/README.md +96 -0
- package/dist/client/client/api.d.ts +85 -0
- package/dist/client/client/assetUrl.d.ts +51 -0
- package/dist/client/client/config.d.ts +58 -0
- package/dist/client/client/events.d.ts +14 -0
- package/dist/client/client/expose.d.ts +8 -0
- package/dist/client/client/grapesjs/LoginDialog.d.ts +15 -0
- package/dist/client/client/grapesjs/PublicationManager.d.ts +72 -0
- package/dist/client/client/grapesjs/PublicationUi.d.ts +62 -0
- package/dist/client/client/grapesjs/blocks.d.ts +1 -0
- package/dist/client/client/grapesjs/breadcrumbs.d.ts +1 -0
- package/dist/client/client/grapesjs/footer.d.ts +2 -0
- package/dist/client/client/grapesjs/index.d.ts +5 -0
- package/dist/client/client/grapesjs/internal-links.d.ts +1 -0
- package/dist/client/client/grapesjs/new-page-dialog.d.ts +2 -0
- package/dist/client/client/grapesjs/openImport.d.ts +9 -0
- package/dist/client/client/grapesjs/page-panel.d.ts +3 -0
- package/dist/client/client/grapesjs/project-bar.d.ts +1 -0
- package/dist/client/client/grapesjs/rich-text.d.ts +1 -0
- package/dist/client/client/grapesjs/semantic.d.ts +1 -0
- package/dist/client/client/grapesjs/settings.d.ts +2 -0
- package/dist/client/client/grapesjs/storage.d.ts +1 -0
- package/dist/client/client/grapesjs/symbolDialogs.d.ts +3 -0
- package/dist/client/client/index.d.ts +5 -0
- package/dist/client/client/publication-transformers.d.ts +41 -0
- package/dist/client/client/utils.d.ts +2 -0
- package/dist/client/constants.d.ts +29 -0
- package/dist/client/css/admin.css +4491 -0
- package/dist/client/index.html +9 -0
- package/dist/client/js/main.js +321 -0
- package/dist/client/js/main.js.LICENSE.txt +24 -0
- package/dist/client/page.d.ts +2 -0
- package/dist/client/types.d.ts +334 -0
- package/dist/plugins/client/client/api.d.ts +85 -0
- package/dist/plugins/client/client/api.js +114 -0
- package/dist/plugins/client/client/api.js.map +1 -0
- package/dist/plugins/client/client/assetUrl.d.ts +51 -0
- package/dist/plugins/client/client/assetUrl.js +224 -0
- package/dist/plugins/client/client/assetUrl.js.map +1 -0
- package/dist/plugins/client/client/config.d.ts +58 -0
- package/dist/plugins/client/client/config.js +90 -0
- package/dist/plugins/client/client/config.js.map +1 -0
- package/dist/plugins/client/client/events.d.ts +14 -0
- package/dist/plugins/client/client/events.js +34 -0
- package/dist/plugins/client/client/events.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/LoginDialog.d.ts +15 -0
- package/dist/plugins/client/client/grapesjs/LoginDialog.js +195 -0
- package/dist/plugins/client/client/grapesjs/LoginDialog.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/PublicationManager.d.ts +72 -0
- package/dist/plugins/client/client/grapesjs/PublicationManager.js +356 -0
- package/dist/plugins/client/client/grapesjs/PublicationManager.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/PublicationUi.d.ts +62 -0
- package/dist/plugins/client/client/grapesjs/PublicationUi.js +336 -0
- package/dist/plugins/client/client/grapesjs/PublicationUi.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/blocks.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/blocks.js +37 -0
- package/dist/plugins/client/client/grapesjs/blocks.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/breadcrumbs.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/breadcrumbs.js +75 -0
- package/dist/plugins/client/client/grapesjs/breadcrumbs.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/footer.d.ts +2 -0
- package/dist/plugins/client/client/grapesjs/footer.js +28 -0
- package/dist/plugins/client/client/grapesjs/footer.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/index.d.ts +5 -0
- package/dist/plugins/client/client/grapesjs/index.js +313 -0
- package/dist/plugins/client/client/grapesjs/index.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/internal-links.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/internal-links.js +219 -0
- package/dist/plugins/client/client/grapesjs/internal-links.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/new-page-dialog.d.ts +2 -0
- package/dist/plugins/client/client/grapesjs/new-page-dialog.js +83 -0
- package/dist/plugins/client/client/grapesjs/new-page-dialog.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/openImport.d.ts +9 -0
- package/dist/plugins/client/client/grapesjs/openImport.js +74 -0
- package/dist/plugins/client/client/grapesjs/openImport.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/page-panel.d.ts +3 -0
- package/dist/plugins/client/client/grapesjs/page-panel.js +113 -0
- package/dist/plugins/client/client/grapesjs/page-panel.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/project-bar.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/project-bar.js +104 -0
- package/dist/plugins/client/client/grapesjs/project-bar.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/rich-text.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/rich-text.js +31 -0
- package/dist/plugins/client/client/grapesjs/rich-text.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/semantic.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/semantic.js +110 -0
- package/dist/plugins/client/client/grapesjs/semantic.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/settings.d.ts +2 -0
- package/dist/plugins/client/client/grapesjs/settings.js +198 -0
- package/dist/plugins/client/client/grapesjs/settings.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/storage.d.ts +1 -0
- package/dist/plugins/client/client/grapesjs/storage.js +126 -0
- package/dist/plugins/client/client/grapesjs/storage.js.map +1 -0
- package/dist/plugins/client/client/grapesjs/symbolDialogs.d.ts +3 -0
- package/dist/plugins/client/client/grapesjs/symbolDialogs.js +36 -0
- package/dist/plugins/client/client/grapesjs/symbolDialogs.js.map +1 -0
- package/dist/plugins/client/client/publication-transformers.d.ts +41 -0
- package/dist/plugins/client/client/publication-transformers.js +238 -0
- package/dist/plugins/client/client/publication-transformers.js.map +1 -0
- package/dist/plugins/client/client/utils.d.ts +2 -0
- package/dist/plugins/client/client/utils.js +25 -0
- package/dist/plugins/client/client/utils.js.map +1 -0
- package/dist/plugins/client/constants.d.ts +29 -0
- package/dist/plugins/client/constants.js +46 -0
- package/dist/plugins/client/constants.js.map +1 -0
- package/dist/plugins/client/page.d.ts +2 -0
- package/dist/plugins/client/page.js +31 -0
- package/dist/plugins/client/page.js.map +1 -0
- package/dist/plugins/client/plugins/client/11ty.d.ts +17 -0
- package/dist/plugins/client/plugins/client/11ty.js +86 -0
- package/dist/plugins/client/plugins/client/11ty.js.map +1 -0
- package/dist/plugins/client/plugins/client/publicationRenderer.d.ts +2 -0
- package/dist/plugins/client/plugins/client/publicationRenderer.js +170 -0
- package/dist/plugins/client/plugins/client/publicationRenderer.js.map +1 -0
- package/dist/plugins/client/plugins/client/template.d.ts +2 -0
- package/dist/plugins/client/plugins/client/template.js +183 -0
- package/dist/plugins/client/plugins/client/template.js.map +1 -0
- package/dist/plugins/client/plugins/client/website-info.d.ts +1 -0
- package/dist/plugins/client/plugins/client/website-info.js +72 -0
- package/dist/plugins/client/plugins/client/website-info.js.map +1 -0
- package/dist/plugins/client/types.d.ts +334 -0
- package/dist/plugins/client/types.js +74 -0
- package/dist/plugins/client/types.js.map +1 -0
- package/dist/plugins/server/constants.d.ts +29 -0
- package/dist/plugins/server/constants.js +49 -0
- package/dist/plugins/server/constants.js.map +1 -0
- package/dist/plugins/server/plugins/server/AuthPlugin.d.ts +1 -0
- package/dist/plugins/server/plugins/server/AuthPlugin.js +40 -0
- package/dist/plugins/server/plugins/server/AuthPlugin.js.map +1 -0
- package/dist/plugins/server/plugins/server/Cache.d.ts +2 -0
- package/dist/plugins/server/plugins/server/Cache.js +32 -0
- package/dist/plugins/server/plugins/server/Cache.js.map +1 -0
- package/dist/plugins/server/plugins/server/DownloadConnector.d.ts +29 -0
- package/dist/plugins/server/plugins/server/DownloadConnector.js +129 -0
- package/dist/plugins/server/plugins/server/DownloadConnector.js.map +1 -0
- package/dist/plugins/server/plugins/server/FtpConnector.d.ts +86 -0
- package/dist/plugins/server/plugins/server/FtpConnector.js +526 -0
- package/dist/plugins/server/plugins/server/FtpConnector.js.map +1 -0
- package/dist/plugins/server/plugins/server/GitlabConnector.d.ts +87 -0
- package/dist/plugins/server/plugins/server/GitlabConnector.js +564 -0
- package/dist/plugins/server/plugins/server/GitlabConnector.js.map +1 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.d.ts +0 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.js +14 -0
- package/dist/plugins/server/plugins/server/PublicationOptimizer.js.map +1 -0
- package/dist/plugins/server/plugins/server/SslPlugin.d.ts +1 -0
- package/dist/plugins/server/plugins/server/SslPlugin.js +86 -0
- package/dist/plugins/server/plugins/server/SslPlugin.js.map +1 -0
- package/dist/plugins/server/plugins/server/StaticPlugin.d.ts +1 -0
- package/dist/plugins/server/plugins/server/StaticPlugin.js +78 -0
- package/dist/plugins/server/plugins/server/StaticPlugin.js.map +1 -0
- package/dist/plugins/server/server/config.d.ts +59 -0
- package/dist/plugins/server/server/config.js +181 -0
- package/dist/plugins/server/server/config.js.map +1 -0
- package/dist/plugins/server/server/connectors/FsHosting.d.ts +13 -0
- package/dist/plugins/server/server/connectors/FsHosting.js +54 -0
- package/dist/plugins/server/server/connectors/FsHosting.js.map +1 -0
- package/dist/plugins/server/server/connectors/FsStorage.d.ts +43 -0
- package/dist/plugins/server/server/connectors/FsStorage.js +257 -0
- package/dist/plugins/server/server/connectors/FsStorage.js.map +1 -0
- package/dist/plugins/server/server/connectors/connectors.d.ts +87 -0
- package/dist/plugins/server/server/connectors/connectors.js +127 -0
- package/dist/plugins/server/server/connectors/connectors.js.map +1 -0
- package/dist/plugins/server/server/events.d.ts +26 -0
- package/dist/plugins/server/server/events.js +31 -0
- package/dist/plugins/server/server/events.js.map +1 -0
- package/dist/plugins/server/server/jobs.d.ts +12 -0
- package/dist/plugins/server/server/jobs.js +77 -0
- package/dist/plugins/server/server/jobs.js.map +1 -0
- package/dist/plugins/server/server/utils/validation.d.ts +7 -0
- package/dist/plugins/server/server/utils/validation.js +38 -0
- package/dist/plugins/server/server/utils/validation.js.map +1 -0
- package/dist/plugins/server/types.d.ts +334 -0
- package/dist/plugins/server/types.js +78 -0
- package/dist/plugins/server/types.js.map +1 -0
- package/dist/server/constants.js +29 -0
- package/dist/server/plugins/server/Cache.js +15 -0
- package/dist/server/server/api/api.js +20 -0
- package/dist/server/server/api/connectorApi.js +216 -0
- package/dist/server/server/api/publicationApi.js +108 -0
- package/dist/server/server/api/websiteApi.js +296 -0
- package/dist/server/server/cli.js +68 -0
- package/dist/server/server/config.js +120 -0
- package/dist/server/server/connectors/FsHosting.js +35 -0
- package/dist/server/server/connectors/FsStorage.js +225 -0
- package/dist/server/server/connectors/connectors.js +89 -0
- package/dist/server/server/events.js +14 -0
- package/dist/server/server/expose.js +27 -0
- package/dist/server/server/express.js +47 -0
- package/dist/server/server/index.js +90 -0
- package/dist/server/server/jobs.js +48 -0
- package/dist/server/server/utils/validation.js +15 -0
- package/dist/server/types.js +34 -0
- package/package.json +209 -0
- package/public/assets/container.png +0 -0
- package/public/assets/favicon.png +0 -0
- package/public/assets/logo-silex-small.png +0 -0
- package/public/robots.txt +2 -0
- package/public/silex.js +24 -0
- package/src/css/_mixins.scss +8 -0
- package/src/css/_variables.scss +33 -0
- package/src/css/dialog.scss +41 -0
- package/src/css/footer.scss +12 -0
- package/src/css/grapesjs-light.scss +180 -0
- package/src/css/grapesjs.scss +152 -0
- package/src/css/index.scss +32 -0
- package/src/css/light.scss +7 -0
- package/src/css/loader.scss +12 -0
- package/src/css/page-panel.scss +65 -0
- package/src/css/project-bar.scss +102 -0
- package/src/css/silex.scss +189 -0
- package/src/css/website-info.scss +14 -0
- package/src/html/debug.pug +8 -0
- package/src/html/index.pug +39 -0
- package/src/html/templates/includes.pug +1 -0
- package/src/html/templates/workspace.pug +2 -0
- package/src/ts/client/api.ts +144 -0
- package/src/ts/client/assetUrl.test.ts +125 -0
- package/src/ts/client/assetUrl.ts +235 -0
- package/src/ts/client/config.ts +105 -0
- package/src/ts/client/events.ts +34 -0
- package/src/ts/client/expose.ts +30 -0
- package/src/ts/client/grapesjs/LoginDialog.ts +204 -0
- package/src/ts/client/grapesjs/PublicationManager.ts +370 -0
- package/src/ts/client/grapesjs/PublicationUi.ts +342 -0
- package/src/ts/client/grapesjs/blocks.ts +37 -0
- package/src/ts/client/grapesjs/breadcrumbs.ts +79 -0
- package/src/ts/client/grapesjs/eleventy.ts +47 -0
- package/src/ts/client/grapesjs/footer.ts +27 -0
- package/src/ts/client/grapesjs/index.ts +335 -0
- package/src/ts/client/grapesjs/internal-links.test.ts +105 -0
- package/src/ts/client/grapesjs/internal-links.ts +225 -0
- package/src/ts/client/grapesjs/new-page-dialog.ts +90 -0
- package/src/ts/client/grapesjs/openImport.ts +81 -0
- package/src/ts/client/grapesjs/page-panel.ts +118 -0
- package/src/ts/client/grapesjs/project-bar.ts +107 -0
- package/src/ts/client/grapesjs/rich-text.ts +33 -0
- package/src/ts/client/grapesjs/semantic.ts +114 -0
- package/src/ts/client/grapesjs/settings.ts +208 -0
- package/src/ts/client/grapesjs/storage.ts +121 -0
- package/src/ts/client/grapesjs/symbolDialogs.ts +38 -0
- package/src/ts/client/index.ts +98 -0
- package/src/ts/client/publication-transformers.test.ts +199 -0
- package/src/ts/client/publication-transformers.ts +263 -0
- package/src/ts/client/utils.ts +28 -0
- package/src/ts/constants.ts +52 -0
- package/src/ts/externs.ts +18 -0
- package/src/ts/page.ts +31 -0
- package/src/ts/plugins/client/11ty.ts +104 -0
- package/src/ts/plugins/client/publicationRenderer.ts +174 -0
- package/src/ts/plugins/client/template.ts +192 -0
- package/src/ts/plugins/client/website-info.ts +84 -0
- package/src/ts/plugins/server/AuthPlugin.ts +38 -0
- package/src/ts/plugins/server/Cache.ts +28 -0
- package/src/ts/plugins/server/DownloadConnector.ts +148 -0
- package/src/ts/plugins/server/FtpConnector.test.ts +82 -0
- package/src/ts/plugins/server/FtpConnector.ts +609 -0
- package/src/ts/plugins/server/GitlabConnector.ts +644 -0
- package/src/ts/plugins/server/PublicationOptimizer.ts +14 -0
- package/src/ts/plugins/server/SslPlugin.ts +84 -0
- package/src/ts/plugins/server/StaticPlugin.ts +79 -0
- package/src/ts/server/api/api.ts +19 -0
- package/src/ts/server/api/connectorApi.ts +345 -0
- package/src/ts/server/api/publicationApi.ts +159 -0
- package/src/ts/server/api/websiteApi.ts +432 -0
- package/src/ts/server/cli.ts +65 -0
- package/src/ts/server/config.ts +189 -0
- package/src/ts/server/connectors/FsHosting.ts +60 -0
- package/src/ts/server/connectors/FsStorage.test.ts +51 -0
- package/src/ts/server/connectors/FsStorage.ts +261 -0
- package/src/ts/server/connectors/connectors.ts +203 -0
- package/src/ts/server/events.ts +37 -0
- package/src/ts/server/expose.ts +19 -0
- package/src/ts/server/express.ts +70 -0
- package/src/ts/server/index.ts +100 -0
- package/src/ts/server/jobs.test.ts +75 -0
- package/src/ts/server/jobs.ts +87 -0
- package/src/ts/server/utils/BackwardCompat.ts +552 -0
- package/src/ts/server/utils/validation.ts +34 -0
- package/src/ts/types.ts +339 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import express, { Application } from 'express'
|
|
19
|
+
import bodyParser from 'body-parser'
|
|
20
|
+
import compression from 'compression'
|
|
21
|
+
import cookieParser from 'cookie-parser'
|
|
22
|
+
import session from 'cookie-session'
|
|
23
|
+
import cors from 'cors'
|
|
24
|
+
|
|
25
|
+
import { ServerConfig } from './config'
|
|
26
|
+
import { ServerEvent } from './events'
|
|
27
|
+
|
|
28
|
+
export function create(config: ServerConfig): Application {
|
|
29
|
+
// Express app
|
|
30
|
+
const app = express()
|
|
31
|
+
app.set('config', config)
|
|
32
|
+
|
|
33
|
+
// CORS
|
|
34
|
+
const options = config.expressOptions
|
|
35
|
+
if (options.cors) {
|
|
36
|
+
console.info('> CORS are ENABLED:', options.cors)
|
|
37
|
+
app.use(cors({
|
|
38
|
+
origin: options.cors,
|
|
39
|
+
}))
|
|
40
|
+
}
|
|
41
|
+
// compress gzip when possible
|
|
42
|
+
app.use(compression() as any)
|
|
43
|
+
|
|
44
|
+
// cookie & session
|
|
45
|
+
app.use(bodyParser.json({ limit: options.jsonLimit }))
|
|
46
|
+
app.use(bodyParser.text({ limit: options.textLimit }))
|
|
47
|
+
app.use(bodyParser.urlencoded({ limit: options.urlencodedLimit }))
|
|
48
|
+
console.info('> Session name:', options.sessionName)
|
|
49
|
+
app.use(cookieParser() as any)
|
|
50
|
+
app.use(session({
|
|
51
|
+
name: options.sessionName,
|
|
52
|
+
secret: options.sessionSecret,
|
|
53
|
+
}) as any)
|
|
54
|
+
return app
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function start(app: Application): Promise<Application> {
|
|
58
|
+
const config = app.get('config') as ServerConfig
|
|
59
|
+
|
|
60
|
+
// Plugins hook to create API routes
|
|
61
|
+
config.emit(ServerEvent.STARTUP_START, { app })
|
|
62
|
+
|
|
63
|
+
// Start server
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
app.listen(config.port, () => {
|
|
66
|
+
config.emit(ServerEvent.STARTUP_END, { app })
|
|
67
|
+
resolve(app)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import * as silexApp from './express'
|
|
19
|
+
import api from './api/api'
|
|
20
|
+
import { ServerConfig } from './config'
|
|
21
|
+
import dotenv from 'dotenv'
|
|
22
|
+
import { join } from 'path'
|
|
23
|
+
|
|
24
|
+
// Expose API to calling app as function silex()
|
|
25
|
+
export * from './expose'
|
|
26
|
+
|
|
27
|
+
// Main app
|
|
28
|
+
export default async function silex() {
|
|
29
|
+
// Load env vars from .env file if any
|
|
30
|
+
const curDirEnv = dotenv.config()
|
|
31
|
+
if (curDirEnv.error) {
|
|
32
|
+
if(curDirEnv.error['code'] === 'ENOENT') {
|
|
33
|
+
console.info('> No .env file found in current directory')
|
|
34
|
+
} else {
|
|
35
|
+
throw curDirEnv.error
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
console.info('> Env vars loaded from .env file')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Load default env vars
|
|
42
|
+
// This will not override existing env vars
|
|
43
|
+
const DEFAULT_ENV_FILE = join(__dirname, '../../../.env.default')
|
|
44
|
+
const rootDirEnv = dotenv.config({ path: DEFAULT_ENV_FILE })
|
|
45
|
+
if (rootDirEnv.error) {
|
|
46
|
+
if(rootDirEnv.error['code'] === 'ENOENT') {
|
|
47
|
+
throw new Error(`\n\nFailed to load default env vars. File not found ${DEFAULT_ENV_FILE}\n\n`)
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error(`\n\nFailed to load default env vars. Error in ${DEFAULT_ENV_FILE}: ${ rootDirEnv.error.message }\n\n`)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
console.info('> Default env vars loaded')
|
|
53
|
+
|
|
54
|
+
// Get the default config object
|
|
55
|
+
const config = new ServerConfig()
|
|
56
|
+
|
|
57
|
+
// start silex
|
|
58
|
+
const app = silexApp.create(config)
|
|
59
|
+
|
|
60
|
+
// Serve the client config file
|
|
61
|
+
await config.addRoutes(app)
|
|
62
|
+
|
|
63
|
+
// Load the config files
|
|
64
|
+
await config.loadConfigFiles()
|
|
65
|
+
|
|
66
|
+
// Init the connectors in case no plugin adds them
|
|
67
|
+
await config.initDefaultConnectors()
|
|
68
|
+
|
|
69
|
+
// APIs
|
|
70
|
+
app.use('/api', api(config))
|
|
71
|
+
|
|
72
|
+
// Start the server
|
|
73
|
+
await silexApp.start(app)
|
|
74
|
+
|
|
75
|
+
// All good, server is ready
|
|
76
|
+
console.info(`
|
|
77
|
+
I'm ready, listening to port ${config.port}
|
|
78
|
+
`)
|
|
79
|
+
if (config.debug) {
|
|
80
|
+
startLiverReload()
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// livereload
|
|
85
|
+
async function startLiverReload() {
|
|
86
|
+
// Load modules only when needed (they may not even be installed)
|
|
87
|
+
const { createServer } = await import('livereload')
|
|
88
|
+
const { resolve } = await import('path')
|
|
89
|
+
const dist = resolve(__dirname, '../../client')
|
|
90
|
+
const server = createServer({
|
|
91
|
+
delay: 0,
|
|
92
|
+
}, () => {
|
|
93
|
+
console.info(`\n> Debug mode\n> Live reload server is running.\n> Watching ${dist}`)
|
|
94
|
+
})
|
|
95
|
+
server.watch(dist)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (require.main === module) {
|
|
99
|
+
silex()
|
|
100
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { JobData, JobStatus } from '../types'
|
|
19
|
+
import { startJob, jobSuccess, jobError, getJob, killJob } from './jobs'
|
|
20
|
+
import { expect, afterEach, it, describe } from '@jest/globals'
|
|
21
|
+
|
|
22
|
+
let job: JobData | undefined
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
// Avoid memory leak
|
|
25
|
+
if(job) killJob(job)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
describe('Job Module', () => {
|
|
29
|
+
it('should start a job', () => {
|
|
30
|
+
const {jobId} = startJob('Test job')
|
|
31
|
+
job = getJob(jobId)
|
|
32
|
+
expect(job).not.toBeNull()
|
|
33
|
+
if (job) {
|
|
34
|
+
expect(job.jobId).toEqual(jobId)
|
|
35
|
+
expect(job.status).toEqual(JobStatus.IN_PROGRESS)
|
|
36
|
+
expect(job.message).toEqual('Test job')
|
|
37
|
+
killJob(job)
|
|
38
|
+
expect(getJob(jobId)).toBeUndefined()
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should end a job with success', () => {
|
|
43
|
+
const {jobId} = startJob('Test job')
|
|
44
|
+
const result = jobSuccess(jobId, 'Job completed successfully')
|
|
45
|
+
expect(result).toBeTruthy()
|
|
46
|
+
job = getJob(jobId)
|
|
47
|
+
expect(job).not.toBeNull()
|
|
48
|
+
if (job) {
|
|
49
|
+
expect(job.status).toEqual(JobStatus.SUCCESS)
|
|
50
|
+
expect(job.message).toEqual('Job completed successfully')
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('should end a job with error', () => {
|
|
55
|
+
const {jobId} = startJob('Test job')
|
|
56
|
+
const result = jobError(jobId, 'Job ended with error')
|
|
57
|
+
expect(result).toBeTruthy()
|
|
58
|
+
job = getJob(jobId)
|
|
59
|
+
expect(job).not.toBeNull()
|
|
60
|
+
if (job) {
|
|
61
|
+
expect(job.status).toEqual(JobStatus.ERROR)
|
|
62
|
+
expect(job.message).toEqual('Job ended with error')
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('should not find a job after ending', done => {
|
|
67
|
+
const {jobId} = startJob('Test job')
|
|
68
|
+
jobSuccess(jobId, 'Job completed successfully')
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
job = getJob(jobId)
|
|
71
|
+
expect(job).not.toBeUndefined()
|
|
72
|
+
done()
|
|
73
|
+
}, 1000)
|
|
74
|
+
})
|
|
75
|
+
})
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Silex website builder, free/libre no-code tool for makers.
|
|
3
|
+
* Copyright (c) 2023 lexoyo and Silex Labs foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { JobData, JobStatus, JobId } from '../types'
|
|
19
|
+
|
|
20
|
+
// Delay after which the job is deleted from memory
|
|
21
|
+
const TIME_TO_KEEP_AFTER_STOP = 60*10*1000 // 10 min
|
|
22
|
+
|
|
23
|
+
// Store the jobs in memory
|
|
24
|
+
const jobs = new Array<JobData>()
|
|
25
|
+
|
|
26
|
+
// Key which will change on server restart
|
|
27
|
+
const processKey = Math.ceil(Math.random() * 1000000)
|
|
28
|
+
|
|
29
|
+
// Next id for the next job
|
|
30
|
+
let nextJobId = 0
|
|
31
|
+
|
|
32
|
+
// Create a new job
|
|
33
|
+
export function startJob(message = ''): JobData {
|
|
34
|
+
const jobId = `${processKey}_${++nextJobId}`
|
|
35
|
+
const job: JobData = {
|
|
36
|
+
jobId,
|
|
37
|
+
status: JobStatus.IN_PROGRESS,
|
|
38
|
+
message: message
|
|
39
|
+
}
|
|
40
|
+
jobs.push(job)
|
|
41
|
+
return job
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Retriev a job if it exists
|
|
45
|
+
export function getJob(id: JobId): JobData | undefined {
|
|
46
|
+
return jobs.find(job => job.jobId === id)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
// End the job with success
|
|
51
|
+
export function jobSuccess(id: JobId, message = ''): boolean {
|
|
52
|
+
return end(id, JobStatus.SUCCESS, message)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// End the job with error
|
|
56
|
+
export function jobError(id: JobId, message = ''): boolean {
|
|
57
|
+
return end(id, JobStatus.ERROR, message)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Remove a job from memory
|
|
61
|
+
// This is also used in unit tests to avoid memory lea
|
|
62
|
+
export function killJob(job: JobData) {
|
|
63
|
+
clearTimeout(job._timeout)
|
|
64
|
+
jobs.splice(jobs.findIndex(j => job.jobId === j.jobId), 1)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// End the job
|
|
68
|
+
function end(id: JobId, status: JobStatus, message = ''): boolean {
|
|
69
|
+
const job = getJob(id)
|
|
70
|
+
if(job) {
|
|
71
|
+
job.status = status
|
|
72
|
+
if(message) job.message = message
|
|
73
|
+
job._timeout = setTimeout(() => killJob(job), TIME_TO_KEEP_AFTER_STOP)
|
|
74
|
+
return true
|
|
75
|
+
}
|
|
76
|
+
return false
|
|
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 }
|