stonyx 0.2.3-alpha.4 → 0.2.3-alpha.40
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 -5
- 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 +49 -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 +98 -0
- package/dist/modules.d.ts +5 -0
- package/dist/modules.js +98 -0
- package/dist/util/extension-resolution.d.ts +22 -0
- package/dist/util/extension-resolution.js +24 -0
- package/dist/util/import-config.d.ts +22 -0
- package/dist/util/import-config.js +36 -0
- package/dist/util/import-module-config.d.ts +16 -0
- package/dist/util/import-module-config.js +25 -0
- package/dist/util/resolve-entry-point.d.ts +1 -0
- package/dist/util/resolve-entry-point.js +14 -0
- package/dist/util/resolve-module-name.d.ts +14 -0
- package/dist/util/resolve-module-name.js +33 -0
- package/package.json +43 -12
- package/scripts/acceptance-ratchet.js +108 -0
- package/scripts/postinstall.js +29 -3
- package/.claude/index.md +0 -96
- 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/discord-conventions.md +0 -62
- package/docs/conventions/framework-modules.md +0 -127
- package/docs/conventions/index.md +0 -24
- package/docs/conventions/orm-conventions.md +0 -158
- package/docs/conventions/project-structure.md +0 -105
- 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/src/cli/help.js +0 -48
- package/src/cli/load-commands.js +0 -56
- package/src/cli/new.js +0 -237
- 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 -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
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
* Expected-failures ratchet for the fresh-clone scaffold acceptance harness.
|
|
4
|
+
*
|
|
5
|
+
* The harness (abofs/stonyx#89) is RED BY DESIGN until #90, #91 and #92 land.
|
|
6
|
+
* Running it bare in CI produces a permanently-red check, which is the highest-
|
|
7
|
+
* leverage place for a vacuous check to hide: nobody re-examines a check that is
|
|
8
|
+
* always red, and it cannot signal a NEW failure because it is already failing.
|
|
9
|
+
*
|
|
10
|
+
* This wrapper diffs the observed red set against
|
|
11
|
+
* `test/acceptance/expected-failures.json` IN BOTH DIRECTIONS:
|
|
12
|
+
*
|
|
13
|
+
* green today — the known reds are the baseline, so nobody is trained to
|
|
14
|
+
* ignore a red check;
|
|
15
|
+
* red on new — an unlisted failure is a regression;
|
|
16
|
+
* red on fixed — an assertion that starts PASSING while still listed fails the
|
|
17
|
+
* job, which mechanically forces each of #90-#92 to shrink the
|
|
18
|
+
* baseline in its own PR.
|
|
19
|
+
*
|
|
20
|
+
* Usage: pnpm test:acceptance:ratchet
|
|
21
|
+
*/
|
|
22
|
+
import { spawn } from 'child_process';
|
|
23
|
+
import { readFileSync } from 'fs';
|
|
24
|
+
import path from 'path';
|
|
25
|
+
import { fileURLToPath } from 'url';
|
|
26
|
+
|
|
27
|
+
const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
28
|
+
const BASELINE = path.join(REPO_ROOT, 'test', 'acceptance', 'expected-failures.json');
|
|
29
|
+
|
|
30
|
+
// The control flags hand-patch the generated project, so a controlled run says
|
|
31
|
+
// nothing about the baseline. Refuse rather than silently ratchet against it.
|
|
32
|
+
if (process.env.STONYX_ACCEPTANCE_CONTROL) {
|
|
33
|
+
console.error(
|
|
34
|
+
'STONYX_ACCEPTANCE_CONTROL is set. The ratchet compares an UNMODIFIED run against the\n' +
|
|
35
|
+
'baseline; a control run hand-patches the generated project and would falsify it.\n' +
|
|
36
|
+
'Run `pnpm test:acceptance` directly to exercise a control.'
|
|
37
|
+
);
|
|
38
|
+
process.exit(2);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const baseline = JSON.parse(readFileSync(BASELINE, 'utf8'));
|
|
42
|
+
const modulePrefix = `${baseline.module} > `;
|
|
43
|
+
const expected = new Map(baseline.expectedFailures.map(entry => [entry.name, entry.issue]));
|
|
44
|
+
|
|
45
|
+
const child = spawn(
|
|
46
|
+
process.execPath,
|
|
47
|
+
['--import', 'tsx', 'node_modules/qunit/bin/qunit.js', 'test/acceptance/**/*-test.ts'],
|
|
48
|
+
{ cwd: REPO_ROOT, env: { ...process.env, STONYX_ACCEPTANCE: '1' }, stdio: ['inherit', 'pipe', 'inherit'] }
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
let tap = '';
|
|
52
|
+
|
|
53
|
+
child.stdout.on('data', chunk => {
|
|
54
|
+
tap += String(chunk);
|
|
55
|
+
process.stdout.write(chunk);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
child.on('close', () => {
|
|
59
|
+
const observed = new Map();
|
|
60
|
+
|
|
61
|
+
for (const line of tap.split('\n')) {
|
|
62
|
+
const match = /^(not ok|ok) \d+ (.*)$/.exec(line.trim());
|
|
63
|
+
if (!match) continue;
|
|
64
|
+
|
|
65
|
+
const name = match[2].startsWith(modulePrefix) ? match[2].slice(modulePrefix.length) : match[2];
|
|
66
|
+
observed.set(name, match[1] === 'ok');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (observed.size === 0) {
|
|
70
|
+
fail(['The acceptance run produced no TAP assertions at all. This is a harness or setup failure, not a result.']);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const problems = [];
|
|
74
|
+
|
|
75
|
+
for (const [name, passed] of observed) {
|
|
76
|
+
if (!passed && !expected.has(name)) {
|
|
77
|
+
problems.push(`NEW FAILURE (not in the baseline): ${name}\n A regression, or an assertion that needs an owning issue before it is baselined.`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (passed && expected.has(name)) {
|
|
81
|
+
problems.push(
|
|
82
|
+
`NOW PASSING but still baselined (issue #${expected.get(name)}): ${name}\n` +
|
|
83
|
+
' Delete this entry from test/acceptance/expected-failures.json in the PR that fixed it.'
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (const name of expected.keys()) {
|
|
89
|
+
if (!observed.has(name)) {
|
|
90
|
+
problems.push(`BASELINED ASSERTION NOT FOUND: ${name}\n It was renamed or removed. Update the baseline in the same PR.`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (problems.length) fail(problems);
|
|
95
|
+
|
|
96
|
+
const stillRed = [...expected.keys()].filter(name => observed.get(name) === false);
|
|
97
|
+
|
|
98
|
+
console.log(`\n# acceptance ratchet: OK — ${observed.size} assertions, ${stillRed.length} expected failures, 0 unexpected.`);
|
|
99
|
+
for (const name of stillRed) console.log(`# expected red (#${expected.get(name)}): ${name}`);
|
|
100
|
+
process.exit(0);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
function fail(problems) {
|
|
104
|
+
console.error('\n# acceptance ratchet: FAILED\n');
|
|
105
|
+
for (const problem of problems) console.error(` - ${problem}\n`);
|
|
106
|
+
console.error('See test/acceptance/expected-failures.json and docs/testing.md.');
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
// Skip postinstall for global installations
|
|
2
|
+
const isGlobal = !process.env.INIT_CWD || process.env.npm_config_global === 'true';
|
|
3
|
+
if (isGlobal) process.exit(0);
|
|
4
|
+
|
|
5
|
+
const { existsSync } = await import('node:fs');
|
|
6
|
+
const { copyFile, createDirectory } = await import('@stonyx/utils/file');
|
|
2
7
|
|
|
3
8
|
const projectDir = process.env.INIT_CWD;
|
|
4
9
|
const configDir = `${projectDir}/config`;
|
|
5
|
-
|
|
10
|
+
|
|
11
|
+
// Detect consumer project type: presence of `tsconfig.json` in the consumer
|
|
12
|
+
// root signals a TypeScript project (see abofs/stonyx#62). TS consumers can't
|
|
13
|
+
// use the `.js` stub, so we ship both templates and copy the matching one.
|
|
14
|
+
const isTypeScriptConsumer = existsSync(`${projectDir}/tsconfig.json`);
|
|
15
|
+
const extension = isTypeScriptConsumer ? 'ts' : 'js';
|
|
16
|
+
const envFile = `environment.${extension}`;
|
|
17
|
+
const templateFile = `environment copy.${extension}`;
|
|
18
|
+
|
|
19
|
+
// Skip if the consumer ships its own `config/environment copy.{ts,js}` template —
|
|
20
|
+
// they manage their own bootstrap (see abofs/stonyx#54, extended in abofs/stonyx#62
|
|
21
|
+
// to honor either extension).
|
|
22
|
+
if (
|
|
23
|
+
existsSync(`${configDir}/environment copy.ts`) ||
|
|
24
|
+
existsSync(`${configDir}/environment copy.js`)
|
|
25
|
+
) process.exit(0);
|
|
26
|
+
|
|
27
|
+
// Don't overwrite an existing consumer config (either extension).
|
|
28
|
+
if (
|
|
29
|
+
existsSync(`${configDir}/environment.ts`) ||
|
|
30
|
+
existsSync(`${configDir}/environment.js`)
|
|
31
|
+
) process.exit(0);
|
|
6
32
|
|
|
7
33
|
createDirectory(configDir);
|
|
8
34
|
|
|
9
|
-
copyFile(`./config
|
|
35
|
+
copyFile(`./config/${templateFile}`, `${configDir}/${envFile}`).then(result => {
|
|
10
36
|
if (result) console.log(`Stonyx: ${envFile} has been successfully created. Please see README.md for more information.`);
|
|
11
37
|
});
|
package/.claude/index.md
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# Stonyx CLI Guide
|
|
2
|
-
|
|
3
|
-
See [docs/index.md](../docs/index.md) for full documentation including conventions, modules, lifecycle, and API reference.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Stonyx is the core framework package. The CLI is provided by the `stonyx` binary defined in `package.json`.
|
|
8
|
-
|
|
9
|
-
In a project that depends on `stonyx`:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
pnpm add -D stonyx
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
The CLI is then available as `npx stonyx` or via pnpm scripts.
|
|
16
|
-
|
|
17
|
-
## Commands
|
|
18
|
-
|
|
19
|
-
### `stonyx serve` (alias: `s`)
|
|
20
|
-
|
|
21
|
-
Bootstrap Stonyx and run the application.
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
stonyx serve # loads app.js by default
|
|
25
|
-
stonyx serve --entry custom.js # custom entry point
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Behavior:
|
|
29
|
-
1. Loads `.env` file
|
|
30
|
-
2. Imports `config/environment.js`
|
|
31
|
-
3. Initializes Stonyx with all detected `@stonyx/*` modules
|
|
32
|
-
4. Runs startup lifecycle hooks
|
|
33
|
-
5. Imports and instantiates the entry point class
|
|
34
|
-
6. Registers SIGTERM/SIGINT handlers for graceful shutdown
|
|
35
|
-
|
|
36
|
-
### `stonyx test` (alias: `t`)
|
|
37
|
-
|
|
38
|
-
Bootstrap Stonyx in test mode and run QUnit tests.
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
stonyx test # runs test/**/*-test.js
|
|
42
|
-
stonyx test test/unit/foo-test.js # specific file
|
|
43
|
-
stonyx test "test/integration/**/*-test.js" # glob pattern
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Sets `NODE_ENV=test` and auto-loads test setup which merges `test/config/environment.js` overrides.
|
|
47
|
-
|
|
48
|
-
### `stonyx help` (alias: `h`)
|
|
49
|
-
|
|
50
|
-
Show available commands including built-in and module-provided commands.
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
stonyx help
|
|
54
|
-
stonyx --help
|
|
55
|
-
stonyx -h
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### `stonyx new <app-name>`
|
|
59
|
-
|
|
60
|
-
Scaffold a new Stonyx project with interactive module selection.
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
stonyx new my-backend
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Prompts for:
|
|
67
|
-
- Package name
|
|
68
|
-
- Which `@stonyx/*` modules to include (REST server, WebSockets, ORM, cron, OAuth, events)
|
|
69
|
-
|
|
70
|
-
Creates:
|
|
71
|
-
- `package.json` with selected dependencies
|
|
72
|
-
- `app.js` entry point
|
|
73
|
-
- `config/environment.js` and `config/environment.example.js`
|
|
74
|
-
- Module-specific directories (`models/`, `requests/`, `crons/`, etc.)
|
|
75
|
-
- `test/` structure with `unit/`, `integration/`, `acceptance/`
|
|
76
|
-
- `.gitignore` and `.nvmrc`
|
|
77
|
-
- Runs `pnpm install`
|
|
78
|
-
|
|
79
|
-
## Module Command System
|
|
80
|
-
|
|
81
|
-
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.
|
|
82
|
-
|
|
83
|
-
Module commands appear under "Module commands" in `stonyx help` output. They can optionally request Stonyx bootstrap before running (via `bootstrap: true`).
|
|
84
|
-
|
|
85
|
-
## Creating a Stonyx Project Manually
|
|
86
|
-
|
|
87
|
-
If not using `stonyx new`:
|
|
88
|
-
|
|
89
|
-
1. Create project directory
|
|
90
|
-
2. Add `.nvmrc` with current LTS Node version
|
|
91
|
-
3. `pnpm init` and set `"type": "module"`
|
|
92
|
-
4. `pnpm add -D stonyx` plus desired `@stonyx/*` modules
|
|
93
|
-
5. Create `config/environment.js` with module config
|
|
94
|
-
6. Create `app.js` entry point class
|
|
95
|
-
7. Create standard directories per selected modules
|
|
96
|
-
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,62 +0,0 @@
|
|
|
1
|
-
# Discord Conventions
|
|
2
|
-
|
|
3
|
-
Conventions for projects using `@stonyx/discord`.
|
|
4
|
-
|
|
5
|
-
## Command Files
|
|
6
|
-
|
|
7
|
-
- One class per file in the configured command directory (default: `discord-commands/`)
|
|
8
|
-
- Each file default-exports a class extending `Command` from `@stonyx/discord`
|
|
9
|
-
- Class must define a `data` property (a `SlashCommandBuilder` instance) and an `async execute(interaction)` method
|
|
10
|
-
- Class ordering: static properties → `data` → `execute()`
|
|
11
|
-
- Filenames use kebab-case; `forEachFileImport` converts to camelCase for internal registration
|
|
12
|
-
- Permission checks belong in the consuming application, not in the module
|
|
13
|
-
|
|
14
|
-
```js
|
|
15
|
-
import { Command } from '@stonyx/discord';
|
|
16
|
-
import { SlashCommandBuilder } from 'discord.js';
|
|
17
|
-
|
|
18
|
-
export default class PingCommand extends Command {
|
|
19
|
-
data = new SlashCommandBuilder()
|
|
20
|
-
.setName('ping')
|
|
21
|
-
.setDescription('Replies with Pong!');
|
|
22
|
-
|
|
23
|
-
async execute(interaction) {
|
|
24
|
-
await interaction.reply('Pong!');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Event Handler Files
|
|
30
|
-
|
|
31
|
-
- One class per file in the configured event directory (default: `discord-events/`)
|
|
32
|
-
- Each file default-exports a class extending `EventHandler` from `@stonyx/discord`
|
|
33
|
-
- Class must set `static event` to a valid Discord.js event name (e.g., `'messageCreate'`, `'voiceStateUpdate'`)
|
|
34
|
-
- Class must implement a `handle(...args)` method matching the Discord.js event signature
|
|
35
|
-
- Class ordering: static properties → `handle()`
|
|
36
|
-
|
|
37
|
-
```js
|
|
38
|
-
import { EventHandler } from '@stonyx/discord';
|
|
39
|
-
|
|
40
|
-
export default class WelcomeHandler extends EventHandler {
|
|
41
|
-
static event = 'guildMemberAdd';
|
|
42
|
-
|
|
43
|
-
handle(member) {
|
|
44
|
-
// Welcome new member
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Configuration
|
|
50
|
-
|
|
51
|
-
- Config namespace: `config.discord`
|
|
52
|
-
- Environment variables prefixed with `DISCORD_`
|
|
53
|
-
- Logging: `log.discord()` — configured via `logColor: '#7289da'` and `logMethod: 'discord'`
|
|
54
|
-
- Intent auto-derivation: the module computes required gateway intents from discovered event handlers; use `additionalIntents` in config for edge cases
|
|
55
|
-
|
|
56
|
-
## Module Keywords
|
|
57
|
-
|
|
58
|
-
```json
|
|
59
|
-
"keywords": ["stonyx-async", "stonyx-module"]
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
`stonyx-async` indicates the module's `init()` is async and must be awaited by the framework.
|