stonyx 0.2.3-beta.6 → 0.2.3-beta.60
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/config/{environment.js → environment copy.ts } +16 -12
- 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 +26 -0
- package/dist/cli/new.js +293 -0
- package/dist/cli/serve.d.ts +6 -0
- package/dist/cli/serve.js +45 -0
- package/dist/cli/test-setup.d.ts +1 -0
- package/dist/cli/test-setup.js +30 -0
- package/dist/cli/test.d.ts +4 -0
- package/dist/cli/test.js +23 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +53 -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 +22 -0
- package/dist/main.js +94 -0
- package/dist/modules.d.ts +5 -0
- package/dist/modules.js +93 -0
- package/dist/util/import-config.d.ts +1 -0
- package/dist/util/import-config.js +15 -0
- package/package.json +41 -12
- package/scripts/postinstall.js +29 -3
- 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/src/cli/help.js +0 -29
- package/src/cli/load-commands.js +0 -56
- package/src/cli/serve.js +0 -38
- package/src/cli/test-setup.js +0 -8
- package/src/cli/test.js +0 -27
- package/src/cli.js +0 -61
- 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/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/src/cli/help.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export default async function help({ args, builtInCommands, loadModuleCommands } = {}) {
|
|
2
|
-
console.log('\nUsage: stonyx <command> [...args]\n');
|
|
3
|
-
console.log('Commands:\n');
|
|
4
|
-
|
|
5
|
-
if (builtInCommands) {
|
|
6
|
-
for (const [name, { description }] of Object.entries(builtInCommands)) {
|
|
7
|
-
console.log(` ${name.padEnd(20)} ${description}`);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (loadModuleCommands) {
|
|
12
|
-
try {
|
|
13
|
-
const moduleCommands = await loadModuleCommands();
|
|
14
|
-
const entries = Object.entries(moduleCommands);
|
|
15
|
-
|
|
16
|
-
if (entries.length) {
|
|
17
|
-
console.log('\nModule commands:\n');
|
|
18
|
-
|
|
19
|
-
for (const [name, { description }] of entries) {
|
|
20
|
-
console.log(` ${name.padEnd(20)} ${description}`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
} catch {
|
|
24
|
-
// Module commands not available (e.g., no project context)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
console.log('\nAliases: s=serve, t=test, h=help\n');
|
|
29
|
-
}
|
package/src/cli/load-commands.js
DELETED
|
@@ -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/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
|
-
}
|
package/src/cli/test-setup.js
DELETED
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
|
-
}
|