@rexeus/typeweaver-gen 0.5.1 → 0.6.1
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/dist/index.cjs +250 -209
- package/dist/index.d.cts +193 -185
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +284 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +239 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +9 -9
- package/dist/index.d.ts +0 -276
- package/dist/index.js +0 -220
- package/dist/metafile-cjs.json +0 -1
- package/dist/metafile-esm.json +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,233 +1,274 @@
|
|
|
1
|
-
'
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
8
27
|
|
|
9
|
-
|
|
10
|
-
|
|
28
|
+
//#endregion
|
|
29
|
+
let node_fs = require("node:fs");
|
|
30
|
+
node_fs = __toESM(node_fs);
|
|
31
|
+
let node_path = require("node:path");
|
|
32
|
+
node_path = __toESM(node_path);
|
|
33
|
+
let ejs = require("ejs");
|
|
11
34
|
|
|
12
|
-
|
|
35
|
+
//#region src/plugins/types.ts
|
|
36
|
+
/**
|
|
37
|
+
* Plugin loading error
|
|
38
|
+
*/
|
|
13
39
|
var PluginLoadError = class extends Error {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
40
|
+
constructor(pluginName, message) {
|
|
41
|
+
super(`Failed to load plugin '${pluginName}': ${message}`);
|
|
42
|
+
this.pluginName = pluginName;
|
|
43
|
+
this.name = "PluginLoadError";
|
|
44
|
+
}
|
|
19
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Plugin dependency error
|
|
48
|
+
*/
|
|
20
49
|
var PluginDependencyError = class extends Error {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.name = "PluginDependencyError";
|
|
28
|
-
}
|
|
50
|
+
constructor(pluginName, missingDependency) {
|
|
51
|
+
super(`Plugin '${pluginName}' depends on '${missingDependency}' which is not loaded`);
|
|
52
|
+
this.pluginName = pluginName;
|
|
53
|
+
this.missingDependency = missingDependency;
|
|
54
|
+
this.name = "PluginDependencyError";
|
|
55
|
+
}
|
|
29
56
|
};
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/plugins/BasePlugin.ts
|
|
60
|
+
/**
|
|
61
|
+
* Base class for typeweaver plugins
|
|
62
|
+
* Provides default implementations and common utilities
|
|
63
|
+
*/
|
|
30
64
|
var BasePlugin = class {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const libIndexPath = path__default.default.join("lib", libNamespace, "index.ts");
|
|
70
|
-
if (fs__default.default.existsSync(path__default.default.join(libDir, "index.ts"))) {
|
|
71
|
-
context.addGeneratedFile(libIndexPath);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
65
|
+
description;
|
|
66
|
+
author;
|
|
67
|
+
depends;
|
|
68
|
+
config;
|
|
69
|
+
constructor(config = {}) {
|
|
70
|
+
this.config = config;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Default implementation - override in subclasses if needed
|
|
74
|
+
*/
|
|
75
|
+
async initialize(_context) {}
|
|
76
|
+
/**
|
|
77
|
+
* Default implementation - override in subclasses if needed
|
|
78
|
+
*/
|
|
79
|
+
collectResources(resources) {
|
|
80
|
+
return resources;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Default implementation - override in subclasses if needed
|
|
84
|
+
*/
|
|
85
|
+
async finalize(_context) {}
|
|
86
|
+
/**
|
|
87
|
+
* Copy lib files from plugin package to generated lib folder
|
|
88
|
+
*/
|
|
89
|
+
copyLibFiles(context, libSourceDir, libNamespace) {
|
|
90
|
+
const libDir = node_path.default.join(context.outputDir, "lib", libNamespace);
|
|
91
|
+
node_fs.default.mkdirSync(libDir, { recursive: true });
|
|
92
|
+
if (node_fs.default.existsSync(libSourceDir)) {
|
|
93
|
+
const files = node_fs.default.readdirSync(libSourceDir);
|
|
94
|
+
for (const file of files) {
|
|
95
|
+
const sourcePath = node_path.default.join(libSourceDir, file);
|
|
96
|
+
const targetPath = node_path.default.join(libDir, file);
|
|
97
|
+
if (node_fs.default.statSync(sourcePath).isFile()) node_fs.default.copyFileSync(sourcePath, targetPath);
|
|
98
|
+
}
|
|
99
|
+
const libIndexPath = node_path.default.join("lib", libNamespace, "index.ts");
|
|
100
|
+
if (node_fs.default.existsSync(node_path.default.join(libDir, "index.ts"))) context.addGeneratedFile(libIndexPath);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
75
103
|
};
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/plugins/BaseTemplatePlugin.ts
|
|
107
|
+
/**
|
|
108
|
+
* Base class for template-based generator plugins
|
|
109
|
+
* Provides utilities for working with EJS templates
|
|
110
|
+
*/
|
|
76
111
|
var BaseTemplatePlugin = class extends BasePlugin {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
112
|
+
/**
|
|
113
|
+
* Render an EJS template with the given data
|
|
114
|
+
*/
|
|
115
|
+
renderTemplate(templatePath, data) {
|
|
116
|
+
return (0, ejs.render)(node_fs.default.readFileSync(templatePath, "utf8"), data);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Write a file relative to the output directory
|
|
120
|
+
*/
|
|
121
|
+
writeFile(context, relativePath, content) {
|
|
122
|
+
context.writeFile(relativePath, content);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Ensure a directory exists
|
|
126
|
+
*/
|
|
127
|
+
ensureDir(context, relativePath) {
|
|
128
|
+
const fullPath = node_path.default.join(context.outputDir, relativePath);
|
|
129
|
+
node_fs.default.mkdirSync(fullPath, { recursive: true });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get the template path for this plugin
|
|
133
|
+
*/
|
|
134
|
+
getTemplatePath(context, templateName) {
|
|
135
|
+
return node_path.default.join(context.templateDir, templateName);
|
|
136
|
+
}
|
|
103
137
|
};
|
|
104
138
|
|
|
105
|
-
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/plugins/PluginRegistry.ts
|
|
141
|
+
/**
|
|
142
|
+
* Registry for managing typeweaver plugins
|
|
143
|
+
*/
|
|
106
144
|
var PluginRegistry = class {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
this.plugins.clear();
|
|
152
|
-
}
|
|
145
|
+
plugins;
|
|
146
|
+
constructor() {
|
|
147
|
+
this.plugins = /* @__PURE__ */ new Map();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Register a plugin
|
|
151
|
+
*/
|
|
152
|
+
register(plugin, config) {
|
|
153
|
+
if (this.plugins.has(plugin.name)) {
|
|
154
|
+
console.info(`Skipping duplicate registration of required plugin: ${plugin.name}`);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const registration = {
|
|
158
|
+
name: plugin.name,
|
|
159
|
+
plugin,
|
|
160
|
+
config
|
|
161
|
+
};
|
|
162
|
+
this.plugins.set(plugin.name, registration);
|
|
163
|
+
console.info(`Registered plugin: ${plugin.name}`);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Get a registered plugin
|
|
167
|
+
*/
|
|
168
|
+
get(name) {
|
|
169
|
+
return this.plugins.get(name);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get all registered plugins
|
|
173
|
+
*/
|
|
174
|
+
getAll() {
|
|
175
|
+
return Array.from(this.plugins.values());
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Check if a plugin is registered
|
|
179
|
+
*/
|
|
180
|
+
has(name) {
|
|
181
|
+
return this.plugins.has(name);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Clear all registered plugins (except required ones)
|
|
185
|
+
*/
|
|
186
|
+
clear() {
|
|
187
|
+
this.plugins.clear();
|
|
188
|
+
}
|
|
153
189
|
};
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/plugins/PluginContext.ts
|
|
193
|
+
/**
|
|
194
|
+
* Builder for plugin contexts
|
|
195
|
+
*/
|
|
154
196
|
var PluginContextBuilder = class {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
clearGeneratedFiles() {
|
|
208
|
-
this.generatedFiles.clear();
|
|
209
|
-
}
|
|
197
|
+
generatedFiles = /* @__PURE__ */ new Set();
|
|
198
|
+
/**
|
|
199
|
+
* Create a basic plugin context
|
|
200
|
+
*/
|
|
201
|
+
createPluginContext(params) {
|
|
202
|
+
return {
|
|
203
|
+
outputDir: params.outputDir,
|
|
204
|
+
inputDir: params.inputDir,
|
|
205
|
+
config: params.config
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Create a generator context with utilities
|
|
210
|
+
*/
|
|
211
|
+
createGeneratorContext(params) {
|
|
212
|
+
return {
|
|
213
|
+
...this.createPluginContext(params),
|
|
214
|
+
resources: params.resources,
|
|
215
|
+
templateDir: params.templateDir,
|
|
216
|
+
coreDir: params.coreDir,
|
|
217
|
+
writeFile: (relativePath, content) => {
|
|
218
|
+
const fullPath = node_path.default.join(params.outputDir, relativePath);
|
|
219
|
+
const dir = node_path.default.dirname(fullPath);
|
|
220
|
+
node_fs.default.mkdirSync(dir, { recursive: true });
|
|
221
|
+
node_fs.default.writeFileSync(fullPath, content);
|
|
222
|
+
this.generatedFiles.add(relativePath);
|
|
223
|
+
console.info(`Generated: ${relativePath}`);
|
|
224
|
+
},
|
|
225
|
+
renderTemplate: (templatePath, data) => {
|
|
226
|
+
const fullTemplatePath = node_path.default.isAbsolute(templatePath) ? templatePath : node_path.default.join(params.templateDir, templatePath);
|
|
227
|
+
return (0, ejs.render)(node_fs.default.readFileSync(fullTemplatePath, "utf8"), data);
|
|
228
|
+
},
|
|
229
|
+
addGeneratedFile: (relativePath) => {
|
|
230
|
+
this.generatedFiles.add(relativePath);
|
|
231
|
+
},
|
|
232
|
+
getGeneratedFiles: () => {
|
|
233
|
+
return Array.from(this.generatedFiles);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get all generated files
|
|
239
|
+
*/
|
|
240
|
+
getGeneratedFiles() {
|
|
241
|
+
return Array.from(this.generatedFiles);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Clear generated files tracking
|
|
245
|
+
*/
|
|
246
|
+
clearGeneratedFiles() {
|
|
247
|
+
this.generatedFiles.clear();
|
|
248
|
+
}
|
|
210
249
|
};
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/helpers/Path.ts
|
|
211
253
|
var Path = class {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return posixPath;
|
|
224
|
-
}
|
|
254
|
+
static relative(from, to) {
|
|
255
|
+
const relativePath = node_path.default.relative(from, to);
|
|
256
|
+
if (relativePath.includes("node_modules")) {
|
|
257
|
+
const parts = relativePath.split(node_path.default.sep);
|
|
258
|
+
const index = parts.indexOf("node_modules");
|
|
259
|
+
return parts.slice(index + 1).join("/");
|
|
260
|
+
}
|
|
261
|
+
const posixPath = relativePath.split(node_path.default.sep).join("/");
|
|
262
|
+
if (!posixPath.startsWith("./") && !posixPath.startsWith("../")) return `./${posixPath}`;
|
|
263
|
+
return posixPath;
|
|
264
|
+
}
|
|
225
265
|
};
|
|
226
266
|
|
|
267
|
+
//#endregion
|
|
227
268
|
exports.BasePlugin = BasePlugin;
|
|
228
269
|
exports.BaseTemplatePlugin = BaseTemplatePlugin;
|
|
229
270
|
exports.Path = Path;
|
|
230
271
|
exports.PluginContextBuilder = PluginContextBuilder;
|
|
231
272
|
exports.PluginDependencyError = PluginDependencyError;
|
|
232
273
|
exports.PluginLoadError = PluginLoadError;
|
|
233
|
-
exports.PluginRegistry = PluginRegistry;
|
|
274
|
+
exports.PluginRegistry = PluginRegistry;
|