stonyx 0.2.3-alpha.1 → 0.2.3-alpha.11
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 +11 -4
- package/package.json +8 -3
- package/src/cli/new.js +5 -0
- package/src/cli.js +1 -1
- package/src/main.js +1 -1
- 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/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/README.md
CHANGED
|
@@ -5,19 +5,23 @@
|
|
|
5
5
|
- 100% JavaScript (ES Modules)
|
|
6
6
|
- Drop-in module system — no boilerplate
|
|
7
7
|
- Automatic async module loading and initialization
|
|
8
|
-
- Built-in CLI for bootstrapping and testing
|
|
8
|
+
- Built-in CLI for scaffolding, bootstrapping, and testing
|
|
9
9
|
|
|
10
10
|
## Quick Start
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
-
npm install stonyx
|
|
13
|
+
npm install -g stonyx
|
|
14
|
+
stonyx new my-app
|
|
15
|
+
cd my-app
|
|
16
|
+
stonyx serve
|
|
14
17
|
```
|
|
15
18
|
|
|
16
|
-
The
|
|
19
|
+
The `new` command walks you through module selection and generates a ready-to-run project. From there, the CLI handles bootstrapping:
|
|
17
20
|
|
|
18
21
|
```bash
|
|
19
22
|
stonyx serve # Bootstrap + run app.js
|
|
20
23
|
stonyx test # Bootstrap + run tests
|
|
24
|
+
stonyx help # Show all available commands
|
|
21
25
|
```
|
|
22
26
|
|
|
23
27
|
Stonyx reads `config/environment.js`, initializes all `@stonyx/*` modules from your `devDependencies`, and runs your application.
|
|
@@ -40,8 +44,11 @@ Stonyx reads `config/environment.js`, initializes all `@stonyx/*` modules from y
|
|
|
40
44
|
| Module | Description |
|
|
41
45
|
|--------|-------------|
|
|
42
46
|
| [@stonyx/cron](https://github.com/abofs/stonyx-cron) | Lightweight async job scheduling |
|
|
43
|
-
| [@stonyx/
|
|
47
|
+
| [@stonyx/events](https://github.com/abofs/stonyx-events) | Pub/sub event system |
|
|
48
|
+
| [@stonyx/oauth](https://github.com/abofs/stonyx-oauth) | OAuth provider integration |
|
|
44
49
|
| [@stonyx/orm](https://github.com/abofs/stonyx-orm) | ORM with models, relationships, and serializers |
|
|
50
|
+
| [@stonyx/rest-server](https://github.com/abofs/stonyx-rest-server) | Dynamic REST server with auto-route registration |
|
|
51
|
+
| [@stonyx/sockets](https://github.com/abofs/stonyx-sockets) | WebSocket server and client |
|
|
45
52
|
|
|
46
53
|
## License
|
|
47
54
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stonyx",
|
|
3
|
-
"version": "0.2.3-alpha.
|
|
3
|
+
"version": "0.2.3-alpha.11",
|
|
4
4
|
"description": "Base stonyx framework module",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -18,6 +18,11 @@
|
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "git+https://github.com/abofs/stonyx.git"
|
|
20
20
|
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src",
|
|
23
|
+
"config",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
21
26
|
"publishConfig": {
|
|
22
27
|
"provenance": true
|
|
23
28
|
},
|
|
@@ -30,10 +35,10 @@
|
|
|
30
35
|
"url": "https://github.com/abofs/stonyx/issues"
|
|
31
36
|
},
|
|
32
37
|
"dependencies": {
|
|
33
|
-
"
|
|
38
|
+
"@stonyx/utils": "0.2.3-beta.7",
|
|
39
|
+
"@stonyx/logs": "^1.0.0"
|
|
34
40
|
},
|
|
35
41
|
"devDependencies": {
|
|
36
|
-
"@stonyx/utils": "0.2.3-beta.5",
|
|
37
42
|
"qunit": "^2.24.1",
|
|
38
43
|
"sinon": "^21.0.0"
|
|
39
44
|
},
|
package/src/cli/new.js
CHANGED
|
@@ -33,6 +33,11 @@ const MODULE_OPTIONS = [
|
|
|
33
33
|
{
|
|
34
34
|
question: 'Will this project need pub/sub events?',
|
|
35
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']
|
|
36
41
|
}
|
|
37
42
|
];
|
|
38
43
|
|
package/src/cli.js
CHANGED
package/src/main.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import Chronicle from '
|
|
17
|
+
import Chronicle from '@stonyx/logs';
|
|
18
18
|
import loadModules from './modules.js';
|
|
19
19
|
import { kebabCaseToCamelCase } from '@stonyx/utils/string';
|
|
20
20
|
import { mergeObject } from '@stonyx/utils/object';
|
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.
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# Developing Modules
|
|
2
|
-
|
|
3
|
-
Guide for building custom Stonyx modules.
|
|
4
|
-
|
|
5
|
-
## Package Setup
|
|
6
|
-
|
|
7
|
-
Your module's `package.json` must include:
|
|
8
|
-
|
|
9
|
-
```json
|
|
10
|
-
{
|
|
11
|
-
"name": "@stonyx/my-module",
|
|
12
|
-
"keywords": ["stonyx-module"],
|
|
13
|
-
"main": "src/index.js"
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Add `stonyx-async` to keywords if your module requires asynchronous initialization.
|
|
18
|
-
|
|
19
|
-
## Module Class
|
|
20
|
-
|
|
21
|
-
Export a default class. Optionally define `init()`, `startup()`, and `shutdown()` methods:
|
|
22
|
-
|
|
23
|
-
```js
|
|
24
|
-
export default class MyModule {
|
|
25
|
-
// Called during module loading (async modules only)
|
|
26
|
-
async init() {
|
|
27
|
-
// Connect to services, load resources, etc.
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Called after ALL modules are initialized, before app entry runs
|
|
31
|
-
async startup() {
|
|
32
|
-
// Register routes, start listeners, etc.
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Called on SIGTERM/SIGINT, in reverse load order
|
|
36
|
-
async shutdown() {
|
|
37
|
-
// Close connections, flush data, etc.
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Default Configuration
|
|
43
|
-
|
|
44
|
-
Async modules must include `config/environment.js` with sensible defaults:
|
|
45
|
-
|
|
46
|
-
```js
|
|
47
|
-
export default {
|
|
48
|
-
logColor: 'cyan',
|
|
49
|
-
logMethod: 'myModule',
|
|
50
|
-
logTimestamp: true,
|
|
51
|
-
// Module-specific defaults...
|
|
52
|
-
};
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
User project config is merged on top of these defaults.
|
|
56
|
-
|
|
57
|
-
## Waiting for Other Modules
|
|
58
|
-
|
|
59
|
-
If your module depends on another async module being ready:
|
|
60
|
-
|
|
61
|
-
```js
|
|
62
|
-
import { waitForModule } from 'stonyx';
|
|
63
|
-
|
|
64
|
-
export default class MyModule {
|
|
65
|
-
async init() {
|
|
66
|
-
await waitForModule('rest-server');
|
|
67
|
-
// @stonyx/rest-server is now fully initialized
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
Pass the module name without the `@stonyx/` prefix.
|
|
73
|
-
|
|
74
|
-
## Standalone Development
|
|
75
|
-
|
|
76
|
-
When running a module standalone (project path contains `stonyx-`), Stonyx auto-transforms the config structure. Your module's config is wrapped under its camelCase name:
|
|
77
|
-
|
|
78
|
-
```js
|
|
79
|
-
// If your module is @stonyx/rest-server and config is { port: 3000 }
|
|
80
|
-
// Stonyx transforms it to: { restServer: { port: 3000 } }
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Custom CLI Commands
|
|
84
|
-
|
|
85
|
-
Modules can register CLI commands by adding a `./commands` export:
|
|
86
|
-
|
|
87
|
-
```json
|
|
88
|
-
{
|
|
89
|
-
"exports": {
|
|
90
|
-
"./commands": "./src/commands.js"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
```js
|
|
96
|
-
// src/commands.js
|
|
97
|
-
export default {
|
|
98
|
-
'my-module:setup': {
|
|
99
|
-
description: 'Initialize module resources',
|
|
100
|
-
bootstrap: true,
|
|
101
|
-
run: async ({ args, cwd }) => {
|
|
102
|
-
// Command implementation
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
Use namespaced command names (e.g., `my-module:setup`) to avoid conflicts with other modules. See [CLI](cli.md#module-commands) for details.
|
package/docs/index.md
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# Stonyx Documentation
|
|
2
|
-
|
|
3
|
-
## Guides
|
|
4
|
-
|
|
5
|
-
- [CLI](cli.md) — Commands, usage, and module-contributed commands
|
|
6
|
-
- [Configuration](configuration.md) — Environment config, module config, and test overrides
|
|
7
|
-
- [Modules](modules.md) — Module discovery, sync vs async, and official modules
|
|
8
|
-
- [Lifecycle](lifecycle.md) — Startup/shutdown hooks and signal handling
|
|
9
|
-
- [Logging](logging.md) — Color-coded logging via Chronicle
|
|
10
|
-
- [Testing](testing.md) — Running tests, config overrides, and integration helpers
|
|
11
|
-
- [Developing Modules](developing-modules.md) — Guide for building custom Stonyx modules
|
|
12
|
-
|
|
13
|
-
## Reference
|
|
14
|
-
|
|
15
|
-
- [API Reference](api.md) — Public exports and class documentation
|
package/docs/lifecycle.md
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# Lifecycle Hooks
|
|
2
|
-
|
|
3
|
-
Stonyx modules can define `startup()` and `shutdown()` methods that run at specific points in the application lifecycle.
|
|
4
|
-
|
|
5
|
-
## Startup Hooks
|
|
6
|
-
|
|
7
|
-
Called sequentially (in module load order) after all modules have been initialized, right before your application entry point runs.
|
|
8
|
-
|
|
9
|
-
```js
|
|
10
|
-
export default class MyModule {
|
|
11
|
-
async startup() {
|
|
12
|
-
// Called after all modules are init'd, before app.js runs
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Shutdown Hooks
|
|
18
|
-
|
|
19
|
-
Called sequentially in **reverse** module load order when the process receives `SIGTERM` or `SIGINT`. Errors in one hook do not prevent other hooks from running.
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
export default class MyModule {
|
|
23
|
-
async shutdown() {
|
|
24
|
-
// Clean up connections, flush buffers, etc.
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Signal Handling
|
|
30
|
-
|
|
31
|
-
The `stonyx serve` command registers signal handlers automatically:
|
|
32
|
-
|
|
33
|
-
- **SIGTERM** — triggers shutdown hooks, then `process.exit(0)`
|
|
34
|
-
- **SIGINT** — triggers shutdown hooks, then `process.exit(0)`
|
|
35
|
-
|
|
36
|
-
Shutdown is idempotent — calling the handler multiple times only runs hooks once.
|
|
37
|
-
|
|
38
|
-
## Using Lifecycle Hooks Directly
|
|
39
|
-
|
|
40
|
-
For advanced use cases, the lifecycle functions are available as a public export:
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
import { runStartupHooks, runShutdownHooks } from 'stonyx/lifecycle';
|
|
44
|
-
|
|
45
|
-
await runStartupHooks(modules); // Calls startup() on each module in order
|
|
46
|
-
await runShutdownHooks(modules); // Calls shutdown() on each module in reverse order
|
|
47
|
-
```
|
package/docs/logging.md
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# Logging
|
|
2
|
-
|
|
3
|
-
Stonyx provides centralized, color-coded logging via [Chronicle](https://github.com/abofs/chronicle).
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
Every Stonyx instance creates a Chronicle logger with a default `title` log type (green). Modules and user services can register additional log types with custom colors.
|
|
8
|
-
|
|
9
|
-
## Module Logs
|
|
10
|
-
|
|
11
|
-
Modules that specify `logColor` in their configuration automatically get a Chronicle log type:
|
|
12
|
-
|
|
13
|
-
```js
|
|
14
|
-
// config/environment.js
|
|
15
|
-
export default {
|
|
16
|
-
restServer: {
|
|
17
|
-
logColor: 'yellow',
|
|
18
|
-
logMethod: 'api', // Optional — defaults to the config key name
|
|
19
|
-
logTimestamp: true, // Optional — adds timestamps to log output
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
This creates a `chronicle.api()` method that outputs in yellow with timestamps.
|
|
25
|
-
|
|
26
|
-
## Custom Logs
|
|
27
|
-
|
|
28
|
-
You can define logs for any class or service in your project — not just Stonyx modules:
|
|
29
|
-
|
|
30
|
-
```js
|
|
31
|
-
export default {
|
|
32
|
-
myWorker: {
|
|
33
|
-
logColor: 'cyan',
|
|
34
|
-
logMethod: 'worker',
|
|
35
|
-
logTimestamp: true,
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Any top-level config key with a `logColor` property will have a log type created automatically.
|
|
41
|
-
|
|
42
|
-
## Accessing the Logger
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
import log from 'stonyx/log';
|
|
46
|
-
|
|
47
|
-
log.title('Application started');
|
|
48
|
-
log.api('Request received'); // If restServer config defines logMethod: 'api'
|
|
49
|
-
log.worker('Processing job'); // If myWorker config defines logMethod: 'worker'
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
The `stonyx/log` export is a live reference to the Chronicle instance. It will throw if accessed before Stonyx is initialized.
|
package/docs/modules.md
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# Module System
|
|
2
|
-
|
|
3
|
-
Stonyx uses a plug-and-play module architecture. Modules are automatically detected, loaded, and initialized at startup.
|
|
4
|
-
|
|
5
|
-
## How Modules Are Discovered
|
|
6
|
-
|
|
7
|
-
Stonyx scans your project's `devDependencies` for packages prefixed with `@stonyx/`. Each matching package must include the `stonyx-module` keyword in its `package.json` to be loaded.
|
|
8
|
-
|
|
9
|
-
```json
|
|
10
|
-
{
|
|
11
|
-
"name": "@stonyx/my-module",
|
|
12
|
-
"keywords": ["stonyx-module"],
|
|
13
|
-
"main": "src/index.js"
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Sync vs Async Modules
|
|
18
|
-
|
|
19
|
-
### Sync Modules
|
|
20
|
-
|
|
21
|
-
Modules with only the `stonyx-module` keyword are treated as synchronous. They are instantiated but their promise resolves immediately — no init phase is awaited.
|
|
22
|
-
|
|
23
|
-
### Async Modules
|
|
24
|
-
|
|
25
|
-
Modules that also include the `stonyx-async` keyword require initialization before they're ready:
|
|
26
|
-
|
|
27
|
-
```json
|
|
28
|
-
{
|
|
29
|
-
"keywords": ["stonyx-module", "stonyx-async"]
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Async modules **must** include a `config/environment.js` with default configuration. This is merged with the user's project config before initialization.
|
|
34
|
-
|
|
35
|
-
Async modules can define an `init()` method that Stonyx awaits:
|
|
36
|
-
|
|
37
|
-
```js
|
|
38
|
-
export default class MyModule {
|
|
39
|
-
async init() {
|
|
40
|
-
// Connect to database, start server, etc.
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
All module `init()` calls run concurrently via `Promise.all`.
|
|
46
|
-
|
|
47
|
-
## Module Lifecycle
|
|
48
|
-
|
|
49
|
-
1. **Discovery** — scan `devDependencies` for `@stonyx/*` packages
|
|
50
|
-
2. **Validation** — verify `stonyx-module` keyword exists
|
|
51
|
-
3. **Config merge** — async module defaults merged with user config
|
|
52
|
-
4. **Log setup** — module-specific Chronicle log created if `logColor` is set
|
|
53
|
-
5. **Instantiation** — module class is `new`'d
|
|
54
|
-
6. **Initialization** — `init()` called (async modules only)
|
|
55
|
-
7. **Startup hooks** — `startup()` called after all modules init (see [Lifecycle](lifecycle.md))
|
|
56
|
-
8. **Shutdown hooks** — `shutdown()` called on process exit (see [Lifecycle](lifecycle.md))
|
|
57
|
-
|
|
58
|
-
## waitForModule
|
|
59
|
-
|
|
60
|
-
For submodule developers who need to ensure another async module is ready:
|
|
61
|
-
|
|
62
|
-
```js
|
|
63
|
-
import { waitForModule } from 'stonyx';
|
|
64
|
-
|
|
65
|
-
await waitForModule('rest-server'); // Waits for @stonyx/rest-server
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
> **Note:** `waitForModule` is only needed during submodule development or testing. End-user applications don't need it — the CLI ensures all modules are initialized before running your app.
|
|
69
|
-
|
|
70
|
-
## Official Modules
|
|
71
|
-
|
|
72
|
-
| Module | Description |
|
|
73
|
-
|--------|-------------|
|
|
74
|
-
| [@stonyx/cron](https://github.com/abofs/stonyx-cron) | Lightweight async job scheduling with min-heap |
|
|
75
|
-
| [@stonyx/rest-server](https://github.com/abofs/stonyx-rest-server) | Dynamic REST server with auto-route registration |
|
|
76
|
-
| [@stonyx/orm](https://github.com/abofs/stonyx-orm) | ORM with models, relationships, serializers, and optional REST integration |
|
|
77
|
-
|
|
78
|
-
See each module's repository for its specific documentation.
|
package/docs/testing.md
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# Testing
|
|
2
|
-
|
|
3
|
-
Stonyx includes built-in test infrastructure using [QUnit](https://qunitjs.com/).
|
|
4
|
-
|
|
5
|
-
## Running Tests
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
stonyx test # Runs test/**/*-test.js by default
|
|
9
|
-
stonyx test "test/unit/**/*.js" # Custom glob pattern
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
The test command:
|
|
13
|
-
1. Sets `NODE_ENV=test`
|
|
14
|
-
2. Bootstraps Stonyx via a `--require` setup file
|
|
15
|
-
3. Applies [test config overrides](configuration.md#test-environment-overrides)
|
|
16
|
-
4. Runs QUnit with the specified glob
|
|
17
|
-
|
|
18
|
-
## Test Config Overrides
|
|
19
|
-
|
|
20
|
-
Create `test/config/environment.js` to override configuration during tests:
|
|
21
|
-
|
|
22
|
-
```js
|
|
23
|
-
export default {
|
|
24
|
-
debug: false,
|
|
25
|
-
restServer: { port: 0 },
|
|
26
|
-
};
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
These are deep-merged into the main config. See [Configuration](configuration.md#test-environment-overrides).
|
|
30
|
-
|
|
31
|
-
## Integration Test Helper
|
|
32
|
-
|
|
33
|
-
For tests that need Stonyx fully initialized (e.g., testing modules with database connections):
|
|
34
|
-
|
|
35
|
-
```js
|
|
36
|
-
import { setupIntegrationTests } from 'stonyx/test-helpers';
|
|
37
|
-
|
|
38
|
-
const { module, test } = QUnit;
|
|
39
|
-
|
|
40
|
-
module('My Integration Test', function(hooks) {
|
|
41
|
-
setupIntegrationTests(hooks);
|
|
42
|
-
|
|
43
|
-
test('can access modules', function(assert) {
|
|
44
|
-
// Stonyx is fully initialized here
|
|
45
|
-
assert.ok(true);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
`setupIntegrationTests` adds a `before` hook that waits for `Stonyx.ready` to resolve.
|
|
51
|
-
|
|
52
|
-
## Test File Convention
|
|
53
|
-
|
|
54
|
-
Place tests under `test/` with the `-test.js` suffix:
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
test/
|
|
58
|
-
unit/
|
|
59
|
-
my-feature-test.js
|
|
60
|
-
cli/
|
|
61
|
-
serve-test.js
|
|
62
|
-
integration/
|
|
63
|
-
api-test.js
|
|
64
|
-
```
|
package/scripts/postinstall.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { copyFile, createDirectory } from '@stonyx/utils/file';
|
|
2
|
-
|
|
3
|
-
const projectDir = process.env.INIT_CWD;
|
|
4
|
-
const configDir = `${projectDir}/config`;
|
|
5
|
-
const envFile = 'environment.js';
|
|
6
|
-
|
|
7
|
-
createDirectory(configDir);
|
|
8
|
-
|
|
9
|
-
copyFile(`./config/environment copy.js`, `${configDir}/${envFile}`).then(result => {
|
|
10
|
-
if (result) console.log(`Stonyx: ${envFile} has been successfully created. Please see README.md for more information.`);
|
|
11
|
-
});
|