@nebula.js/cli-serve 2.0.0-beta.1
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/CHANGELOG.md +116 -0
- package/LICENSE +21 -0
- package/README.md +88 -0
- package/assets/logo.svg +17 -0
- package/command.js +13 -0
- package/data/apps/ctrl00.qvf +0 -0
- package/dist/525.js +1 -0
- package/dist/68664da4962ed33db33eb4d2b892c198.ttf +0 -0
- package/dist/eDev.html +16 -0
- package/dist/eDev.js +2 -0
- package/dist/eDev.js.LICENSE.txt +51 -0
- package/dist/eHub.html +20 -0
- package/dist/eHub.js +2 -0
- package/dist/eHub.js.LICENSE.txt +49 -0
- package/dist/eRender.html +28 -0
- package/dist/eRender.js +2 -0
- package/dist/eRender.js.LICENSE.txt +51 -0
- package/dist/editor.worker.js +1 -0
- package/dist/json.worker.js +1 -0
- package/dist/njs.png +0 -0
- package/docker-compose.yml +13 -0
- package/lib/engine.js +49 -0
- package/lib/init-config.js +80 -0
- package/lib/placeholder.js +7 -0
- package/lib/serve.js +191 -0
- package/lib/sn.js +1 -0
- package/lib/snapshot-router.js +58 -0
- package/lib/snapshot-server.js +83 -0
- package/lib/webpack.build.js +125 -0
- package/lib/webpack.prod.js +69 -0
- package/lib/webpack.serve.js +214 -0
- package/package.json +69 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/* eslint global-require: 0 */
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const express = require('express');
|
|
5
|
+
|
|
6
|
+
const webpack = require('webpack');
|
|
7
|
+
const WebpackDevServer = require('webpack-dev-server');
|
|
8
|
+
|
|
9
|
+
const snapshooterFn = require('./snapshot-server');
|
|
10
|
+
const snapshotRouter = require('./snapshot-router');
|
|
11
|
+
|
|
12
|
+
module.exports = async ({
|
|
13
|
+
host,
|
|
14
|
+
port,
|
|
15
|
+
disableHostCheck,
|
|
16
|
+
enigmaConfig,
|
|
17
|
+
webIntegrationId,
|
|
18
|
+
snName,
|
|
19
|
+
snUrl,
|
|
20
|
+
dev = false,
|
|
21
|
+
open = true,
|
|
22
|
+
entryWatcher,
|
|
23
|
+
watcher,
|
|
24
|
+
serveConfig,
|
|
25
|
+
}) => {
|
|
26
|
+
let config;
|
|
27
|
+
let contentBase;
|
|
28
|
+
|
|
29
|
+
const snapshotRoute = '/njs';
|
|
30
|
+
|
|
31
|
+
const snapshooter = snapshooterFn({ snapshotUrl: `http://${host}:${port}/eRender.html` });
|
|
32
|
+
|
|
33
|
+
(serveConfig.snapshots || []).forEach((s) => {
|
|
34
|
+
snapshooter.storeSnapshot(s);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const snapRouter = snapshotRouter({
|
|
38
|
+
base: `http://${host}:${port}${snapshotRoute}`,
|
|
39
|
+
snapshotUrl: `http://${host}:${port}/eRender.html`,
|
|
40
|
+
snapshooter,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const themes = serveConfig.themes || [];
|
|
44
|
+
const renderConfigs = serveConfig.renderConfigs || [];
|
|
45
|
+
|
|
46
|
+
if (dev) {
|
|
47
|
+
const webpackConfig = require('./webpack.build');
|
|
48
|
+
const srcDir = path.resolve(__dirname, '../web');
|
|
49
|
+
const distDir = path.resolve(srcDir, '../dist');
|
|
50
|
+
contentBase = distDir;
|
|
51
|
+
config = webpackConfig({
|
|
52
|
+
srcDir,
|
|
53
|
+
distDir,
|
|
54
|
+
dev: true,
|
|
55
|
+
serveConfig,
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
const webpackConfig = require('./webpack.prod');
|
|
59
|
+
const srcDir = path.resolve(__dirname, '../dist');
|
|
60
|
+
contentBase = srcDir;
|
|
61
|
+
config = webpackConfig({
|
|
62
|
+
srcDir,
|
|
63
|
+
serveConfig,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const options = {
|
|
67
|
+
client: {
|
|
68
|
+
logging: 'none',
|
|
69
|
+
overlay: {
|
|
70
|
+
warnings: false,
|
|
71
|
+
errors: true,
|
|
72
|
+
},
|
|
73
|
+
progress: true,
|
|
74
|
+
},
|
|
75
|
+
hot: dev,
|
|
76
|
+
host,
|
|
77
|
+
port,
|
|
78
|
+
allowedHosts: disableHostCheck ? 'all' : 'auto',
|
|
79
|
+
open,
|
|
80
|
+
historyApiFallback: {
|
|
81
|
+
index: '/eHub.html',
|
|
82
|
+
},
|
|
83
|
+
static: {
|
|
84
|
+
directory: contentBase,
|
|
85
|
+
watch: {
|
|
86
|
+
ignored: /node_modules/,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
onBeforeSetupMiddleware(devServer) {
|
|
90
|
+
const { app } = devServer;
|
|
91
|
+
app.use(snapshotRoute, snapRouter);
|
|
92
|
+
|
|
93
|
+
if (entryWatcher) {
|
|
94
|
+
entryWatcher.addRoutes(app);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
app.get('/themes', (req, res) => {
|
|
98
|
+
const arr = themes.map((theme) => theme.id);
|
|
99
|
+
res.json(arr);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
app.get('/theme/:id', (req, res) => {
|
|
103
|
+
const t = themes.filter((theme) => theme.id === req.params.id)[0];
|
|
104
|
+
if (!t) {
|
|
105
|
+
res.sendStatus('404');
|
|
106
|
+
} else {
|
|
107
|
+
res.json(t.theme);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
app.get('/render-configs', (_, res) => {
|
|
112
|
+
res.json(renderConfigs);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
app.get('/render-config/:id', (req, res) => {
|
|
116
|
+
const renderConfig = renderConfigs.filter((r) => r.id === req.params.id)[0];
|
|
117
|
+
if (!renderConfig) {
|
|
118
|
+
res.sendStatus('404');
|
|
119
|
+
} else {
|
|
120
|
+
res.json(renderConfig.render);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
app.get('/info', (req, res) => {
|
|
125
|
+
res.json({
|
|
126
|
+
enigma: enigmaConfig,
|
|
127
|
+
webIntegrationId,
|
|
128
|
+
supernova: {
|
|
129
|
+
name: snName,
|
|
130
|
+
url: snUrl,
|
|
131
|
+
},
|
|
132
|
+
sock: {
|
|
133
|
+
port: entryWatcher && entryWatcher.port,
|
|
134
|
+
},
|
|
135
|
+
flags: serveConfig.flags,
|
|
136
|
+
themes: themes.map((theme) => theme.id),
|
|
137
|
+
types: serveConfig.types,
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
if (serveConfig.resources) {
|
|
142
|
+
app.use('/resources', express.static(serveConfig.resources));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
app.use('/assets', express.static(path.resolve(__dirname, '../assets')));
|
|
146
|
+
},
|
|
147
|
+
proxy: [
|
|
148
|
+
{
|
|
149
|
+
context: '/render',
|
|
150
|
+
target: `http://${host}:${port}/eRender.html`,
|
|
151
|
+
ignorePath: true,
|
|
152
|
+
logLevel: 'error',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
context: '/dev',
|
|
156
|
+
target: `http://${host}:${port}/eDev.html`,
|
|
157
|
+
ignorePath: true,
|
|
158
|
+
logLevel: 'error',
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const compiler = webpack(config);
|
|
164
|
+
const server = new WebpackDevServer(options, compiler);
|
|
165
|
+
|
|
166
|
+
const close = () => {
|
|
167
|
+
server.stop();
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
['SIGINT', 'SIGTERM'].forEach((signal) => {
|
|
171
|
+
process.on(signal, close);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
if (watcher) {
|
|
175
|
+
let inError = false;
|
|
176
|
+
watcher.on('event', (event) => {
|
|
177
|
+
if (event.code === 'ERROR') {
|
|
178
|
+
inError = true;
|
|
179
|
+
server.sockWrite(server.sockets, 'errors', [event.error.stack]);
|
|
180
|
+
} else if (event.code === 'BUNDLE_END' && inError) {
|
|
181
|
+
inError = false;
|
|
182
|
+
server.sockWrite(server.sockets, 'ok');
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let initiated = false;
|
|
188
|
+
|
|
189
|
+
return new Promise((resolve) => {
|
|
190
|
+
// eslint-disable-line consistent-return
|
|
191
|
+
compiler.hooks.done.tap('nebula serve', (stats) => {
|
|
192
|
+
if (!initiated) {
|
|
193
|
+
initiated = true;
|
|
194
|
+
const url = `http://${host}:${port}`;
|
|
195
|
+
console.log(`Development server running at ${chalk.green(url)}`);
|
|
196
|
+
|
|
197
|
+
resolve({
|
|
198
|
+
context: '',
|
|
199
|
+
url,
|
|
200
|
+
close,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
if (stats.hasErrors()) {
|
|
204
|
+
stats.compilation.errors.forEach((e) => {
|
|
205
|
+
console.log(chalk.red(e));
|
|
206
|
+
});
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
server.start();
|
|
213
|
+
});
|
|
214
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nebula.js/cli-serve",
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "QlikTech International AB",
|
|
7
|
+
"keywords": [],
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/qlik-oss/nebula.js.git"
|
|
14
|
+
},
|
|
15
|
+
"main": "lib/serve.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"assets",
|
|
18
|
+
"command.js",
|
|
19
|
+
"data",
|
|
20
|
+
"dist",
|
|
21
|
+
"docker-compose.yml",
|
|
22
|
+
"lib"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "cross-env NODE_ENV=production DEFAULTS=true webpack --config ./lib/webpack.build.js",
|
|
26
|
+
"lint": "eslint web",
|
|
27
|
+
"prepublishOnly": "rm -rf dist && yarn run build"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@nebula.js/cli-build": "^2.0.0-beta.1",
|
|
31
|
+
"body-parser": "1.19.0",
|
|
32
|
+
"chalk": "4.1.2",
|
|
33
|
+
"chokidar": "3.5.2",
|
|
34
|
+
"cross-env": "7.0.3",
|
|
35
|
+
"express": "4.17.1",
|
|
36
|
+
"extend": "3.0.2",
|
|
37
|
+
"html-webpack-plugin": "5.3.2",
|
|
38
|
+
"portfinder": "1.0.28",
|
|
39
|
+
"puppeteer": "10.2.0",
|
|
40
|
+
"regenerator-runtime": "0.13.9",
|
|
41
|
+
"source-map-loader": "3.0.0",
|
|
42
|
+
"webpack": "5.51.1",
|
|
43
|
+
"webpack-dev-server": "4.1.1",
|
|
44
|
+
"ws": "8.2.1",
|
|
45
|
+
"yargs": "17.1.1"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@babel/core": "7.15.0",
|
|
49
|
+
"@babel/preset-env": "7.15.0",
|
|
50
|
+
"@babel/preset-react": "7.14.5",
|
|
51
|
+
"@material-ui/core": "4.12.3",
|
|
52
|
+
"@nebula.js/nucleus": "^2.0.0-beta.1",
|
|
53
|
+
"@nebula.js/snapshooter": "^2.0.0-beta.1",
|
|
54
|
+
"@nebula.js/stardust": "^2.0.0-beta.1",
|
|
55
|
+
"@nebula.js/ui": "^2.0.0-beta.1",
|
|
56
|
+
"autosuggest-highlight": "3.1.1",
|
|
57
|
+
"babel-loader": "8.2.2",
|
|
58
|
+
"d3-require": "1.2.4",
|
|
59
|
+
"enigma.js": "2.7.3",
|
|
60
|
+
"eslint-import-resolver-alias": "1.1.2",
|
|
61
|
+
"eslint-import-resolver-webpack": "0.13.1",
|
|
62
|
+
"monaco-editor": "0.27.0",
|
|
63
|
+
"monaco-editor-webpack-plugin": "4.1.2",
|
|
64
|
+
"react": "17.0.2",
|
|
65
|
+
"react-dom": "17.0.2",
|
|
66
|
+
"webpack-cli": "4.8.0"
|
|
67
|
+
},
|
|
68
|
+
"gitHead": "851bf623f70a49f07615fe3b7e37b8b44fad534f"
|
|
69
|
+
}
|