stonyx 0.2.3-beta.8 → 0.2.3-beta.80

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 (67) hide show
  1. package/README.md +16 -5
  2. package/config/{environment.js → environment copy.ts } +16 -12
  3. package/dist/cli/help.d.ts +8 -0
  4. package/dist/cli/help.js +43 -0
  5. package/dist/cli/load-commands.d.ts +10 -0
  6. package/dist/cli/load-commands.js +49 -0
  7. package/dist/cli/new.d.ts +26 -0
  8. package/dist/cli/new.js +293 -0
  9. package/dist/cli/serve.d.ts +6 -0
  10. package/dist/cli/serve.js +49 -0
  11. package/dist/cli/test-setup.d.ts +1 -0
  12. package/dist/cli/test-setup.js +30 -0
  13. package/dist/cli/test.d.ts +4 -0
  14. package/dist/cli/test.js +23 -0
  15. package/dist/cli.d.ts +2 -0
  16. package/dist/cli.js +53 -0
  17. package/dist/exports/config.d.ts +2 -0
  18. package/dist/exports/config.js +2 -0
  19. package/dist/exports/log.d.ts +2 -0
  20. package/{src → dist}/exports/log.js +1 -2
  21. package/dist/exports/test-helpers.d.ts +5 -0
  22. package/dist/exports/test-helpers.js +7 -0
  23. package/dist/lifecycle.d.ts +7 -0
  24. package/dist/lifecycle.js +18 -0
  25. package/dist/main.d.ts +22 -0
  26. package/dist/main.js +98 -0
  27. package/dist/modules.d.ts +5 -0
  28. package/dist/modules.js +93 -0
  29. package/dist/util/import-config.d.ts +1 -0
  30. package/dist/util/import-config.js +10 -0
  31. package/dist/util/resolve-entry-point.d.ts +1 -0
  32. package/dist/util/resolve-entry-point.js +14 -0
  33. package/dist/util/resolve-module-name.d.ts +14 -0
  34. package/dist/util/resolve-module-name.js +33 -0
  35. package/package.json +41 -12
  36. package/scripts/postinstall.js +24 -2
  37. package/.claude/index.md +0 -96
  38. package/.github/workflows/ci.yml +0 -16
  39. package/.github/workflows/publish.yml +0 -51
  40. package/docs/api.md +0 -89
  41. package/docs/cli.md +0 -78
  42. package/docs/configuration.md +0 -72
  43. package/docs/conventions/discord-conventions.md +0 -62
  44. package/docs/conventions/framework-modules.md +0 -127
  45. package/docs/conventions/index.md +0 -24
  46. package/docs/conventions/orm-conventions.md +0 -158
  47. package/docs/conventions/project-structure.md +0 -105
  48. package/docs/conventions/rest-conventions.md +0 -96
  49. package/docs/conventions/testing-conventions.md +0 -56
  50. package/docs/developing-modules.md +0 -108
  51. package/docs/index.md +0 -15
  52. package/docs/lifecycle.md +0 -47
  53. package/docs/logging.md +0 -52
  54. package/docs/modules.md +0 -78
  55. package/docs/testing.md +0 -64
  56. package/src/cli/help.js +0 -48
  57. package/src/cli/load-commands.js +0 -56
  58. package/src/cli/new.js +0 -237
  59. package/src/cli/serve.js +0 -38
  60. package/src/cli/test-setup.js +0 -8
  61. package/src/cli/test.js +0 -27
  62. package/src/cli.js +0 -63
  63. package/src/exports/config.js +0 -3
  64. package/src/exports/test-helpers.js +0 -8
  65. package/src/lifecycle.js +0 -17
  66. package/src/main.js +0 -101
  67. package/src/modules.js +0 -112
