@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.
- package/README.md +71 -0
- package/bin/rspack.cjs +9 -0
- package/bin/webpack.cjs +6 -0
- package/default-rspack-config.cjs +3 -0
- package/default-webpack-config.cjs +3 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +266 -0
- package/dist/commands/assemble.d.ts +13 -0
- package/dist/commands/assemble.d.ts.map +1 -0
- package/dist/commands/assemble.js +225 -0
- package/dist/commands/build.d.ts +32 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +86 -0
- package/dist/commands/debug.d.ts +14 -0
- package/dist/commands/debug.d.ts.map +1 -0
- package/dist/commands/debug.js +37 -0
- package/dist/commands/develop.d.ts +18 -0
- package/dist/commands/develop.d.ts.map +1 -0
- package/dist/commands/develop.js +135 -0
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +4 -0
- package/dist/commands/start.d.ts +9 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +44 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/runner.d.ts +2 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +14 -0
- package/dist/utils/config.d.ts +24 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +75 -0
- package/dist/utils/debugger.d.ts +2 -0
- package/dist/utils/debugger.d.ts.map +1 -0
- package/dist/utils/debugger.js +66 -0
- package/dist/utils/dependencies.d.ts +9 -0
- package/dist/utils/dependencies.d.ts.map +1 -0
- package/dist/utils/dependencies.js +37 -0
- package/dist/utils/devserver.d.ts +5 -0
- package/dist/utils/devserver.d.ts.map +1 -0
- package/dist/utils/devserver.js +30 -0
- package/dist/utils/helpers.d.ts +4 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/helpers.js +16 -0
- package/dist/utils/importmap.d.ts +53 -0
- package/dist/utils/importmap.d.ts.map +1 -0
- package/dist/utils/importmap.js +312 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +10 -0
- package/dist/utils/npmConfig.d.ts +14 -0
- package/dist/utils/npmConfig.d.ts.map +1 -0
- package/dist/utils/npmConfig.js +39 -0
- package/dist/utils/packages.d.ts +15 -0
- package/dist/utils/packages.d.ts.map +1 -0
- package/dist/utils/packages.js +92 -0
- package/dist/utils/port.d.ts +15 -0
- package/dist/utils/port.d.ts.map +1 -0
- package/dist/utils/port.js +44 -0
- package/dist/utils/types.d.ts +16 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +1 -0
- package/dist/utils/untar.d.ts +5 -0
- package/dist/utils/untar.d.ts.map +1 -0
- package/dist/utils/untar.js +14 -0
- package/dist/utils/variables.d.ts +2 -0
- package/dist/utils/variables.d.ts.map +1 -0
- package/dist/utils/variables.js +5 -0
- package/package.json +116 -0
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# egen
|
|
2
|
+
|
|
3
|
+
The one stop CLI for using the Egen 3.0 Frontend app.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
You need Node.js (>= 20.11.0) with NPM. We recommend using version 22 (LTS) or later.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
You can run the tool without installation using `npx`, which is part of NPM. Just make sure to fulfill the prerequisites.
|
|
12
|
+
|
|
13
|
+
Alternatively, install the application globally using `npm i -g @egen-civitas/egen`. Then you can run the tool without `npx`, e.g., instead of `npx @egen-civitas/egen ...` you run `egen ...`.
|
|
14
|
+
|
|
15
|
+
## Available Commands
|
|
16
|
+
|
|
17
|
+
The following commands are available. For an up-to-date help on your installation run `npx @egen-civitas/egen --help`.
|
|
18
|
+
|
|
19
|
+
The `--help` flag can also be applied to any command below, resulting in detailed information about the available options.
|
|
20
|
+
|
|
21
|
+
### `start`
|
|
22
|
+
|
|
23
|
+
> For developers.
|
|
24
|
+
|
|
25
|
+
Starts the app shell configured for the SPA reference application. Includes a default import map working against a working snapshot on the CDN.
|
|
26
|
+
|
|
27
|
+
Example:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
# run the command
|
|
31
|
+
npx @egen-civitas/egen
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### `develop`
|
|
35
|
+
|
|
36
|
+
> For developers and implementers.
|
|
37
|
+
|
|
38
|
+
Performs a debug build of the app shell and runs it against a given Egen backend. Can be proxied to any network and used with any import map configuration.
|
|
39
|
+
|
|
40
|
+
Example:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
# run the command
|
|
44
|
+
npx @egen-civitas/egen develop
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `build`
|
|
48
|
+
|
|
49
|
+
> For implementers.
|
|
50
|
+
|
|
51
|
+
Builds the app shell with a given configuration. Provides the assets necessary for the app shell in a distribution.
|
|
52
|
+
|
|
53
|
+
Example:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
# run the command
|
|
57
|
+
npx @egen-civitas/egen build
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### `assemble`
|
|
61
|
+
|
|
62
|
+
> For implementers.
|
|
63
|
+
|
|
64
|
+
Assembles an import map incl. assets to provide the frontend module assets for a distribution.
|
|
65
|
+
|
|
66
|
+
Example:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
# run the command
|
|
70
|
+
npx @egen-civitas/egen assemble
|
|
71
|
+
```
|
package/bin/rspack.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Re-export the rspack CLI so that packages depending on
|
|
4
|
+
// egen get the `rspack` command without needing a direct
|
|
5
|
+
// dependency on @rspack/cli.
|
|
6
|
+
const { RspackCLI } = require('@rspack/cli');
|
|
7
|
+
|
|
8
|
+
const cli = new RspackCLI();
|
|
9
|
+
cli.run(process.argv);
|
package/bin/webpack.cjs
ADDED
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAc,EAAE,KAAK,IAAI,EAAE,MAAM,OAAO,CAAC;AAkCzC,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,YAmW/B"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import yargs from "yargs";
|
|
3
|
+
import { fork } from "child_process";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { getAvailablePort, getImportmapAndRoutes, isPortAvailable, logFail, mergeImportmapAndRoutes, proxyImportmapAndRoutes, resolvePackages, runProject, trimEnd } from "./utils/index.js";
|
|
6
|
+
const runner = resolve(import.meta.dirname, `runner.js`);
|
|
7
|
+
const root = resolve(import.meta.dirname, '..');
|
|
8
|
+
function runCommand(type, args) {
|
|
9
|
+
const ps = fork(runner, [], {
|
|
10
|
+
cwd: type === 'runBuild' ? root : process.cwd()
|
|
11
|
+
});
|
|
12
|
+
ps.send({
|
|
13
|
+
type,
|
|
14
|
+
args
|
|
15
|
+
});
|
|
16
|
+
ps.on('exit', (code)=>process.exit(code || 0));
|
|
17
|
+
}
|
|
18
|
+
export function buildCli(y) {
|
|
19
|
+
y.command('develop', 'Starts a new frontend module development session with the Egen app shell.', (argv)=>argv.option('port', {
|
|
20
|
+
describe: 'The port where the dev server should run. Defaults to 8081, or the next available port.',
|
|
21
|
+
type: 'number'
|
|
22
|
+
}).option('host', {
|
|
23
|
+
default: 'localhost',
|
|
24
|
+
describe: 'The host name or IP for the server to use.',
|
|
25
|
+
type: 'string'
|
|
26
|
+
}).option('backend', {
|
|
27
|
+
default: 'http://localhost:8081',
|
|
28
|
+
describe: 'The backend to proxy API requests to.',
|
|
29
|
+
type: 'string',
|
|
30
|
+
coerce: (arg)=>arg.endsWith('/') ? arg.slice(0, -1) : arg
|
|
31
|
+
}).option('add-cookie', {
|
|
32
|
+
default: '',
|
|
33
|
+
describe: 'Additional cookies to provide when proxying.',
|
|
34
|
+
type: 'string'
|
|
35
|
+
}).option('spa-path', {
|
|
36
|
+
default: '/egen-civitas/spa/',
|
|
37
|
+
describe: 'The path of the application on the target server.',
|
|
38
|
+
type: 'string'
|
|
39
|
+
}).option('api-url', {
|
|
40
|
+
default: '/egen-civitas/',
|
|
41
|
+
describe: 'The URL of the API. Can be a path if the API is on the same target server.',
|
|
42
|
+
type: 'string'
|
|
43
|
+
}).option('open', {
|
|
44
|
+
default: true,
|
|
45
|
+
describe: 'Immediately opens the SPA page URL in the browser.',
|
|
46
|
+
type: 'boolean'
|
|
47
|
+
}).option('config-url', {
|
|
48
|
+
default: [],
|
|
49
|
+
describe: 'The URL to a valid frontend configuration. Can be used multiple times.',
|
|
50
|
+
type: 'array',
|
|
51
|
+
string: true
|
|
52
|
+
}).option('config-file', {
|
|
53
|
+
default: [],
|
|
54
|
+
describe: 'The path to a frontend configuration file. Can be used multiple times.',
|
|
55
|
+
type: 'array',
|
|
56
|
+
string: true
|
|
57
|
+
}).option('sources', {
|
|
58
|
+
describe: 'Runs the projects from the provided source directories. Can be used multiple times. Defaults to the current directory if neither --sources nor --packages is specified.',
|
|
59
|
+
type: 'array',
|
|
60
|
+
string: true
|
|
61
|
+
}).option('packages', {
|
|
62
|
+
default: [],
|
|
63
|
+
describe: 'Runs the projects by package name, resolved from the current workspace. Can be used multiple times.',
|
|
64
|
+
type: 'array',
|
|
65
|
+
string: true
|
|
66
|
+
}).option('shared-dependencies', {
|
|
67
|
+
default: [],
|
|
68
|
+
describe: 'The additional shared dependencies besides the ones from the app shell.',
|
|
69
|
+
type: 'array'
|
|
70
|
+
}).option('importmap', {
|
|
71
|
+
default: 'importmap.json',
|
|
72
|
+
describe: 'The import map to use. Can be a path to a valid import map to be taken literally, an URL, or a fixed JSON object.',
|
|
73
|
+
type: 'string'
|
|
74
|
+
}).option('routes', {
|
|
75
|
+
default: 'routes.registry.json',
|
|
76
|
+
describe: 'The routes.registry.json file to use. Can be a path to a valid routes registry to be taken literally, an URL, or a fixed JSON object.',
|
|
77
|
+
type: 'string'
|
|
78
|
+
}).option('support-offline', {
|
|
79
|
+
default: false,
|
|
80
|
+
describe: 'Determines if a service worker should be installed for offline support.',
|
|
81
|
+
type: 'boolean'
|
|
82
|
+
}).option('use-rspack', {
|
|
83
|
+
default: undefined,
|
|
84
|
+
describe: "Set this flag to force the CLI to attempt to use the Rspack Dev Server. Note that this will fail if the project you are using it in doesn't use Rspack.",
|
|
85
|
+
type: 'boolean'
|
|
86
|
+
}), async (args)=>{
|
|
87
|
+
let port;
|
|
88
|
+
if (args.port === undefined) {
|
|
89
|
+
port = await getAvailablePort(8081);
|
|
90
|
+
} else {
|
|
91
|
+
// handle case where user has specified a port to run on
|
|
92
|
+
if (!await isPortAvailable(args.port)) {
|
|
93
|
+
console.error(`Error: Port ${args.port} is already in use. Please choose a different port.`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
port = args.port;
|
|
97
|
+
}
|
|
98
|
+
let resolvedFromPackages = [];
|
|
99
|
+
if (args.packages.length > 0) {
|
|
100
|
+
try {
|
|
101
|
+
resolvedFromPackages = await resolvePackages(args.packages);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
logFail(e.message);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const explicitSources = args.sources ?? [];
|
|
108
|
+
const combined = [
|
|
109
|
+
...explicitSources,
|
|
110
|
+
...resolvedFromPackages
|
|
111
|
+
];
|
|
112
|
+
// De-duplicate by resolved absolute path
|
|
113
|
+
const seen = new Set();
|
|
114
|
+
const deduplicated = combined.filter((s)=>{
|
|
115
|
+
const abs = resolve(s);
|
|
116
|
+
if (seen.has(abs)) return false;
|
|
117
|
+
seen.add(abs);
|
|
118
|
+
return true;
|
|
119
|
+
});
|
|
120
|
+
const sources = deduplicated.length > 0 ? deduplicated : [
|
|
121
|
+
'.'
|
|
122
|
+
];
|
|
123
|
+
runCommand('runDevelop', {
|
|
124
|
+
configUrls: args['config-url'],
|
|
125
|
+
configFiles: args['config-file'],
|
|
126
|
+
...args,
|
|
127
|
+
port,
|
|
128
|
+
...proxyImportmapAndRoutes(await mergeImportmapAndRoutes(await getImportmapAndRoutes(args.importmap, args.routes, port), await runProject(port, sources, args['use-rspack']), args.backend, args.spaPath), args.backend, args.spaPath)
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
y.command('build', 'Builds a new app shell.', (argv)=>argv.option('target', {
|
|
132
|
+
default: 'dist',
|
|
133
|
+
describe: 'The target directory where the build artifacts will be stored.',
|
|
134
|
+
type: 'string',
|
|
135
|
+
coerce: (arg)=>resolve(process.cwd(), arg)
|
|
136
|
+
}).option('registry', {
|
|
137
|
+
alias: 'reg',
|
|
138
|
+
default: 'https://registry.npmjs.org/',
|
|
139
|
+
describe: 'The NPM registry used for getting the packages.',
|
|
140
|
+
type: 'string'
|
|
141
|
+
}).option('fresh', {
|
|
142
|
+
default: false,
|
|
143
|
+
describe: 'Whether to clear the output directory before running the build.',
|
|
144
|
+
type: 'boolean'
|
|
145
|
+
}).option('support-offline', {
|
|
146
|
+
default: false,
|
|
147
|
+
describe: 'Determines if a service worker should be installed for offline support.',
|
|
148
|
+
type: 'boolean'
|
|
149
|
+
}).option('build-config', {
|
|
150
|
+
describe: 'Path to the SPA build config JSON',
|
|
151
|
+
type: 'string',
|
|
152
|
+
coerce: (arg)=>resolve(process.cwd(), arg)
|
|
153
|
+
}).option('spa-path', {
|
|
154
|
+
default: '/egen-civitas/spa/',
|
|
155
|
+
describe: 'The path of the application on the target server.',
|
|
156
|
+
type: 'string'
|
|
157
|
+
}).option('page-title', {
|
|
158
|
+
default: 'Egen',
|
|
159
|
+
describe: 'The title of the web app usually displayed in the browser tab.'
|
|
160
|
+
}).option('api-url', {
|
|
161
|
+
default: '/egen-civitas/',
|
|
162
|
+
describe: 'The URL of the API. Can be a path if the API is on the same target server.',
|
|
163
|
+
type: 'string'
|
|
164
|
+
}).option('config-url', {
|
|
165
|
+
default: [],
|
|
166
|
+
describe: 'The URL to a frontend configuration. Can be used multiple times. Resolved by the client during initialization.',
|
|
167
|
+
type: 'array',
|
|
168
|
+
string: true
|
|
169
|
+
}).option('config-path', {
|
|
170
|
+
default: [],
|
|
171
|
+
describe: 'The path to a frontend configuration file. Can be used multiple times. The file is copied directly into the build directory.',
|
|
172
|
+
type: 'array',
|
|
173
|
+
coerce: (arg)=>arg.map((p)=>resolve(process.cwd(), p))
|
|
174
|
+
}).option('importmap', {
|
|
175
|
+
default: undefined,
|
|
176
|
+
describe: 'The import map to use. Can be a path to an import map to be taken literally, an URL, or a fixed JSON object.',
|
|
177
|
+
type: 'string'
|
|
178
|
+
}).option('routes', {
|
|
179
|
+
default: undefined,
|
|
180
|
+
describe: 'The routes registry to use. Can be a path to an routes registry to be taken literally, an URL, or a fixed JSON object.',
|
|
181
|
+
type: 'string'
|
|
182
|
+
}).option('default-locale', {
|
|
183
|
+
default: '',
|
|
184
|
+
describe: "The locale to use as a default for this build of the app shell. Should be a value that's valid to use in an HTML lang attribute, e.g., en or en_GB.",
|
|
185
|
+
type: 'string'
|
|
186
|
+
}).option('env', {
|
|
187
|
+
default: 'production',
|
|
188
|
+
describe: 'The environment to build for. e.g., development, production.',
|
|
189
|
+
type: 'string'
|
|
190
|
+
}).option('asset', {
|
|
191
|
+
default: [],
|
|
192
|
+
describe: "The path to CSS or JS assets to copy into 'assets/' in the build directory, and include as <link> and <script> tags in the generated HTML. Can be used multiple times.",
|
|
193
|
+
type: 'array',
|
|
194
|
+
coerce: (arg)=>arg.map((p)=>resolve(process.cwd(), p))
|
|
195
|
+
}), async (args)=>runCommand('runBuild', {
|
|
196
|
+
...args,
|
|
197
|
+
configUrls: args['config-url'],
|
|
198
|
+
configPaths: args['config-path'],
|
|
199
|
+
assets: args['asset']
|
|
200
|
+
}));
|
|
201
|
+
y.command('assemble', 'Assembles an import map incl. all required resources.', (argv)=>argv.option('target', {
|
|
202
|
+
default: 'dist',
|
|
203
|
+
description: 'The target directory where the gathered artifacts will be stored.',
|
|
204
|
+
type: 'string',
|
|
205
|
+
coerce: (arg)=>resolve(process.cwd(), arg)
|
|
206
|
+
}).option('registry', {
|
|
207
|
+
alias: 'reg',
|
|
208
|
+
default: '',
|
|
209
|
+
description: 'The NPM registry used for getting the packages.',
|
|
210
|
+
type: 'string',
|
|
211
|
+
coerce: (arg)=>trimEnd(arg, '/')
|
|
212
|
+
}).option('config', {
|
|
213
|
+
default: [
|
|
214
|
+
'spa-build-config.json'
|
|
215
|
+
],
|
|
216
|
+
description: 'Path to a SPA assemble config JSON.',
|
|
217
|
+
type: 'array',
|
|
218
|
+
coerce: (arg)=>arg.map((p)=>resolve(process.cwd(), p))
|
|
219
|
+
}).option('config-file', {
|
|
220
|
+
default: [],
|
|
221
|
+
describe: 'Reference to a frontend configuration file. Can be used multiple times. Configurations are merged in the order specified into egen-config.json.',
|
|
222
|
+
type: 'array',
|
|
223
|
+
coerce: (arg)=>arg.map((p)=>resolve(process.cwd(), p))
|
|
224
|
+
}).option('hash-files', {
|
|
225
|
+
default: false,
|
|
226
|
+
alias: [
|
|
227
|
+
'hasn',
|
|
228
|
+
'hash-importmap'
|
|
229
|
+
],
|
|
230
|
+
description: 'Determines whether to include a content-specific hash for the generated JSON files. This is useful if you want to be able to cache those files.',
|
|
231
|
+
type: 'boolean'
|
|
232
|
+
}).option('fresh', {
|
|
233
|
+
default: false,
|
|
234
|
+
description: 'Determines if the output directory should be cleaned before the run.',
|
|
235
|
+
type: 'boolean'
|
|
236
|
+
}).option('manifest', {
|
|
237
|
+
default: false,
|
|
238
|
+
description: 'Whether to output a manifest',
|
|
239
|
+
type: 'boolean'
|
|
240
|
+
}).option('build-routes', {
|
|
241
|
+
default: true,
|
|
242
|
+
description: 'Whether to compile all module routes.json into a master routes.json',
|
|
243
|
+
type: 'boolean'
|
|
244
|
+
}).option('mode', {
|
|
245
|
+
choices: [
|
|
246
|
+
'config',
|
|
247
|
+
'survey'
|
|
248
|
+
],
|
|
249
|
+
default: 'survey',
|
|
250
|
+
description: 'The source of the frontend modules to assemble. `config` uses a configuration file specified via `--config`. `survey` starts an interactive command-line survey.',
|
|
251
|
+
type: 'string'
|
|
252
|
+
}), (args)=>runCommand('runAssemble', {
|
|
253
|
+
...args,
|
|
254
|
+
configFiles: args['config-file']
|
|
255
|
+
}));
|
|
256
|
+
y.command([
|
|
257
|
+
'start',
|
|
258
|
+
'$0'
|
|
259
|
+
], 'Starts the app shell using the provided configuration. This uses express for serving static files with some proxy middleware.', (argv)=>argv.number('port').default('port', 8081).describe('port', 'The port where the dev server should run.').string('host').default('host', 'localhost').describe('host', 'The host name or IP for the server to use.').string('backend').default('backend', 'http://localhost:8081/').describe('backend', 'The backend to proxy API requests to.').string('add-cookie').default('add-cookie', '').describe('add-cookie', 'Additional cookies to provide when proxying.').boolean('open').default('open', false).describe('open', 'Immediately opens the SPA page URL in the browser.'), (args)=>runCommand('runStart', {
|
|
260
|
+
...args
|
|
261
|
+
}));
|
|
262
|
+
return y.epilog('The SPA assemble config JSON is a JSON file, typically `spa-assemble-config.json`, which defines parameters for the `build` and `assemble` ' + 'commands. The keys used by `build` are:\n' + ' `apiUrl`, `spaPath`, `configPaths`, `configUrls`, `importmap`, `pageTitle`, and `supportOffline`;\n' + 'each of which is equivalent to the corresponding command line argument (see `egen build --help`). ' + 'Multiple values provided to `configPaths` and `configUrls` should be comma-separated.\n' + 'The keys used by `assemble` are:\n' + ' frontendModules \tAn object which specifies which frontend modules to include. It should have package names ' + 'for keys and versions for values.\n' + ' publicUrl \tThe URL at which the frontend modules will be made available. Can be relative to the importmap. ' + 'Defaults to `.` (which means they will be colocated with the import map).\n\n' + 'For more information visit https://github.com/egen-civitas/egen-esm-core.').help().demandCommand().strict();
|
|
263
|
+
}
|
|
264
|
+
// In ESM, the yargs default export is a factory function, not a pre-invoked Argv instance.
|
|
265
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
266
|
+
buildCli(yargs(process.argv.slice(2))).argv;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface AssembleArgs {
|
|
2
|
+
target: string;
|
|
3
|
+
mode: string;
|
|
4
|
+
config: Array<string>;
|
|
5
|
+
registry?: string;
|
|
6
|
+
configFiles: Array<string>;
|
|
7
|
+
hashFiles: boolean;
|
|
8
|
+
fresh: boolean;
|
|
9
|
+
buildRoutes: boolean;
|
|
10
|
+
manifest: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function runAssemble(args: AssembleArgs): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=assemble.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assemble.d.ts","sourceRoot":"","sources":["../../src/commands/assemble.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAuMD,wBAAsB,WAAW,CAAC,IAAI,EAAE,YAAY,iBAgGnD"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import merge from "lodash/merge.js";
|
|
3
|
+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { resolve, dirname, basename } from "node:path";
|
|
6
|
+
import { Readable } from "node:stream";
|
|
7
|
+
import { checkbox, input } from "@inquirer/prompts";
|
|
8
|
+
import npmRegistryFetch from "npm-registry-fetch";
|
|
9
|
+
import pacote from "pacote";
|
|
10
|
+
import semver from "semver";
|
|
11
|
+
import { contentHash, logInfo, logWarn, untar } from "../utils/index.js";
|
|
12
|
+
import { getNpmRegistryConfiguration } from "../utils/npmConfig.js";
|
|
13
|
+
async function readConfig(mode, configs, fetchOptions) {
|
|
14
|
+
switch(mode){
|
|
15
|
+
// curly-braces are here to add a lexical scope which allows us to safely
|
|
16
|
+
// declare variables
|
|
17
|
+
case 'config':
|
|
18
|
+
{
|
|
19
|
+
if (configs.length === 0) {
|
|
20
|
+
configs = [
|
|
21
|
+
resolve(process.cwd(), 'spa-build-config.json')
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
const results = {
|
|
25
|
+
configs: [],
|
|
26
|
+
errors: []
|
|
27
|
+
};
|
|
28
|
+
for (const config of configs){
|
|
29
|
+
if (!existsSync(config)) {
|
|
30
|
+
results.errors.push(new Error(`Could not find the config file "${config}".`));
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
logInfo(`Reading configuration ${config} ...`);
|
|
34
|
+
results.configs.push({
|
|
35
|
+
...JSON.parse(await readFile(config, 'utf8'))
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (results.errors.length > 0) {
|
|
39
|
+
throw new Error(results.errors.reduce((str, e, idx)=>{
|
|
40
|
+
if (idx > 0) {
|
|
41
|
+
str += '\n\n';
|
|
42
|
+
}
|
|
43
|
+
return str + e.message;
|
|
44
|
+
}, ''));
|
|
45
|
+
}
|
|
46
|
+
return results.configs.reduce((config, newConfig)=>{
|
|
47
|
+
// excludes are processed for each config in turn; this ensure that modules removed in one config can
|
|
48
|
+
// be added back by providing another config override
|
|
49
|
+
if (Array.isArray(newConfig.frontendModuleExcludes)) {
|
|
50
|
+
newConfig.frontendModuleExcludes.forEach((exclude)=>{
|
|
51
|
+
if (typeof exclude === 'string' && config.frontendModules[exclude]) {
|
|
52
|
+
delete config.frontendModules[exclude];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (newConfig.frontendModules) {
|
|
57
|
+
config.frontendModules = {
|
|
58
|
+
...config.frontendModules,
|
|
59
|
+
...newConfig.frontendModules
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return config;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
case 'survey':
|
|
66
|
+
{
|
|
67
|
+
logInfo(`Loading available frontend modules ...`);
|
|
68
|
+
// see https://github.com/npm/registry/blob/main/docs/REGISTRY-API.md#get-v1search for what these
|
|
69
|
+
// options mean; in essence, we search for anything with the keyword egen that has at least one
|
|
70
|
+
// stable version; quality is down-scored because that metric favours smaller apps over core
|
|
71
|
+
// community assets. Maintenance is boosted to de-score relatively unmaintained apps, as the framework
|
|
72
|
+
// still has a fair bit of churn
|
|
73
|
+
const packages = await npmRegistryFetch.json(`/-/v1/search?text=app%20keywords:egen¬:unstable&quality=0.001&maintenance=3.0&size=250`, fetchOptions).then((res)=>res.objects.map((m)=>({
|
|
74
|
+
name: m.package.name,
|
|
75
|
+
version: m.package.version
|
|
76
|
+
})).filter((m)=>m.name.endsWith('-app')));
|
|
77
|
+
const selectedPackages = await checkbox({
|
|
78
|
+
message: 'Select frontend modules to include:',
|
|
79
|
+
choices: packages.map((pckg)=>({
|
|
80
|
+
name: pckg.name,
|
|
81
|
+
value: pckg
|
|
82
|
+
})),
|
|
83
|
+
pageSize: 20
|
|
84
|
+
});
|
|
85
|
+
const frontendModules = {};
|
|
86
|
+
for (const pckg of selectedPackages){
|
|
87
|
+
const version = await input({
|
|
88
|
+
message: `Version for "${pckg.name}"?`,
|
|
89
|
+
default: pckg.version,
|
|
90
|
+
validate: (value)=>{
|
|
91
|
+
if (!semver.validRange(value)) {
|
|
92
|
+
return `${value} does not appear to be a valid semver or version range. See https://semver.npmjs.com/#syntax-examples.`;
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
frontendModules[pckg.name] = version;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
publicUrl: '.',
|
|
101
|
+
frontendModules
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
frontendModules: {},
|
|
107
|
+
publicUrl: '.'
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async function downloadPackage(esmName, esmVersion, baseDir, fetchOptions) {
|
|
111
|
+
if (esmVersion && esmVersion.startsWith('file:')) {
|
|
112
|
+
const source = resolve(baseDir, esmVersion.substring(5));
|
|
113
|
+
return readFile(source);
|
|
114
|
+
} else if (esmVersion && /^https?:\/\//.test(esmVersion)) {
|
|
115
|
+
const response = await fetch(esmVersion);
|
|
116
|
+
if (!response.ok) {
|
|
117
|
+
throw new Error(`Failed to download package from ${esmVersion}: ${response.status} ${response.statusText}`);
|
|
118
|
+
}
|
|
119
|
+
return Buffer.from(await response.arrayBuffer());
|
|
120
|
+
} else {
|
|
121
|
+
const packageName = esmVersion ? `${esmName}@${esmVersion}` : esmName;
|
|
122
|
+
const tarManifest = await pacote.manifest(packageName, fetchOptions);
|
|
123
|
+
if (!Boolean(tarManifest) || !Boolean(tarManifest._resolved) || !Boolean(tarManifest._integrity)) {
|
|
124
|
+
throw new Error(`Failed to load manifest for ${packageName} from registry ${fetchOptions.registry}`);
|
|
125
|
+
}
|
|
126
|
+
return pacote.tarball(tarManifest._resolved, {
|
|
127
|
+
...fetchOptions,
|
|
128
|
+
integrity: tarManifest._integrity
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function extractFiles(buffer, targetDir) {
|
|
133
|
+
const packageRoot = 'package';
|
|
134
|
+
const rs = Readable.from(buffer);
|
|
135
|
+
const files = await untar(rs);
|
|
136
|
+
const packageJson = JSON.parse(files[`${packageRoot}/package.json`].toString('utf8'));
|
|
137
|
+
const version = packageJson.version ?? '0.0.0';
|
|
138
|
+
const entryModule = packageJson.browser ?? packageJson.module ?? packageJson.main;
|
|
139
|
+
const fileName = basename(entryModule);
|
|
140
|
+
const sourceDir = dirname(entryModule);
|
|
141
|
+
let outputDir = `${targetDir}-${version}`;
|
|
142
|
+
await mkdir(outputDir, {
|
|
143
|
+
recursive: true
|
|
144
|
+
});
|
|
145
|
+
await Promise.all(Object.keys(files).filter((m)=>m.startsWith(`${packageRoot}/${sourceDir}`)).map(async (m)=>{
|
|
146
|
+
const content = files[m];
|
|
147
|
+
const fileName = m.replace(`${packageRoot}/${sourceDir}/`, '');
|
|
148
|
+
const targetFile = resolve(outputDir, fileName);
|
|
149
|
+
await mkdir(dirname(targetFile), {
|
|
150
|
+
recursive: true
|
|
151
|
+
});
|
|
152
|
+
await writeFile(targetFile, content);
|
|
153
|
+
}));
|
|
154
|
+
return [
|
|
155
|
+
fileName,
|
|
156
|
+
version
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
export async function runAssemble(args) {
|
|
160
|
+
const npmConf = getNpmRegistryConfiguration(args.registry);
|
|
161
|
+
const config = await readConfig(args.mode, args.config, npmConf);
|
|
162
|
+
const importmap = {
|
|
163
|
+
imports: {}
|
|
164
|
+
};
|
|
165
|
+
const require = createRequire(import.meta.url);
|
|
166
|
+
const versionManifest = {
|
|
167
|
+
coreVersion: require(resolve(import.meta.dirname, '..', '..', 'package.json')).version,
|
|
168
|
+
frontendModules: {}
|
|
169
|
+
};
|
|
170
|
+
const routes = {};
|
|
171
|
+
logInfo(`Assembling dependencies and building import map and routes registry...`);
|
|
172
|
+
const { frontendModules = {}, publicUrl = '.' } = config;
|
|
173
|
+
if (args.fresh && existsSync(args.target)) {
|
|
174
|
+
await rm(args.target, {
|
|
175
|
+
recursive: true,
|
|
176
|
+
force: true
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
await mkdir(args.target, {
|
|
180
|
+
recursive: true
|
|
181
|
+
});
|
|
182
|
+
await Promise.all(Object.keys(frontendModules).map(async (esmName)=>{
|
|
183
|
+
const esmVersion = frontendModules[esmName];
|
|
184
|
+
const tgzBuffer = await downloadPackage(esmName, esmVersion, process.cwd(), npmConf);
|
|
185
|
+
const baseDirName = `${esmName}`.replace(/^@/, '').replace(/\//, '-');
|
|
186
|
+
const [fileName, version] = await extractFiles(tgzBuffer, resolve(args.target, baseDirName));
|
|
187
|
+
const dirName = `${baseDirName}-${version}`;
|
|
188
|
+
const appRoutes = resolve(args.target, dirName, 'routes.json');
|
|
189
|
+
if (existsSync(appRoutes)) {
|
|
190
|
+
try {
|
|
191
|
+
routes[esmName] = JSON.parse(await readFile(appRoutes, 'utf8'));
|
|
192
|
+
routes[esmName]['version'] = version;
|
|
193
|
+
} catch (e) {
|
|
194
|
+
logWarn(`Error while processing routes for ${esmName} using ${appRoutes}: ${e}`);
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
logWarn(`Routes file ${appRoutes} does not exist. We expect that routes file to be defined by ${esmName}. Note that this means that no pages or extensions for ${esmName} will be available.`);
|
|
198
|
+
if (routes.hasOwnProperty(esmName)) {
|
|
199
|
+
delete routes[esmName];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
importmap.imports[esmName] = `${publicUrl}/${dirName}/${fileName}`;
|
|
203
|
+
versionManifest.frontendModules[esmName] = version;
|
|
204
|
+
}));
|
|
205
|
+
await writeFile(resolve(args.target, `importmap${args.hashFiles ? '.' + contentHash(importmap) : ''}.json`), JSON.stringify(importmap), 'utf8');
|
|
206
|
+
if (args.buildRoutes) {
|
|
207
|
+
await writeFile(resolve(args.target, `routes.registry${args.hashFiles ? '.' + contentHash(routes) : ''}.json`), JSON.stringify(routes), 'utf-8');
|
|
208
|
+
}
|
|
209
|
+
if (args.configFiles && args.configFiles.length > 0) {
|
|
210
|
+
const assembledConfig = args.configFiles.reduce((merged, file)=>{
|
|
211
|
+
try {
|
|
212
|
+
const config = JSON.parse(readFileSync(file, 'utf8'));
|
|
213
|
+
return merge(merged, config);
|
|
214
|
+
} catch (e) {
|
|
215
|
+
logWarn(`Error while processing config file ${file}: ${e}`);
|
|
216
|
+
}
|
|
217
|
+
return merged;
|
|
218
|
+
}, {});
|
|
219
|
+
await writeFile(resolve(args.target, `egen-config${args.hashFiles ? '.' + contentHash(assembledConfig) : ''}.json`), JSON.stringify(assembledConfig), 'utf8');
|
|
220
|
+
}
|
|
221
|
+
if (args.manifest) {
|
|
222
|
+
await writeFile(resolve(args.target, 'spa-assemble-config.json'), JSON.stringify(versionManifest), 'utf8');
|
|
223
|
+
}
|
|
224
|
+
logInfo(`Finished assembling frontend distribution`);
|
|
225
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface BuildArgs {
|
|
2
|
+
target: string;
|
|
3
|
+
registry: string;
|
|
4
|
+
defaultLocale: string;
|
|
5
|
+
importmap?: string;
|
|
6
|
+
routes?: string;
|
|
7
|
+
spaPath: string;
|
|
8
|
+
fresh?: boolean;
|
|
9
|
+
apiUrl: string;
|
|
10
|
+
pageTitle: string;
|
|
11
|
+
supportOffline?: boolean;
|
|
12
|
+
configUrls: Array<string>;
|
|
13
|
+
configPaths: Array<string>;
|
|
14
|
+
buildConfig?: string;
|
|
15
|
+
env: string;
|
|
16
|
+
assets: Array<string>;
|
|
17
|
+
}
|
|
18
|
+
export type BuildConfig = Partial<{
|
|
19
|
+
apiUrl: string;
|
|
20
|
+
configUrls: Array<string>;
|
|
21
|
+
configPaths: Array<string>;
|
|
22
|
+
defaultLocale: string;
|
|
23
|
+
pageTitle: string;
|
|
24
|
+
supportOffline: boolean;
|
|
25
|
+
importmap: string;
|
|
26
|
+
routes: string;
|
|
27
|
+
spaPath: string;
|
|
28
|
+
env: string;
|
|
29
|
+
assets: Array<string>;
|
|
30
|
+
}>;
|
|
31
|
+
export declare function runBuild(args: BuildArgs): Promise<void>;
|
|
32
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACvB;AAED,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACvB,CAAC,CAAC;AAiBH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,SAAS,iBAoG7C"}
|