@egen-civitas/egen 1.0.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.
Files changed (75) hide show
  1. package/README.md +71 -0
  2. package/bin/rspack.cjs +9 -0
  3. package/bin/webpack.cjs +6 -0
  4. package/default-rspack-config.cjs +3 -0
  5. package/default-webpack-config.cjs +3 -0
  6. package/dist/cli.d.ts +4 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +266 -0
  9. package/dist/commands/assemble.d.ts +13 -0
  10. package/dist/commands/assemble.d.ts.map +1 -0
  11. package/dist/commands/assemble.js +225 -0
  12. package/dist/commands/build.d.ts +32 -0
  13. package/dist/commands/build.d.ts.map +1 -0
  14. package/dist/commands/build.js +86 -0
  15. package/dist/commands/debug.d.ts +14 -0
  16. package/dist/commands/debug.d.ts.map +1 -0
  17. package/dist/commands/debug.js +37 -0
  18. package/dist/commands/develop.d.ts +18 -0
  19. package/dist/commands/develop.d.ts.map +1 -0
  20. package/dist/commands/develop.js +135 -0
  21. package/dist/commands/index.d.ts +5 -0
  22. package/dist/commands/index.d.ts.map +1 -0
  23. package/dist/commands/index.js +4 -0
  24. package/dist/commands/start.d.ts +9 -0
  25. package/dist/commands/start.d.ts.map +1 -0
  26. package/dist/commands/start.js +44 -0
  27. package/dist/index.d.ts +3 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +2 -0
  30. package/dist/runner.d.ts +2 -0
  31. package/dist/runner.d.ts.map +1 -0
  32. package/dist/runner.js +14 -0
  33. package/dist/utils/config.d.ts +24 -0
  34. package/dist/utils/config.d.ts.map +1 -0
  35. package/dist/utils/config.js +75 -0
  36. package/dist/utils/debugger.d.ts +2 -0
  37. package/dist/utils/debugger.d.ts.map +1 -0
  38. package/dist/utils/debugger.js +66 -0
  39. package/dist/utils/dependencies.d.ts +9 -0
  40. package/dist/utils/dependencies.d.ts.map +1 -0
  41. package/dist/utils/dependencies.js +37 -0
  42. package/dist/utils/devserver.d.ts +5 -0
  43. package/dist/utils/devserver.d.ts.map +1 -0
  44. package/dist/utils/devserver.js +30 -0
  45. package/dist/utils/helpers.d.ts +4 -0
  46. package/dist/utils/helpers.d.ts.map +1 -0
  47. package/dist/utils/helpers.js +16 -0
  48. package/dist/utils/importmap.d.ts +53 -0
  49. package/dist/utils/importmap.d.ts.map +1 -0
  50. package/dist/utils/importmap.js +312 -0
  51. package/dist/utils/index.d.ts +10 -0
  52. package/dist/utils/index.d.ts.map +1 -0
  53. package/dist/utils/index.js +9 -0
  54. package/dist/utils/logger.d.ts +4 -0
  55. package/dist/utils/logger.d.ts.map +1 -0
  56. package/dist/utils/logger.js +10 -0
  57. package/dist/utils/npmConfig.d.ts +14 -0
  58. package/dist/utils/npmConfig.d.ts.map +1 -0
  59. package/dist/utils/npmConfig.js +39 -0
  60. package/dist/utils/packages.d.ts +15 -0
  61. package/dist/utils/packages.d.ts.map +1 -0
  62. package/dist/utils/packages.js +92 -0
  63. package/dist/utils/port.d.ts +15 -0
  64. package/dist/utils/port.d.ts.map +1 -0
  65. package/dist/utils/port.js +44 -0
  66. package/dist/utils/types.d.ts +16 -0
  67. package/dist/utils/types.d.ts.map +1 -0
  68. package/dist/utils/types.js +1 -0
  69. package/dist/utils/untar.d.ts +5 -0
  70. package/dist/utils/untar.d.ts.map +1 -0
  71. package/dist/utils/untar.js +14 -0
  72. package/dist/utils/variables.d.ts +2 -0
  73. package/dist/utils/variables.d.ts.map +1 -0
  74. package/dist/utils/variables.js +5 -0
  75. package/package.json +116 -0
