@rexeus/typeweaver-gen 0.0.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.js ADDED
@@ -0,0 +1,928 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+
4
+ class PluginLoadError extends Error {
5
+ constructor(pluginName, message) {
6
+ super(`Failed to load plugin '${pluginName}': ${message}`);
7
+ this.pluginName = pluginName;
8
+ this.name = "PluginLoadError";
9
+ }
10
+ }
11
+ class PluginDependencyError extends Error {
12
+ constructor(pluginName, missingDependency) {
13
+ super(
14
+ `Plugin '${pluginName}' depends on '${missingDependency}' which is not loaded`
15
+ );
16
+ this.pluginName = pluginName;
17
+ this.missingDependency = missingDependency;
18
+ this.name = "PluginDependencyError";
19
+ }
20
+ }
21
+
22
+ class BasePlugin {
23
+ description;
24
+ author;
25
+ depends;
26
+ config;
27
+ constructor(config = {}) {
28
+ this.config = config;
29
+ }
30
+ /**
31
+ * Default implementation - override in subclasses if needed
32
+ */
33
+ async initialize(context) {
34
+ }
35
+ /**
36
+ * Default implementation - override in subclasses if needed
37
+ */
38
+ collectResources(resources) {
39
+ return resources;
40
+ }
41
+ /**
42
+ * Default implementation - override in subclasses if needed
43
+ */
44
+ async finalize(context) {
45
+ }
46
+ /**
47
+ * Copy lib files from plugin package to generated lib folder
48
+ */
49
+ copyLibFiles(context, libSourceDir, libNamespace) {
50
+ const libDir = path.join(context.outputDir, "lib", libNamespace);
51
+ fs.mkdirSync(libDir, { recursive: true });
52
+ if (fs.existsSync(libSourceDir)) {
53
+ const files = fs.readdirSync(libSourceDir);
54
+ for (const file of files) {
55
+ const sourcePath = path.join(libSourceDir, file);
56
+ const targetPath = path.join(libDir, file);
57
+ if (fs.statSync(sourcePath).isFile()) {
58
+ fs.copyFileSync(sourcePath, targetPath);
59
+ }
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ function getDefaultExportFromCjs (x) {
66
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
67
+ }
68
+
69
+ var ejs$1 = {};
70
+
71
+ var utils = {};
72
+
73
+ var hasRequiredUtils;
74
+
75
+ function requireUtils () {
76
+ if (hasRequiredUtils) return utils;
77
+ hasRequiredUtils = 1;
78
+ (function (exports) {
79
+ var regExpChars = /[|\\{}()[\]^$+*?.]/g;
80
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
81
+ var hasOwn = function(obj, key) {
82
+ return hasOwnProperty.apply(obj, [key]);
83
+ };
84
+ exports.escapeRegExpChars = function(string) {
85
+ if (!string) {
86
+ return "";
87
+ }
88
+ return String(string).replace(regExpChars, "\\$&");
89
+ };
90
+ var _ENCODE_HTML_RULES = {
91
+ "&": "&",
92
+ "<": "&lt;",
93
+ ">": "&gt;",
94
+ '"': "&#34;",
95
+ "'": "&#39;"
96
+ };
97
+ var _MATCH_HTML = /[&<>'"]/g;
98
+ function encode_char(c) {
99
+ return _ENCODE_HTML_RULES[c] || c;
100
+ }
101
+ var escapeFuncStr = `var _ENCODE_HTML_RULES = {
102
+ "&": "&amp;"
103
+ , "<": "&lt;"
104
+ , ">": "&gt;"
105
+ , '"': "&#34;"
106
+ , "'": "&#39;"
107
+ }
108
+ , _MATCH_HTML = /[&<>'"]/g;
109
+ function encode_char(c) {
110
+ return _ENCODE_HTML_RULES[c] || c;
111
+ };
112
+ `;
113
+ exports.escapeXML = function(markup) {
114
+ return markup == void 0 ? "" : String(markup).replace(_MATCH_HTML, encode_char);
115
+ };
116
+ function escapeXMLToString() {
117
+ return Function.prototype.toString.call(this) + ";\n" + escapeFuncStr;
118
+ }
119
+ try {
120
+ if (typeof Object.defineProperty === "function") {
121
+ Object.defineProperty(exports.escapeXML, "toString", { value: escapeXMLToString });
122
+ } else {
123
+ exports.escapeXML.toString = escapeXMLToString;
124
+ }
125
+ } catch (err) {
126
+ console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)");
127
+ }
128
+ exports.shallowCopy = function(to, from) {
129
+ from = from || {};
130
+ if (to !== null && to !== void 0) {
131
+ for (var p in from) {
132
+ if (!hasOwn(from, p)) {
133
+ continue;
134
+ }
135
+ if (p === "__proto__" || p === "constructor") {
136
+ continue;
137
+ }
138
+ to[p] = from[p];
139
+ }
140
+ }
141
+ return to;
142
+ };
143
+ exports.shallowCopyFromList = function(to, from, list) {
144
+ list = list || [];
145
+ from = from || {};
146
+ if (to !== null && to !== void 0) {
147
+ for (var i = 0; i < list.length; i++) {
148
+ var p = list[i];
149
+ if (typeof from[p] != "undefined") {
150
+ if (!hasOwn(from, p)) {
151
+ continue;
152
+ }
153
+ if (p === "__proto__" || p === "constructor") {
154
+ continue;
155
+ }
156
+ to[p] = from[p];
157
+ }
158
+ }
159
+ }
160
+ return to;
161
+ };
162
+ exports.cache = {
163
+ _data: {},
164
+ set: function(key, val) {
165
+ this._data[key] = val;
166
+ },
167
+ get: function(key) {
168
+ return this._data[key];
169
+ },
170
+ remove: function(key) {
171
+ delete this._data[key];
172
+ },
173
+ reset: function() {
174
+ this._data = {};
175
+ }
176
+ };
177
+ exports.hyphenToCamel = function(str) {
178
+ return str.replace(/-[a-z]/g, function(match) {
179
+ return match[1].toUpperCase();
180
+ });
181
+ };
182
+ exports.createNullProtoObjWherePossible = function() {
183
+ if (typeof Object.create == "function") {
184
+ return function() {
185
+ return /* @__PURE__ */ Object.create(null);
186
+ };
187
+ }
188
+ if (!({ __proto__: null } instanceof Object)) {
189
+ return function() {
190
+ return { __proto__: null };
191
+ };
192
+ }
193
+ return function() {
194
+ return {};
195
+ };
196
+ }();
197
+ exports.hasOwnOnlyObject = function(obj) {
198
+ var o = exports.createNullProtoObjWherePossible();
199
+ for (var p in obj) {
200
+ if (hasOwn(obj, p)) {
201
+ o[p] = obj[p];
202
+ }
203
+ }
204
+ return o;
205
+ };
206
+ } (utils));
207
+ return utils;
208
+ }
209
+
210
+ var version = "3.1.10";
211
+ var require$$3 = {
212
+ version: version};
213
+
214
+ var hasRequiredEjs;
215
+
216
+ function requireEjs () {
217
+ if (hasRequiredEjs) return ejs$1;
218
+ hasRequiredEjs = 1;
219
+ (function (exports) {
220
+ /**
221
+ * @file Embedded JavaScript templating engine. {@link http://ejs.co}
222
+ * @author Matthew Eernisse <mde@fleegix.org>
223
+ * @author Tiancheng "Timothy" Gu <timothygu99@gmail.com>
224
+ * @project EJS
225
+ * @license {@link http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0}
226
+ */
227
+ var fs$1 = fs;
228
+ var path$1 = path;
229
+ var utils = requireUtils();
230
+ var scopeOptionWarned = false;
231
+ var _VERSION_STRING = require$$3.version;
232
+ var _DEFAULT_OPEN_DELIMITER = "<";
233
+ var _DEFAULT_CLOSE_DELIMITER = ">";
234
+ var _DEFAULT_DELIMITER = "%";
235
+ var _DEFAULT_LOCALS_NAME = "locals";
236
+ var _NAME = "ejs";
237
+ var _REGEX_STRING = "(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)";
238
+ var _OPTS_PASSABLE_WITH_DATA = [
239
+ "delimiter",
240
+ "scope",
241
+ "context",
242
+ "debug",
243
+ "compileDebug",
244
+ "client",
245
+ "_with",
246
+ "rmWhitespace",
247
+ "strict",
248
+ "filename",
249
+ "async"
250
+ ];
251
+ var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat("cache");
252
+ var _BOM = /^\uFEFF/;
253
+ var _JS_IDENTIFIER = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
254
+ exports.cache = utils.cache;
255
+ exports.fileLoader = fs$1.readFileSync;
256
+ exports.localsName = _DEFAULT_LOCALS_NAME;
257
+ exports.promiseImpl = new Function("return this;")().Promise;
258
+ exports.resolveInclude = function(name, filename, isDir) {
259
+ var dirname = path$1.dirname;
260
+ var extname = path$1.extname;
261
+ var resolve = path$1.resolve;
262
+ var includePath = resolve(isDir ? filename : dirname(filename), name);
263
+ var ext = extname(name);
264
+ if (!ext) {
265
+ includePath += ".ejs";
266
+ }
267
+ return includePath;
268
+ };
269
+ function resolvePaths(name, paths) {
270
+ var filePath;
271
+ if (paths.some(function(v) {
272
+ filePath = exports.resolveInclude(name, v, true);
273
+ return fs$1.existsSync(filePath);
274
+ })) {
275
+ return filePath;
276
+ }
277
+ }
278
+ function getIncludePath(path2, options) {
279
+ var includePath;
280
+ var filePath;
281
+ var views = options.views;
282
+ var match = /^[A-Za-z]+:\\|^\//.exec(path2);
283
+ if (match && match.length) {
284
+ path2 = path2.replace(/^\/*/, "");
285
+ if (Array.isArray(options.root)) {
286
+ includePath = resolvePaths(path2, options.root);
287
+ } else {
288
+ includePath = exports.resolveInclude(path2, options.root || "/", true);
289
+ }
290
+ } else {
291
+ if (options.filename) {
292
+ filePath = exports.resolveInclude(path2, options.filename);
293
+ if (fs$1.existsSync(filePath)) {
294
+ includePath = filePath;
295
+ }
296
+ }
297
+ if (!includePath && Array.isArray(views)) {
298
+ includePath = resolvePaths(path2, views);
299
+ }
300
+ if (!includePath && typeof options.includer !== "function") {
301
+ throw new Error('Could not find the include file "' + options.escapeFunction(path2) + '"');
302
+ }
303
+ }
304
+ return includePath;
305
+ }
306
+ function handleCache(options, template) {
307
+ var func;
308
+ var filename = options.filename;
309
+ var hasTemplate = arguments.length > 1;
310
+ if (options.cache) {
311
+ if (!filename) {
312
+ throw new Error("cache option requires a filename");
313
+ }
314
+ func = exports.cache.get(filename);
315
+ if (func) {
316
+ return func;
317
+ }
318
+ if (!hasTemplate) {
319
+ template = fileLoader(filename).toString().replace(_BOM, "");
320
+ }
321
+ } else if (!hasTemplate) {
322
+ if (!filename) {
323
+ throw new Error("Internal EJS error: no file name or template provided");
324
+ }
325
+ template = fileLoader(filename).toString().replace(_BOM, "");
326
+ }
327
+ func = exports.compile(template, options);
328
+ if (options.cache) {
329
+ exports.cache.set(filename, func);
330
+ }
331
+ return func;
332
+ }
333
+ function tryHandleCache(options, data, cb) {
334
+ var result;
335
+ if (!cb) {
336
+ if (typeof exports.promiseImpl == "function") {
337
+ return new exports.promiseImpl(function(resolve, reject) {
338
+ try {
339
+ result = handleCache(options)(data);
340
+ resolve(result);
341
+ } catch (err) {
342
+ reject(err);
343
+ }
344
+ });
345
+ } else {
346
+ throw new Error("Please provide a callback function");
347
+ }
348
+ } else {
349
+ try {
350
+ result = handleCache(options)(data);
351
+ } catch (err) {
352
+ return cb(err);
353
+ }
354
+ cb(null, result);
355
+ }
356
+ }
357
+ function fileLoader(filePath) {
358
+ return exports.fileLoader(filePath);
359
+ }
360
+ function includeFile(path2, options) {
361
+ var opts = utils.shallowCopy(utils.createNullProtoObjWherePossible(), options);
362
+ opts.filename = getIncludePath(path2, opts);
363
+ if (typeof options.includer === "function") {
364
+ var includerResult = options.includer(path2, opts.filename);
365
+ if (includerResult) {
366
+ if (includerResult.filename) {
367
+ opts.filename = includerResult.filename;
368
+ }
369
+ if (includerResult.template) {
370
+ return handleCache(opts, includerResult.template);
371
+ }
372
+ }
373
+ }
374
+ return handleCache(opts);
375
+ }
376
+ function rethrow(err, str, flnm, lineno, esc) {
377
+ var lines = str.split("\n");
378
+ var start = Math.max(lineno - 3, 0);
379
+ var end = Math.min(lines.length, lineno + 3);
380
+ var filename = esc(flnm);
381
+ var context = lines.slice(start, end).map(function(line, i) {
382
+ var curr = i + start + 1;
383
+ return (curr == lineno ? " >> " : " ") + curr + "| " + line;
384
+ }).join("\n");
385
+ err.path = filename;
386
+ err.message = (filename || "ejs") + ":" + lineno + "\n" + context + "\n\n" + err.message;
387
+ throw err;
388
+ }
389
+ function stripSemi(str) {
390
+ return str.replace(/;(\s*$)/, "$1");
391
+ }
392
+ exports.compile = function compile(template, opts) {
393
+ var templ;
394
+ if (opts && opts.scope) {
395
+ if (!scopeOptionWarned) {
396
+ console.warn("`scope` option is deprecated and will be removed in EJS 3");
397
+ scopeOptionWarned = true;
398
+ }
399
+ if (!opts.context) {
400
+ opts.context = opts.scope;
401
+ }
402
+ delete opts.scope;
403
+ }
404
+ templ = new Template(template, opts);
405
+ return templ.compile();
406
+ };
407
+ exports.render = function(template, d, o) {
408
+ var data = d || utils.createNullProtoObjWherePossible();
409
+ var opts = o || utils.createNullProtoObjWherePossible();
410
+ if (arguments.length == 2) {
411
+ utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
412
+ }
413
+ return handleCache(opts, template)(data);
414
+ };
415
+ exports.renderFile = function() {
416
+ var args = Array.prototype.slice.call(arguments);
417
+ var filename = args.shift();
418
+ var cb;
419
+ var opts = { filename };
420
+ var data;
421
+ var viewOpts;
422
+ if (typeof arguments[arguments.length - 1] == "function") {
423
+ cb = args.pop();
424
+ }
425
+ if (args.length) {
426
+ data = args.shift();
427
+ if (args.length) {
428
+ utils.shallowCopy(opts, args.pop());
429
+ } else {
430
+ if (data.settings) {
431
+ if (data.settings.views) {
432
+ opts.views = data.settings.views;
433
+ }
434
+ if (data.settings["view cache"]) {
435
+ opts.cache = true;
436
+ }
437
+ viewOpts = data.settings["view options"];
438
+ if (viewOpts) {
439
+ utils.shallowCopy(opts, viewOpts);
440
+ }
441
+ }
442
+ utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
443
+ }
444
+ opts.filename = filename;
445
+ } else {
446
+ data = utils.createNullProtoObjWherePossible();
447
+ }
448
+ return tryHandleCache(opts, data, cb);
449
+ };
450
+ exports.Template = Template;
451
+ exports.clearCache = function() {
452
+ exports.cache.reset();
453
+ };
454
+ function Template(text, optsParam) {
455
+ var opts = utils.hasOwnOnlyObject(optsParam);
456
+ var options = utils.createNullProtoObjWherePossible();
457
+ this.templateText = text;
458
+ this.mode = null;
459
+ this.truncate = false;
460
+ this.currentLine = 1;
461
+ this.source = "";
462
+ options.client = opts.client || false;
463
+ options.escapeFunction = opts.escape || opts.escapeFunction || utils.escapeXML;
464
+ options.compileDebug = opts.compileDebug !== false;
465
+ options.debug = !!opts.debug;
466
+ options.filename = opts.filename;
467
+ options.openDelimiter = opts.openDelimiter || exports.openDelimiter || _DEFAULT_OPEN_DELIMITER;
468
+ options.closeDelimiter = opts.closeDelimiter || exports.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
469
+ options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
470
+ options.strict = opts.strict || false;
471
+ options.context = opts.context;
472
+ options.cache = opts.cache || false;
473
+ options.rmWhitespace = opts.rmWhitespace;
474
+ options.root = opts.root;
475
+ options.includer = opts.includer;
476
+ options.outputFunctionName = opts.outputFunctionName;
477
+ options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
478
+ options.views = opts.views;
479
+ options.async = opts.async;
480
+ options.destructuredLocals = opts.destructuredLocals;
481
+ options.legacyInclude = typeof opts.legacyInclude != "undefined" ? !!opts.legacyInclude : true;
482
+ if (options.strict) {
483
+ options._with = false;
484
+ } else {
485
+ options._with = typeof opts._with != "undefined" ? opts._with : true;
486
+ }
487
+ this.opts = options;
488
+ this.regex = this.createRegex();
489
+ }
490
+ Template.modes = {
491
+ EVAL: "eval",
492
+ ESCAPED: "escaped",
493
+ RAW: "raw",
494
+ COMMENT: "comment",
495
+ LITERAL: "literal"
496
+ };
497
+ Template.prototype = {
498
+ createRegex: function() {
499
+ var str = _REGEX_STRING;
500
+ var delim = utils.escapeRegExpChars(this.opts.delimiter);
501
+ var open = utils.escapeRegExpChars(this.opts.openDelimiter);
502
+ var close = utils.escapeRegExpChars(this.opts.closeDelimiter);
503
+ str = str.replace(/%/g, delim).replace(/</g, open).replace(/>/g, close);
504
+ return new RegExp(str);
505
+ },
506
+ compile: function() {
507
+ var src;
508
+ var fn;
509
+ var opts = this.opts;
510
+ var prepended = "";
511
+ var appended = "";
512
+ var escapeFn = opts.escapeFunction;
513
+ var ctor;
514
+ var sanitizedFilename = opts.filename ? JSON.stringify(opts.filename) : "undefined";
515
+ if (!this.source) {
516
+ this.generateSource();
517
+ prepended += ' var __output = "";\n function __append(s) { if (s !== undefined && s !== null) __output += s }\n';
518
+ if (opts.outputFunctionName) {
519
+ if (!_JS_IDENTIFIER.test(opts.outputFunctionName)) {
520
+ throw new Error("outputFunctionName is not a valid JS identifier.");
521
+ }
522
+ prepended += " var " + opts.outputFunctionName + " = __append;\n";
523
+ }
524
+ if (opts.localsName && !_JS_IDENTIFIER.test(opts.localsName)) {
525
+ throw new Error("localsName is not a valid JS identifier.");
526
+ }
527
+ if (opts.destructuredLocals && opts.destructuredLocals.length) {
528
+ var destructuring = " var __locals = (" + opts.localsName + " || {}),\n";
529
+ for (var i = 0; i < opts.destructuredLocals.length; i++) {
530
+ var name = opts.destructuredLocals[i];
531
+ if (!_JS_IDENTIFIER.test(name)) {
532
+ throw new Error("destructuredLocals[" + i + "] is not a valid JS identifier.");
533
+ }
534
+ if (i > 0) {
535
+ destructuring += ",\n ";
536
+ }
537
+ destructuring += name + " = __locals." + name;
538
+ }
539
+ prepended += destructuring + ";\n";
540
+ }
541
+ if (opts._with !== false) {
542
+ prepended += " with (" + opts.localsName + " || {}) {\n";
543
+ appended += " }\n";
544
+ }
545
+ appended += " return __output;\n";
546
+ this.source = prepended + this.source + appended;
547
+ }
548
+ if (opts.compileDebug) {
549
+ src = "var __line = 1\n , __lines = " + JSON.stringify(this.templateText) + "\n , __filename = " + sanitizedFilename + ";\ntry {\n" + this.source + "} catch (e) {\n rethrow(e, __lines, __filename, __line, escapeFn);\n}\n";
550
+ } else {
551
+ src = this.source;
552
+ }
553
+ if (opts.client) {
554
+ src = "escapeFn = escapeFn || " + escapeFn.toString() + ";\n" + src;
555
+ if (opts.compileDebug) {
556
+ src = "rethrow = rethrow || " + rethrow.toString() + ";\n" + src;
557
+ }
558
+ }
559
+ if (opts.strict) {
560
+ src = '"use strict";\n' + src;
561
+ }
562
+ if (opts.debug) {
563
+ console.log(src);
564
+ }
565
+ if (opts.compileDebug && opts.filename) {
566
+ src = src + "\n//# sourceURL=" + sanitizedFilename + "\n";
567
+ }
568
+ try {
569
+ if (opts.async) {
570
+ try {
571
+ ctor = new Function("return (async function(){}).constructor;")();
572
+ } catch (e) {
573
+ if (e instanceof SyntaxError) {
574
+ throw new Error("This environment does not support async/await");
575
+ } else {
576
+ throw e;
577
+ }
578
+ }
579
+ } else {
580
+ ctor = Function;
581
+ }
582
+ fn = new ctor(opts.localsName + ", escapeFn, include, rethrow", src);
583
+ } catch (e) {
584
+ if (e instanceof SyntaxError) {
585
+ if (opts.filename) {
586
+ e.message += " in " + opts.filename;
587
+ }
588
+ e.message += " while compiling ejs\n\n";
589
+ e.message += "If the above error is not helpful, you may want to try EJS-Lint:\n";
590
+ e.message += "https://github.com/RyanZim/EJS-Lint";
591
+ if (!opts.async) {
592
+ e.message += "\n";
593
+ e.message += "Or, if you meant to create an async function, pass `async: true` as an option.";
594
+ }
595
+ }
596
+ throw e;
597
+ }
598
+ var returnedFn = opts.client ? fn : function anonymous(data) {
599
+ var include = function(path2, includeData) {
600
+ var d = utils.shallowCopy(utils.createNullProtoObjWherePossible(), data);
601
+ if (includeData) {
602
+ d = utils.shallowCopy(d, includeData);
603
+ }
604
+ return includeFile(path2, opts)(d);
605
+ };
606
+ return fn.apply(
607
+ opts.context,
608
+ [data || utils.createNullProtoObjWherePossible(), escapeFn, include, rethrow]
609
+ );
610
+ };
611
+ if (opts.filename && typeof Object.defineProperty === "function") {
612
+ var filename = opts.filename;
613
+ var basename = path$1.basename(filename, path$1.extname(filename));
614
+ try {
615
+ Object.defineProperty(returnedFn, "name", {
616
+ value: basename,
617
+ writable: false,
618
+ enumerable: false,
619
+ configurable: true
620
+ });
621
+ } catch (e) {
622
+ }
623
+ }
624
+ return returnedFn;
625
+ },
626
+ generateSource: function() {
627
+ var opts = this.opts;
628
+ if (opts.rmWhitespace) {
629
+ this.templateText = this.templateText.replace(/[\r\n]+/g, "\n").replace(/^\s+|\s+$/gm, "");
630
+ }
631
+ this.templateText = this.templateText.replace(/[ \t]*<%_/gm, "<%_").replace(/_%>[ \t]*/gm, "_%>");
632
+ var self = this;
633
+ var matches = this.parseTemplateText();
634
+ var d = this.opts.delimiter;
635
+ var o = this.opts.openDelimiter;
636
+ var c = this.opts.closeDelimiter;
637
+ if (matches && matches.length) {
638
+ matches.forEach(function(line, index) {
639
+ var closing;
640
+ if (line.indexOf(o + d) === 0 && line.indexOf(o + d + d) !== 0) {
641
+ closing = matches[index + 2];
642
+ if (!(closing == d + c || closing == "-" + d + c || closing == "_" + d + c)) {
643
+ throw new Error('Could not find matching close tag for "' + line + '".');
644
+ }
645
+ }
646
+ self.scanLine(line);
647
+ });
648
+ }
649
+ },
650
+ parseTemplateText: function() {
651
+ var str = this.templateText;
652
+ var pat = this.regex;
653
+ var result = pat.exec(str);
654
+ var arr = [];
655
+ var firstPos;
656
+ while (result) {
657
+ firstPos = result.index;
658
+ if (firstPos !== 0) {
659
+ arr.push(str.substring(0, firstPos));
660
+ str = str.slice(firstPos);
661
+ }
662
+ arr.push(result[0]);
663
+ str = str.slice(result[0].length);
664
+ result = pat.exec(str);
665
+ }
666
+ if (str) {
667
+ arr.push(str);
668
+ }
669
+ return arr;
670
+ },
671
+ _addOutput: function(line) {
672
+ if (this.truncate) {
673
+ line = line.replace(/^(?:\r\n|\r|\n)/, "");
674
+ this.truncate = false;
675
+ }
676
+ if (!line) {
677
+ return line;
678
+ }
679
+ line = line.replace(/\\/g, "\\\\");
680
+ line = line.replace(/\n/g, "\\n");
681
+ line = line.replace(/\r/g, "\\r");
682
+ line = line.replace(/"/g, '\\"');
683
+ this.source += ' ; __append("' + line + '")\n';
684
+ },
685
+ scanLine: function(line) {
686
+ var self = this;
687
+ var d = this.opts.delimiter;
688
+ var o = this.opts.openDelimiter;
689
+ var c = this.opts.closeDelimiter;
690
+ var newLineCount = 0;
691
+ newLineCount = line.split("\n").length - 1;
692
+ switch (line) {
693
+ case o + d:
694
+ case o + d + "_":
695
+ this.mode = Template.modes.EVAL;
696
+ break;
697
+ case o + d + "=":
698
+ this.mode = Template.modes.ESCAPED;
699
+ break;
700
+ case o + d + "-":
701
+ this.mode = Template.modes.RAW;
702
+ break;
703
+ case o + d + "#":
704
+ this.mode = Template.modes.COMMENT;
705
+ break;
706
+ case o + d + d:
707
+ this.mode = Template.modes.LITERAL;
708
+ this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")\n';
709
+ break;
710
+ case d + d + c:
711
+ this.mode = Template.modes.LITERAL;
712
+ this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")\n';
713
+ break;
714
+ case d + c:
715
+ case "-" + d + c:
716
+ case "_" + d + c:
717
+ if (this.mode == Template.modes.LITERAL) {
718
+ this._addOutput(line);
719
+ }
720
+ this.mode = null;
721
+ this.truncate = line.indexOf("-") === 0 || line.indexOf("_") === 0;
722
+ break;
723
+ default:
724
+ if (this.mode) {
725
+ switch (this.mode) {
726
+ case Template.modes.EVAL:
727
+ case Template.modes.ESCAPED:
728
+ case Template.modes.RAW:
729
+ if (line.lastIndexOf("//") > line.lastIndexOf("\n")) {
730
+ line += "\n";
731
+ }
732
+ }
733
+ switch (this.mode) {
734
+ // Just executing code
735
+ case Template.modes.EVAL:
736
+ this.source += " ; " + line + "\n";
737
+ break;
738
+ // Exec, esc, and output
739
+ case Template.modes.ESCAPED:
740
+ this.source += " ; __append(escapeFn(" + stripSemi(line) + "))\n";
741
+ break;
742
+ // Exec and output
743
+ case Template.modes.RAW:
744
+ this.source += " ; __append(" + stripSemi(line) + ")\n";
745
+ break;
746
+ case Template.modes.COMMENT:
747
+ break;
748
+ // Literal <%% mode, append as raw output
749
+ case Template.modes.LITERAL:
750
+ this._addOutput(line);
751
+ break;
752
+ }
753
+ } else {
754
+ this._addOutput(line);
755
+ }
756
+ }
757
+ if (self.opts.compileDebug && newLineCount) {
758
+ this.currentLine += newLineCount;
759
+ this.source += " ; __line = " + this.currentLine + "\n";
760
+ }
761
+ }
762
+ };
763
+ exports.escapeXML = utils.escapeXML;
764
+ exports.__express = exports.renderFile;
765
+ exports.VERSION = _VERSION_STRING;
766
+ exports.name = _NAME;
767
+ if (typeof window != "undefined") {
768
+ window.ejs = exports;
769
+ }
770
+ } (ejs$1));
771
+ return ejs$1;
772
+ }
773
+
774
+ var ejsExports = requireEjs();
775
+ var ejs = /*@__PURE__*/getDefaultExportFromCjs(ejsExports);
776
+
777
+ class BaseTemplatePlugin extends BasePlugin {
778
+ /**
779
+ * Render an EJS template with the given data
780
+ */
781
+ renderTemplate(templatePath, data) {
782
+ const template = fs.readFileSync(templatePath, "utf8");
783
+ return ejs.render(template, data);
784
+ }
785
+ /**
786
+ * Write a file relative to the output directory
787
+ */
788
+ writeFile(context, relativePath, content) {
789
+ context.writeFile(relativePath, content);
790
+ }
791
+ /**
792
+ * Ensure a directory exists
793
+ */
794
+ ensureDir(context, relativePath) {
795
+ const fullPath = path.join(context.outputDir, relativePath);
796
+ fs.mkdirSync(fullPath, { recursive: true });
797
+ }
798
+ /**
799
+ * Get the template path for this plugin
800
+ */
801
+ getTemplatePath(context, templateName) {
802
+ return path.join(context.templateDir, templateName);
803
+ }
804
+ }
805
+
806
+ class PluginRegistry {
807
+ plugins;
808
+ constructor() {
809
+ this.plugins = /* @__PURE__ */ new Map();
810
+ }
811
+ /**
812
+ * Register a plugin
813
+ */
814
+ register(plugin, config) {
815
+ if (this.plugins.has(plugin.name)) {
816
+ console.info(
817
+ `Skipping duplicate registration of required plugin: ${plugin.name}`
818
+ );
819
+ return;
820
+ }
821
+ const registration = {
822
+ name: plugin.name,
823
+ plugin,
824
+ config
825
+ };
826
+ this.plugins.set(plugin.name, registration);
827
+ console.info(`Registered plugin: ${plugin.name}`);
828
+ }
829
+ /**
830
+ * Get a registered plugin
831
+ */
832
+ get(name) {
833
+ return this.plugins.get(name);
834
+ }
835
+ /**
836
+ * Get all registered plugins
837
+ */
838
+ getAll() {
839
+ return Array.from(this.plugins.values());
840
+ }
841
+ /**
842
+ * Check if a plugin is registered
843
+ */
844
+ has(name) {
845
+ return this.plugins.has(name);
846
+ }
847
+ /**
848
+ * Clear all registered plugins (except required ones)
849
+ */
850
+ clear() {
851
+ this.plugins.clear();
852
+ }
853
+ }
854
+
855
+ class PluginContextBuilder {
856
+ generatedFiles = /* @__PURE__ */ new Set();
857
+ /**
858
+ * Create a basic plugin context
859
+ */
860
+ createPluginContext(params) {
861
+ return {
862
+ outputDir: params.outputDir,
863
+ inputDir: params.inputDir,
864
+ config: params.config
865
+ };
866
+ }
867
+ /**
868
+ * Create a generator context with utilities
869
+ */
870
+ createGeneratorContext(params) {
871
+ const pluginContext = this.createPluginContext(params);
872
+ return {
873
+ ...pluginContext,
874
+ resources: params.resources,
875
+ templateDir: params.templateDir,
876
+ coreDir: params.coreDir,
877
+ // Utility functions
878
+ writeFile: (relativePath, content) => {
879
+ const fullPath = path.join(params.outputDir, relativePath);
880
+ const dir = path.dirname(fullPath);
881
+ fs.mkdirSync(dir, { recursive: true });
882
+ fs.writeFileSync(fullPath, content);
883
+ this.generatedFiles.add(relativePath);
884
+ console.info(`Generated: ${relativePath}`);
885
+ },
886
+ renderTemplate: (templatePath, data) => {
887
+ const fullTemplatePath = path.isAbsolute(templatePath) ? templatePath : path.join(params.templateDir, templatePath);
888
+ const template = fs.readFileSync(fullTemplatePath, "utf8");
889
+ return ejs.render(template, data);
890
+ },
891
+ addGeneratedFile: (relativePath) => {
892
+ this.generatedFiles.add(relativePath);
893
+ },
894
+ getGeneratedFiles: () => {
895
+ return Array.from(this.generatedFiles);
896
+ }
897
+ };
898
+ }
899
+ /**
900
+ * Get all generated files
901
+ */
902
+ getGeneratedFiles() {
903
+ return Array.from(this.generatedFiles);
904
+ }
905
+ /**
906
+ * Clear generated files tracking
907
+ */
908
+ clearGeneratedFiles() {
909
+ this.generatedFiles.clear();
910
+ }
911
+ }
912
+
913
+ class Path {
914
+ static relative(from, to) {
915
+ const relativePath = path.relative(from, to);
916
+ if (relativePath.includes("node_modules")) {
917
+ const parts = relativePath.split(path.sep);
918
+ const index = parts.indexOf("node_modules");
919
+ return parts.slice(index + 1).join(path.sep);
920
+ }
921
+ if (!relativePath.startsWith("./") && !relativePath.startsWith("../")) {
922
+ return `./${relativePath}`;
923
+ }
924
+ return relativePath;
925
+ }
926
+ }
927
+
928
+ export { BasePlugin, BaseTemplatePlugin, Path, PluginContextBuilder, PluginDependencyError, PluginLoadError, PluginRegistry };