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/dist/main.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
import Chronicle from '@stonyx/logs';
|
|
17
|
+
import loadModules from './modules.js';
|
|
18
|
+
import { kebabCaseToCamelCase } from '@stonyx/utils/string';
|
|
19
|
+
import { mergeObject } from '@stonyx/utils/object';
|
|
20
|
+
export default class Stonyx {
|
|
21
|
+
static initialized = false;
|
|
22
|
+
static modulePromises = {};
|
|
23
|
+
static instance;
|
|
24
|
+
static ready;
|
|
25
|
+
config;
|
|
26
|
+
chronicle;
|
|
27
|
+
modules;
|
|
28
|
+
constructor(config, rootPath) {
|
|
29
|
+
if (Stonyx.instance)
|
|
30
|
+
return Stonyx.instance;
|
|
31
|
+
Stonyx.instance = this;
|
|
32
|
+
Stonyx.ready = this.start(config, rootPath);
|
|
33
|
+
}
|
|
34
|
+
async start(config, rootPath) {
|
|
35
|
+
if (!config)
|
|
36
|
+
throw new Error('Stonyx requires full environment configuration on startup');
|
|
37
|
+
if (!rootPath)
|
|
38
|
+
throw new Error('Stonyx requires root project\'s path on startup');
|
|
39
|
+
// Transform config from stonyx-modules running as a standalone
|
|
40
|
+
if (rootPath.includes('stonyx-')) {
|
|
41
|
+
const dirName = rootPath.split('/').pop() ?? '';
|
|
42
|
+
const moduleName = kebabCaseToCamelCase(dirName.replace('stonyx-', ''));
|
|
43
|
+
config = { [moduleName]: config, ...(config.modules || {}) };
|
|
44
|
+
delete config.modules;
|
|
45
|
+
}
|
|
46
|
+
this.config = config;
|
|
47
|
+
this.chronicle = new Chronicle({ additionalLogs: { title: 'green' } });
|
|
48
|
+
Stonyx.initialized = true;
|
|
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
|
+
}
|
|
57
|
+
catch { /* no test overrides found */ }
|
|
58
|
+
}
|
|
59
|
+
this.modules = await loadModules(config, rootPath, this.chronicle);
|
|
60
|
+
this.configureUserLogs();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Allows users to define their own log for any extra class via environment config
|
|
64
|
+
*/
|
|
65
|
+
configureUserLogs() {
|
|
66
|
+
const { chronicle } = this;
|
|
67
|
+
for (const [className, config] of Object.entries(this.config)) {
|
|
68
|
+
if (!config || typeof config !== 'object')
|
|
69
|
+
continue;
|
|
70
|
+
if (className in chronicle)
|
|
71
|
+
continue;
|
|
72
|
+
const { logColor, logMethod, logTimestamp } = config;
|
|
73
|
+
if (!logColor)
|
|
74
|
+
continue;
|
|
75
|
+
chronicle.defineType(logMethod || className, logColor, { logTimestamp: !!logTimestamp });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
static get log() {
|
|
79
|
+
if (!Stonyx.initialized)
|
|
80
|
+
throw new Error('Stonyx has not been initialized yet');
|
|
81
|
+
return Stonyx.instance.chronicle;
|
|
82
|
+
}
|
|
83
|
+
static get config() {
|
|
84
|
+
if (!Stonyx.initialized)
|
|
85
|
+
throw new Error('Stonyx has not been initialized yet');
|
|
86
|
+
return Stonyx.instance.config;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export { waitForModule } from './modules.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { StoynxModule } from './lifecycle.js';
|
|
2
|
+
import type Chronicle from '@stonyx/logs';
|
|
3
|
+
export type StoynxConfig = Record<string, Record<string, unknown> | unknown>;
|
|
4
|
+
export default function loadModules(config: StoynxConfig, rootPath: string, chronicle: Chronicle): Promise<StoynxModule[]>;
|
|
5
|
+
export declare function waitForModule(moduleName: string): Promise<void>;
|
package/dist/modules.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
const modulePromises = {};
|
|
9
|
+
// Configure module-specific logging
|
|
10
|
+
function configureLog(chronicle, module, config) {
|
|
11
|
+
const { logColor, logMethod, logTimestamp } = config;
|
|
12
|
+
if (!logColor)
|
|
13
|
+
return;
|
|
14
|
+
chronicle.defineType(logMethod || module, logColor, { logTimestamp: !!logTimestamp });
|
|
15
|
+
}
|
|
16
|
+
function initializeModule(moduleName, moduleClass, modules, initPromises) {
|
|
17
|
+
const moduleInstance = new moduleClass();
|
|
18
|
+
modules.push(moduleInstance);
|
|
19
|
+
if (!moduleInstance.init)
|
|
20
|
+
return;
|
|
21
|
+
initPromises.push((async () => {
|
|
22
|
+
await moduleInstance.init();
|
|
23
|
+
modulePromises[moduleName]?.resolve();
|
|
24
|
+
})());
|
|
25
|
+
}
|
|
26
|
+
export default async function loadModules(config, rootPath, chronicle) {
|
|
27
|
+
const modules = [];
|
|
28
|
+
const initPromises = [];
|
|
29
|
+
const rootPackage = await readFile(`${rootPath}/package.json`, { json: true });
|
|
30
|
+
const dependencies = (rootPackage.devDependencies || {});
|
|
31
|
+
const projectName = typeof rootPackage.name === 'string' ? rootPackage.name : '';
|
|
32
|
+
// Expose rootPath to public configuration
|
|
33
|
+
config.rootPath = rootPath;
|
|
34
|
+
const moduleDependencies = Object.keys(dependencies).filter((moduleName) => moduleName.startsWith('@stonyx/'));
|
|
35
|
+
// Setup module promises prior to initialization
|
|
36
|
+
for (const moduleName of moduleDependencies) {
|
|
37
|
+
const promise = {};
|
|
38
|
+
modulePromises[moduleName] = promise;
|
|
39
|
+
promise.ready = new Promise(resolve => promise.resolve = resolve);
|
|
40
|
+
}
|
|
41
|
+
// Standalone module configuration
|
|
42
|
+
if (Array.isArray(rootPackage.keywords) && rootPackage.keywords.includes('stonyx-module')) {
|
|
43
|
+
configureLog(chronicle, projectName, config);
|
|
44
|
+
const entryPoint = typeof rootPackage.main === 'string' ? rootPackage.main : '';
|
|
45
|
+
const { default: moduleClass } = await import(`${rootPath}/${entryPoint}`);
|
|
46
|
+
initializeModule(projectName, moduleClass, modules, initPromises);
|
|
47
|
+
}
|
|
48
|
+
for (const moduleName of moduleDependencies) {
|
|
49
|
+
const modulePackage = await readFile(`${rootPath}/node_modules/${moduleName}/package.json`, { json: true, missingFileCallback: (_filePath) => {
|
|
50
|
+
console.warn(`Warning: Could not locate stonyx module: "${moduleName}". Module was not loaded`);
|
|
51
|
+
return '';
|
|
52
|
+
} });
|
|
53
|
+
if (!modulePackage)
|
|
54
|
+
continue;
|
|
55
|
+
const keywords = Array.isArray(modulePackage.keywords) ? modulePackage.keywords : [];
|
|
56
|
+
if (!keywords.includes('stonyx-module')) {
|
|
57
|
+
console.warn(`Warning: Stonyx modules must contain the "stonyx-module" keyword. Module was not loaded`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!keywords.includes('stonyx-async')) {
|
|
61
|
+
modulePromises[moduleName].resolve();
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
// Load & Configure Async Modules
|
|
66
|
+
const { default: moduleConfig } = await import(`${rootPath}/node_modules/${moduleName}/config/environment.js`);
|
|
67
|
+
const module = kebabCaseToCamelCase(moduleName.split('/').pop() ?? moduleName);
|
|
68
|
+
const userConfig = config[module] || {};
|
|
69
|
+
const finalConfig = mergeObject(moduleConfig, userConfig);
|
|
70
|
+
config[module] = finalConfig;
|
|
71
|
+
// Configure module-specific logging
|
|
72
|
+
configureLog(chronicle, module, finalConfig);
|
|
73
|
+
const entryPoint = modulePackage.main;
|
|
74
|
+
const { default: moduleClass } = await import(`${rootPath}/node_modules/${moduleName}/${entryPoint}`);
|
|
75
|
+
initializeModule(moduleName, moduleClass, modules, initPromises);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error(error);
|
|
79
|
+
throw new Error(`Stonyx modules with async loading must have a config/environment.js file with default configurations. Module "${moduleName}" failed to load.`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Wait until all modules are initialized
|
|
83
|
+
await Promise.all(initPromises);
|
|
84
|
+
return modules;
|
|
85
|
+
}
|
|
86
|
+
export async function waitForModule(moduleName) {
|
|
87
|
+
const fullName = `@stonyx/${moduleName}`;
|
|
88
|
+
const modulePromise = modulePromises[fullName];
|
|
89
|
+
if (!modulePromise)
|
|
90
|
+
throw new Error(`Could wait for module: ${fullName}. Module was not registered in project dependencies`);
|
|
91
|
+
await modulePromises[fullName].ready;
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stonyx",
|
|
3
|
-
"version": "0.2.3-alpha.
|
|
3
|
+
"version": "0.2.3-alpha.21",
|
|
4
4
|
"description": "Base stonyx framework module",
|
|
5
|
-
"main": "main.js",
|
|
5
|
+
"main": "dist/main.js",
|
|
6
|
+
"types": "dist/main.d.ts",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"bin": {
|
|
8
|
-
"stonyx": "./
|
|
9
|
+
"stonyx": "./dist/cli.js"
|
|
9
10
|
},
|
|
10
11
|
"exports": {
|
|
11
|
-
".":
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"./
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/main.d.ts",
|
|
14
|
+
"default": "./dist/main.js"
|
|
15
|
+
},
|
|
16
|
+
"./config": {
|
|
17
|
+
"types": "./dist/exports/config.d.ts",
|
|
18
|
+
"default": "./dist/exports/config.js"
|
|
19
|
+
},
|
|
20
|
+
"./log": {
|
|
21
|
+
"types": "./dist/exports/log.d.ts",
|
|
22
|
+
"default": "./dist/exports/log.js"
|
|
23
|
+
},
|
|
24
|
+
"./test-helpers": {
|
|
25
|
+
"types": "./dist/exports/test-helpers.d.ts",
|
|
26
|
+
"default": "./dist/exports/test-helpers.js"
|
|
27
|
+
},
|
|
28
|
+
"./lifecycle": {
|
|
29
|
+
"types": "./dist/lifecycle.d.ts",
|
|
30
|
+
"default": "./dist/lifecycle.js"
|
|
31
|
+
}
|
|
16
32
|
},
|
|
17
33
|
"repository": {
|
|
18
34
|
"type": "git",
|
|
19
35
|
"url": "git+https://github.com/abofs/stonyx.git"
|
|
20
36
|
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"config",
|
|
40
|
+
"README.md"
|
|
41
|
+
],
|
|
21
42
|
"publishConfig": {
|
|
22
43
|
"provenance": true
|
|
23
44
|
},
|
|
@@ -30,16 +51,22 @@
|
|
|
30
51
|
"url": "https://github.com/abofs/stonyx/issues"
|
|
31
52
|
},
|
|
32
53
|
"dependencies": {
|
|
33
|
-
"
|
|
54
|
+
"@stonyx/utils": "0.2.3-beta.20",
|
|
55
|
+
"@stonyx/logs": "1.0.1-beta.13"
|
|
34
56
|
},
|
|
35
57
|
"devDependencies": {
|
|
36
|
-
"@
|
|
58
|
+
"@types/node": "^25.5.2",
|
|
59
|
+
"@types/qunit": "^2.19.13",
|
|
60
|
+
"@types/sinon": "^21.0.1",
|
|
37
61
|
"qunit": "^2.24.1",
|
|
38
|
-
"sinon": "^21.0.0"
|
|
62
|
+
"sinon": "^21.0.0",
|
|
63
|
+
"typescript": "^5.8.3"
|
|
39
64
|
},
|
|
40
65
|
"scripts": {
|
|
66
|
+
"build": "tsc",
|
|
67
|
+
"build:test": "tsc -p tsconfig.test.json",
|
|
41
68
|
"start": "node .",
|
|
42
|
-
"test": "qunit",
|
|
69
|
+
"test": "pnpm build && pnpm build:test && qunit 'dist-test/test/**/*-test.js'",
|
|
43
70
|
"error": "echo \"Error: no error handling\" && exit 1",
|
|
44
71
|
"postinstall": "node scripts/postinstall.js"
|
|
45
72
|
}
|
package/.claude/index.md
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# Stonyx CLI Guide
|
|
2
|
-
|
|
3
|
-
## Installation
|
|
4
|
-
|
|
5
|
-
Stonyx is the core framework package. The CLI is provided by the `stonyx` binary defined in `package.json`.
|
|
6
|
-
|
|
7
|
-
In a project that depends on `stonyx`:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
pnpm add -D stonyx
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
The CLI is then available as `npx stonyx` or via pnpm scripts.
|
|
14
|
-
|
|
15
|
-
## Commands
|
|
16
|
-
|
|
17
|
-
### `stonyx serve` (alias: `s`)
|
|
18
|
-
|
|
19
|
-
Bootstrap Stonyx and run the application.
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
stonyx serve # loads app.js by default
|
|
23
|
-
stonyx serve --entry custom.js # custom entry point
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Behavior:
|
|
27
|
-
1. Loads `.env` file
|
|
28
|
-
2. Imports `config/environment.js`
|
|
29
|
-
3. Initializes Stonyx with all detected `@stonyx/*` modules
|
|
30
|
-
4. Runs startup lifecycle hooks
|
|
31
|
-
5. Imports and instantiates the entry point class
|
|
32
|
-
6. Registers SIGTERM/SIGINT handlers for graceful shutdown
|
|
33
|
-
|
|
34
|
-
### `stonyx test` (alias: `t`)
|
|
35
|
-
|
|
36
|
-
Bootstrap Stonyx in test mode and run QUnit tests.
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
stonyx test # runs test/**/*-test.js
|
|
40
|
-
stonyx test test/unit/foo-test.js # specific file
|
|
41
|
-
stonyx test "test/integration/**/*-test.js" # glob pattern
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Sets `NODE_ENV=test` and auto-loads test setup which merges `test/config/environment.js` overrides.
|
|
45
|
-
|
|
46
|
-
### `stonyx help` (alias: `h`)
|
|
47
|
-
|
|
48
|
-
Show available commands including built-in and module-provided commands.
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
stonyx help
|
|
52
|
-
stonyx --help
|
|
53
|
-
stonyx -h
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### `stonyx new <app-name>`
|
|
57
|
-
|
|
58
|
-
Scaffold a new Stonyx project with interactive module selection.
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
stonyx new my-backend
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
Prompts for:
|
|
65
|
-
- Package name
|
|
66
|
-
- Which `@stonyx/*` modules to include (REST server, WebSockets, ORM, cron, OAuth, events)
|
|
67
|
-
|
|
68
|
-
Creates:
|
|
69
|
-
- `package.json` with selected dependencies
|
|
70
|
-
- `app.js` entry point
|
|
71
|
-
- `config/environment.js` and `config/environment.example.js`
|
|
72
|
-
- Module-specific directories (`models/`, `requests/`, `crons/`, etc.)
|
|
73
|
-
- `test/` structure with `unit/`, `integration/`, `acceptance/`
|
|
74
|
-
- `.gitignore` and `.nvmrc`
|
|
75
|
-
- Runs `pnpm install`
|
|
76
|
-
|
|
77
|
-
## Module Command System
|
|
78
|
-
|
|
79
|
-
Stonyx modules can register CLI commands by exporting a `./commands` entry in their `package.json` exports map. The CLI auto-discovers these from installed `@stonyx/*` packages.
|
|
80
|
-
|
|
81
|
-
Module commands appear under "Module commands" in `stonyx help` output. They can optionally request Stonyx bootstrap before running (via `bootstrap: true`).
|
|
82
|
-
|
|
83
|
-
## Creating a Stonyx Project Manually
|
|
84
|
-
|
|
85
|
-
If not using `stonyx new`:
|
|
86
|
-
|
|
87
|
-
1. Create project directory
|
|
88
|
-
2. Add `.nvmrc` with current LTS Node version
|
|
89
|
-
3. `pnpm init` and set `"type": "module"`
|
|
90
|
-
4. `pnpm add -D stonyx` plus desired `@stonyx/*` modules
|
|
91
|
-
5. Create `config/environment.js` with module config
|
|
92
|
-
6. Create `app.js` entry point class
|
|
93
|
-
7. Create standard directories per selected modules
|
|
94
|
-
8. Add `@abofs/code-conventions` for linting
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
branches: [dev, main]
|
|
6
|
-
|
|
7
|
-
concurrency:
|
|
8
|
-
group: ci-${{ github.head_ref || github.ref }}
|
|
9
|
-
cancel-in-progress: true
|
|
10
|
-
|
|
11
|
-
permissions:
|
|
12
|
-
contents: read
|
|
13
|
-
|
|
14
|
-
jobs:
|
|
15
|
-
test:
|
|
16
|
-
uses: abofs/stonyx-workflows/.github/workflows/ci.yml@main
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
name: Publish to NPM
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
repository_dispatch:
|
|
5
|
-
types: [cascade-publish]
|
|
6
|
-
workflow_dispatch:
|
|
7
|
-
inputs:
|
|
8
|
-
version-type:
|
|
9
|
-
description: 'Version type'
|
|
10
|
-
required: true
|
|
11
|
-
type: choice
|
|
12
|
-
options:
|
|
13
|
-
- patch
|
|
14
|
-
- minor
|
|
15
|
-
- major
|
|
16
|
-
custom-version:
|
|
17
|
-
description: 'Custom version (optional, overrides version-type)'
|
|
18
|
-
required: false
|
|
19
|
-
type: string
|
|
20
|
-
pull_request:
|
|
21
|
-
types: [opened, synchronize, reopened]
|
|
22
|
-
branches: [main]
|
|
23
|
-
push:
|
|
24
|
-
branches: [main]
|
|
25
|
-
|
|
26
|
-
concurrency:
|
|
27
|
-
group: ${{ github.event_name == 'repository_dispatch' && 'cascade-update' || format('publish-{0}', github.ref) }}
|
|
28
|
-
cancel-in-progress: false
|
|
29
|
-
|
|
30
|
-
permissions:
|
|
31
|
-
contents: write
|
|
32
|
-
id-token: write
|
|
33
|
-
pull-requests: write
|
|
34
|
-
|
|
35
|
-
jobs:
|
|
36
|
-
publish:
|
|
37
|
-
if: "!contains(github.event.head_commit.message, '[skip ci]')"
|
|
38
|
-
uses: abofs/stonyx-workflows/.github/workflows/npm-publish.yml@main
|
|
39
|
-
with:
|
|
40
|
-
version-type: ${{ github.event.inputs.version-type }}
|
|
41
|
-
custom-version: ${{ github.event.inputs.custom-version }}
|
|
42
|
-
cascade-source: ${{ github.event.client_payload.source_package || '' }}
|
|
43
|
-
secrets: inherit
|
|
44
|
-
|
|
45
|
-
cascade:
|
|
46
|
-
needs: publish
|
|
47
|
-
uses: abofs/stonyx-workflows/.github/workflows/cascade.yml@main
|
|
48
|
-
with:
|
|
49
|
-
package-name: ${{ needs.publish.outputs.package-name }}
|
|
50
|
-
published-version: ${{ needs.publish.outputs.published-version }}
|
|
51
|
-
secrets: inherit
|
package/docs/api.md
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# API Reference
|
|
2
|
-
|
|
3
|
-
Public exports available from the `stonyx` package.
|
|
4
|
-
|
|
5
|
-
## Exports Map
|
|
6
|
-
|
|
7
|
-
| Import Path | Export | Description |
|
|
8
|
-
|-------------|--------|-------------|
|
|
9
|
-
| `stonyx` | `default` (Stonyx class) | Main framework class (singleton) |
|
|
10
|
-
| `stonyx` | `waitForModule(name)` | Wait for an async module to be ready |
|
|
11
|
-
| `stonyx/config` | `default` (config object) | Live reference to Stonyx configuration |
|
|
12
|
-
| `stonyx/log` | `default` (Chronicle instance) | Live reference to Chronicle logger |
|
|
13
|
-
| `stonyx/lifecycle` | `runStartupHooks(modules)` | Run startup hooks on a module array |
|
|
14
|
-
| `stonyx/lifecycle` | `runShutdownHooks(modules)` | Run shutdown hooks in reverse order |
|
|
15
|
-
| `stonyx/test-helpers` | `setupIntegrationTests(hooks)` | QUnit hook for integration test setup |
|
|
16
|
-
|
|
17
|
-
## Stonyx Class
|
|
18
|
-
|
|
19
|
-
```js
|
|
20
|
-
import Stonyx from 'stonyx';
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### Constructor
|
|
24
|
-
|
|
25
|
-
```js
|
|
26
|
-
new Stonyx(config, rootPath)
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
- **config** — Full environment configuration object
|
|
30
|
-
- **rootPath** — Absolute path to the project root
|
|
31
|
-
|
|
32
|
-
Returns the existing instance if one already exists (singleton pattern).
|
|
33
|
-
|
|
34
|
-
### Static Properties
|
|
35
|
-
|
|
36
|
-
| Property | Type | Description |
|
|
37
|
-
|----------|------|-------------|
|
|
38
|
-
| `Stonyx.instance` | `Stonyx` | The singleton instance |
|
|
39
|
-
| `Stonyx.ready` | `Promise` | Resolves when all modules are initialized |
|
|
40
|
-
| `Stonyx.initialized` | `boolean` | Whether Stonyx has started initialization |
|
|
41
|
-
|
|
42
|
-
### Static Getters
|
|
43
|
-
|
|
44
|
-
| Getter | Returns | Throws |
|
|
45
|
-
|--------|---------|--------|
|
|
46
|
-
| `Stonyx.config` | Config object | If not initialized |
|
|
47
|
-
| `Stonyx.log` | Chronicle instance | If not initialized |
|
|
48
|
-
|
|
49
|
-
### Instance Properties
|
|
50
|
-
|
|
51
|
-
| Property | Type | Description |
|
|
52
|
-
|----------|------|-------------|
|
|
53
|
-
| `instance.config` | `object` | Merged environment configuration |
|
|
54
|
-
| `instance.chronicle` | `Chronicle` | Logger instance |
|
|
55
|
-
| `instance.modules` | `Array` | Loaded module instances |
|
|
56
|
-
|
|
57
|
-
## waitForModule
|
|
58
|
-
|
|
59
|
-
```js
|
|
60
|
-
import { waitForModule } from 'stonyx';
|
|
61
|
-
|
|
62
|
-
await waitForModule('rest-server');
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
Waits for a specific `@stonyx/*` module to complete initialization. Pass the module name **without** the `@stonyx/` prefix.
|
|
66
|
-
|
|
67
|
-
Throws if the module is not registered in project dependencies.
|
|
68
|
-
|
|
69
|
-
## Lifecycle Functions
|
|
70
|
-
|
|
71
|
-
```js
|
|
72
|
-
import { runStartupHooks, runShutdownHooks } from 'stonyx/lifecycle';
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### runStartupHooks(modules)
|
|
76
|
-
|
|
77
|
-
Calls `startup()` on each module in array order. Skips modules without a `startup` method.
|
|
78
|
-
|
|
79
|
-
### runShutdownHooks(modules)
|
|
80
|
-
|
|
81
|
-
Calls `shutdown()` on each module in **reverse** array order. Errors are caught and logged — one failing hook does not prevent others from running.
|
|
82
|
-
|
|
83
|
-
## setupIntegrationTests
|
|
84
|
-
|
|
85
|
-
```js
|
|
86
|
-
import { setupIntegrationTests } from 'stonyx/test-helpers';
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
Registers a QUnit `before` hook that waits for `Stonyx.ready`. Use within a `module()` block to ensure Stonyx is fully initialized before tests run.
|
package/docs/cli.md
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# CLI
|
|
2
|
-
|
|
3
|
-
Stonyx includes a CLI that handles bootstrapping, module initialization, and application execution.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
stonyx <command> [...args]
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Built-in Commands
|
|
12
|
-
|
|
13
|
-
| Command | Alias | Description |
|
|
14
|
-
|---------|-------|-------------|
|
|
15
|
-
| `serve` | `s` | Bootstrap Stonyx and run the app |
|
|
16
|
-
| `test` | `t` | Bootstrap Stonyx in test mode and run tests |
|
|
17
|
-
| `help` | `h` | Show available commands |
|
|
18
|
-
|
|
19
|
-
### serve
|
|
20
|
-
|
|
21
|
-
Bootstraps Stonyx (loads config, initializes modules, runs lifecycle hooks), then imports your application entry point.
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
stonyx serve # Runs app.js by default
|
|
25
|
-
stonyx serve --entry custom.js # Runs a custom entry file
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
The serve command also registers `SIGTERM` and `SIGINT` handlers that run [shutdown hooks](lifecycle.md) before exiting.
|
|
29
|
-
|
|
30
|
-
### test
|
|
31
|
-
|
|
32
|
-
Runs your test suite using [QUnit](https://qunitjs.com/) with automatic Stonyx bootstrapping. Sets `NODE_ENV=test` and applies any [test config overrides](configuration.md#test-environment-overrides).
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
stonyx test # Runs test/**/*-test.js by default
|
|
36
|
-
stonyx test "test/unit/**/*.js" # Custom test glob
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### help
|
|
40
|
-
|
|
41
|
-
Displays all available commands, including any [module commands](#module-commands).
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
stonyx help
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Module Commands
|
|
48
|
-
|
|
49
|
-
Stonyx modules can register custom CLI commands by exporting a `./commands` entry in their `package.json`. These are automatically discovered and available through the CLI.
|
|
50
|
-
|
|
51
|
-
```json
|
|
52
|
-
{
|
|
53
|
-
"exports": {
|
|
54
|
-
"./commands": "./src/commands.js"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
The commands file should export an object mapping command names to definitions:
|
|
60
|
-
|
|
61
|
-
```js
|
|
62
|
-
export default {
|
|
63
|
-
'db:migrate': {
|
|
64
|
-
description: 'Run database migrations',
|
|
65
|
-
bootstrap: true,
|
|
66
|
-
run: async ({ args, cwd }) => { /* ... */ }
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
- **`bootstrap: true`** — Stonyx will be fully initialized before the command runs
|
|
72
|
-
- **`bootstrap: false`** — The command runs without Stonyx initialization
|
|
73
|
-
|
|
74
|
-
Module commands appear under "Module commands" in `stonyx help` output. If two modules register the same command name, the first one loaded wins and a warning is printed.
|
|
75
|
-
|
|
76
|
-
## Environment Variables
|
|
77
|
-
|
|
78
|
-
The CLI automatically loads `.env` files via `process.loadEnvFile()` before executing any command.
|
package/docs/configuration.md
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# Configuration
|
|
2
|
-
|
|
3
|
-
Stonyx uses a centralized configuration file that all modules read from at startup.
|
|
4
|
-
|
|
5
|
-
## Environment Config
|
|
6
|
-
|
|
7
|
-
Your project's configuration lives at `config/environment.js`:
|
|
8
|
-
|
|
9
|
-
```js
|
|
10
|
-
const { DEBUG, NODE_ENV } = process.env;
|
|
11
|
-
|
|
12
|
-
const environment = NODE_ENV ?? 'development';
|
|
13
|
-
|
|
14
|
-
export default {
|
|
15
|
-
environment,
|
|
16
|
-
debug: DEBUG ?? environment === 'development',
|
|
17
|
-
|
|
18
|
-
// Module-specific configuration
|
|
19
|
-
restServer: { logColor: 'yellow', port: 3000 },
|
|
20
|
-
cron: { log: true },
|
|
21
|
-
};
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
This file is auto-generated on `npm install` via the postinstall script if it doesn't already exist.
|
|
25
|
-
|
|
26
|
-
> **Note:** `config/environment.js` is gitignored by default so each environment can have its own settings.
|
|
27
|
-
|
|
28
|
-
## Module Configuration
|
|
29
|
-
|
|
30
|
-
Each Stonyx module reads its configuration from a top-level key matching its camelCase name. For example, `@stonyx/rest-server` reads from `config.restServer`.
|
|
31
|
-
|
|
32
|
-
Async modules ship with their own default config at `config/environment.js` inside the module package. Your project config is merged on top of these defaults — you only need to specify overrides.
|
|
33
|
-
|
|
34
|
-
## Logging Configuration
|
|
35
|
-
|
|
36
|
-
Any config key with a `logColor` property automatically creates a [Chronicle](logging.md) log type:
|
|
37
|
-
|
|
38
|
-
```js
|
|
39
|
-
export default {
|
|
40
|
-
myService: {
|
|
41
|
-
logColor: 'purple', // Required — enables log creation
|
|
42
|
-
logMethod: 'highlight', // Optional — custom method name (defaults to key name)
|
|
43
|
-
logTimestamp: true, // Optional — include timestamps
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
This works for both module configs and custom service configs. See [Logging](logging.md) for details.
|
|
49
|
-
|
|
50
|
-
## Test Environment Overrides
|
|
51
|
-
|
|
52
|
-
When `NODE_ENV=test`, Stonyx automatically looks for `test/config/environment.js` in your project root:
|
|
53
|
-
|
|
54
|
-
```js
|
|
55
|
-
// test/config/environment.js
|
|
56
|
-
export default {
|
|
57
|
-
debug: false,
|
|
58
|
-
restServer: { port: 0 },
|
|
59
|
-
};
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
These overrides are deep-merged into the main config using in-place mutation, so any existing references (like `stonyx/config` exports) stay valid.
|
|
63
|
-
|
|
64
|
-
## Accessing Config at Runtime
|
|
65
|
-
|
|
66
|
-
```js
|
|
67
|
-
import config from 'stonyx/config';
|
|
68
|
-
|
|
69
|
-
console.log(config.environment); // 'development', 'test', etc.
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
The `stonyx/config` export is a live reference to the Stonyx instance config. It will throw if accessed before Stonyx is initialized.
|