stonyx 0.2.3-alpha.2 → 0.2.3-alpha.21
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 +16 -4
- package/dist/cli/help.d.ts +8 -0
- package/dist/cli/help.js +43 -0
- package/dist/cli/load-commands.d.ts +10 -0
- package/dist/cli/load-commands.js +49 -0
- package/dist/cli/new.d.ts +17 -0
- package/dist/cli/new.js +236 -0
- package/dist/cli/serve.d.ts +5 -0
- package/dist/cli/serve.js +29 -0
- package/dist/cli/test-setup.d.ts +1 -0
- package/{src → dist}/cli/test-setup.js +5 -8
- package/dist/cli/test.d.ts +3 -0
- package/dist/cli/test.js +23 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +52 -0
- package/dist/exports/config.d.ts +2 -0
- package/dist/exports/config.js +2 -0
- package/dist/exports/log.d.ts +2 -0
- package/{src → dist}/exports/log.js +1 -2
- package/dist/exports/test-helpers.d.ts +5 -0
- package/dist/exports/test-helpers.js +7 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.js +18 -0
- package/dist/main.d.ts +21 -0
- package/dist/main.js +89 -0
- package/dist/modules.d.ts +5 -0
- package/dist/modules.js +92 -0
- package/package.json +39 -12
- package/.claude/index.md +0 -94
- package/.github/workflows/ci.yml +0 -16
- package/.github/workflows/publish.yml +0 -51
- package/docs/api.md +0 -89
- package/docs/cli.md +0 -78
- package/docs/configuration.md +0 -72
- package/docs/conventions/framework-modules.md +0 -121
- package/docs/conventions/index.md +0 -23
- package/docs/conventions/orm-conventions.md +0 -158
- package/docs/conventions/project-structure.md +0 -106
- package/docs/conventions/rest-conventions.md +0 -96
- package/docs/conventions/testing-conventions.md +0 -56
- package/docs/developing-modules.md +0 -108
- package/docs/index.md +0 -15
- package/docs/lifecycle.md +0 -47
- package/docs/logging.md +0 -52
- package/docs/modules.md +0 -78
- package/docs/testing.md +0 -64
- package/scripts/postinstall.js +0 -11
- package/src/cli/help.js +0 -48
- package/src/cli/load-commands.js +0 -56
- package/src/cli/new.js +0 -232
- package/src/cli/serve.js +0 -38
- package/src/cli/test.js +0 -27
- package/src/cli.js +0 -63
- package/src/exports/config.js +0 -3
- package/src/exports/test-helpers.js +0 -8
- package/src/lifecycle.js +0 -17
- package/src/main.js +0 -101
- package/src/modules.js +0 -112
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
|
-
});
|
package/src/exports/config.js
DELETED
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
|
-
}
|