@equinor/fusion-framework-cli 0.1.14 → 0.2.0
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 +11 -0
- package/bin/app-config.js +82 -0
- package/bin/create-config.js +18 -14
- package/bin/dev-portal/assets/index.59335b01.js +390 -0
- package/bin/dev-portal/index.html +1 -1
- package/bin/main.js +5 -3
- package/bin/serve.js +78 -5
- package/package.json +6 -3
- package/bin/dev-portal/assets/index.8bf617d0.js +0 -363
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta charset="UTF-8" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Fusion Framework Dev Portal</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index.
|
|
8
|
+
<script type="module" crossorigin src="/assets/index.59335b01.js"></script>
|
|
9
9
|
|
|
10
10
|
<body>
|
|
11
11
|
<div id="root"></div>
|
package/bin/main.js
CHANGED
|
@@ -13,6 +13,7 @@ import ora from 'ora';
|
|
|
13
13
|
import { build, mergeConfig } from 'vite';
|
|
14
14
|
import startDevServer from './serve.js';
|
|
15
15
|
import createConfig from './create-config.js';
|
|
16
|
+
import { resolveAppConfig } from './app-config.js';
|
|
16
17
|
const program = new Command();
|
|
17
18
|
program.name('fusion-framework-cli');
|
|
18
19
|
program.description('CLI for Fusion Framework');
|
|
@@ -22,12 +23,13 @@ const app = program
|
|
|
22
23
|
.description('Tooling for developing applications build on Fusion Framework');
|
|
23
24
|
app.command('dev')
|
|
24
25
|
.description('Create a development server')
|
|
25
|
-
.option('-p, --port <number>', '
|
|
26
|
+
.option('-p, --port <number>', 'dev-server port', '3000')
|
|
26
27
|
.action((port) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
28
|
const spinner = ora('Loading configuration').start();
|
|
28
|
-
const
|
|
29
|
+
const viteConfig = mergeConfig(yield createConfig(), { server: port });
|
|
30
|
+
const appConfig = yield resolveAppConfig();
|
|
29
31
|
spinner.succeed('Configuration loaded');
|
|
30
|
-
startDevServer(
|
|
32
|
+
startDevServer({ viteConfig, appConfig });
|
|
31
33
|
}));
|
|
32
34
|
app.command('build').action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
35
|
build(mergeConfig(yield createConfig(), { build: { emptyOutDir: true } }));
|
package/bin/serve.js
CHANGED
|
@@ -15,21 +15,94 @@ dns.setDefaultResultOrder('verbatim');
|
|
|
15
15
|
import path from 'path';
|
|
16
16
|
import kleur from 'kleur';
|
|
17
17
|
import ora from 'ora';
|
|
18
|
+
import { createProxyMiddleware, responseInterceptor } from 'http-proxy-middleware';
|
|
18
19
|
const resolveRelativePath = (relative) => path.resolve(new URL(relative, import.meta.url).pathname);
|
|
19
20
|
export const server = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
21
|
var _a, _b;
|
|
21
|
-
const
|
|
22
|
+
const { manifest: appManifest } = config.appConfig;
|
|
22
23
|
const app = express();
|
|
23
|
-
const port = (_b = (_a = config.server) === null || _a === void 0 ? void 0 : _a.port) !== null && _b !== void 0 ? _b : 3000;
|
|
24
|
-
const
|
|
24
|
+
const port = (_b = (_a = config.viteConfig.server) === null || _a === void 0 ? void 0 : _a.port) !== null && _b !== void 0 ? _b : 3000;
|
|
25
|
+
const host = `http://localhost:${port}`;
|
|
26
|
+
const spinner = ora('Configuring dev-server').start();
|
|
27
|
+
const vite = yield createServer(config.viteConfig);
|
|
28
|
+
spinner.succeed('Configured dev-server');
|
|
29
|
+
/** expose middlewares from vite (dev-server) */
|
|
25
30
|
app.use(vite.middlewares);
|
|
31
|
+
/** serve static files (portal prebuild) */
|
|
26
32
|
app.use(express.static(resolveRelativePath('dev-portal'), { index: false }));
|
|
33
|
+
app.use(createProxyMiddleware('/_discovery/environments/current', {
|
|
34
|
+
target: 'https://pro-s-portal-ci.azurewebsites.net',
|
|
35
|
+
changeOrigin: true,
|
|
36
|
+
selfHandleResponse: true,
|
|
37
|
+
onProxyRes: responseInterceptor((responseBuffer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const response = JSON.parse(responseBuffer.toString('utf8'));
|
|
39
|
+
response.environmentName = 'DEVELOPMENT';
|
|
40
|
+
response.services = response.services.filter((x) => x.key !== 'app');
|
|
41
|
+
response.services.push({
|
|
42
|
+
key: 'app',
|
|
43
|
+
uri: host,
|
|
44
|
+
});
|
|
45
|
+
return JSON.stringify(response);
|
|
46
|
+
})),
|
|
47
|
+
}));
|
|
48
|
+
app.get('/api/apps/:appKey/config',
|
|
49
|
+
// '/api/widget/:appKey/config',
|
|
50
|
+
createProxyMiddleware('/api/apps/*/config', {
|
|
51
|
+
target: 'https://pro-s-portal-ci.azurewebsites.net',
|
|
52
|
+
changeOrigin: true,
|
|
53
|
+
selfHandleResponse: true,
|
|
54
|
+
onProxyRes: responseInterceptor((responseBuffer, proxyRes, req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const { appKey } = req.params;
|
|
56
|
+
if (appManifest.appKey === appKey) {
|
|
57
|
+
const { endpoints, environment } = config.appConfig;
|
|
58
|
+
const response = { endpoints, environment };
|
|
59
|
+
if (Number(proxyRes.statusCode) === 404) {
|
|
60
|
+
res.statusCode = 200;
|
|
61
|
+
return JSON.stringify(response);
|
|
62
|
+
}
|
|
63
|
+
return JSON.stringify(Object.assign(JSON.parse(responseBuffer.toString('utf8')), response));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return responseBuffer;
|
|
67
|
+
}
|
|
68
|
+
})),
|
|
69
|
+
}));
|
|
70
|
+
app.get('/api/apps/:appKey', createProxyMiddleware('/api/apps/*', {
|
|
71
|
+
target: 'https://pro-s-portal-ci.azurewebsites.net',
|
|
72
|
+
changeOrigin: true,
|
|
73
|
+
selfHandleResponse: true,
|
|
74
|
+
onProxyRes: responseInterceptor((responseBuffer, proxyRes, req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
const { appKey } = req.params;
|
|
76
|
+
if (appManifest.appKey === appKey) {
|
|
77
|
+
const response = Object.assign(Object.assign({}, appManifest), { entry: new URL(appManifest.main, host).href });
|
|
78
|
+
if (Number(proxyRes.statusCode) === 404) {
|
|
79
|
+
res.statusCode = 200;
|
|
80
|
+
return JSON.stringify(response);
|
|
81
|
+
}
|
|
82
|
+
return JSON.stringify(Object.assign(JSON.parse(responseBuffer.toString('utf8')), response));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return responseBuffer;
|
|
86
|
+
}
|
|
87
|
+
})),
|
|
88
|
+
}));
|
|
27
89
|
app.use('*', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
90
|
const htmlRaw = readFileSync(resolveRelativePath('dev-portal/index.html'), 'utf-8');
|
|
29
91
|
const html = yield vite.transformIndexHtml(req.url, htmlRaw);
|
|
30
92
|
res.send(html);
|
|
31
93
|
}));
|
|
32
|
-
|
|
33
|
-
|
|
94
|
+
spinner.start('Starting dev-server');
|
|
95
|
+
const instance = app.listen(port);
|
|
96
|
+
vite.watcher.on('change', (x) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
if (x === config.appConfig.dev.configSource.file) {
|
|
98
|
+
console.log('🛠', kleur.red('config changed, closing dev server'));
|
|
99
|
+
yield vite.close();
|
|
100
|
+
instance.close();
|
|
101
|
+
console.log('🚀', kleur.green('restarting server, please wait'));
|
|
102
|
+
server(config);
|
|
103
|
+
}
|
|
104
|
+
}));
|
|
105
|
+
spinner.succeed(`dev server started`);
|
|
106
|
+
console.log('🔗', kleur.underline().green(new URL(`/apps/${appManifest.appKey}`, host).href));
|
|
34
107
|
});
|
|
35
108
|
export default server;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"Fusion",
|
|
6
6
|
"Fusion Framework",
|
|
@@ -24,16 +24,18 @@
|
|
|
24
24
|
"prepack": "yarn build"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"@equinor/fusion-observable": "^1.4.1",
|
|
27
28
|
"@vitejs/plugin-react": "^2.2.0",
|
|
28
29
|
"commander": "^9.4.1",
|
|
29
30
|
"express": "^4.18.2",
|
|
30
31
|
"find-up": "^6.3.0",
|
|
32
|
+
"http-proxy-middleware": "^2.0.6",
|
|
31
33
|
"kleur": "^4.1.5",
|
|
32
34
|
"ora": "^6.1.2",
|
|
33
35
|
"vite": "^3.2.0"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
|
-
"@equinor/fusion-framework-react": "^1.3.
|
|
38
|
+
"@equinor/fusion-framework-react": "^1.3.12",
|
|
37
39
|
"@equinor/fusion-react-progress-indicator": "^0.1.5",
|
|
38
40
|
"@equinor/fusion-react-styles": "^0.5.5",
|
|
39
41
|
"@types/express": "^4.17.14",
|
|
@@ -41,7 +43,8 @@
|
|
|
41
43
|
"@types/react-dom": "^18.0.7",
|
|
42
44
|
"react": "^18.2.0",
|
|
43
45
|
"react-dom": "^18.2.0",
|
|
46
|
+
"react-router-dom": "^6.4.3",
|
|
44
47
|
"typescript": "^4.8.4"
|
|
45
48
|
},
|
|
46
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "98a8a5c6f02ac739adda41bb26f43e3255d450bb"
|
|
47
50
|
}
|