wmx-os-core 0.1.0
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/package.json +18 -0
- package/src/config.ts +41 -0
- package/src/context.ts +20 -0
- package/src/index.ts +6 -0
- package/src/logger.ts +25 -0
- package/src/plugin.ts +14 -0
- package/tsconfig.json +8 -0
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wmx-os-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc --project tsconfig.json",
|
|
9
|
+
"dev": "tsc --project tsconfig.json --watch"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"chalk": "^5.0.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/node": "^26.0.1",
|
|
16
|
+
"typescript": "^5.4.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
2
|
+
import { join, resolve } from "path";
|
|
3
|
+
|
|
4
|
+
export interface WmxConfig {
|
|
5
|
+
framework?: string;
|
|
6
|
+
backend?: string;
|
|
7
|
+
database?: string;
|
|
8
|
+
ignore?: string[];
|
|
9
|
+
plugins?: string[];
|
|
10
|
+
deploy?: {
|
|
11
|
+
provider: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const CONFIG_FILENAME = ".wmxrc.json";
|
|
16
|
+
|
|
17
|
+
export function loadConfig(cwd: string): WmxConfig | null {
|
|
18
|
+
let current = resolve(cwd);
|
|
19
|
+
|
|
20
|
+
while (true) {
|
|
21
|
+
const candidate = join(current, CONFIG_FILENAME);
|
|
22
|
+
|
|
23
|
+
if (existsSync(candidate)) {
|
|
24
|
+
try {
|
|
25
|
+
const raw = readFileSync(candidate, "utf-8");
|
|
26
|
+
return JSON.parse(raw) as WmxConfig;
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const parent = resolve(current, "..");
|
|
33
|
+
if (parent === current) return null;
|
|
34
|
+
current = parent;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function saveConfig(config: WmxConfig, dir: string): void {
|
|
39
|
+
const configPath = join(dir, CONFIG_FILENAME);
|
|
40
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
41
|
+
}
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { loadConfig } from "./config.js";
|
|
2
|
+
import { logger, Logger } from "./logger.js";
|
|
3
|
+
import type { WmxConfig } from "./config.js";
|
|
4
|
+
|
|
5
|
+
export interface WmxContext {
|
|
6
|
+
cwd: string;
|
|
7
|
+
config: WmxConfig | null;
|
|
8
|
+
logger: Logger;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function createContext(): Promise<WmxContext> {
|
|
12
|
+
const cwd = process.cwd();
|
|
13
|
+
const config = loadConfig(cwd);
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
cwd,
|
|
17
|
+
config,
|
|
18
|
+
logger,
|
|
19
|
+
};
|
|
20
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { logger, Logger } from "./logger.js";
|
|
2
|
+
export type { WmxConfig } from "./config.js";
|
|
3
|
+
export { loadConfig, saveConfig } from "./config.js";
|
|
4
|
+
export type { WmxContext } from "./context.js";
|
|
5
|
+
export { createContext } from "./context.js";
|
|
6
|
+
export type { WmxCommand, WmxPlugin } from "./plugin.js";
|
package/src/logger.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
|
|
3
|
+
export class Logger {
|
|
4
|
+
info(message: string): void {
|
|
5
|
+
console.log(`${chalk.blue("[i]")} ${message}`);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
success(message: string): void {
|
|
9
|
+
console.log(`${chalk.green("[ok]")} ${message}`);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
warn(message: string): void {
|
|
13
|
+
console.warn(`${chalk.yellow("[!]")} ${message}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
error(message: string): void {
|
|
17
|
+
console.error(`${chalk.red("[x]")} ${message}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
debug(message: string): void {
|
|
21
|
+
console.log(`${chalk.gray("[...]")} ${message}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const logger = new Logger();
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { WmxContext } from "./context.js";
|
|
2
|
+
|
|
3
|
+
export interface WmxCommand {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
options?: Record<string, string>;
|
|
7
|
+
run(options: Record<string, unknown>, context: WmxContext): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface WmxPlugin {
|
|
11
|
+
name: string;
|
|
12
|
+
version: string;
|
|
13
|
+
commands?: WmxCommand[];
|
|
14
|
+
}
|