@@ -1,56 +0,0 @@
1
- import { readFile } from 'fs/promises';
2
- import path from 'path';
3
-
4
- export default async function loadModuleCommands() {
5
- const cwd = process.cwd();
6
- const commands = {};
7
-
8
- let projectPackage;
9
-
10
- try {
11
- const raw = await readFile(path.join(cwd, 'package.json'), 'utf8');
12
- projectPackage = JSON.parse(raw);
13
- } catch {
14
- return commands;
15
- }
16
-
17
- const allDeps = {
18
- ...projectPackage.dependencies,
19
- ...projectPackage.devDependencies
20
- };
21
-
22
- const stonyxModules = Object.keys(allDeps).filter(name => name.startsWith('@stonyx/'));
23
-
24
- for (const moduleName of stonyxModules) {
25
- let modulePackage;
26
-
27
- try {
28
- const raw = await readFile(path.join(cwd, 'node_modules', moduleName, 'package.json'), 'utf8');
29
- modulePackage = JSON.parse(raw);
30
- } catch {
31
- continue;
32
- }
33
-
34
- const { exports: moduleExports } = modulePackage;
35
-
36
- if (!moduleExports || !moduleExports['./commands']) continue;
37
-
38
- try {
39
- const commandsModule = await import(path.join(cwd, 'node_modules', moduleName, moduleExports['./commands']));
40
- const moduleCommands = commandsModule.default;
41
-
42
- for (const [name, command] of Object.entries(moduleCommands)) {
43
- if (commands[name]) {
44
- console.warn(`Warning: Command "${name}" from ${moduleName} conflicts with existing command. Skipping.`);
45
- continue;
46
- }
47
-
48
- commands[name] = { ...command, module: moduleName };
49
- }
50
- } catch {
51
- continue;
52
- }
53
- }
54
-
55
- return commands;
56
- }
package/src/cli/new.js DELETED
@@ -1,237 +0,0 @@
1
- import { confirm, prompt } from '@stonyx/utils/prompt';
2
- import { createFile, createDirectory, copyFile, fileExists } from '@stonyx/utils/file';
3
- import { spawn } from 'child_process';
4
- import path from 'path';
5
- import { fileURLToPath } from 'url';
6
-
7
- const MODULE_OPTIONS = [
8
- {
9
- question: 'Will this project need a REST server?',
10
- package: '@stonyx/rest-server',
11
- dirs: ['requests']
12
- },
13
- {
14
- question: 'Will this project need WebSockets?',
15
- package: '@stonyx/sockets',
16
- dirs: ['socket-handlers']
17
- },
18
- {
19
- question: 'Will this project need data management?',
20
- package: '@stonyx/orm',
21
- dirs: ['models', 'serializers', 'access', 'transforms', 'hooks'],
22
- files: { 'config/db-schema.js': generateDbSchema }
23
- },
24
- {
25
- question: 'Will this project need scheduled tasks (cron)?',
26
- package: '@stonyx/cron',
27
- dirs: ['crons']
28
- },
29
- {
30
- question: 'Will this project need OAuth?',
31
- package: '@stonyx/oauth'
32
- },
33
- {
34
- question: 'Will this project need pub/sub events?',
35
- package: '@stonyx/events'
36
- },
37
- {
38
- question: 'Will this project need a Discord bot?',
39
- package: '@stonyx/discord',
40
- dirs: ['discord-commands', 'discord-events']
41
- }
42
- ];
43
-
44
- function generateDbSchema() {
45
- return `import { Model, hasMany } from '@stonyx/orm';
46
-
47
- export default class DBModel extends Model {
48
- // Define your collections here
49
- // examples = hasMany('example');
50
- }
51
- `;
52
- }
53
-
54
- function generatePackageJson(name, selectedModules) {
55
- const devDependencies = { stonyx: 'latest' };
56
-
57
- for (const mod of selectedModules) {
58
- devDependencies[mod.package] = 'latest';
59
- }
60
-
61
- // Sort dependencies alphabetically
62
- const sorted = Object.fromEntries(
63
- Object.entries(devDependencies).sort(([a], [b]) => a.localeCompare(b))
64
- );
65
-
66
- return JSON.stringify({
67
- name,
68
- version: '0.1.0',
69
- type: 'module',
70
- private: true,
71
- scripts: {
72
- start: 'stonyx serve',
73
- test: 'stonyx test'
74
- },
75
- devDependencies: sorted
76
- }, null, 2) + '\n';
77
- }
78
-
79
- function generateAppJs() {
80
- return `import log from 'stonyx/log';
81
-
82
- export default class App {
83
- constructor() {
84
- if (App.instance) return App.instance;
85
- App.instance = this;
86
-
87
- this.ready = this.init();
88
- }
89
-
90
- async init() {
91
- log.info('Initializing Application');
92
-
93
- // Application setup here
94
-
95
- log.info('Application has been initialized');
96
- }
97
- }
98
- `;
99
- }
100
-
101
- function generateEnvironmentJs() {
102
- return `export default {
103
- }
104
- `;
105
- }
106
-
107
- function generateEnvironmentExampleJs() {
108
- return `// Copy this file to environment.js and fill in your values
109
- // All values should use environment variables with ?? fallback defaults
110
-
111
- const {
112
- NODE_ENV,
113
- } = process.env;
114
-
115
- const environment = NODE_ENV ?? 'development';
116
-
117
- export default {
118
- }
119
- `;
120
- }
121
-
122
- function generateGitignore() {
123
- return `node_modules/
124
- .env
125
- db.json
126
- *.log
127
- `;
128
- }
129
-
130
- function runPnpmInstall(projectDir) {
131
- return new Promise((resolve, reject) => {
132
- const child = spawn('pnpm', ['install'], {
133
- cwd: projectDir,
134
- stdio: 'inherit'
135
- });
136
-
137
- child.on('close', code => {
138
- if (code === 0) resolve();
139
- else reject(new Error(`pnpm install exited with code ${code}`));
140
- });
141
-
142
- child.on('error', reject);
143
- });
144
- }
145
-
146
- export default async function newCommand({ args }) {
147
- let appName = args[0];
148
-
149
- if (!appName) {
150
- appName = await prompt('Project name:');
151
- }
152
-
153
- if (!appName) {
154
- console.error('Project name is required.');
155
- process.exit(1);
156
- }
157
-
158
- const projectDir = path.resolve(process.cwd(), appName);
159
-
160
- if (await fileExists(projectDir)) {
161
- console.error(`Directory "${appName}" already exists.`);
162
- process.exit(1);
163
- }
164
-
165
- console.log(`\nScaffolding new Stonyx project: ${appName}\n`);
166
-
167
- // Prompt for module selection
168
- const selectedModules = [];
169
-
170
- for (const mod of MODULE_OPTIONS) {
171
- if (await confirm(mod.question)) {
172
- selectedModules.push(mod);
173
- }
174
- }
175
-
176
- console.log('\nCreating project structure...\n');
177
-
178
- // Create project directory
179
- await createDirectory(projectDir);
180
-
181
- // Copy .nvmrc from monorepo root
182
- const monorepoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
183
- const nvmrcSource = path.join(monorepoRoot, '.nvmrc');
184
-
185
- if (await fileExists(nvmrcSource)) {
186
- await copyFile(nvmrcSource, path.join(projectDir, '.nvmrc'));
187
- }
188
-
189
- // Generate core files
190
- await createFile(path.join(projectDir, 'package.json'), generatePackageJson(appName, selectedModules));
191
- await createFile(path.join(projectDir, 'app.js'), generateAppJs());
192
- await createFile(path.join(projectDir, '.gitignore'), generateGitignore());
193
-
194
- // Create config directory and files
195
- await createFile(path.join(projectDir, 'config', 'environment.js'), generateEnvironmentJs());
196
- await createFile(path.join(projectDir, 'config', 'environment.example.js'), generateEnvironmentExampleJs());
197
-
198
- // Create module-specific directories and files
199
- for (const mod of selectedModules) {
200
- if (mod.dirs) {
201
- for (const dir of mod.dirs) {
202
- await createDirectory(path.join(projectDir, dir));
203
- // Create .gitkeep so empty dirs are tracked
204
- await createFile(path.join(projectDir, dir, '.gitkeep'), '');
205
- }
206
- }
207
-
208
- if (mod.files) {
209
- for (const [filePath, generator] of Object.entries(mod.files)) {
210
- await createFile(path.join(projectDir, filePath), generator());
211
- }
212
- }
213
- }
214
-
215
- // Create test structure
216
- await createDirectory(path.join(projectDir, 'test', 'unit'));
217
- await createFile(path.join(projectDir, 'test', 'unit', '.gitkeep'), '');
218
- await createDirectory(path.join(projectDir, 'test', 'integration'));
219
- await createFile(path.join(projectDir, 'test', 'integration', '.gitkeep'), '');
220
- await createDirectory(path.join(projectDir, 'test', 'acceptance'));
221
- await createFile(path.join(projectDir, 'test', 'acceptance', '.gitkeep'), '');
222
-
223
- // Create test config
224
- await createFile(path.join(projectDir, 'test', 'config', 'environment.js'), `export default {\n // Test-specific config overrides\n}\n`);
225
-
226
- console.log('Installing dependencies...\n');
227
-
228
- try {
229
- await runPnpmInstall(projectDir);
230
- } catch (error) {
231
- console.error('Failed to install dependencies. Run `pnpm install` manually in the project directory.');
232
- }
233
-
234
- console.log(`\n✓ Project "${appName}" created successfully!`);
235
- console.log(`\n cd ${appName}`);
236
- console.log(` stonyx serve\n`);
237
- }
package/src/cli/serve.js DELETED
@@ -1,38 +0,0 @@
1
- import { runStartupHooks, runShutdownHooks } from '../lifecycle.js';
2
-
3
- export function createShutdownHandler(modules) {
4
- let shuttingDown = false;
5
- return async () => {
6
- if (shuttingDown) return;
7
- shuttingDown = true;
8
-
9
- await runShutdownHooks(modules);
10
- process.exit(0);
11
- };
12
- }
13
-
14
- export default async function serve({ args }) {
15
- const cwd = process.cwd();
16
- const entryFlag = args.indexOf('--entry');
17
- const entryPoint = entryFlag !== -1 ? args[entryFlag + 1] : 'app.js';
18
-
19
- const { default: config } = await import(`${cwd}/config/environment.js`);
20
- const { default: Stonyx } = await import('../main.js');
21
-
22
- new Stonyx(config, cwd);
23
- await Stonyx.ready;
24
-
25
- const { modules } = Stonyx.instance;
26
- await runStartupHooks(modules);
27
-
28
- const shutdown = createShutdownHandler(modules);
29
-
30
- process.on('SIGTERM', shutdown);
31
- process.on('SIGINT', shutdown);
32
-
33
- const entryModule = await import(`${cwd}/${entryPoint}`);
34
-
35
- if (entryModule.default) {
36
- new entryModule.default();
37
- }
38
- }
@@ -1,8 +0,0 @@
1
- import { pathToFileURL } from 'url';
2
-
3
- const cwd = process.cwd();
4
-
5
- const { default: Stonyx } = await import('stonyx');
6
- const { default: config } = await import(pathToFileURL(`${cwd}/config/environment.js`));
7
-
8
- new Stonyx(config, cwd);
package/src/cli/test.js DELETED
@@ -1,27 +0,0 @@
1
- import { spawn } from 'child_process';
2
- import { fileURLToPath, pathToFileURL } from 'url';
3
- import path from 'path';
4
-
5
- export default async function test({ args }) {
6
- const cwd = process.cwd();
7
- const setupFile = path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'test-setup.js');
8
- const setupFileUrl = pathToFileURL(setupFile).href;
9
- const qunitBin = path.resolve(cwd, 'node_modules/qunit/bin/qunit.js');
10
-
11
- // Default to conventional test glob if no args provided
12
- const testArgs = args.length > 0 ? args : ['test/**/*-test.js'];
13
-
14
- const child = spawn(process.execPath, [
15
- '--import', setupFileUrl,
16
- qunitBin,
17
- ...testArgs
18
- ], {
19
- cwd,
20
- stdio: 'inherit',
21
- env: { ...process.env, NODE_ENV: 'test' }
22
- });
23
-
24
- child.on('close', (code) => {
25
- process.exit(code);
26
- });
27
- }
package/src/cli.js DELETED
@@ -1,63 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import serve from './cli/serve.js';
4
- import test from './cli/test.js';
5
- import help from './cli/help.js';
6
- import newCommand from './cli/new.js';
7
- import loadModuleCommands from './cli/load-commands.js';
8
-
9
- try { process.loadEnvFile(); } catch { /* no .env file */ }
10
-
11
- const aliases = { s: 'serve', t: 'test', h: 'help', n: 'new' };
12
-
13
- const builtInCommands = {
14
- serve: { description: 'Bootstrap Stonyx and run the app', run: serve },
15
- test: { description: 'Bootstrap Stonyx in test mode and run tests', run: test },
16
- new: { description: 'Scaffold a new Stonyx project', run: newCommand },
17
- help: { description: 'Show available commands', run: help }
18
- };
19
-
20
- const args = process.argv.slice(2);
21
- const commandName = aliases[args[0]] || args[0];
22
- const commandArgs = args.slice(1);
23
-
24
- async function main() {
25
- if (!commandName || commandName === 'help') {
26
- await help({ args: commandArgs, builtInCommands, loadModuleCommands });
27
- return;
28
- }
29
-
30
- const builtIn = builtInCommands[commandName];
31
-
32
- if (builtIn) {
33
- await builtIn.run({ args: commandArgs });
34
- return;
35
- }
36
-
37
- // Search module commands
38
- const moduleCommands = await loadModuleCommands();
39
- const moduleCommand = moduleCommands[commandName];
40
-
41
- if (moduleCommand) {
42
- const cwd = process.cwd();
43
-
44
- if (moduleCommand.bootstrap) {
45
- const { default: config } = await import(`${cwd}/config/environment.js`);
46
- const { default: Stonyx } = await import('./main.js');
47
- new Stonyx(config, cwd);
48
- await Stonyx.ready;
49
- }
50
-
51
- await moduleCommand.run({ args: commandArgs, cwd });
52
- return;
53
- }
54
-
55
- console.error(`Unknown command: ${args[0]}\n`);
56
- await help({ args: [], builtInCommands, loadModuleCommands });
57
- process.exit(1);
58
- }
59
-
60
- main().catch(error => {
61
- console.error(error);
62
- process.exit(1);
63
- });
@@ -1,3 +0,0 @@
1
- import Stonyx from 'stonyx';
2
-
3
- export default Stonyx.config;
@@ -1,8 +0,0 @@
1
- import Stonyx from 'stonyx';
2
-
3
- export function setupIntegrationTests(hooks) {
4
- hooks.before(async function() {
5
- await Stonyx.ready;
6
- console.log('Stonyx ready');
7
- });
8
- }
package/src/lifecycle.js DELETED
@@ -1,17 +0,0 @@
1
- export async function runStartupHooks(modules) {
2
- for (const module of modules) {
3
- if (typeof module.startup === 'function') await module.startup();
4
- }
5
- }
6
-
7
- export async function runShutdownHooks(modules) {
8
- for (const module of [...modules].reverse()) {
9
- if (typeof module.shutdown === 'function') {
10
- try {
11
- await module.shutdown();
12
- } catch (error) {
13
- console.error('Error during module shutdown:', error);
14
- }
15
- }
16
- }
17
- }
package/src/main.js DELETED
@@ -1,101 +0,0 @@
1
- /*
2
- * Copyright 2025 Stone Costa
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import Chronicle from 'node-chronicle';
18
- import loadModules from './modules.js';
19
- import { kebabCaseToCamelCase } from '@stonyx/utils/string';
20
- import { mergeObject } from '@stonyx/utils/object';
21
-
22
- export default class Stonyx {
23
- static initialized = false
24
- static modulePromises = {};
25
-
26
- constructor(config, rootPath) {
27
- if (Stonyx.instance) return Stonyx.instance;
28
-
29
- Stonyx.instance = this;
30
- Stonyx.ready = this.start(config, rootPath);
31
- }
32
-
33
- async start(config, rootPath) {
34
- if (!config) throw new Error('Stonyx requires full environment configuration on startup');
35
- if (!rootPath) throw new Error('Stonyx requires root project\'s path on startup');
36
-
37
- // Transform config from stonyx-modules running as a standalone
38
- if (rootPath.includes('stonyx-')) {
39
- const moduleName = kebabCaseToCamelCase(rootPath.split('/').pop().replace('stonyx-', ''));
40
- config = { [moduleName]: config, ...(config.modules || {}) };
41
- delete config.modules;
42
- }
43
-
44
- this.config = config;
45
- this.chronicle = new Chronicle({ additionalLogs: { title: 'green' }});
46
-
47
- Stonyx.initialized = true;
48
-
49
- // Auto-merge test environment overrides (after initialized flag, before modules load)
50
- // Uses in-place mutation to preserve existing references (e.g. stonyx/config export cache)
51
- if (process.env.NODE_ENV === 'test') {
52
- try {
53
- const { default: testOverrides } = await import(`${rootPath}/test/config/environment.js`);
54
- const merged = mergeObject(config, testOverrides);
55
- Object.assign(config, merged);
56
- } catch { /* no test overrides found */ }
57
- }
58
-
59
- this.modules = await loadModules(config, rootPath, this.chronicle);
60
- this.configureUserLogs();
61
- }
62
-
63
- /**
64
- * Allows users to define their own log for any extra class via environment config
65
- * {
66
- * myClass: {
67
- * logColor: 'purple',
68
- * logMethod: 'highlight'
69
- * logTimestamp: true
70
- * }
71
- & }
72
- */
73
- configureUserLogs() {
74
- const { chronicle } = this;
75
-
76
- for (const [ className, config ] of Object.entries(this.config)) {
77
- if (!config || typeof config !== 'object') continue;
78
- if (chronicle[className]) continue;
79
-
80
- const { logColor, logMethod, logTimestamp } = config;
81
-
82
- if (!logColor) continue;
83
-
84
- chronicle.defineType(logMethod || className, logColor, { logTimestamp: !!logTimestamp });
85
- }
86
- }
87
-
88
- static get log() {
89
- if (!Stonyx.initialized) throw new Error('Stonyx has not been initialized yet');
90
-
91
- return Stonyx.instance.chronicle;
92
- }
93
-
94
- static get config() {
95
- if (!Stonyx.initialized) throw new Error('Stonyx has not been initialized yet');
96
-
97
- return Stonyx.instance.config;
98
- }
99
- }
100
-
101
- export { waitForModule } from './modules.js';
package/src/modules.js DELETED
@@ -1,112 +0,0 @@
1
- /**
2
- * Validates and initializes stonyx modules
3
- * TODO: Refactor into a ModuleLoader class (good coding exercise)
4
- */
5
- import { readFile } from '@stonyx/utils/file';
6
- import { kebabCaseToCamelCase } from '@stonyx/utils/string';
7
- import { mergeObject } from '@stonyx/utils/object';
8
-
9
- const modulePromises = {};
10
-
11
- // Configure module-specific logging
12
- function configureLog(chronicle, module, config) {
13
- const { logColor, logMethod, logTimestamp } = config;
14
- if (!logColor) return;
15
-
16
- chronicle.defineType(logMethod || module, logColor, { logTimestamp: !!logTimestamp });
17
- }
18
-
19
- function initializeModule(moduleName, moduleClass, modules, initPromises) {
20
- const moduleInstance = new moduleClass();
21
-
22
- modules.push(moduleInstance);
23
-
24
- if (!moduleInstance.init) return;
25
-
26
- initPromises.push((async () => {
27
- await moduleInstance.init();
28
- modulePromises[moduleName]?.resolve();
29
- })());
30
- }
31
-
32
- export default async function(config, rootPath, chronicle) {
33
- const modules = [];
34
- const initPromises = [];
35
- const rootPackage = await readFile(`${rootPath}/package.json`, { json: true });
36
- const { devDependencies:dependencies, name:projectName } = rootPackage;
37
-
38
- // Expose rootPath to public configuration
39
- config.rootPath = rootPath;
40
-
41
- const moduleDependencies = Object.keys(dependencies).filter(moduleName => moduleName.startsWith('@stonyx/'));
42
-
43
- // Setup module promises prior to initialization
44
- for (const moduleName of moduleDependencies) {
45
- const promise = {};
46
- modulePromises[moduleName] = promise;
47
- promise.ready = new Promise(resolve => promise.resolve = resolve);
48
- }
49
-
50
- // Standalone module configuration
51
- if (rootPackage.keywords?.includes('stonyx-module')) {
52
- configureLog(chronicle, projectName, config);
53
-
54
- const { main: entryPoint } = rootPackage;
55
- const { default: moduleClass } = await import(`${rootPath}/${entryPoint}`);
56
- initializeModule(rootPackage.name, moduleClass, modules, initPromises);
57
- }
58
-
59
- for (const moduleName of moduleDependencies) {
60
- const modulePackage = await readFile(`${rootPath}/node_modules/${moduleName}/package.json`, { json: true, missingFileCallback: () => {
61
- console.warn(`Warning: Could not locate stonyx module: "${moduleName}". Module was not loaded`);
62
- }});
63
-
64
- if (!modulePackage) continue;
65
-
66
- const { keywords } = modulePackage;
67
-
68
- if (!keywords.includes('stonyx-module')) {
69
- console.warn(`Warning: Stonyx modules must contain the "stonyx-module" keyword. Module was not loaded`);
70
- continue;
71
- }
72
-
73
- if (!keywords.includes('stonyx-async')) {
74
- modulePromises[moduleName].resolve();
75
- continue;
76
- }
77
-
78
- try {
79
- // Load & Configure Async Modules
80
- const { default: moduleConfig } = await import(`${rootPath}/node_modules/${moduleName}/config/environment.js`);
81
-
82
- const module = kebabCaseToCamelCase(moduleName.split('/').pop());
83
- const userConfig = config[module] || {};
84
- const finalConfig = mergeObject(moduleConfig, userConfig);
85
- config[module] = finalConfig;
86
-
87
- // Configure module-specific logging
88
- configureLog(chronicle, module, finalConfig);
89
-
90
- const { main: entryPoint } = modulePackage;
91
- const { default: moduleClass } = await import(`${rootPath}/node_modules/${moduleName}/${entryPoint}`);
92
- initializeModule(moduleName, moduleClass, modules, initPromises);
93
- } catch (error) {
94
- console.error(error);
95
- throw new Error(`Stonyx modules with async loading must have a config/environment.js file with default configurations. Module "${moduleName}" failed to load.`);
96
- }
97
- }
98
-
99
- // Wait until all modules are initialized
100
- await Promise.all(initPromises);
101
-
102
- return modules;
103
- }
104
-
105
- export async function waitForModule(module) {
106
- module = `@stonyx/${module}`;
107
- const modulePromise = modulePromises[module];
108
-
109
- if (!modulePromise) throw new Error(`Could wait for module: ${module}. Module was not registered in project dependencies`);
110
-
111
- await modulePromises[module].ready;
112
- }