@webtypen/webframez-core 0.3.35 → 0.3.37
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 +6 -6
- package/bin/webframez.cjs +8 -0
- package/dist/BuildApplication.d.ts +70 -0
- package/dist/BuildApplication.js +251 -0
- package/dist/Cli.d.ts +1 -0
- package/dist/Cli.js +124 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/info.js +1 -1
- package/package.json +6 -2
- /package/{AGENTS.md → agents/webframez_rules.md} +0 -0
package/README.md
CHANGED
|
@@ -20,14 +20,14 @@ This README reflects the current API in this repository and focuses on:
|
|
|
20
20
|
npm i @webtypen/webframez-core
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Agent-Regeln fuer Codex und Copilot
|
|
24
24
|
|
|
25
|
-
Das Paket enthaelt
|
|
25
|
+
Das Paket enthaelt unter agents/webframez_rules.md empfohlene Arbeitsregeln fuer AI-Coding-Agents in Webframez-Projekten.
|
|
26
26
|
|
|
27
27
|
Nach der Installation liegt die Datei im Paket unter:
|
|
28
28
|
|
|
29
29
|
```text
|
|
30
|
-
node_modules/@webtypen/webframez-core/
|
|
30
|
+
node_modules/@webtypen/webframez-core/agents/webframez_rules.md
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
Die Regeln beschreiben unter anderem:
|
|
@@ -35,7 +35,7 @@ Die Regeln beschreiben unter anderem:
|
|
|
35
35
|
- bevorzugte Nutzung der vorhandenen Helper wie StringFunctions, NumericFunctions und DateFunctions
|
|
36
36
|
- Verwendung der Webframez-Abstraktionen fuer Request, Response, Middleware, Storage, Datatables und Routes
|
|
37
37
|
|
|
38
|
-
Wichtig: AGENTS.md-Dateien haben keine universell standardisierte Import-Funktion. Die praktikable Variante ist deshalb, die Paket
|
|
38
|
+
Wichtig: AGENTS.md-Dateien haben keine universell standardisierte Import-Funktion. Die praktikable Variante ist deshalb, die Regeldatei aus dem Paket in der AGENTS.md des eigenen Projekts explizit zu referenzieren und projektspezifische Regeln lokal zu ergaenzen.
|
|
39
39
|
|
|
40
40
|
Beispiel fuer eine eigene AGENTS.md im Consumer-Projekt:
|
|
41
41
|
|
|
@@ -45,7 +45,7 @@ Beispiel fuer eine eigene AGENTS.md im Consumer-Projekt:
|
|
|
45
45
|
Dieses Projekt verwendet @webtypen/webframez-core.
|
|
46
46
|
|
|
47
47
|
Uebernimm fuer alle Webframez-bezogenen Implementierungen die Konventionen aus:
|
|
48
|
-
./node_modules/@webtypen/webframez-core/
|
|
48
|
+
./node_modules/@webtypen/webframez-core/agents/webframez_rules.md
|
|
49
49
|
|
|
50
50
|
Insbesondere gilt:
|
|
51
51
|
- fuer ObjectId-Konvertierungen Model.objectId(...) oder die passende Model-Instanzmethode verwenden
|
|
@@ -57,7 +57,7 @@ Projektspezifische Ergaenzung:
|
|
|
57
57
|
- Antworten im Backoffice sollen das Format { status, message, data } einhalten
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
Wenn eine Regel aus der lokalen Projekt-AGENTS.md einer Regel aus der
|
|
60
|
+
Wenn eine Regel aus der lokalen Projekt-AGENTS.md einer Regel aus der Paketdatei widerspricht, sollte die lokale Projektregel Vorrang haben.
|
|
61
61
|
|
|
62
62
|
## Basic Web Setup
|
|
63
63
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type WebframezBuildRuntimeFile = string | {
|
|
2
|
+
from: string;
|
|
3
|
+
to?: string;
|
|
4
|
+
optional?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type WebframezBuildContext = {
|
|
7
|
+
projectRoot: string;
|
|
8
|
+
stagingDir: string;
|
|
9
|
+
outDir: string;
|
|
10
|
+
config: WebframezAppConfig;
|
|
11
|
+
run: (binaryName: string, args: string[], envAdditions?: Record<string, string>) => Promise<number>;
|
|
12
|
+
};
|
|
13
|
+
export type WebframezBuildPlugin = {
|
|
14
|
+
name?: string;
|
|
15
|
+
beforeBuild?: (context: WebframezBuildContext) => Promise<void> | void;
|
|
16
|
+
afterTypescriptBuild?: (context: WebframezBuildContext) => Promise<void> | void;
|
|
17
|
+
afterRuntimeFilesCopied?: (context: WebframezBuildContext) => Promise<void> | void;
|
|
18
|
+
buildAssets?: (context: WebframezBuildContext) => Promise<void> | void;
|
|
19
|
+
validateBuild?: (context: WebframezBuildContext) => Promise<void> | void;
|
|
20
|
+
};
|
|
21
|
+
export type WebframezBuildConfig = {
|
|
22
|
+
dir?: string;
|
|
23
|
+
tsconfig?: string;
|
|
24
|
+
entry?: string;
|
|
25
|
+
runtimeFiles?: WebframezBuildRuntimeFile[];
|
|
26
|
+
prunePaths?: string[];
|
|
27
|
+
plugins?: Array<string | WebframezBuildPlugin | ((config: WebframezAppConfig) => WebframezBuildPlugin)>;
|
|
28
|
+
};
|
|
29
|
+
export type WebframezAppConfig = {
|
|
30
|
+
setup?: (context: {
|
|
31
|
+
mode: "web" | "console" | "build";
|
|
32
|
+
projectRoot: string;
|
|
33
|
+
}) => Promise<void> | void;
|
|
34
|
+
kernel?: any;
|
|
35
|
+
consoleKernel?: any;
|
|
36
|
+
kernelConsole?: any;
|
|
37
|
+
config?: Record<string, unknown>;
|
|
38
|
+
jobs?: any[];
|
|
39
|
+
modules?: any[];
|
|
40
|
+
datatables?: any;
|
|
41
|
+
errorHandler?: any;
|
|
42
|
+
onEnd?: (...args: any[]) => Promise<void> | void;
|
|
43
|
+
build?: WebframezBuildConfig;
|
|
44
|
+
};
|
|
45
|
+
type BuildApplicationOptions = {
|
|
46
|
+
outDir: string;
|
|
47
|
+
};
|
|
48
|
+
export declare class BuildApplication {
|
|
49
|
+
private readonly projectRoot;
|
|
50
|
+
private readonly config;
|
|
51
|
+
private readonly outDir;
|
|
52
|
+
private readonly buildRoot;
|
|
53
|
+
private readonly stagingDir;
|
|
54
|
+
private readonly buildId;
|
|
55
|
+
constructor(projectRoot: string, config: WebframezAppConfig, options: BuildApplicationOptions);
|
|
56
|
+
run(): Promise<void>;
|
|
57
|
+
private createContext;
|
|
58
|
+
private callHook;
|
|
59
|
+
private runTypescriptBuild;
|
|
60
|
+
private copyRuntimeFiles;
|
|
61
|
+
private validateCoreBuild;
|
|
62
|
+
private promoteBuild;
|
|
63
|
+
private loadPlugins;
|
|
64
|
+
private discoverPackagePlugins;
|
|
65
|
+
private resolvePlugin;
|
|
66
|
+
private runOrFail;
|
|
67
|
+
private runBinary;
|
|
68
|
+
private resolveBinary;
|
|
69
|
+
}
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BuildApplication = void 0;
|
|
16
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
17
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
18
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
19
|
+
const node_child_process_1 = require("node:child_process");
|
|
20
|
+
function timestamp() {
|
|
21
|
+
return new Date().toISOString().replace(/[-:TZ.]/g, "");
|
|
22
|
+
}
|
|
23
|
+
function normalizePackageWebframezPlugins(value) {
|
|
24
|
+
if (!value) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
if (typeof value === "string") {
|
|
28
|
+
return [value];
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
return value.filter((entry) => typeof entry === "string");
|
|
32
|
+
}
|
|
33
|
+
if (typeof value.plugin === "string") {
|
|
34
|
+
return [value.plugin];
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(value.plugins)) {
|
|
37
|
+
return value.plugins.filter((entry) => typeof entry === "string");
|
|
38
|
+
}
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
class BuildApplication {
|
|
42
|
+
constructor(projectRoot, config, options) {
|
|
43
|
+
var _a;
|
|
44
|
+
this.projectRoot = projectRoot;
|
|
45
|
+
this.config = config;
|
|
46
|
+
this.outDir = node_path_1.default.resolve(projectRoot, options.outDir || ((_a = config.build) === null || _a === void 0 ? void 0 : _a.dir) || "build");
|
|
47
|
+
this.buildId = timestamp();
|
|
48
|
+
this.buildRoot = node_path_1.default.resolve(projectRoot, ".webframez-build");
|
|
49
|
+
this.stagingDir = node_path_1.default.join(this.buildRoot, `.building-${this.buildId}`);
|
|
50
|
+
}
|
|
51
|
+
run() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const context = this.createContext();
|
|
54
|
+
const plugins = this.loadPlugins();
|
|
55
|
+
yield promises_1.default.rm(this.stagingDir, { recursive: true, force: true });
|
|
56
|
+
yield promises_1.default.mkdir(this.stagingDir, { recursive: true });
|
|
57
|
+
try {
|
|
58
|
+
yield this.callHook(plugins, "beforeBuild", context);
|
|
59
|
+
yield this.runTypescriptBuild(context);
|
|
60
|
+
yield this.callHook(plugins, "afterTypescriptBuild", context);
|
|
61
|
+
yield this.copyRuntimeFiles();
|
|
62
|
+
yield this.callHook(plugins, "afterRuntimeFilesCopied", context);
|
|
63
|
+
yield this.callHook(plugins, "buildAssets", context);
|
|
64
|
+
yield this.validateCoreBuild();
|
|
65
|
+
yield this.callHook(plugins, "validateBuild", context);
|
|
66
|
+
yield this.promoteBuild();
|
|
67
|
+
console.log(`[webframez] Build ready: ${node_path_1.default.relative(this.projectRoot, this.outDir) || this.outDir}`);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
yield promises_1.default.rm(this.stagingDir, { recursive: true, force: true });
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
createContext() {
|
|
76
|
+
return {
|
|
77
|
+
projectRoot: this.projectRoot,
|
|
78
|
+
stagingDir: this.stagingDir,
|
|
79
|
+
outDir: this.outDir,
|
|
80
|
+
config: this.config,
|
|
81
|
+
run: (binaryName, args, envAdditions) => this.runBinary(binaryName, args, envAdditions),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
callHook(plugins, hookName, context) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
for (const plugin of plugins) {
|
|
87
|
+
const hook = plugin[hookName];
|
|
88
|
+
if (typeof hook !== "function") {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
console.log(`[webframez] ${plugin.name || "plugin"}:${String(hookName)}`);
|
|
92
|
+
yield hook(context);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
runTypescriptBuild(context) {
|
|
97
|
+
var _a;
|
|
98
|
+
const tsconfig = node_path_1.default.resolve(this.projectRoot, ((_a = this.config.build) === null || _a === void 0 ? void 0 : _a.tsconfig) || "tsconfig.json");
|
|
99
|
+
return this.runOrFail(context, "tsc", ["-p", tsconfig, "--outDir", this.stagingDir]);
|
|
100
|
+
}
|
|
101
|
+
copyRuntimeFiles() {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const runtimeFiles = ((_a = this.config.build) === null || _a === void 0 ? void 0 : _a.runtimeFiles) || [
|
|
105
|
+
{ from: ".env", optional: true },
|
|
106
|
+
{ from: "storage", optional: true },
|
|
107
|
+
"node_modules",
|
|
108
|
+
];
|
|
109
|
+
for (const entry of runtimeFiles) {
|
|
110
|
+
const from = typeof entry === "string" ? entry : entry.from;
|
|
111
|
+
const to = typeof entry === "string" ? entry : entry.to || entry.from;
|
|
112
|
+
const optional = typeof entry === "string" ? false : entry.optional === true;
|
|
113
|
+
const sourcePath = node_path_1.default.resolve(this.projectRoot, from);
|
|
114
|
+
const targetPath = node_path_1.default.resolve(this.stagingDir, to);
|
|
115
|
+
if (!node_fs_1.default.existsSync(sourcePath)) {
|
|
116
|
+
if (optional) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
throw new Error(`Runtime file does not exist: ${from}`);
|
|
120
|
+
}
|
|
121
|
+
yield promises_1.default.rm(targetPath, { recursive: true, force: true });
|
|
122
|
+
yield promises_1.default.mkdir(node_path_1.default.dirname(targetPath), { recursive: true });
|
|
123
|
+
yield promises_1.default.cp(sourcePath, targetPath, {
|
|
124
|
+
recursive: true,
|
|
125
|
+
dereference: false,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
for (const prunePath of ((_b = this.config.build) === null || _b === void 0 ? void 0 : _b.prunePaths) || []) {
|
|
129
|
+
yield promises_1.default.rm(node_path_1.default.resolve(this.stagingDir, prunePath), { recursive: true, force: true });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
validateCoreBuild() {
|
|
134
|
+
var _a;
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const entry = ((_a = this.config.build) === null || _a === void 0 ? void 0 : _a.entry) || "app.js";
|
|
137
|
+
const entryPath = node_path_1.default.resolve(this.stagingDir, entry);
|
|
138
|
+
if (!node_fs_1.default.existsSync(entryPath)) {
|
|
139
|
+
throw new Error(`Build entry missing: ${entry}`);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
promoteBuild() {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const previousDir = node_path_1.default.join(this.buildRoot, `.previous-${this.buildId}`);
|
|
146
|
+
yield promises_1.default.mkdir(node_path_1.default.dirname(this.outDir), { recursive: true });
|
|
147
|
+
yield promises_1.default.rm(previousDir, { recursive: true, force: true });
|
|
148
|
+
let movedPrevious = false;
|
|
149
|
+
try {
|
|
150
|
+
if (node_fs_1.default.existsSync(this.outDir)) {
|
|
151
|
+
yield promises_1.default.rename(this.outDir, previousDir);
|
|
152
|
+
movedPrevious = true;
|
|
153
|
+
}
|
|
154
|
+
yield promises_1.default.rename(this.stagingDir, this.outDir);
|
|
155
|
+
yield promises_1.default.rm(previousDir, { recursive: true, force: true });
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (movedPrevious && !node_fs_1.default.existsSync(this.outDir) && node_fs_1.default.existsSync(previousDir)) {
|
|
159
|
+
yield promises_1.default.rename(previousDir, this.outDir);
|
|
160
|
+
}
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
loadPlugins() {
|
|
166
|
+
var _a;
|
|
167
|
+
const plugins = [];
|
|
168
|
+
for (const pluginInput of ((_a = this.config.build) === null || _a === void 0 ? void 0 : _a.plugins) || []) {
|
|
169
|
+
const plugin = this.resolvePlugin(pluginInput, this.projectRoot);
|
|
170
|
+
if (plugin) {
|
|
171
|
+
plugins.push(plugin);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for (const pluginSpec of this.discoverPackagePlugins()) {
|
|
175
|
+
const plugin = this.resolvePlugin(pluginSpec.spec, pluginSpec.packageRoot);
|
|
176
|
+
if (plugin) {
|
|
177
|
+
plugins.push(plugin);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return plugins;
|
|
181
|
+
}
|
|
182
|
+
discoverPackagePlugins() {
|
|
183
|
+
const packageJsonPath = node_path_1.default.resolve(this.projectRoot, "package.json");
|
|
184
|
+
if (!node_fs_1.default.existsSync(packageJsonPath)) {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
const packageJson = JSON.parse(node_fs_1.default.readFileSync(packageJsonPath, "utf-8"));
|
|
188
|
+
const dependencyNames = new Set([
|
|
189
|
+
...Object.keys(packageJson.dependencies || {}),
|
|
190
|
+
...Object.keys(packageJson.devDependencies || {}),
|
|
191
|
+
...Object.keys(packageJson.peerDependencies || {}),
|
|
192
|
+
]);
|
|
193
|
+
const discovered = [];
|
|
194
|
+
for (const dependencyName of dependencyNames) {
|
|
195
|
+
const dependencyPackageJsonPath = node_path_1.default.resolve(this.projectRoot, "node_modules", dependencyName, "package.json");
|
|
196
|
+
if (!node_fs_1.default.existsSync(dependencyPackageJsonPath)) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const dependencyPackageJson = JSON.parse(node_fs_1.default.readFileSync(dependencyPackageJsonPath, "utf-8"));
|
|
200
|
+
for (const plugin of normalizePackageWebframezPlugins(dependencyPackageJson.webframez)) {
|
|
201
|
+
discovered.push({
|
|
202
|
+
spec: plugin,
|
|
203
|
+
packageRoot: node_path_1.default.dirname(dependencyPackageJsonPath),
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return discovered;
|
|
208
|
+
}
|
|
209
|
+
resolvePlugin(pluginInput, baseDir) {
|
|
210
|
+
let pluginModule = pluginInput;
|
|
211
|
+
if (typeof pluginInput === "string") {
|
|
212
|
+
const pluginPath = pluginInput.startsWith(".")
|
|
213
|
+
? node_path_1.default.resolve(baseDir, pluginInput)
|
|
214
|
+
: require.resolve(pluginInput, { paths: [this.projectRoot, baseDir] });
|
|
215
|
+
pluginModule = require(pluginPath);
|
|
216
|
+
}
|
|
217
|
+
const pluginFactoryOrObject = pluginModule.default || pluginModule.createPlugin || pluginModule;
|
|
218
|
+
const plugin = typeof pluginFactoryOrObject === "function" ? pluginFactoryOrObject(this.config) : pluginFactoryOrObject;
|
|
219
|
+
return plugin || null;
|
|
220
|
+
}
|
|
221
|
+
runOrFail(context, binaryName, args) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
const code = yield context.run(binaryName, args);
|
|
224
|
+
if (code !== 0) {
|
|
225
|
+
throw new Error(`${binaryName} exited with code ${code}`);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
runBinary(binaryName, args, envAdditions = {}) {
|
|
230
|
+
const binaryPath = this.resolveBinary(binaryName);
|
|
231
|
+
return new Promise((resolve, reject) => {
|
|
232
|
+
const child = (0, node_child_process_1.spawn)(binaryPath, args, {
|
|
233
|
+
cwd: this.projectRoot,
|
|
234
|
+
stdio: "inherit",
|
|
235
|
+
shell: false,
|
|
236
|
+
env: Object.assign(Object.assign({}, process.env), envAdditions),
|
|
237
|
+
});
|
|
238
|
+
child.on("error", reject);
|
|
239
|
+
child.on("close", (code) => resolve(code || 0));
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
resolveBinary(name) {
|
|
243
|
+
const extension = process.platform === "win32" ? ".cmd" : "";
|
|
244
|
+
const localBinary = node_path_1.default.resolve(this.projectRoot, "node_modules", ".bin", `${name}${extension}`);
|
|
245
|
+
if (node_fs_1.default.existsSync(localBinary)) {
|
|
246
|
+
return localBinary;
|
|
247
|
+
}
|
|
248
|
+
return name;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.BuildApplication = BuildApplication;
|
package/dist/Cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runWebframezCli(argv?: string[], projectRoot?: string): Promise<void>;
|
package/dist/Cli.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.runWebframezCli = void 0;
|
|
16
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
17
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
18
|
+
const ConsoleApplication_1 = require("./ConsoleApplication");
|
|
19
|
+
const BuildApplication_1 = require("./BuildApplication");
|
|
20
|
+
function printHelp() {
|
|
21
|
+
console.log([
|
|
22
|
+
"webframez CLI",
|
|
23
|
+
"",
|
|
24
|
+
"Usage:",
|
|
25
|
+
" webframez run [command] [options]",
|
|
26
|
+
" webframez build [--dir=./build]",
|
|
27
|
+
"",
|
|
28
|
+
"Options:",
|
|
29
|
+
" --config=webframez.config.ts",
|
|
30
|
+
" --dir=./build-target-dir",
|
|
31
|
+
].join("\n"));
|
|
32
|
+
}
|
|
33
|
+
function readOption(args, name) {
|
|
34
|
+
const prefix = `--${name}=`;
|
|
35
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
36
|
+
const value = args[index];
|
|
37
|
+
if (value === `--${name}`) {
|
|
38
|
+
return args[index + 1] || null;
|
|
39
|
+
}
|
|
40
|
+
if (value.startsWith(prefix)) {
|
|
41
|
+
return value.slice(prefix.length);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function registerTsNode(projectRoot) {
|
|
47
|
+
const tsNodeRegister = require.resolve("ts-node/register/transpile-only", {
|
|
48
|
+
paths: [projectRoot, __dirname],
|
|
49
|
+
});
|
|
50
|
+
require(tsNodeRegister);
|
|
51
|
+
}
|
|
52
|
+
function loadConfig(projectRoot, args) {
|
|
53
|
+
const configuredPath = readOption(args, "config");
|
|
54
|
+
const candidates = configuredPath
|
|
55
|
+
? [configuredPath]
|
|
56
|
+
: ["webframez.config.ts", "webframez.config.js", "webframez.config.cjs"];
|
|
57
|
+
for (const candidate of candidates) {
|
|
58
|
+
const configPath = node_path_1.default.resolve(projectRoot, candidate);
|
|
59
|
+
if (!node_fs_1.default.existsSync(configPath)) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (configPath.endsWith(".ts")) {
|
|
63
|
+
registerTsNode(projectRoot);
|
|
64
|
+
}
|
|
65
|
+
const imported = require(configPath);
|
|
66
|
+
return imported.default || imported;
|
|
67
|
+
}
|
|
68
|
+
throw new Error("Missing webframez.config.ts");
|
|
69
|
+
}
|
|
70
|
+
function runConsole(projectRoot, cliArgs) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const config = loadConfig(projectRoot, cliArgs);
|
|
73
|
+
if (config.setup) {
|
|
74
|
+
yield config.setup({ mode: "console", projectRoot });
|
|
75
|
+
}
|
|
76
|
+
const app = new ConsoleApplication_1.ConsoleApplication();
|
|
77
|
+
const originalArgv = process.argv;
|
|
78
|
+
process.argv = [process.argv[0], "webframez", ...cliArgs];
|
|
79
|
+
try {
|
|
80
|
+
app.boot({
|
|
81
|
+
kernel: config.consoleKernel || config.kernelConsole || config.kernel,
|
|
82
|
+
config: config.config,
|
|
83
|
+
jobs: config.jobs,
|
|
84
|
+
datatables: config.datatables,
|
|
85
|
+
errorHandler: config.errorHandler,
|
|
86
|
+
onEnd: config.onEnd,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
process.argv = originalArgv;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function runBuild(projectRoot, cliArgs) {
|
|
95
|
+
var _a;
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const config = loadConfig(projectRoot, cliArgs);
|
|
98
|
+
if (config.setup) {
|
|
99
|
+
yield config.setup({ mode: "build", projectRoot });
|
|
100
|
+
}
|
|
101
|
+
const outDir = readOption(cliArgs, "dir") || ((_a = config.build) === null || _a === void 0 ? void 0 : _a.dir) || "build";
|
|
102
|
+
const app = new BuildApplication_1.BuildApplication(projectRoot, config, { outDir });
|
|
103
|
+
yield app.run();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function runWebframezCli(argv = process.argv.slice(2), projectRoot = process.cwd()) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const command = argv[0];
|
|
109
|
+
if (!command || command === "--help" || command === "-h" || command === "help") {
|
|
110
|
+
printHelp();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (command === "run") {
|
|
114
|
+
yield runConsole(projectRoot, argv.slice(1));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (command === "build" || command === "buid") {
|
|
118
|
+
yield runBuild(projectRoot, argv.slice(1));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
throw new Error(`Unknown webframez command: ${command}`);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
exports.runWebframezCli = runWebframezCli;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./Controller/Controller";
|
|
|
11
11
|
export * from "./Database/Model";
|
|
12
12
|
export * from "./Database/DBConnection";
|
|
13
13
|
export * from "./ConsoleApplication";
|
|
14
|
+
export * from "./BuildApplication";
|
|
14
15
|
export * from "./LambdaApplication";
|
|
15
16
|
export * from "./WebApplication";
|
|
16
17
|
export * from "./Router/Route";
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __exportStar(require("./Controller/Controller"), exports);
|
|
|
27
27
|
__exportStar(require("./Database/Model"), exports);
|
|
28
28
|
__exportStar(require("./Database/DBConnection"), exports);
|
|
29
29
|
__exportStar(require("./ConsoleApplication"), exports);
|
|
30
|
+
__exportStar(require("./BuildApplication"), exports);
|
|
30
31
|
__exportStar(require("./LambdaApplication"), exports);
|
|
31
32
|
__exportStar(require("./WebApplication"), exports);
|
|
32
33
|
__exportStar(require("./Router/Route"), exports);
|
package/dist/info.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webtypen/webframez-core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.37",
|
|
4
4
|
"description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
|
|
5
5
|
"homepage": "https://webtypen.de/",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"webframez": "./bin/webframez.cjs"
|
|
10
|
+
},
|
|
8
11
|
"author": {
|
|
9
12
|
"name": "Benedict Romp",
|
|
10
13
|
"email": "b.romp@webtypen.de",
|
|
@@ -19,8 +22,9 @@
|
|
|
19
22
|
},
|
|
20
23
|
"files": [
|
|
21
24
|
"dist",
|
|
25
|
+
"bin",
|
|
22
26
|
"README.md",
|
|
23
|
-
"
|
|
27
|
+
"agents"
|
|
24
28
|
],
|
|
25
29
|
"scripts": {
|
|
26
30
|
"build": "tsc",
|
|
File without changes
|