@rexeus/typeweaver-gen 0.5.1 → 0.6.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/dist/index.cjs CHANGED
@@ -1,233 +1,274 @@
1
- 'use strict';
2
-
3
- var fs = require('node:fs');
4
- var path = require('node:path');
5
- var ejs = require('ejs');
6
-
7
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
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
- var fs__default = /*#__PURE__*/_interopDefault(fs);
10
- var path__default = /*#__PURE__*/_interopDefault(path);
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
- // src/plugins/types.ts
35
+ //#region src/plugins/types.ts
36
+ /**
37
+ * Plugin loading error
38
+ */
13
39
  var PluginLoadError = class extends Error {
14
- constructor(pluginName, message) {
15
- super(`Failed to load plugin '${pluginName}': ${message}`);
16
- this.pluginName = pluginName;
17
- this.name = "PluginLoadError";
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
- constructor(pluginName, missingDependency) {
22
- super(
23
- `Plugin '${pluginName}' depends on '${missingDependency}' which is not loaded`
24
- );
25
- this.pluginName = pluginName;
26
- this.missingDependency = missingDependency;
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
- description;
32
- author;
33
- depends;
34
- config;
35
- constructor(config = {}) {
36
- this.config = config;
37
- }
38
- /**
39
- * Default implementation - override in subclasses if needed
40
- */
41
- async initialize(context) {
42
- }
43
- /**
44
- * Default implementation - override in subclasses if needed
45
- */
46
- collectResources(resources) {
47
- return resources;
48
- }
49
- /**
50
- * Default implementation - override in subclasses if needed
51
- */
52
- async finalize(context) {
53
- }
54
- /**
55
- * Copy lib files from plugin package to generated lib folder
56
- */
57
- copyLibFiles(context, libSourceDir, libNamespace) {
58
- const libDir = path__default.default.join(context.outputDir, "lib", libNamespace);
59
- fs__default.default.mkdirSync(libDir, { recursive: true });
60
- if (fs__default.default.existsSync(libSourceDir)) {
61
- const files = fs__default.default.readdirSync(libSourceDir);
62
- for (const file of files) {
63
- const sourcePath = path__default.default.join(libSourceDir, file);
64
- const targetPath = path__default.default.join(libDir, file);
65
- if (fs__default.default.statSync(sourcePath).isFile()) {
66
- fs__default.default.copyFileSync(sourcePath, targetPath);
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
- * Render an EJS template with the given data
79
- */
80
- renderTemplate(templatePath, data) {
81
- const template = fs__default.default.readFileSync(templatePath, "utf8");
82
- return ejs.render(template, data);
83
- }
84
- /**
85
- * Write a file relative to the output directory
86
- */
87
- writeFile(context, relativePath, content) {
88
- context.writeFile(relativePath, content);
89
- }
90
- /**
91
- * Ensure a directory exists
92
- */
93
- ensureDir(context, relativePath) {
94
- const fullPath = path__default.default.join(context.outputDir, relativePath);
95
- fs__default.default.mkdirSync(fullPath, { recursive: true });
96
- }
97
- /**
98
- * Get the template path for this plugin
99
- */
100
- getTemplatePath(context, templateName) {
101
- return path__default.default.join(context.templateDir, templateName);
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
- // src/plugins/PluginRegistry.ts
139
+ //#endregion
140
+ //#region src/plugins/PluginRegistry.ts
141
+ /**
142
+ * Registry for managing typeweaver plugins
143
+ */
106
144
  var PluginRegistry = class {
107
- plugins;
108
- constructor() {
109
- this.plugins = /* @__PURE__ */ new Map();
110
- }
111
- /**
112
- * Register a plugin
113
- */
114
- register(plugin, config) {
115
- if (this.plugins.has(plugin.name)) {
116
- console.info(
117
- `Skipping duplicate registration of required plugin: ${plugin.name}`
118
- );
119
- return;
120
- }
121
- const registration = {
122
- name: plugin.name,
123
- plugin,
124
- config
125
- };
126
- this.plugins.set(plugin.name, registration);
127
- console.info(`Registered plugin: ${plugin.name}`);
128
- }
129
- /**
130
- * Get a registered plugin
131
- */
132
- get(name) {
133
- return this.plugins.get(name);
134
- }
135
- /**
136
- * Get all registered plugins
137
- */
138
- getAll() {
139
- return Array.from(this.plugins.values());
140
- }
141
- /**
142
- * Check if a plugin is registered
143
- */
144
- has(name) {
145
- return this.plugins.has(name);
146
- }
147
- /**
148
- * Clear all registered plugins (except required ones)
149
- */
150
- clear() {
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
- generatedFiles = /* @__PURE__ */ new Set();
156
- /**
157
- * Create a basic plugin context
158
- */
159
- createPluginContext(params) {
160
- return {
161
- outputDir: params.outputDir,
162
- inputDir: params.inputDir,
163
- config: params.config
164
- };
165
- }
166
- /**
167
- * Create a generator context with utilities
168
- */
169
- createGeneratorContext(params) {
170
- const pluginContext = this.createPluginContext(params);
171
- return {
172
- ...pluginContext,
173
- resources: params.resources,
174
- templateDir: params.templateDir,
175
- coreDir: params.coreDir,
176
- // Utility functions
177
- writeFile: (relativePath, content) => {
178
- const fullPath = path__default.default.join(params.outputDir, relativePath);
179
- const dir = path__default.default.dirname(fullPath);
180
- fs__default.default.mkdirSync(dir, { recursive: true });
181
- fs__default.default.writeFileSync(fullPath, content);
182
- this.generatedFiles.add(relativePath);
183
- console.info(`Generated: ${relativePath}`);
184
- },
185
- renderTemplate: (templatePath, data) => {
186
- const fullTemplatePath = path__default.default.isAbsolute(templatePath) ? templatePath : path__default.default.join(params.templateDir, templatePath);
187
- const template = fs__default.default.readFileSync(fullTemplatePath, "utf8");
188
- return ejs.render(template, data);
189
- },
190
- addGeneratedFile: (relativePath) => {
191
- this.generatedFiles.add(relativePath);
192
- },
193
- getGeneratedFiles: () => {
194
- return Array.from(this.generatedFiles);
195
- }
196
- };
197
- }
198
- /**
199
- * Get all generated files
200
- */
201
- getGeneratedFiles() {
202
- return Array.from(this.generatedFiles);
203
- }
204
- /**
205
- * Clear generated files tracking
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
- static relative(from, to) {
213
- const relativePath = path__default.default.relative(from, to);
214
- if (relativePath.includes("node_modules")) {
215
- const parts = relativePath.split(path__default.default.sep);
216
- const index = parts.indexOf("node_modules");
217
- return parts.slice(index + 1).join("/");
218
- }
219
- const posixPath = relativePath.split(path__default.default.sep).join("/");
220
- if (!posixPath.startsWith("./") && !posixPath.startsWith("../")) {
221
- return `./${posixPath}`;
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;