@@ -0,0 +1,86 @@
1
+ import { createRequire } from "node:module";
2
+ import { copyFileSync, existsSync, readdirSync, readFileSync, statSync } from "fs";
3
+ import { basename, join, parse, resolve } from "path";
4
+ import { checkImportmapJson, checkRoutesJson, getImportMap, getRoutes, loadBundlerConfig, logInfo } from "../utils/index.js";
5
+ function loadBuildConfig(buildConfigPath) {
6
+ if (buildConfigPath) {
7
+ return JSON.parse(readFileSync(buildConfigPath, 'utf8'));
8
+ } else {
9
+ return {};
10
+ }
11
+ }
12
+ function addConfigFilesFromPaths(configPaths, targetDir) {
13
+ for (let configPath of configPaths){
14
+ const realPath = resolve(configPath);
15
+ copyFileSync(realPath, join(targetDir, basename(configPath)));
16
+ }
17
+ }
18
+ export async function runBuild(args) {
19
+ const require = createRequire(import.meta.url);
20
+ const rspack = require('@rspack/core');
21
+ const buildConfig = loadBuildConfig(args.buildConfig);
22
+ const configUrls = buildConfig.configUrls || args.configUrls;
23
+ for (let configPath of buildConfig.configPaths || args.configPaths){
24
+ configUrls.push(basename(configPath));
25
+ }
26
+ const importMap = await getImportMap(args.importmap || buildConfig.importmap || 'importmap.json');
27
+ // if we're supplying a URL importmap and the dist folder exists and the raw importmap file doesn't exist
28
+ // we use the nearest thing. Basically, this is added to support the --hash-importmap assemble option.
29
+ if (importMap.type === 'url') {
30
+ if (!/^https?:\/\//.test(importMap.value) && existsSync(args.target) && !existsSync(resolve(args.target, basename(importMap.value)))) {
31
+ const { name: fileName, ext: extension } = parse(importMap.value);
32
+ const paths = readdirSync(args.target).filter((entry)=>entry.startsWith(fileName) && entry.endsWith(extension) && statSync(resolve(args.target, entry)).isFile() && checkImportmapJson(readFileSync(resolve(args.target, entry)).toString()));
33
+ if (paths.length > 0 && paths[0]) {
34
+ importMap.value = importMap.value.replace(/importmap\.json/i, paths[0]);
35
+ }
36
+ }
37
+ }
38
+ const routes = await getRoutes(args.routes || buildConfig.routes || 'routes.registry.json');
39
+ // As above, check for a hashed routes.registry.json if --hash-importmap assmeble option was used
40
+ if (routes.type === 'url') {
41
+ if (!/^https?:\/\//.test(routes.value) && existsSync(args.target) && !existsSync(resolve(args.target, routes.value))) {
42
+ const { name: fileName, ext: extension } = parse(routes.value);
43
+ const paths = readdirSync(args.target).filter((entry)=>entry.startsWith(fileName) && entry.endsWith(extension) && statSync(resolve(args.target, entry)).isFile() && checkRoutesJson(readFileSync(resolve(args.target, entry)).toString()));
44
+ if (paths.length > 0 && paths[0]) {
45
+ routes.value = routes.value.replace(/routes\.registry\.json/i, paths[0]);
46
+ }
47
+ }
48
+ }
49
+ const config = loadBundlerConfig({
50
+ importmap: importMap,
51
+ routes,
52
+ env: buildConfig.env || args.env,
53
+ apiUrl: buildConfig.apiUrl || args.apiUrl,
54
+ configUrls: configUrls,
55
+ defaultLocale: args.defaultLocale || buildConfig.defaultLocale,
56
+ pageTitle: buildConfig.pageTitle || args.pageTitle,
57
+ supportOffline: buildConfig.supportOffline ?? args.supportOffline,
58
+ spaPath: buildConfig.spaPath || args.spaPath,
59
+ fresh: args.fresh ?? false,
60
+ assets: args.assets || buildConfig.assets || []
61
+ });
62
+ logInfo(`Running build process ...`);
63
+ const compiler = rspack({
64
+ ...config,
65
+ output: {
66
+ ...config.output,
67
+ path: args.target
68
+ }
69
+ });
70
+ return await new Promise((resolve, reject)=>{
71
+ compiler.run((err, stats)=>{
72
+ if (err || stats?.hasErrors()) {
73
+ reject(err ?? new Error(stats?.compilation.errors.toString()));
74
+ } else {
75
+ if (stats) {
76
+ console.log(stats.toString({
77
+ colors: true
78
+ }));
79
+ }
80
+ addConfigFilesFromPaths(buildConfig.configPaths || args.configPaths, args.target);
81
+ logInfo(`Build finished.`);
82
+ resolve();
83
+ }
84
+ });
85
+ });
86
+ }
@@ -0,0 +1,14 @@
1
+ import type { ImportmapDeclaration } from '../utils';
2
+ export interface DebugArgs {
3
+ port: number;
4
+ host: string;
5
+ backend: string;
6
+ importmap: ImportmapDeclaration;
7
+ supportOffline?: boolean;
8
+ spaPath: string;
9
+ apiUrl: string;
10
+ configUrls: Array<string>;
11
+ addCookie: string;
12
+ }
13
+ export declare function runDebug(args: DebugArgs): Promise<void>;
14
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/commands/debug.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGrD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,oBAAoB,CAAC;IAChC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,iBAsCvC"}
@@ -0,0 +1,37 @@
1
+ import { createRequire } from "node:module";
2
+ import { loadBundlerConfig, logInfo, logWarn } from "../utils/index.js";
3
+ export function runDebug(args) {
4
+ const require = createRequire(import.meta.url);
5
+ const webpack = require('webpack');
6
+ const WebpackDevServer = require('webpack-dev-server');
7
+ const config = loadBundlerConfig({
8
+ importmap: args.importmap,
9
+ backend: args.backend,
10
+ apiUrl: args.apiUrl,
11
+ supportOffline: args.supportOffline,
12
+ spaPath: args.spaPath,
13
+ configUrls: args.configUrls,
14
+ addCookie: args.addCookie,
15
+ env: 'development'
16
+ });
17
+ logInfo(`Starting the dev server ...`);
18
+ const { host, port } = args;
19
+ const options = {
20
+ ...config['devServer'] ?? {},
21
+ port,
22
+ host,
23
+ publicPath: args.spaPath,
24
+ stats: {
25
+ colors: true
26
+ }
27
+ };
28
+ const server = new WebpackDevServer(webpack(config), options);
29
+ server.listen(port, host, (err)=>{
30
+ if (err) {
31
+ logWarn(`Error: ${err}`);
32
+ } else {
33
+ logInfo(`Listening at http://${host}:${port}`);
34
+ }
35
+ });
36
+ return new Promise(()=>{});
37
+ }
@@ -0,0 +1,18 @@
1
+ import { type ImportmapDeclaration, type RoutesDeclaration } from '../utils';
2
+ export interface DevelopArgs {
3
+ port: number;
4
+ host: string;
5
+ backend: string;
6
+ open: boolean;
7
+ importmap: ImportmapDeclaration;
8
+ routes: RoutesDeclaration;
9
+ watchedRoutesPaths: Record<string, string>;
10
+ spaPath: string;
11
+ apiUrl: string;
12
+ configUrls: Array<string>;
13
+ configFiles: Array<string>;
14
+ addCookie: string;
15
+ supportOffline: boolean;
16
+ }
17
+ export declare function runDevelop(args: DevelopArgs, signal?: AbortSignal): Promise<void>;
18
+ //# sourceMappingURL=develop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"develop.d.ts","sourceRoot":"","sources":["../../src/commands/develop.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,iBAAiB,EAAyC,MAAM,UAAU,CAAC;AAEpH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,oBAAoB,CAAC;IAChC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,WAAW,iBA2KvE"}
@@ -0,0 +1,135 @@
1
+ import { createRequire } from "node:module";
2
+ import express from "express";
3
+ import { createProxyMiddleware } from "http-proxy-middleware";
4
+ import { basename, resolve } from "node:path";
5
+ import { readFileSync } from "node:fs";
6
+ import { readFile } from "node:fs/promises";
7
+ import { logInfo, logWarn, removeTrailingSlash } from "../utils/index.js";
8
+ export async function runDevelop(args, signal) {
9
+ const { backend, host, port, open, importmap, routes, watchedRoutesPaths, configUrls, configFiles, addCookie, supportOffline } = args;
10
+ const apiUrl = removeTrailingSlash(args.apiUrl);
11
+ const spaPath = removeTrailingSlash(args.spaPath);
12
+ const app = express();
13
+ const localConfigUrlPrefix = '__local_config__';
14
+ const localConfigUrls = configFiles.map((path)=>`${spaPath}/${localConfigUrlPrefix}/${basename(path)}`);
15
+ const require = createRequire(import.meta.url);
16
+ const source = resolve(require.resolve('@egen-civitas/esm-app-shell/package.json'), '..', 'dist');
17
+ const index = resolve(source, 'index.html');
18
+ const indexContent = readFileSync(index, 'utf8').replace(/<script>initializeSpa\([\s\S\n]*<\/script>/m, `<script>
19
+ initializeSpa({
20
+ apiUrl: ${JSON.stringify(apiUrl)},
21
+ spaPath: ${JSON.stringify(spaPath)},
22
+ env: "development",
23
+ offline: ${supportOffline},
24
+ configUrls: ${JSON.stringify([
25
+ ...configUrls,
26
+ ...localConfigUrls
27
+ ])},
28
+ });
29
+ </script>
30
+ `).replace(/href="\/egen\/spa/g, `href="${spaPath}`).replace(/src="\/egen\/spa/g, `src="${spaPath}`).replace(/https:\/\/dev3\.egen\.org\/egen\/spa\/importmap\.json/g, `${spaPath}/importmap.json`);
31
+ const swContent = supportOffline ? readFileSync(resolve(source, 'service-worker.js'), 'utf-8').replace(/https:\/\/dev3\.egen\.org\/egen\/spa\//g, `${spaPath}`) : '';
32
+ const pageUrl = `http://${host}:${port}${spaPath}`;
33
+ // Set up routes. Note that different middlewares have different rules
34
+ // about route precedence.
35
+ //
36
+ // HPM/createProxyMiddleware always takes top precedence, so we must
37
+ // explicitly exclude routes that we want to use other handlers for.
38
+ //
39
+ // express.static respects normal route declaration order.
40
+ // Route for custom `importmap.json` goes above static assets
41
+ if (importmap.type === 'inline') {
42
+ app.get(`${spaPath}/importmap.json`, (_, res)=>{
43
+ res.contentType('application/json').send(importmap.value);
44
+ });
45
+ }
46
+ if (routes.type === 'inline') {
47
+ let stringifiedRoutes = routes.value;
48
+ if (watchedRoutesPaths && !!Object.keys(watchedRoutesPaths).length) {
49
+ // watchedRoutesPath is keyed from package to path, but here we need to go from
50
+ // path to package.
51
+ const watchedRoutesByPath = Object.fromEntries(Object.entries(watchedRoutesPaths).map(([k, v])=>[
52
+ v,
53
+ k
54
+ ]));
55
+ logInfo(`Watching routes.json for ${Object.keys(watchedRoutesPaths).join(', ')}`);
56
+ // setup watchers for all the discovered routes.json files which update the in-memory map
57
+ (await import("node-watch")).default(Object.keys(watchedRoutesByPath), {
58
+ delay: 0
59
+ }, async (event, name)=>{
60
+ if (event === 'update') {
61
+ const updatedApp = watchedRoutesByPath[name];
62
+ if (updatedApp) {
63
+ const jsonRoutes = JSON.parse(stringifiedRoutes);
64
+ const version = jsonRoutes[updatedApp]?.version;
65
+ jsonRoutes[updatedApp] = {
66
+ ...JSON.parse(await readFile(name, 'utf8')),
67
+ version
68
+ };
69
+ stringifiedRoutes = JSON.stringify(jsonRoutes);
70
+ logInfo(`Updated routes for ${updatedApp}`);
71
+ }
72
+ }
73
+ });
74
+ }
75
+ app.get(`${spaPath}/routes.registry.json`, (_, res)=>{
76
+ res.contentType('application/json').send(stringifiedRoutes);
77
+ });
78
+ }
79
+ // Route for custom `service-worker.js` before most things
80
+ if (supportOffline) {
81
+ app.get(`${spaPath}/service-worker.js`, (_, res)=>{
82
+ res.contentType('js').send(swContent);
83
+ });
84
+ }
85
+ configFiles.forEach((file, i)=>{
86
+ const url = localConfigUrls[i];
87
+ app.get(url, (_, res)=>{
88
+ res.contentType('application/json').send(readFileSync(resolve(process.cwd(), file)));
89
+ });
90
+ });
91
+ // Escape the spaPath so it can be safely used in a regex
92
+ const escapedSpaPath = spaPath.replace(/[|\\{}()[\]^$+*?.]/g, String.raw`\$&`).replace(/-/g, String.raw`\x2d`);
93
+ // Return our custom `index.html` for all requests beginning with spaPath
94
+ // and not ending in `.js`, `.woff`, `.woff2`, `.json`, or any two- or three-character
95
+ // extension.
96
+ const indexHtmlPathMatcher = new RegExp(String.raw`${escapedSpaPath}\/(?!.*\.(js|woff2?|json|.{2,3}$)).*$`);
97
+ // Route for custom `index.html` goes above static assets
98
+ app.get(indexHtmlPathMatcher, (_, res)=>res.contentType('text/html').send(indexContent));
99
+ // Return static assets for any request for which we have one, except importmap.json and index.html
100
+ app.use(spaPath, express.static(source, {
101
+ index: false
102
+ }));
103
+ // Proxy requests beginning with `apiUrl` but which should not serve `index.html`.
104
+ // This may include the JS bundles when using an import map that refers to
105
+ // JS bundles located at the same domain as `apiUrl`.
106
+ app.use(apiUrl, createProxyMiddleware((path)=>{
107
+ return new RegExp(`${apiUrl}/.*`).test(path) && !indexHtmlPathMatcher.test(path);
108
+ }, {
109
+ target: backend,
110
+ changeOrigin: true,
111
+ onProxyReq (proxyReq) {
112
+ if (addCookie) {
113
+ const origCookie = proxyReq.getHeader('cookie');
114
+ const newCookie = `${origCookie};${addCookie}`;
115
+ proxyReq.setHeader('cookie', newCookie);
116
+ }
117
+ }
118
+ }));
119
+ const server = app.listen(port, host, ()=>{
120
+ logInfo(`Listening at http://${host}:${port}`);
121
+ logInfo(`SPA available at ${pageUrl}`);
122
+ if (open) {
123
+ import("open").then(({ default: open })=>{
124
+ setTimeout(()=>open(pageUrl, {
125
+ wait: false
126
+ }).catch(()=>{
127
+ logWarn(`Unable to open "${pageUrl}" in browser. If you are running in a headless environment, please do not use the --open flag.`);
128
+ }), 2000);
129
+ });
130
+ }
131
+ });
132
+ signal?.addEventListener('abort', ()=>server.close());
133
+ // Keep the promise pending so the runner process doesn't exit
134
+ return new Promise(()=>{});
135
+ }
@@ -0,0 +1,5 @@
1
+ export * from './assemble';
2
+ export * from './build';
3
+ export * from './develop';
4
+ export * from './start';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./assemble.js";
2
+ export * from "./build.js";
3
+ export * from "./develop.js";
4
+ export * from "./start.js";
@@ -0,0 +1,9 @@
1
+ export interface StartArgs {
2
+ port: number;
3
+ host: string;
4
+ open: boolean;
5
+ backend: string;
6
+ addCookie: string;
7
+ }
8
+ export declare function runStart(args: StartArgs, signal?: AbortSignal): Promise<void>;
9
+ //# sourceMappingURL=start.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,WAAW,iBA4C7D"}
@@ -0,0 +1,44 @@
1
+ import { createRequire } from "node:module";
2
+ import express from "express";
3
+ import { createProxyMiddleware } from "http-proxy-middleware";
4
+ import { resolve } from "node:path";
5
+ import { logInfo, logWarn } from "../utils/index.js";
6
+ export function runStart(args, signal) {
7
+ const { backend, host, port, open, addCookie } = args;
8
+ const app = express();
9
+ const require = createRequire(import.meta.url);
10
+ const source = resolve(require.resolve('@egen-civitas/esm-app-shell/package.json'), '..', 'dist');
11
+ const index = resolve(source, 'index.html');
12
+ const spaPath = '/egen-civitas/spa';
13
+ const pageUrl = `http://${host}:${port}${spaPath}`;
14
+ app.use(spaPath, express.static(source));
15
+ app.use('/egen', createProxyMiddleware([
16
+ `/egen-civitas/**`,
17
+ `!${spaPath}/**`
18
+ ], {
19
+ target: backend,
20
+ changeOrigin: true,
21
+ onProxyReq (proxyReq) {
22
+ if (addCookie) {
23
+ const origCookie = proxyReq.getHeader('cookie');
24
+ const newCookie = `${origCookie};${addCookie}`;
25
+ proxyReq.setHeader('cookie', newCookie);
26
+ }
27
+ }
28
+ }));
29
+ app.get('/*', (_, res)=>res.sendFile(index));
30
+ const server = app.listen(port, host, async ()=>{
31
+ logInfo(`Listening at http://${host}:${port}`);
32
+ logInfo(`SPA available at ${pageUrl}`);
33
+ if (open) {
34
+ const { default: openUrl } = await import("open");
35
+ openUrl(pageUrl, {
36
+ wait: false
37
+ }).catch(()=>{
38
+ logWarn(`Unable to open "${pageUrl}" in browser. If you are running in a headless environment, please do not use the --open flag.`);
39
+ });
40
+ }
41
+ });
42
+ signal?.addEventListener('abort', ()=>server.close());
43
+ return new Promise(()=>{});
44
+ }
@@ -0,0 +1,3 @@
1
+ import * as commands from './commands';
2
+ export { commands };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import * as commands from "./commands/index.js";
2
+ export { commands };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":""}
package/dist/runner.js ADDED
@@ -0,0 +1,14 @@
1
+ import * as commands from "./commands/index.js";
2
+ import { logFail } from "./utils/index.js";
3
+ process.on('message', async ({ type, args })=>{
4
+ const command = commands[type];
5
+ if (typeof command === 'function') {
6
+ try {
7
+ await command(args);
8
+ process.exit(0);
9
+ } catch (err) {
10
+ logFail(err.message);
11
+ process.exit(1);
12
+ }
13
+ }
14
+ });
@@ -0,0 +1,24 @@
1
+ import type { ImportmapDeclaration, RoutesDeclaration } from './importmap';
2
+ export interface BuildOptions {
3
+ backend?: string;
4
+ defaultLocale?: string;
5
+ importmap?: ImportmapDeclaration;
6
+ routes?: RoutesDeclaration;
7
+ apiUrl?: string;
8
+ spaPath?: string;
9
+ pageTitle?: string;
10
+ supportOffline?: boolean;
11
+ configUrls?: Array<string>;
12
+ env?: string;
13
+ coreAppsDir?: string;
14
+ addCookie?: string;
15
+ fresh?: boolean;
16
+ assets?: Array<string>;
17
+ }
18
+ /**
19
+ * Maps {@link BuildOptions} to the `EGEN_*` environment variables that the
20
+ * rspack config reads at evaluation time.
21
+ */
22
+ export declare function setBundlerEnv(options?: BuildOptions): void;
23
+ export declare function loadBundlerConfig(options?: BuildOptions): import("@rspack/core").RspackOptions;
24
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAG3E,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,YAAiB,QA2EvD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,YAAiB,wCAa3D"}
@@ -0,0 +1,75 @@
1
+ import { createRequire } from "node:module";
2
+ import { setEnvVariables } from "./variables.js";
3
+ /**
4
+ * Maps {@link BuildOptions} to the `EGEN_*` environment variables that the
5
+ * rspack config reads at evaluation time.
6
+ */ export function setBundlerEnv(options = {}) {
7
+ const variables = {};
8
+ if (typeof options.backend === 'string') {
9
+ variables.EGEN_PROXY_TARGET = options.backend;
10
+ }
11
+ if (typeof options.spaPath === 'string') {
12
+ variables.EGEN_PUBLIC_PATH = options.spaPath;
13
+ }
14
+ if (typeof options.apiUrl === 'string') {
15
+ variables.EGEN_API_URL = options.apiUrl;
16
+ }
17
+ if (typeof options.pageTitle === 'string') {
18
+ variables.EGEN_PAGE_TITLE = options.pageTitle;
19
+ }
20
+ if (typeof options.addCookie === 'string') {
21
+ variables.EGEN_ADD_COOKIE = options.addCookie;
22
+ }
23
+ if (typeof options.supportOffline === 'boolean') {
24
+ variables.EGEN_OFFLINE = options.supportOffline ? 'enable' : 'disable';
25
+ }
26
+ if (Array.isArray(options.configUrls)) {
27
+ variables.EGEN_CONFIG_URLS = options.configUrls.join(';');
28
+ }
29
+ if (typeof options.env === 'string') {
30
+ variables.EGEN_ENV = options.env;
31
+ variables.NODE_ENV = options.env;
32
+ }
33
+ if (typeof options.defaultLocale === 'string') {
34
+ variables.EGEN_ESM_DEFAULT_LOCALE = options.defaultLocale;
35
+ }
36
+ if (typeof options.importmap === 'object') {
37
+ switch(options.importmap.type){
38
+ case 'inline':
39
+ variables.EGEN_ESM_IMPORTMAP = options.importmap.value;
40
+ break;
41
+ case 'url':
42
+ variables.EGEN_ESM_IMPORTMAP_URL = options.importmap.value;
43
+ break;
44
+ }
45
+ }
46
+ if (typeof options.routes === 'object') {
47
+ switch(options.routes.type){
48
+ case 'inline':
49
+ variables.EGEN_ROUTES = options.routes.value;
50
+ break;
51
+ case 'url':
52
+ variables.EGEN_ROUTES_URL = options.routes.value;
53
+ break;
54
+ }
55
+ }
56
+ if (typeof options.coreAppsDir === 'string') {
57
+ variables.EGEN_ESM_CORE_APPS_DIR = options.coreAppsDir;
58
+ }
59
+ if (typeof options.fresh === 'boolean') {
60
+ variables.EGEN_CLEAN_BEFORE_BUILD = options.fresh;
61
+ }
62
+ if (Array.isArray(options.assets)) {
63
+ variables.EGEN_JS_CSS_ASSETS = options.assets.join(';');
64
+ }
65
+ setEnvVariables(variables);
66
+ }
67
+ export function loadBundlerConfig(options = {}) {
68
+ setBundlerEnv(options);
69
+ const require = createRequire(import.meta.url);
70
+ const config = require('@egen-civitas/esm-app-shell/rspack.config.js');
71
+ if (typeof config === 'function') {
72
+ return config({});
73
+ }
74
+ return config;
75
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=debugger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debugger.d.ts","sourceRoot":"","sources":["../../src/utils/debugger.ts"],"names":[],"mappings":""}
@@ -0,0 +1,66 @@
1
+ import { createRequire } from "node:module";
2
+ import { rspack } from "@rspack/core";
3
+ import { RspackDevServer } from "@rspack/dev-server";
4
+ import { dirname } from "node:path";
5
+ import webpack from "webpack";
6
+ import WebpackDevServer from "webpack-dev-server";
7
+ import { logInfo } from "./logger.js";
8
+ function getWebpackEnv() {
9
+ return {
10
+ ...process.env,
11
+ analyze: process.env.BUNDLE_ANALYZE === 'true',
12
+ production: process.env.NODE_ENV === 'production',
13
+ development: process.env.NODE_ENV === 'development'
14
+ };
15
+ }
16
+ function loadConfig(configPath) {
17
+ const require = createRequire(import.meta.url);
18
+ const content = require(configPath);
19
+ if (typeof content === 'function') {
20
+ return content(getWebpackEnv());
21
+ }
22
+ return content;
23
+ }
24
+ function startDevServer(configPath, port, useRspack = false) {
25
+ const config = loadConfig(configPath);
26
+ const devServerOptions = {
27
+ ...config.devServer,
28
+ port,
29
+ static: dirname(configPath)
30
+ };
31
+ let compilationDone = false;
32
+ let serverListening = false;
33
+ function signalReadyIfBothDone() {
34
+ if (compilationDone && serverListening) {
35
+ process.send?.({
36
+ type: 'compilation-complete'
37
+ });
38
+ }
39
+ }
40
+ let server;
41
+ if (!useRspack) {
42
+ const compiler = webpack(config);
43
+ compiler.hooks.done.tap('EgenDevServer', ()=>{
44
+ if (!compilationDone) {
45
+ compilationDone = true;
46
+ signalReadyIfBothDone();
47
+ }
48
+ });
49
+ server = new WebpackDevServer(devServerOptions, compiler);
50
+ } else {
51
+ const compiler = rspack(config);
52
+ compiler.hooks.done.tap('EgenDevServer', ()=>{
53
+ if (!compilationDone) {
54
+ compilationDone = true;
55
+ signalReadyIfBothDone();
56
+ }
57
+ });
58
+ server = new RspackDevServer(devServerOptions, compiler);
59
+ }
60
+ server.startCallback(()=>{
61
+ logInfo(`Listening at http://localhost:${port}`);
62
+ serverListening = true;
63
+ signalReadyIfBothDone();
64
+ });
65
+ }
66
+ process.on('message', ({ source, port, useRspack })=>startDevServer(source, port, useRspack));
@@ -0,0 +1,9 @@
1
+ import type { PackageJson } from './types';
2
+ export declare function getSharedDependencies(): any;
3
+ export declare function getMainBundle(project: PackageJson): {
4
+ path: string;
5
+ name: string;
6
+ dir: string;
7
+ };
8
+ export declare function getAppRoutes(sourceDirectory: string, project: PackageJson): Record<string, unknown>;
9
+ //# sourceMappingURL=dependencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencies.d.ts","sourceRoot":"","sources":["../../src/utils/dependencies.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,wBAAgB,qBAAqB,QAGpC;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW;;;;EAcjD;AAED,wBAAgB,YAAY,CAAC,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAsBnG"}
@@ -0,0 +1,37 @@
1
+ import { createRequire } from "node:module";
2
+ import { basename, dirname, resolve } from "node:path";
3
+ import { existsSync, readFileSync, statSync } from "node:fs";
4
+ import { inc } from "semver";
5
+ export function getSharedDependencies() {
6
+ const require = createRequire(import.meta.url);
7
+ return require('@egen-civitas/esm-app-shell/dependencies.json');
8
+ }
9
+ export function getMainBundle(project) {
10
+ const file = project.browser || project.module || project.main;
11
+ if (!file) {
12
+ throw Error('Could not find project to run. If you ran this outside of a directory containing an app, make sure you specify --sources.');
13
+ }
14
+ return {
15
+ path: file,
16
+ name: basename(file),
17
+ dir: dirname(file)
18
+ };
19
+ }
20
+ export function getAppRoutes(sourceDirectory, project) {
21
+ const routesPath = resolve(sourceDirectory, 'src', 'routes.json');
22
+ if (!existsSync(routesPath)) {
23
+ return {};
24
+ }
25
+ const stats = statSync(routesPath);
26
+ if (!stats.isFile()) {
27
+ return {};
28
+ }
29
+ const json = JSON.parse(readFileSync(routesPath, {
30
+ encoding: 'utf-8'
31
+ }));
32
+ if (!(typeof json === 'object')) {
33
+ return {};
34
+ }
35
+ json['version'] = project.version ? inc(project.version, 'prerelease', 'local') : undefined;
36
+ return json;
37
+ }
@@ -0,0 +1,5 @@
1
+ export declare function startDevServer(source: string, port: number, cwd?: string, useRspack?: boolean): {
2
+ process: import("child_process").ChildProcess;
3
+ ready: Promise<void>;
4
+ };
5
+ //# sourceMappingURL=devserver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devserver.d.ts","sourceRoot":"","sources":["../../src/utils/devserver.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,SAAgB,EAAE,SAAS,GAAE,OAAe;;;EAqB3G"}