@lazyapps/bootstrap 0.1.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/LICENSE +15 -0
- package/README.md +13 -0
- package/index.js +55 -0
- package/package.json +59 -0
- package/svelte.js +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Oliver Sturm
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @lazyapps/bootstrap
|
|
2
|
+
|
|
3
|
+
Composition orchestrator for LazyApps applications. Wires together framework components and enables flexible deployment topologies from monolith to fully distributed.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @lazyapps/bootstrap
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Part of LazyApps
|
|
12
|
+
|
|
13
|
+
This package is part of the [LazyApps](https://github.com/oliversturm/lazyapps-libs) event-sourcing and CQRS framework.
|
package/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { startCommandProcessor } from '@lazyapps/command-processor';
|
|
2
|
+
import { startReadModels } from '@lazyapps/readmodels';
|
|
3
|
+
import { getLogger } from '@lazyapps/logger';
|
|
4
|
+
import { startSvelteKit } from './svelte.js';
|
|
5
|
+
|
|
6
|
+
const log = getLogger('BS', 'INIT');
|
|
7
|
+
|
|
8
|
+
let signalHandlersInstalled = false;
|
|
9
|
+
const handleSignals = (server) => {
|
|
10
|
+
const handler = (signal) => {
|
|
11
|
+
log.info(`Signal ${signal} received`);
|
|
12
|
+
server.close(() => {
|
|
13
|
+
log.info('Server closed, exiting process');
|
|
14
|
+
process.exit(0);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (!signalHandlersInstalled) {
|
|
19
|
+
// Let's just do this once per process, since it's possible we're in a monolith
|
|
20
|
+
process.on('SIGTERM', handler);
|
|
21
|
+
process.on('SIGINT', handler);
|
|
22
|
+
signalHandlersInstalled = true;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function start({
|
|
27
|
+
correlation: correlationConfig,
|
|
28
|
+
commands,
|
|
29
|
+
readModels,
|
|
30
|
+
changeNotifier,
|
|
31
|
+
svelte,
|
|
32
|
+
}) {
|
|
33
|
+
if (commands) {
|
|
34
|
+
log.debug('Starting command processor');
|
|
35
|
+
startCommandProcessor(correlationConfig, commands).then((server) => {
|
|
36
|
+
handleSignals(server);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (readModels) {
|
|
40
|
+
log.debug('Starting read models');
|
|
41
|
+
startReadModels(correlationConfig, readModels).then((server) => {
|
|
42
|
+
handleSignals(server);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (changeNotifier) {
|
|
46
|
+
log.debug('Starting change notifier');
|
|
47
|
+
changeNotifier.listener(correlationConfig).then((server) => {
|
|
48
|
+
handleSignals(server);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (svelte) {
|
|
52
|
+
log.debug('Starting SvelteKit frontend');
|
|
53
|
+
startSvelteKit(correlationConfig, svelte);
|
|
54
|
+
}
|
|
55
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lazyapps/bootstrap",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Composition orchestrator for LazyApps applications",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./index.js",
|
|
8
|
+
"./svelte": "./svelte.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"*.js"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"event-sourcing",
|
|
15
|
+
"cqrs",
|
|
16
|
+
"lazyapps",
|
|
17
|
+
"bootstrap",
|
|
18
|
+
"orchestrator"
|
|
19
|
+
],
|
|
20
|
+
"author": "Oliver Sturm",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/oliversturm/lazyapps-libs.git",
|
|
25
|
+
"directory": "packages/bootstrap"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/oliversturm/lazyapps-libs/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/oliversturm/lazyapps-libs/tree/main/packages/bootstrap#readme",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18.20.3 || >=20.18.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"eslint": "^8.46.0",
|
|
36
|
+
"vitest": "^4.0.18"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@lazyapps/command-processor": "^0.1.0",
|
|
40
|
+
"@lazyapps/logger": "^0.1.0",
|
|
41
|
+
"@lazyapps/readmodels": "^0.1.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"vite": ">=5.0.0",
|
|
45
|
+
"@sveltejs/kit": ">=2.0.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"vite": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"@sveltejs/kit": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"type": "module",
|
|
56
|
+
"scripts": {
|
|
57
|
+
"test": "vitest"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/svelte.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createServer, createLogger as createViteLogger } from 'vite';
|
|
2
|
+
import { sveltekit } from '@sveltejs/kit/vite';
|
|
3
|
+
import { getLogger } from '@lazyapps/logger';
|
|
4
|
+
|
|
5
|
+
// Note, the custom logger stuff is currently
|
|
6
|
+
// missing from vite docs. Best example I found
|
|
7
|
+
// is here: https://github.com/vitejs/vite/issues/10940
|
|
8
|
+
// There's a PR for the upcoming docs as well,
|
|
9
|
+
// but it's hard to read and not very verbose.
|
|
10
|
+
|
|
11
|
+
const log = getLogger('BS/Svelte');
|
|
12
|
+
const viteLog = getLogger('BS/Svelte/Vite');
|
|
13
|
+
const viteOrigLogger = createViteLogger();
|
|
14
|
+
// Sometimes vite sends empty output with a
|
|
15
|
+
// warn level, so prevent this from being logged.
|
|
16
|
+
const wrap = (f) => (msg) => (msg ? f(msg) : undefined);
|
|
17
|
+
const customLogger = {
|
|
18
|
+
...viteOrigLogger,
|
|
19
|
+
info: wrap(viteLog.info), // ignoring second parameter options
|
|
20
|
+
warn: wrap(viteLog.warn),
|
|
21
|
+
error: wrap(viteLog.error),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const startSvelteKit = ({
|
|
25
|
+
port = 5173,
|
|
26
|
+
host = 'localhost',
|
|
27
|
+
logLevel = 'info',
|
|
28
|
+
mqCommandsPort = 51883,
|
|
29
|
+
mqQueriesPort = 51884,
|
|
30
|
+
} = {}) => {
|
|
31
|
+
const config = {
|
|
32
|
+
plugins: [sveltekit()],
|
|
33
|
+
|
|
34
|
+
server: {
|
|
35
|
+
host,
|
|
36
|
+
port,
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
define: {
|
|
40
|
+
// Decided to use the 'process.env' prefix here, because
|
|
41
|
+
// otherwise the defined value will be marked as an error
|
|
42
|
+
// by eslint. In the context of this monolith setup, the
|
|
43
|
+
// use as an actual environment variable is not relevant.
|
|
44
|
+
'process.env.MQ_COMMANDS_PORT': JSON.stringify(mqCommandsPort),
|
|
45
|
+
'process.env.MQ_QUERIES_PORT': JSON.stringify(mqQueriesPort),
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
clearScreen: false,
|
|
49
|
+
logLevel,
|
|
50
|
+
customLogger,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return createServer(config)
|
|
54
|
+
.then((server) =>
|
|
55
|
+
server.listen().then(() => {
|
|
56
|
+
server.printUrls();
|
|
57
|
+
}),
|
|
58
|
+
)
|
|
59
|
+
.then(() => {
|
|
60
|
+
log.debug(`SvelteKit frontend started on ${host}:${port}`);
|
|
61
|
+
})
|
|
62
|
+
.catch((err) => {
|
|
63
|
+
log.error(
|
|
64
|
+
`An error occurred starting the SvelteKit frontend on ${host}:${port}`,
|
|
65
|
+
err,
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
};
|