stonyx 0.2.3-alpha.7 → 0.2.3-alpha.71
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 +30 -7
- 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 +72 -0
- package/dist/cli/new.js +422 -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 +102 -0
- package/dist/modules.d.ts +5 -0
- package/dist/modules.js +186 -0
- package/dist/util/duplicate-core.d.ts +186 -0
- package/dist/util/duplicate-core.js +377 -0
- package/dist/util/import-config.d.ts +52 -0
- package/dist/util/import-config.js +256 -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 +41 -12
- package/scripts/postinstall.js +24 -2
- 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 -190
- 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
package/README.md
CHANGED
|
@@ -1,26 +1,45 @@
|
|
|
1
|
+
[](https://github.com/abofs/stonyx/actions/workflows/ci.yml)
|
|
2
|
+
[](https://www.npmjs.com/package/stonyx)
|
|
3
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
4
|
+
|
|
1
5
|
# Stonyx
|
|
2
6
|
|
|
3
7
|
**Stonyx** is a lightweight, modular framework for building modern Node.js applications. It provides a plug-and-play architecture, centralized color-coded logging, and seamless async module integration.
|
|
4
8
|
|
|
5
|
-
- 100% JavaScript (ES Modules)
|
|
6
9
|
- Drop-in module system — no boilerplate
|
|
7
10
|
- Automatic async module loading and initialization
|
|
8
|
-
- Built-in CLI for bootstrapping and testing
|
|
11
|
+
- Built-in CLI for scaffolding, bootstrapping, and testing
|
|
9
12
|
|
|
10
13
|
## Quick Start
|
|
11
14
|
|
|
12
15
|
```bash
|
|
13
|
-
npm install stonyx
|
|
16
|
+
npm install -g stonyx
|
|
17
|
+
stonyx new my-app
|
|
18
|
+
cd my-app
|
|
19
|
+
stonyx serve
|
|
14
20
|
```
|
|
15
21
|
|
|
16
|
-
The
|
|
22
|
+
The `new` command walks you through module selection and generates a ready-to-run project. From there, the CLI handles bootstrapping:
|
|
17
23
|
|
|
18
24
|
```bash
|
|
19
|
-
stonyx serve # Bootstrap + run app.js
|
|
25
|
+
stonyx serve # Bootstrap + run app.ts (or app.js)
|
|
20
26
|
stonyx test # Bootstrap + run tests
|
|
27
|
+
stonyx help # Show all available commands
|
|
21
28
|
```
|
|
22
29
|
|
|
23
|
-
Stonyx reads `config/environment.js`, initializes all `@stonyx/*` modules from your `devDependencies`, and runs your application.
|
|
30
|
+
Stonyx reads `config/environment.ts` (preferred) or `config/environment.js`, initializes all `@stonyx/*` modules from your `devDependencies`, and runs your application.
|
|
31
|
+
|
|
32
|
+
## Exports
|
|
33
|
+
|
|
34
|
+
| Import | Exports |
|
|
35
|
+
|--------|---------|
|
|
36
|
+
| `stonyx` | `Stonyx` class (default), `waitForModule(name)`; type `StoynxConfig` |
|
|
37
|
+
| `stonyx/config` | The Stonyx config object (default), bound at first import |
|
|
38
|
+
| `stonyx/log` | The Chronicle logger (default), bound at first import |
|
|
39
|
+
| `stonyx/lifecycle` | `runStartupHooks(modules)`, `runShutdownHooks(modules)` |
|
|
40
|
+
| `stonyx/test-helpers` | `setupIntegrationTests(hooks)` |
|
|
41
|
+
|
|
42
|
+
`stonyx/config` and `stonyx/log` throw at import time if Stonyx is not yet initialized, so a static `import` of either fails the importing module even if the value is never read. Import them only from code that loads after bootstrap (your app code under `stonyx serve`, or a module's `init()` path). Their default export is bound once, at first import, so it does not follow an in-process reboot (see [Testing](docs/testing.md#booting-stonyx-more-than-once-in-one-process)). See the [API Reference](docs/api.md) for details.
|
|
24
43
|
|
|
25
44
|
## Documentation
|
|
26
45
|
|
|
@@ -40,8 +59,12 @@ Stonyx reads `config/environment.js`, initializes all `@stonyx/*` modules from y
|
|
|
40
59
|
| Module | Description |
|
|
41
60
|
|--------|-------------|
|
|
42
61
|
| [@stonyx/cron](https://github.com/abofs/stonyx-cron) | Lightweight async job scheduling |
|
|
43
|
-
| [@stonyx/
|
|
62
|
+
| [@stonyx/discord](https://github.com/abofs/stonyx-discord) | Discord bot with command and event handler auto-discovery |
|
|
63
|
+
| [@stonyx/events](https://github.com/abofs/stonyx-events) | Pub/sub event system |
|
|
64
|
+
| [@stonyx/oauth](https://github.com/abofs/stonyx-oauth) | OAuth provider integration |
|
|
44
65
|
| [@stonyx/orm](https://github.com/abofs/stonyx-orm) | ORM with models, relationships, and serializers |
|
|
66
|
+
| [@stonyx/rest-server](https://github.com/abofs/stonyx-rest-server) | Dynamic REST server with auto-route registration |
|
|
67
|
+
| [@stonyx/sockets](https://github.com/abofs/stonyx-sockets) | WebSocket server and client |
|
|
45
68
|
|
|
46
69
|
## License
|
|
47
70
|
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import type { StoynxConfig } from 'stonyx';
|
|
2
|
+
|
|
3
|
+
// project configuration, override-able by listed environment variables
|
|
4
|
+
const {
|
|
5
|
+
DEBUG,
|
|
6
|
+
NODE_ENV,
|
|
7
|
+
} = process.env;
|
|
8
|
+
|
|
9
|
+
const environment = NODE_ENV ?? 'development';
|
|
10
|
+
|
|
11
|
+
const config: StoynxConfig = {
|
|
12
|
+
environment,
|
|
13
|
+
debug: DEBUG ?? environment === 'development',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default config;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CommandDefinition } from './load-commands.js';
|
|
2
|
+
interface HelpOptions {
|
|
3
|
+
args?: string[];
|
|
4
|
+
builtInCommands?: Record<string, CommandDefinition>;
|
|
5
|
+
loadModuleCommands?: () => Promise<Record<string, CommandDefinition>>;
|
|
6
|
+
}
|
|
7
|
+
export default function help({ args, builtInCommands, loadModuleCommands }?: HelpOptions): Promise<void>;
|
|
8
|
+
export {};
|
package/dist/cli/help.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export default async function help({ args, builtInCommands, loadModuleCommands } = {}) {
|
|
2
|
+
console.log('\nUsage: stonyx <command> [...args]\n');
|
|
3
|
+
console.log('Commands:\n');
|
|
4
|
+
if (builtInCommands) {
|
|
5
|
+
for (const [name, { description }] of Object.entries(builtInCommands)) {
|
|
6
|
+
console.log(` ${name.padEnd(20)} ${description}`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
if (loadModuleCommands) {
|
|
10
|
+
try {
|
|
11
|
+
const moduleCommands = await loadModuleCommands();
|
|
12
|
+
const entries = Object.entries(moduleCommands);
|
|
13
|
+
if (entries.length) {
|
|
14
|
+
console.log('\nModule commands:\n');
|
|
15
|
+
for (const [name, { description }] of entries) {
|
|
16
|
+
console.log(` ${name.padEnd(20)} ${description}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Module commands not available (e.g., no project context)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
console.log('\nAliases: s=serve, t=test, n=new, h=help\n');
|
|
25
|
+
console.log('Project conventions:\n');
|
|
26
|
+
console.log(' Entry point: app.ts (or app.js)');
|
|
27
|
+
console.log(' Config: config/environment.ts (or .js)');
|
|
28
|
+
console.log(' DB schema: config/db-schema.js');
|
|
29
|
+
console.log(' Models: models/');
|
|
30
|
+
console.log(' Serializers: serializers/');
|
|
31
|
+
console.log(' Access control: access/');
|
|
32
|
+
console.log(' Transforms: transforms/');
|
|
33
|
+
console.log(' Hooks: hooks/');
|
|
34
|
+
console.log(' REST requests: requests/');
|
|
35
|
+
console.log(' Cron jobs: crons/');
|
|
36
|
+
console.log(' Tests: test/{unit,integration,acceptance}/');
|
|
37
|
+
console.log('');
|
|
38
|
+
console.log(' Logging: import log from \'stonyx/log\' (never console.log)');
|
|
39
|
+
console.log(' Utilities: import from \'@stonyx/utils/*\' (never raw fs)');
|
|
40
|
+
console.log(' Lint config: import from \'@abofs/code-conventions\'');
|
|
41
|
+
console.log(' Package manager: pnpm');
|
|
42
|
+
console.log('');
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface CommandDefinition {
|
|
2
|
+
description: string;
|
|
3
|
+
run: (ctx: {
|
|
4
|
+
args: string[];
|
|
5
|
+
cwd?: string;
|
|
6
|
+
}) => Promise<void>;
|
|
7
|
+
bootstrap?: boolean;
|
|
8
|
+
module?: string;
|
|
9
|
+
}
|
|
10
|
+
export default function loadModuleCommands(): Promise<Record<string, CommandDefinition>>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
export default async function loadModuleCommands() {
|
|
4
|
+
const cwd = process.cwd();
|
|
5
|
+
const commands = {};
|
|
6
|
+
let projectPackage;
|
|
7
|
+
try {
|
|
8
|
+
const raw = await readFile(path.join(cwd, 'package.json'), 'utf8');
|
|
9
|
+
projectPackage = JSON.parse(raw);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return commands;
|
|
13
|
+
}
|
|
14
|
+
const allDeps = {
|
|
15
|
+
...projectPackage.dependencies,
|
|
16
|
+
...projectPackage.devDependencies
|
|
17
|
+
};
|
|
18
|
+
const stonyxModules = Object.keys(allDeps).filter(name => name.startsWith('@stonyx/'));
|
|
19
|
+
for (const moduleName of stonyxModules) {
|
|
20
|
+
let modulePackage;
|
|
21
|
+
try {
|
|
22
|
+
const raw = await readFile(path.join(cwd, 'node_modules', moduleName, 'package.json'), 'utf8');
|
|
23
|
+
modulePackage = JSON.parse(raw);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const moduleExports = modulePackage.exports;
|
|
29
|
+
if (!moduleExports || !moduleExports['./commands'])
|
|
30
|
+
continue;
|
|
31
|
+
try {
|
|
32
|
+
const commandsModule = await import(path.join(cwd, 'node_modules', moduleName, moduleExports['./commands']));
|
|
33
|
+
if (!commandsModule.default || typeof commandsModule.default !== 'object')
|
|
34
|
+
continue;
|
|
35
|
+
const moduleCommands = commandsModule.default;
|
|
36
|
+
for (const [name, command] of Object.entries(moduleCommands)) {
|
|
37
|
+
if (commands[name]) {
|
|
38
|
+
console.warn(`Warning: Command "${name}" from ${moduleName} conflicts with existing command. Skipping.`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
commands[name] = { ...command, module: moduleName };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return commands;
|
|
49
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
interface ModuleOption {
|
|
2
|
+
question: string;
|
|
3
|
+
package: string;
|
|
4
|
+
dirs?: string[];
|
|
5
|
+
files?: Record<string, () => string>;
|
|
6
|
+
}
|
|
7
|
+
export declare const MODULE_OPTIONS: ModuleOption[];
|
|
8
|
+
export declare function generateDbSchema(): string;
|
|
9
|
+
/**
|
|
10
|
+
* The version of the `stonyx` package running this generator, read from its own
|
|
11
|
+
* `package.json` at call time.
|
|
12
|
+
*
|
|
13
|
+
* Read rather than hardcoded on purpose: a literal would be correct on the day
|
|
14
|
+
* it was written and silently stale on every day after (abofs/stonyx#113).
|
|
15
|
+
*/
|
|
16
|
+
export declare function readCoreVersion(): string;
|
|
17
|
+
/**
|
|
18
|
+
* The npm dist-tag naming the release line a version belongs to:
|
|
19
|
+
* `0.2.3-beta.96` -> `beta`, `0.2.3-alpha.4` -> `alpha`, `0.2.2` -> `latest`.
|
|
20
|
+
*
|
|
21
|
+
* Every scaffolded `@stonyx/*` module is requested on the same line as the core
|
|
22
|
+
* that scaffolded it, so the generated project cannot mix a prerelease core with
|
|
23
|
+
* modules from the stable line (or the reverse).
|
|
24
|
+
*
|
|
25
|
+
* Throws, rather than guessing, when the prerelease identifier is not usable as a
|
|
26
|
+
* dist-tag. Returning it verbatim was only safe for *alphabetic* identifiers: npm
|
|
27
|
+
* parses a numeric or wildcard identifier as a version **range**, so `0.2.3-0`
|
|
28
|
+
* emitted `"0"` and `0.2.3-x` emitted `"x"`, both of which install with rc=0 and
|
|
29
|
+
* silently resolve the module's `latest` release -- for `@stonyx/orm` that is
|
|
30
|
+
* `0.3.1`, which pins `stonyx@0.2.3-beta.11` and so reproduces abofs/stonyx#113
|
|
31
|
+
* through a different door, with no error. `0.2.3-0` is reachable from this
|
|
32
|
+
* repo's own `publish.yml` `custom-version` dispatch input, which accepts any
|
|
33
|
+
* semver string and also expands the keyword `prerelease` to `x.y.z-0`.
|
|
34
|
+
*
|
|
35
|
+
* Two bounds remain, both loud rather than silent:
|
|
36
|
+
*
|
|
37
|
+
* - An alphabetic identifier is assumed to also be a published dist-tag name.
|
|
38
|
+
* True for `beta` and `alpha`, the only two lines the fleet publishes; a core
|
|
39
|
+
* released as e.g. `0.2.3-rc.1` with no `rc` dist-tag scaffolds an unresolvable
|
|
40
|
+
* module specifier, which fails `pnpm install` with
|
|
41
|
+
* `ERR_PNPM_NO_MATCHING_VERSION`. The tag has to exist on every package in
|
|
42
|
+
* `MODULE_OPTIONS`, not only on the core.
|
|
43
|
+
* - On the stable line this returns `latest`, the correct tag for that line -- but
|
|
44
|
+
* only useful once the *modules* have advanced their own `latest` tags. Today
|
|
45
|
+
* `@stonyx/orm@latest` is `0.3.1` and pins `stonyx@0.2.3-beta.11`, so the module
|
|
46
|
+
* `latest` tags must advance before the core's does (abofs/stonyx#115).
|
|
47
|
+
*/
|
|
48
|
+
export declare function releaseTagFor(version: string): string;
|
|
49
|
+
export declare function generatePackageJson(name: string, selectedModules: ModuleOption[], coreVersion?: string): string;
|
|
50
|
+
export declare function generateAppTs(): string;
|
|
51
|
+
export declare function generateEnvironmentTs(): string;
|
|
52
|
+
export declare function generateTestEnvironmentTs(): string;
|
|
53
|
+
export declare function generateSetupTs(): string;
|
|
54
|
+
export declare function generateZzExitTestTs(): string;
|
|
55
|
+
export declare function generateEnvironmentExampleTs(): string;
|
|
56
|
+
export declare function generateGitignore(): string;
|
|
57
|
+
export declare function generateTsConfig(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Rejects when `pnpm install` fails, either by exiting non-zero or by failing to
|
|
60
|
+
* spawn. Exported so the rejection path is testable without a network round-trip.
|
|
61
|
+
*/
|
|
62
|
+
export declare function runPnpmInstall(projectDir: string): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Write every scaffolded file to disk given a resolved project directory,
|
|
65
|
+
* app name, and pre-selected module options. Factored out of `newCommand`
|
|
66
|
+
* so tests can exercise the file-writing path without interactive prompts.
|
|
67
|
+
*/
|
|
68
|
+
export declare function scaffoldProject(projectDir: string, appName: string, selectedModules: ModuleOption[]): Promise<void>;
|
|
69
|
+
export default function newCommand({ args }: {
|
|
70
|
+
args: string[];
|
|
71
|
+
}): Promise<void>;
|
|
72
|
+
export {};
|