stonyx 0.2.3-beta.2 → 0.2.3-beta.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 +12 -4
- package/package.json +8 -3
- package/src/cli/help.js +48 -29
- package/src/cli/new.js +237 -0
- package/src/cli.js +4 -2
- package/src/main.js +1 -1
- 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,12 @@ 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/discord](https://github.com/abofs/stonyx-discord) | Discord bot with command and event handler auto-discovery |
|
|
48
|
+
| [@stonyx/events](https://github.com/abofs/stonyx-events) | Pub/sub event system |
|
|
49
|
+
| [@stonyx/oauth](https://github.com/abofs/stonyx-oauth) | OAuth provider integration |
|
|
44
50
|
| [@stonyx/orm](https://github.com/abofs/stonyx-orm) | ORM with models, relationships, and serializers |
|
|
51
|
+
| [@stonyx/rest-server](https://github.com/abofs/stonyx-rest-server) | Dynamic REST server with auto-route registration |
|
|
52
|
+
| [@stonyx/sockets](https://github.com/abofs/stonyx-sockets) | WebSocket server and client |
|
|
45
53
|
|
|
46
54
|
## License
|
|
47
55
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stonyx",
|
|
3
|
-
"version": "0.2.3-beta.
|
|
3
|
+
"version": "0.2.3-beta.21",
|
|
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.10",
|
|
39
|
+
"@stonyx/logs": "1.0.1-beta.5"
|
|
34
40
|
},
|
|
35
41
|
"devDependencies": {
|
|
36
|
-
"@stonyx/utils": "0.2.3-beta.3",
|
|
37
42
|
"qunit": "^2.24.1",
|
|
38
43
|
"sinon": "^21.0.0"
|
|
39
44
|
},
|
package/src/cli/help.js
CHANGED
|
@@ -1,29 +1,48 @@
|
|
|
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
|
-
|
|
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, n=new, h=help\n');
|
|
29
|
+
|
|
30
|
+
console.log('Project conventions:\n');
|
|
31
|
+
console.log(' Entry point: app.js');
|
|
32
|
+
console.log(' Config: config/environment.js');
|
|
33
|
+
console.log(' DB schema: config/db-schema.js');
|
|
34
|
+
console.log(' Models: models/');
|
|
35
|
+
console.log(' Serializers: serializers/');
|
|
36
|
+
console.log(' Access control: access/');
|
|
37
|
+
console.log(' Transforms: transforms/');
|
|
38
|
+
console.log(' Hooks: hooks/');
|
|
39
|
+
console.log(' REST requests: requests/');
|
|
40
|
+
console.log(' Cron jobs: crons/');
|
|
41
|
+
console.log(' Tests: test/{unit,integration,acceptance}/');
|
|
42
|
+
console.log('');
|
|
43
|
+
console.log(' Logging: import log from \'stonyx/log\' (never console.log)');
|
|
44
|
+
console.log(' Utilities: import from \'@stonyx/utils/*\' (never raw fs)');
|
|
45
|
+
console.log(' Lint config: import from \'@abofs/code-conventions\'');
|
|
46
|
+
console.log(' Package manager: pnpm');
|
|
47
|
+
console.log('');
|
|
48
|
+
}
|
package/src/cli/new.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { confirm, prompt } from '@stonyx/utils/prompt';
|
|
2
|
+
import { createFile, createDirectory, copyFile, fileExists } from '@stonyx/utils/file';
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
|
|
7
|
+
const MODULE_OPTIONS = [
|
|
8
|
+
{
|
|
9
|
+
question: 'Will this project need a REST server?',
|
|
10
|
+
package: '@stonyx/rest-server',
|
|
11
|
+
dirs: ['requests']
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
question: 'Will this project need WebSockets?',
|
|
15
|
+
package: '@stonyx/sockets',
|
|
16
|
+
dirs: ['socket-handlers']
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
question: 'Will this project need data management?',
|
|
20
|
+
package: '@stonyx/orm',
|
|
21
|
+
dirs: ['models', 'serializers', 'access', 'transforms', 'hooks'],
|
|
22
|
+
files: { 'config/db-schema.js': generateDbSchema }
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
question: 'Will this project need scheduled tasks (cron)?',
|
|
26
|
+
package: '@stonyx/cron',
|
|
27
|
+
dirs: ['crons']
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
question: 'Will this project need OAuth?',
|
|
31
|
+
package: '@stonyx/oauth'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
question: 'Will this project need pub/sub events?',
|
|
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']
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
function generateDbSchema() {
|
|
45
|
+
return `import { Model, hasMany } from '@stonyx/orm';
|
|
46
|
+
|
|
47
|
+
export default class DBModel extends Model {
|
|
48
|
+
// Define your collections here
|
|
49
|
+
// examples = hasMany('example');
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function generatePackageJson(name, selectedModules) {
|
|
55
|
+
const devDependencies = { stonyx: 'latest' };
|
|
56
|
+
|
|
57
|
+
for (const mod of selectedModules) {
|
|
58
|
+
devDependencies[mod.package] = 'latest';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Sort dependencies alphabetically
|
|
62
|
+
const sorted = Object.fromEntries(
|
|
63
|
+
Object.entries(devDependencies).sort(([a], [b]) => a.localeCompare(b))
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return JSON.stringify({
|
|
67
|
+
name,
|
|
68
|
+
version: '0.1.0',
|
|
69
|
+
type: 'module',
|
|
70
|
+
private: true,
|
|
71
|
+
scripts: {
|
|
72
|
+
start: 'stonyx serve',
|
|
73
|
+
test: 'stonyx test'
|
|
74
|
+
},
|
|
75
|
+
devDependencies: sorted
|
|
76
|
+
}, null, 2) + '\n';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function generateAppJs() {
|
|
80
|
+
return `import log from 'stonyx/log';
|
|
81
|
+
|
|
82
|
+
export default class App {
|
|
83
|
+
constructor() {
|
|
84
|
+
if (App.instance) return App.instance;
|
|
85
|
+
App.instance = this;
|
|
86
|
+
|
|
87
|
+
this.ready = this.init();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async init() {
|
|
91
|
+
log.info('Initializing Application');
|
|
92
|
+
|
|
93
|
+
// Application setup here
|
|
94
|
+
|
|
95
|
+
log.info('Application has been initialized');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function generateEnvironmentJs() {
|
|
102
|
+
return `export default {
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function generateEnvironmentExampleJs() {
|
|
108
|
+
return `// Copy this file to environment.js and fill in your values
|
|
109
|
+
// All values should use environment variables with ?? fallback defaults
|
|
110
|
+
|
|
111
|
+
const {
|
|
112
|
+
NODE_ENV,
|
|
113
|
+
} = process.env;
|
|
114
|
+
|
|
115
|
+
const environment = NODE_ENV ?? 'development';
|
|
116
|
+
|
|
117
|
+
export default {
|
|
118
|
+
}
|
|
119
|
+
`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function generateGitignore() {
|
|
123
|
+
return `node_modules/
|
|
124
|
+
.env
|
|
125
|
+
db.json
|
|
126
|
+
*.log
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function runPnpmInstall(projectDir) {
|
|
131
|
+
return new Promise((resolve, reject) => {
|
|
132
|
+
const child = spawn('pnpm', ['install'], {
|
|
133
|
+
cwd: projectDir,
|
|
134
|
+
stdio: 'inherit'
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
child.on('close', code => {
|
|
138
|
+
if (code === 0) resolve();
|
|
139
|
+
else reject(new Error(`pnpm install exited with code ${code}`));
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
child.on('error', reject);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export default async function newCommand({ args }) {
|
|
147
|
+
let appName = args[0];
|
|
148
|
+
|
|
149
|
+
if (!appName) {
|
|
150
|
+
appName = await prompt('Project name:');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!appName) {
|
|
154
|
+
console.error('Project name is required.');
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const projectDir = path.resolve(process.cwd(), appName);
|
|
159
|
+
|
|
160
|
+
if (await fileExists(projectDir)) {
|
|
161
|
+
console.error(`Directory "${appName}" already exists.`);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
console.log(`\nScaffolding new Stonyx project: ${appName}\n`);
|
|
166
|
+
|
|
167
|
+
// Prompt for module selection
|
|
168
|
+
const selectedModules = [];
|
|
169
|
+
|
|
170
|
+
for (const mod of MODULE_OPTIONS) {
|
|
171
|
+
if (await confirm(mod.question)) {
|
|
172
|
+
selectedModules.push(mod);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
console.log('\nCreating project structure...\n');
|
|
177
|
+
|
|
178
|
+
// Create project directory
|
|
179
|
+
await createDirectory(projectDir);
|
|
180
|
+
|
|
181
|
+
// Copy .nvmrc from monorepo root
|
|
182
|
+
const monorepoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
|
|
183
|
+
const nvmrcSource = path.join(monorepoRoot, '.nvmrc');
|
|
184
|
+
|
|
185
|
+
if (await fileExists(nvmrcSource)) {
|
|
186
|
+
await copyFile(nvmrcSource, path.join(projectDir, '.nvmrc'));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Generate core files
|
|
190
|
+
await createFile(path.join(projectDir, 'package.json'), generatePackageJson(appName, selectedModules));
|
|
191
|
+
await createFile(path.join(projectDir, 'app.js'), generateAppJs());
|
|
192
|
+
await createFile(path.join(projectDir, '.gitignore'), generateGitignore());
|
|
193
|
+
|
|
194
|
+
// Create config directory and files
|
|
195
|
+
await createFile(path.join(projectDir, 'config', 'environment.js'), generateEnvironmentJs());
|
|
196
|
+
await createFile(path.join(projectDir, 'config', 'environment.example.js'), generateEnvironmentExampleJs());
|
|
197
|
+
|
|
198
|
+
// Create module-specific directories and files
|
|
199
|
+
for (const mod of selectedModules) {
|
|
200
|
+
if (mod.dirs) {
|
|
201
|
+
for (const dir of mod.dirs) {
|
|
202
|
+
await createDirectory(path.join(projectDir, dir));
|
|
203
|
+
// Create .gitkeep so empty dirs are tracked
|
|
204
|
+
await createFile(path.join(projectDir, dir, '.gitkeep'), '');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (mod.files) {
|
|
209
|
+
for (const [filePath, generator] of Object.entries(mod.files)) {
|
|
210
|
+
await createFile(path.join(projectDir, filePath), generator());
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Create test structure
|
|
216
|
+
await createDirectory(path.join(projectDir, 'test', 'unit'));
|
|
217
|
+
await createFile(path.join(projectDir, 'test', 'unit', '.gitkeep'), '');
|
|
218
|
+
await createDirectory(path.join(projectDir, 'test', 'integration'));
|
|
219
|
+
await createFile(path.join(projectDir, 'test', 'integration', '.gitkeep'), '');
|
|
220
|
+
await createDirectory(path.join(projectDir, 'test', 'acceptance'));
|
|
221
|
+
await createFile(path.join(projectDir, 'test', 'acceptance', '.gitkeep'), '');
|
|
222
|
+
|
|
223
|
+
// Create test config
|
|
224
|
+
await createFile(path.join(projectDir, 'test', 'config', 'environment.js'), `export default {\n // Test-specific config overrides\n}\n`);
|
|
225
|
+
|
|
226
|
+
console.log('Installing dependencies...\n');
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
await runPnpmInstall(projectDir);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
console.error('Failed to install dependencies. Run `pnpm install` manually in the project directory.');
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
console.log(`\n✓ Project "${appName}" created successfully!`);
|
|
235
|
+
console.log(`\n cd ${appName}`);
|
|
236
|
+
console.log(` stonyx serve\n`);
|
|
237
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import serve from './cli/serve.js';
|
|
4
4
|
import test from './cli/test.js';
|
|
5
5
|
import help from './cli/help.js';
|
|
6
|
+
import newCommand from './cli/new.js';
|
|
6
7
|
import loadModuleCommands from './cli/load-commands.js';
|
|
7
8
|
|
|
8
9
|
try { process.loadEnvFile(); } catch { /* no .env file */ }
|
|
9
10
|
|
|
10
|
-
const aliases = { s: 'serve', t: 'test', h: 'help' };
|
|
11
|
+
const aliases = { s: 'serve', t: 'test', h: 'help', n: 'new' };
|
|
11
12
|
|
|
12
13
|
const builtInCommands = {
|
|
13
14
|
serve: { description: 'Bootstrap Stonyx and run the app', run: serve },
|
|
14
15
|
test: { description: 'Bootstrap Stonyx in test mode and run tests', run: test },
|
|
16
|
+
new: { description: 'Scaffold a new Stonyx project', run: newCommand },
|
|
15
17
|
help: { description: 'Show available commands', run: help }
|
|
16
18
|
};
|
|
17
19
|
|
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/.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
|
-
});
|