telemeister 0.1.21 → 0.1.22

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.
@@ -0,0 +1,1206 @@
1
+ #!/usr/bin/env node
2
+
3
+ // dist/cli/state-manager.js
4
+ import * as fs2 from "fs";
5
+ import * as path2 from "path";
6
+ import { fileURLToPath } from "url";
7
+
8
+ // node_modules/ejs/lib/esm/ejs.js
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+
12
+ // node_modules/ejs/lib/esm/utils.js
13
+ var utils = {};
14
+ var regExpChars = /[|\\{}()[\]^$+*?.]/g;
15
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
16
+ var hasOwn = function(obj, key) {
17
+ return hasOwnProperty.apply(obj, [key]);
18
+ };
19
+ utils.escapeRegExpChars = function(string) {
20
+ if (!string) {
21
+ return "";
22
+ }
23
+ return String(string).replace(regExpChars, "\\$&");
24
+ };
25
+ var _ENCODE_HTML_RULES = {
26
+ "&": "&",
27
+ "<": "&lt;",
28
+ ">": "&gt;",
29
+ '"': "&#34;",
30
+ "'": "&#39;"
31
+ };
32
+ var _MATCH_HTML = /[&<>'"]/g;
33
+ function encode_char(c) {
34
+ return _ENCODE_HTML_RULES[c] || c;
35
+ }
36
+ var escapeFuncStr = `var _ENCODE_HTML_RULES = {
37
+ "&": "&amp;"
38
+ , "<": "&lt;"
39
+ , ">": "&gt;"
40
+ , '"': "&#34;"
41
+ , "'": "&#39;"
42
+ }
43
+ , _MATCH_HTML = /[&<>'"]/g;
44
+ function encode_char(c) {
45
+ return _ENCODE_HTML_RULES[c] || c;
46
+ };
47
+ `;
48
+ utils.escapeXML = function(markup) {
49
+ return markup == void 0 ? "" : String(markup).replace(_MATCH_HTML, encode_char);
50
+ };
51
+ function escapeXMLToString() {
52
+ return Function.prototype.toString.call(this) + ";\n" + escapeFuncStr;
53
+ }
54
+ try {
55
+ if (typeof Object.defineProperty === "function") {
56
+ Object.defineProperty(utils.escapeXML, "toString", { value: escapeXMLToString });
57
+ } else {
58
+ utils.escapeXML.toString = escapeXMLToString;
59
+ }
60
+ } catch (err) {
61
+ console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)");
62
+ }
63
+ utils.shallowCopy = function(to, from) {
64
+ from = from || {};
65
+ if (to !== null && to !== void 0) {
66
+ for (var p in from) {
67
+ if (!hasOwn(from, p)) {
68
+ continue;
69
+ }
70
+ if (p === "__proto__" || p === "constructor") {
71
+ continue;
72
+ }
73
+ to[p] = from[p];
74
+ }
75
+ }
76
+ return to;
77
+ };
78
+ utils.shallowCopyFromList = function(to, from, list) {
79
+ list = list || [];
80
+ from = from || {};
81
+ if (to !== null && to !== void 0) {
82
+ for (var i = 0; i < list.length; i++) {
83
+ var p = list[i];
84
+ if (typeof from[p] != "undefined") {
85
+ if (!hasOwn(from, p)) {
86
+ continue;
87
+ }
88
+ if (p === "__proto__" || p === "constructor") {
89
+ continue;
90
+ }
91
+ to[p] = from[p];
92
+ }
93
+ }
94
+ }
95
+ return to;
96
+ };
97
+ utils.cache = {
98
+ _data: {},
99
+ set: function(key, val) {
100
+ this._data[key] = val;
101
+ },
102
+ get: function(key) {
103
+ return this._data[key];
104
+ },
105
+ remove: function(key) {
106
+ delete this._data[key];
107
+ },
108
+ reset: function() {
109
+ this._data = {};
110
+ }
111
+ };
112
+ utils.hyphenToCamel = function(str) {
113
+ return str.replace(/-[a-z]/g, function(match) {
114
+ return match[1].toUpperCase();
115
+ });
116
+ };
117
+ utils.createNullProtoObjWherePossible = (function() {
118
+ if (typeof Object.create == "function") {
119
+ return function() {
120
+ return /* @__PURE__ */ Object.create(null);
121
+ };
122
+ }
123
+ if (!({ __proto__: null } instanceof Object)) {
124
+ return function() {
125
+ return { __proto__: null };
126
+ };
127
+ }
128
+ return function() {
129
+ return {};
130
+ };
131
+ })();
132
+ utils.hasOwnOnlyObject = function(obj) {
133
+ var o = utils.createNullProtoObjWherePossible();
134
+ for (var p in obj) {
135
+ if (hasOwn(obj, p)) {
136
+ o[p] = obj[p];
137
+ }
138
+ }
139
+ return o;
140
+ };
141
+ if (typeof exports != "undefined") {
142
+ module.exports = utils;
143
+ }
144
+ var utils_default = utils;
145
+
146
+ // node_modules/ejs/lib/esm/ejs.js
147
+ var DECLARATION_KEYWORD = "let";
148
+ var ejs = {};
149
+ var _DEFAULT_OPEN_DELIMITER = "<";
150
+ var _DEFAULT_CLOSE_DELIMITER = ">";
151
+ var _DEFAULT_DELIMITER = "%";
152
+ var _DEFAULT_LOCALS_NAME = "locals";
153
+ var _REGEX_STRING = "(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)";
154
+ var _OPTS_PASSABLE_WITH_DATA = [
155
+ "delimiter",
156
+ "scope",
157
+ "context",
158
+ "debug",
159
+ "compileDebug",
160
+ "client",
161
+ "_with",
162
+ "rmWhitespace",
163
+ "strict",
164
+ "filename",
165
+ "async"
166
+ ];
167
+ var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat("cache");
168
+ var _BOM = /^\uFEFF/;
169
+ var _JS_IDENTIFIER = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
170
+ ejs.cache = utils_default.cache;
171
+ ejs.fileLoader = fs.readFileSync;
172
+ ejs.localsName = _DEFAULT_LOCALS_NAME;
173
+ ejs.promiseImpl = new Function("return this;")().Promise;
174
+ ejs.resolveInclude = function(name, filename, isDir) {
175
+ let dirname3 = path.dirname;
176
+ let extname = path.extname;
177
+ let resolve2 = path.resolve;
178
+ let includePath = resolve2(isDir ? filename : dirname3(filename), name);
179
+ let ext = extname(name);
180
+ if (!ext) {
181
+ includePath += ".ejs";
182
+ }
183
+ return includePath;
184
+ };
185
+ function resolvePaths(name, paths) {
186
+ let filePath;
187
+ if (paths.some(function(v) {
188
+ filePath = ejs.resolveInclude(name, v, true);
189
+ return fs.existsSync(filePath);
190
+ })) {
191
+ return filePath;
192
+ }
193
+ }
194
+ function getIncludePath(path4, options) {
195
+ let includePath;
196
+ let filePath;
197
+ let views = options.views;
198
+ let match = /^[A-Za-z]+:\\|^\//.exec(path4);
199
+ if (match && match.length) {
200
+ path4 = path4.replace(/^\/*/, "");
201
+ if (Array.isArray(options.root)) {
202
+ includePath = resolvePaths(path4, options.root);
203
+ } else {
204
+ includePath = ejs.resolveInclude(path4, options.root || "/", true);
205
+ }
206
+ } else {
207
+ if (options.filename) {
208
+ filePath = ejs.resolveInclude(path4, options.filename);
209
+ if (fs.existsSync(filePath)) {
210
+ includePath = filePath;
211
+ }
212
+ }
213
+ if (!includePath && Array.isArray(views)) {
214
+ includePath = resolvePaths(path4, views);
215
+ }
216
+ if (!includePath && typeof options.includer !== "function") {
217
+ throw new Error('Could not find the include file "' + options.escapeFunction(path4) + '"');
218
+ }
219
+ }
220
+ return includePath;
221
+ }
222
+ function handleCache(options, template) {
223
+ let func;
224
+ let filename = options.filename;
225
+ let hasTemplate = arguments.length > 1;
226
+ if (options.cache) {
227
+ if (!filename) {
228
+ throw new Error("cache option requires a filename");
229
+ }
230
+ func = ejs.cache.get(filename);
231
+ if (func) {
232
+ return func;
233
+ }
234
+ if (!hasTemplate) {
235
+ template = fileLoader(filename).toString().replace(_BOM, "");
236
+ }
237
+ } else if (!hasTemplate) {
238
+ if (!filename) {
239
+ throw new Error("Internal EJS error: no file name or template provided");
240
+ }
241
+ template = fileLoader(filename).toString().replace(_BOM, "");
242
+ }
243
+ func = ejs.compile(template, options);
244
+ if (options.cache) {
245
+ ejs.cache.set(filename, func);
246
+ }
247
+ return func;
248
+ }
249
+ function tryHandleCache(options, data, cb) {
250
+ let result;
251
+ if (!cb) {
252
+ if (typeof ejs.promiseImpl == "function") {
253
+ return new ejs.promiseImpl(function(resolve2, reject) {
254
+ try {
255
+ result = handleCache(options)(data);
256
+ resolve2(result);
257
+ } catch (err) {
258
+ reject(err);
259
+ }
260
+ });
261
+ } else {
262
+ throw new Error("Please provide a callback function");
263
+ }
264
+ } else {
265
+ try {
266
+ result = handleCache(options)(data);
267
+ } catch (err) {
268
+ return cb(err);
269
+ }
270
+ cb(null, result);
271
+ }
272
+ }
273
+ function fileLoader(filePath) {
274
+ return ejs.fileLoader(filePath);
275
+ }
276
+ function includeFile(path4, options) {
277
+ let opts = utils_default.shallowCopy(utils_default.createNullProtoObjWherePossible(), options);
278
+ opts.filename = getIncludePath(path4, opts);
279
+ if (typeof options.includer === "function") {
280
+ let includerResult = options.includer(path4, opts.filename);
281
+ if (includerResult) {
282
+ if (includerResult.filename) {
283
+ opts.filename = includerResult.filename;
284
+ }
285
+ if (includerResult.template) {
286
+ return handleCache(opts, includerResult.template);
287
+ }
288
+ }
289
+ }
290
+ return handleCache(opts);
291
+ }
292
+ function rethrow(err, str, flnm, lineno, esc) {
293
+ let lines = str.split("\n");
294
+ let start = Math.max(lineno - 3, 0);
295
+ let end = Math.min(lines.length, lineno + 3);
296
+ let filename = esc(flnm);
297
+ let context = lines.slice(start, end).map(function(line, i) {
298
+ let curr = i + start + 1;
299
+ return (curr == lineno ? " >> " : " ") + curr + "| " + line;
300
+ }).join("\n");
301
+ err.path = filename;
302
+ err.message = (filename || "ejs") + ":" + lineno + "\n" + context + "\n\n" + err.message;
303
+ throw err;
304
+ }
305
+ function stripSemi(str) {
306
+ return str.replace(/;(\s*$)/, "$1");
307
+ }
308
+ ejs.compile = function compile(template, opts) {
309
+ let templ;
310
+ if (opts && opts.scope) {
311
+ console.warn("`scope` option is deprecated and will be removed in future EJS");
312
+ if (!opts.context) {
313
+ opts.context = opts.scope;
314
+ }
315
+ delete opts.scope;
316
+ }
317
+ templ = new Template(template, opts);
318
+ return templ.compile();
319
+ };
320
+ ejs.render = function(template, d, o) {
321
+ let data = d || utils_default.createNullProtoObjWherePossible();
322
+ let opts = o || utils_default.createNullProtoObjWherePossible();
323
+ if (arguments.length == 2) {
324
+ utils_default.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
325
+ }
326
+ return handleCache(opts, template)(data);
327
+ };
328
+ ejs.renderFile = function() {
329
+ let args = Array.prototype.slice.call(arguments);
330
+ let filename = args.shift();
331
+ let cb;
332
+ let opts = { filename };
333
+ let data;
334
+ let viewOpts;
335
+ if (typeof arguments[arguments.length - 1] == "function") {
336
+ cb = args.pop();
337
+ }
338
+ if (args.length) {
339
+ data = args.shift();
340
+ if (args.length) {
341
+ utils_default.shallowCopy(opts, args.pop());
342
+ } else {
343
+ if (data.settings) {
344
+ if (data.settings.views) {
345
+ opts.views = data.settings.views;
346
+ }
347
+ if (data.settings["view cache"]) {
348
+ opts.cache = true;
349
+ }
350
+ viewOpts = data.settings["view options"];
351
+ if (viewOpts) {
352
+ utils_default.shallowCopy(opts, viewOpts);
353
+ }
354
+ }
355
+ utils_default.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
356
+ }
357
+ opts.filename = filename;
358
+ } else {
359
+ data = utils_default.createNullProtoObjWherePossible();
360
+ }
361
+ return tryHandleCache(opts, data, cb);
362
+ };
363
+ ejs.Template = Template;
364
+ ejs.clearCache = function() {
365
+ ejs.cache.reset();
366
+ };
367
+ function Template(text, optsParam) {
368
+ let opts = utils_default.hasOwnOnlyObject(optsParam);
369
+ let options = utils_default.createNullProtoObjWherePossible();
370
+ this.templateText = text;
371
+ this.mode = null;
372
+ this.truncate = false;
373
+ this.currentLine = 1;
374
+ this.source = "";
375
+ options.client = opts.client || false;
376
+ options.escapeFunction = opts.escape || opts.escapeFunction || utils_default.escapeXML;
377
+ options.compileDebug = opts.compileDebug !== false;
378
+ options.debug = !!opts.debug;
379
+ options.filename = opts.filename;
380
+ options.openDelimiter = opts.openDelimiter || ejs.openDelimiter || _DEFAULT_OPEN_DELIMITER;
381
+ options.closeDelimiter = opts.closeDelimiter || ejs.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
382
+ options.delimiter = opts.delimiter || ejs.delimiter || _DEFAULT_DELIMITER;
383
+ options.strict = opts.strict || false;
384
+ options.context = opts.context;
385
+ options.cache = opts.cache || false;
386
+ options.rmWhitespace = opts.rmWhitespace;
387
+ options.root = opts.root;
388
+ options.includer = opts.includer;
389
+ options.outputFunctionName = opts.outputFunctionName;
390
+ options.localsName = opts.localsName || ejs.localsName || _DEFAULT_LOCALS_NAME;
391
+ options.views = opts.views;
392
+ options.async = opts.async;
393
+ options.destructuredLocals = opts.destructuredLocals;
394
+ options.legacyInclude = typeof opts.legacyInclude != "undefined" ? !!opts.legacyInclude : true;
395
+ if (options.strict) {
396
+ options._with = false;
397
+ } else {
398
+ options._with = typeof opts._with != "undefined" ? opts._with : true;
399
+ }
400
+ this.opts = options;
401
+ this.regex = this.createRegex();
402
+ }
403
+ Template.modes = {
404
+ EVAL: "eval",
405
+ ESCAPED: "escaped",
406
+ RAW: "raw",
407
+ COMMENT: "comment",
408
+ LITERAL: "literal"
409
+ };
410
+ Template.prototype = {
411
+ createRegex: function() {
412
+ let str = _REGEX_STRING;
413
+ let delim = utils_default.escapeRegExpChars(this.opts.delimiter);
414
+ let open = utils_default.escapeRegExpChars(this.opts.openDelimiter);
415
+ let close = utils_default.escapeRegExpChars(this.opts.closeDelimiter);
416
+ str = str.replace(/%/g, delim).replace(/</g, open).replace(/>/g, close);
417
+ return new RegExp(str);
418
+ },
419
+ compile: function() {
420
+ let src;
421
+ let fn;
422
+ let opts = this.opts;
423
+ let prepended = "";
424
+ let appended = "";
425
+ let escapeFn = opts.escapeFunction;
426
+ let ctor;
427
+ let sanitizedFilename = opts.filename ? JSON.stringify(opts.filename) : "undefined";
428
+ if (!this.source) {
429
+ this.generateSource();
430
+ prepended += ` ${DECLARATION_KEYWORD} __output = "";
431
+ function __append(s) { if (s !== undefined && s !== null) __output += s }
432
+ `;
433
+ if (opts.outputFunctionName) {
434
+ if (!_JS_IDENTIFIER.test(opts.outputFunctionName)) {
435
+ throw new Error("outputFunctionName is not a valid JS identifier.");
436
+ }
437
+ prepended += ` ${DECLARATION_KEYWORD} ` + opts.outputFunctionName + " = __append;\n";
438
+ }
439
+ if (opts.localsName && !_JS_IDENTIFIER.test(opts.localsName)) {
440
+ throw new Error("localsName is not a valid JS identifier.");
441
+ }
442
+ if (opts.destructuredLocals && opts.destructuredLocals.length) {
443
+ let destructuring = ` ${DECLARATION_KEYWORD} __locals = (` + opts.localsName + " || {}),\n";
444
+ for (let i = 0; i < opts.destructuredLocals.length; i++) {
445
+ let name = opts.destructuredLocals[i];
446
+ if (!_JS_IDENTIFIER.test(name)) {
447
+ throw new Error("destructuredLocals[" + i + "] is not a valid JS identifier.");
448
+ }
449
+ if (i > 0) {
450
+ destructuring += ",\n ";
451
+ }
452
+ destructuring += name + " = __locals." + name;
453
+ }
454
+ prepended += destructuring + ";\n";
455
+ }
456
+ if (opts._with !== false) {
457
+ prepended += " with (" + opts.localsName + " || {}) {\n";
458
+ appended += " }\n";
459
+ }
460
+ appended += " return __output;\n";
461
+ this.source = prepended + this.source + appended;
462
+ }
463
+ if (opts.compileDebug) {
464
+ src = `${DECLARATION_KEYWORD} __line = 1
465
+ , __lines = ` + JSON.stringify(this.templateText) + "\n , __filename = " + sanitizedFilename + ";\ntry {\n" + this.source + "} catch (e) {\n rethrow(e, __lines, __filename, __line, escapeFn);\n}\n";
466
+ } else {
467
+ src = this.source;
468
+ }
469
+ if (opts.client) {
470
+ src = "escapeFn = escapeFn || " + escapeFn.toString() + ";\n" + src;
471
+ if (opts.compileDebug) {
472
+ src = "rethrow = rethrow || " + rethrow.toString() + ";\n" + src;
473
+ }
474
+ }
475
+ if (opts.strict) {
476
+ src = '"use strict";\n' + src;
477
+ }
478
+ if (opts.debug) {
479
+ console.log(src);
480
+ }
481
+ if (opts.compileDebug && opts.filename) {
482
+ src = src + "\n//# sourceURL=" + sanitizedFilename + "\n";
483
+ }
484
+ try {
485
+ if (opts.async) {
486
+ try {
487
+ ctor = new Function("return (async function(){}).constructor;")();
488
+ } catch (e) {
489
+ if (e instanceof SyntaxError) {
490
+ throw new Error("This environment does not support async/await");
491
+ } else {
492
+ throw e;
493
+ }
494
+ }
495
+ } else {
496
+ ctor = Function;
497
+ }
498
+ fn = new ctor(opts.localsName + ", escapeFn, include, rethrow", src);
499
+ } catch (e) {
500
+ if (e instanceof SyntaxError) {
501
+ if (opts.filename) {
502
+ e.message += " in " + opts.filename;
503
+ }
504
+ e.message += " while compiling ejs\n\n";
505
+ e.message += "If the above error is not helpful, you may want to try EJS-Lint:\n";
506
+ e.message += "https://github.com/RyanZim/EJS-Lint";
507
+ if (!opts.async) {
508
+ e.message += "\n";
509
+ e.message += "Or, if you meant to create an async function, pass `async: true` as an option.";
510
+ }
511
+ }
512
+ throw e;
513
+ }
514
+ let returnedFn = opts.client ? fn : function anonymous(data) {
515
+ let include = function(path4, includeData) {
516
+ let d = utils_default.shallowCopy(utils_default.createNullProtoObjWherePossible(), data);
517
+ if (includeData) {
518
+ d = utils_default.shallowCopy(d, includeData);
519
+ }
520
+ return includeFile(path4, opts)(d);
521
+ };
522
+ return fn.apply(
523
+ opts.context,
524
+ [data || utils_default.createNullProtoObjWherePossible(), escapeFn, include, rethrow]
525
+ );
526
+ };
527
+ if (opts.filename && typeof Object.defineProperty === "function") {
528
+ let filename = opts.filename;
529
+ let basename3 = path.basename(filename, path.extname(filename));
530
+ try {
531
+ Object.defineProperty(returnedFn, "name", {
532
+ value: basename3,
533
+ writable: false,
534
+ enumerable: false,
535
+ configurable: true
536
+ });
537
+ } catch (e) {
538
+ }
539
+ }
540
+ return returnedFn;
541
+ },
542
+ generateSource: function() {
543
+ let opts = this.opts;
544
+ if (opts.rmWhitespace) {
545
+ this.templateText = this.templateText.replace(/[\r\n]+/g, "\n").replace(/^\s+|\s+$/gm, "");
546
+ }
547
+ this.templateText = this.templateText.replace(/[ \t]*<%_/gm, "<%_").replace(/_%>[ \t]*/gm, "_%>");
548
+ let self = this;
549
+ let matches = this.parseTemplateText();
550
+ let d = this.opts.delimiter;
551
+ let o = this.opts.openDelimiter;
552
+ let c = this.opts.closeDelimiter;
553
+ if (matches && matches.length) {
554
+ matches.forEach(function(line, index) {
555
+ let closing;
556
+ if (line.indexOf(o + d) === 0 && line.indexOf(o + d + d) !== 0) {
557
+ closing = matches[index + 2];
558
+ if (!(closing == d + c || closing == "-" + d + c || closing == "_" + d + c)) {
559
+ throw new Error('Could not find matching close tag for "' + line + '".');
560
+ }
561
+ }
562
+ self.scanLine(line);
563
+ });
564
+ }
565
+ },
566
+ parseTemplateText: function() {
567
+ let str = this.templateText;
568
+ let pat = this.regex;
569
+ let result = pat.exec(str);
570
+ let arr = [];
571
+ let firstPos;
572
+ while (result) {
573
+ firstPos = result.index;
574
+ if (firstPos !== 0) {
575
+ arr.push(str.substring(0, firstPos));
576
+ str = str.slice(firstPos);
577
+ }
578
+ arr.push(result[0]);
579
+ str = str.slice(result[0].length);
580
+ result = pat.exec(str);
581
+ }
582
+ if (str) {
583
+ arr.push(str);
584
+ }
585
+ return arr;
586
+ },
587
+ _addOutput: function(line) {
588
+ if (this.truncate) {
589
+ line = line.replace(/^(?:\r\n|\r|\n)/, "");
590
+ this.truncate = false;
591
+ }
592
+ if (!line) {
593
+ return line;
594
+ }
595
+ line = line.replace(/\\/g, "\\\\");
596
+ line = line.replace(/\n/g, "\\n");
597
+ line = line.replace(/\r/g, "\\r");
598
+ line = line.replace(/"/g, '\\"');
599
+ this.source += ' ; __append("' + line + '")\n';
600
+ },
601
+ scanLine: function(line) {
602
+ let self = this;
603
+ let d = this.opts.delimiter;
604
+ let o = this.opts.openDelimiter;
605
+ let c = this.opts.closeDelimiter;
606
+ let newLineCount = 0;
607
+ newLineCount = line.split("\n").length - 1;
608
+ switch (line) {
609
+ case o + d:
610
+ case o + d + "_":
611
+ this.mode = Template.modes.EVAL;
612
+ break;
613
+ case o + d + "=":
614
+ this.mode = Template.modes.ESCAPED;
615
+ break;
616
+ case o + d + "-":
617
+ this.mode = Template.modes.RAW;
618
+ break;
619
+ case o + d + "#":
620
+ this.mode = Template.modes.COMMENT;
621
+ break;
622
+ case o + d + d:
623
+ this.mode = Template.modes.LITERAL;
624
+ this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")\n';
625
+ break;
626
+ case d + d + c:
627
+ this.mode = Template.modes.LITERAL;
628
+ this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")\n';
629
+ break;
630
+ case d + c:
631
+ case "-" + d + c:
632
+ case "_" + d + c:
633
+ if (this.mode == Template.modes.LITERAL) {
634
+ this._addOutput(line);
635
+ }
636
+ this.mode = null;
637
+ this.truncate = line.indexOf("-") === 0 || line.indexOf("_") === 0;
638
+ break;
639
+ default:
640
+ if (this.mode) {
641
+ switch (this.mode) {
642
+ case Template.modes.EVAL:
643
+ case Template.modes.ESCAPED:
644
+ case Template.modes.RAW:
645
+ if (line.lastIndexOf("//") > line.lastIndexOf("\n")) {
646
+ line += "\n";
647
+ }
648
+ }
649
+ switch (this.mode) {
650
+ // Just executing code
651
+ case Template.modes.EVAL:
652
+ this.source += " ; " + line + "\n";
653
+ break;
654
+ // Exec, esc, and output
655
+ case Template.modes.ESCAPED:
656
+ this.source += " ; __append(escapeFn(" + stripSemi(line) + "))\n";
657
+ break;
658
+ // Exec and output
659
+ case Template.modes.RAW:
660
+ this.source += " ; __append(" + stripSemi(line) + ")\n";
661
+ break;
662
+ case Template.modes.COMMENT:
663
+ break;
664
+ // Literal <%% mode, append as raw output
665
+ case Template.modes.LITERAL:
666
+ this._addOutput(line);
667
+ break;
668
+ }
669
+ } else {
670
+ this._addOutput(line);
671
+ }
672
+ }
673
+ if (self.opts.compileDebug && newLineCount) {
674
+ this.currentLine += newLineCount;
675
+ this.source += " ; __line = " + this.currentLine + "\n";
676
+ }
677
+ }
678
+ };
679
+ ejs.escapeXML = utils_default.escapeXML;
680
+ ejs.__express = ejs.renderFile;
681
+ if (typeof window != "undefined") {
682
+ window.ejs = ejs;
683
+ }
684
+ if (typeof module != "undefined") {
685
+ module.exports = ejs;
686
+ }
687
+ var ejs_default = ejs;
688
+
689
+ // dist/cli/state-manager.js
690
+ var __dirname = path2.dirname(fileURLToPath(import.meta.url));
691
+ function getPackageRoot() {
692
+ const currentDir = __dirname;
693
+ const baseName = path2.basename(currentDir);
694
+ if (baseName === "cli" || baseName === "dist") {
695
+ return path2.join(currentDir, "..", "..");
696
+ }
697
+ return path2.join(currentDir, "..");
698
+ }
699
+ function getProjectPaths(cwd) {
700
+ const packageRoot = getPackageRoot();
701
+ return {
702
+ srcDir: path2.join(cwd, "src"),
703
+ docDir: path2.join(cwd, "doc"),
704
+ handlersDir: path2.join(cwd, "src", "handlers"),
705
+ botJsonPath: path2.join(cwd, "bot.json"),
706
+ stateTypesPath: path2.join(cwd, "src", "bot-state-types.ts"),
707
+ botDiagramMdPath: path2.join(cwd, "doc", "bot-diagram.md"),
708
+ botDiagramPngPath: path2.join(cwd, "doc", "bot-diagram.png"),
709
+ // Templates are relative to the package root, not the CLI file
710
+ templatePath: path2.join(packageRoot, "dist", "templates", "handler.ts.ejs")
711
+ };
712
+ }
713
+ function loadBotConfig(cwd) {
714
+ const paths = getProjectPaths(cwd);
715
+ if (!fs2.existsSync(paths.botJsonPath)) {
716
+ return {};
717
+ }
718
+ return JSON.parse(fs2.readFileSync(paths.botJsonPath, "utf-8"));
719
+ }
720
+ function saveBotConfig(config, cwd) {
721
+ const paths = getProjectPaths(cwd);
722
+ fs2.writeFileSync(paths.botJsonPath, JSON.stringify(config, null, 2) + "\n");
723
+ }
724
+ function validateStateName(name) {
725
+ return /^[a-zA-Z][a-zA-Z0-9_]*$/.test(name);
726
+ }
727
+ function pascalCase(str) {
728
+ return str.charAt(0).toUpperCase() + str.slice(1);
729
+ }
730
+ function getHandlerPath(stateName, cwd) {
731
+ return path2.join(getProjectPaths(cwd).handlersDir, stateName, "index.ts");
732
+ }
733
+ function handlerExists(stateName, cwd) {
734
+ return fs2.existsSync(getHandlerPath(stateName, cwd));
735
+ }
736
+ function isHandlerFolderNonEmpty(stateName, cwd) {
737
+ const handlerDir = path2.join(getProjectPaths(cwd).handlersDir, stateName);
738
+ if (!fs2.existsSync(handlerDir))
739
+ return false;
740
+ const files = fs2.readdirSync(handlerDir);
741
+ return files.length > 0;
742
+ }
743
+ function getIncomingTransitions(config, stateName) {
744
+ const incoming = [];
745
+ for (const [from, targets] of Object.entries(config)) {
746
+ if (targets.includes(stateName)) {
747
+ incoming.push(from);
748
+ }
749
+ }
750
+ return incoming;
751
+ }
752
+ function generateTypes(config) {
753
+ const states = Object.keys(config).sort();
754
+ if (states.length === 0) {
755
+ return `// Auto-generated by telemeister state:sync - DO NOT EDIT
756
+ // No states defined yet
757
+
758
+ export type AppStates = never;
759
+
760
+ export type StateTransitions = Record<string, never>;
761
+ `;
762
+ }
763
+ const statesUnion = states.map((s) => `'${s}'`).join(" | ");
764
+ let stateTransitionsContent = "";
765
+ for (const state of states) {
766
+ const targets = config[state] || [];
767
+ if (targets.length === 0) {
768
+ stateTransitionsContent += ` ${state}: void;
769
+ `;
770
+ } else {
771
+ const targetsUnion = [...targets].sort().map((t) => `'${t}'`).join(" | ");
772
+ stateTransitionsContent += ` ${state}: ${targetsUnion} | void;
773
+ `;
774
+ }
775
+ }
776
+ let returnTypesContent = "";
777
+ for (const state of states) {
778
+ const typeName = `${pascalCase(state)}Transitions`;
779
+ returnTypesContent += `export type ${typeName} = Promise<StateTransitions['${state}']>;
780
+ `;
781
+ }
782
+ return `// Auto-generated by telemeister state:sync - DO NOT EDIT
783
+
784
+ export type AppStates = ${statesUnion};
785
+
786
+ export type StateTransitions = {
787
+ ${stateTransitionsContent}};
788
+
789
+ ${returnTypesContent}
790
+ `;
791
+ }
792
+ function generateMermaidDiagram(config) {
793
+ const states = Object.keys(config);
794
+ if (states.length === 0) {
795
+ return "stateDiagram-v2\n [*] --> [*]";
796
+ }
797
+ const transitions = [];
798
+ for (const [from, targets] of Object.entries(config)) {
799
+ for (const to of targets) {
800
+ transitions.push(` ${from} --> ${to}`);
801
+ }
802
+ }
803
+ return `stateDiagram-v2
804
+ ${transitions.join("\n")}`;
805
+ }
806
+ function generateMermaidMarkdown(config) {
807
+ const mermaidCode = generateMermaidDiagram(config);
808
+ return `# Bot State Diagram
809
+
810
+ \`\`\`mermaid
811
+ ${mermaidCode}
812
+ \`\`\`
813
+ `;
814
+ }
815
+ async function generateDiagram(config, cwd) {
816
+ const paths = getProjectPaths(cwd);
817
+ if (!fs2.existsSync(paths.docDir)) {
818
+ fs2.mkdirSync(paths.docDir, { recursive: true });
819
+ }
820
+ const mdContent = generateMermaidMarkdown(config);
821
+ fs2.writeFileSync(paths.botDiagramMdPath, mdContent);
822
+ console.log(`\u{1F4DD} Updated: doc/bot-diagram.md`);
823
+ const mermaidCode = generateMermaidDiagram(config);
824
+ const tempMmdPath = path2.join(cwd, ".temp-diagram.mmd");
825
+ fs2.writeFileSync(tempMmdPath, mermaidCode);
826
+ try {
827
+ const { execSync: execSync2 } = await import("child_process");
828
+ execSync2(`npx mmdc -i "${tempMmdPath}" -o "${paths.botDiagramPngPath}" -b white`, {
829
+ stdio: "pipe",
830
+ cwd
831
+ });
832
+ console.log(`\u{1F4DD} Updated: doc/bot-diagram.png`);
833
+ } catch {
834
+ console.warn(`\u26A0\uFE0F Could not generate PNG diagram (mermaid-cli may not be installed)`);
835
+ } finally {
836
+ fs2.unlinkSync(tempMmdPath);
837
+ }
838
+ }
839
+ async function createHandler(stateName, transitionStates, cwd) {
840
+ const paths = getProjectPaths(cwd);
841
+ const handlerDir = path2.join(paths.handlersDir, stateName);
842
+ const handlerPath = path2.join(handlerDir, "index.ts");
843
+ if (fs2.existsSync(handlerPath)) {
844
+ console.log(`\u23ED\uFE0F Handler already exists: src/handlers/${stateName}/index.ts`);
845
+ return;
846
+ }
847
+ if (!fs2.existsSync(handlerDir)) {
848
+ fs2.mkdirSync(handlerDir, { recursive: true });
849
+ }
850
+ const templateContent = fs2.readFileSync(paths.templatePath, "utf-8");
851
+ const content = ejs_default.render(templateContent, {
852
+ stateName,
853
+ transitionStates: [...transitionStates].sort(),
854
+ pascalCase
855
+ });
856
+ fs2.writeFileSync(handlerPath, content);
857
+ console.log(`\u{1F4DD} Created: src/handlers/${stateName}/index.ts`);
858
+ }
859
+ function updateHandlersIndex(stateName, cwd) {
860
+ const paths = getProjectPaths(cwd);
861
+ const indexPath = path2.join(paths.handlersDir, "index.ts");
862
+ if (!fs2.existsSync(indexPath)) {
863
+ const content2 = `/**
864
+ * State Handlers Index
865
+ *
866
+ * Import all your state handler files here.
867
+ */
868
+
869
+ import './${stateName}/index.js';
870
+ `;
871
+ fs2.writeFileSync(indexPath, content2);
872
+ console.log(`\u{1F4DD} Created: src/handlers/index.ts`);
873
+ return;
874
+ }
875
+ let content = fs2.readFileSync(indexPath, "utf-8");
876
+ const importLine = `import './${stateName}/index.js';`;
877
+ if (content.includes(importLine)) {
878
+ return;
879
+ }
880
+ content = content.trimEnd() + `
881
+ ${importLine}
882
+ `;
883
+ fs2.writeFileSync(indexPath, content);
884
+ console.log(`\u{1F4DD} Updated: src/handlers/index.ts`);
885
+ }
886
+ function removeFromHandlersIndex(stateName, cwd) {
887
+ const paths = getProjectPaths(cwd);
888
+ const indexPath = path2.join(paths.handlersDir, "index.ts");
889
+ if (!fs2.existsSync(indexPath))
890
+ return;
891
+ let content = fs2.readFileSync(indexPath, "utf-8");
892
+ const importLine = `import './${stateName}/index.js';`;
893
+ if (content.includes(importLine)) {
894
+ content = content.replace(new RegExp(`^${importLine.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}
895
+ ?`, "m"), "");
896
+ fs2.writeFileSync(indexPath, content);
897
+ console.log(`\u{1F4DD} Removed import from: src/handlers/index.ts`);
898
+ }
899
+ }
900
+ async function stateAdd(stateName) {
901
+ const cwd = process.cwd();
902
+ if (!stateName) {
903
+ console.error("\u274C Error: State name is required");
904
+ console.error("Usage: telemeister state:add <state-name>");
905
+ process.exit(1);
906
+ }
907
+ if (!validateStateName(stateName)) {
908
+ console.error("\u274C Error: State name must start with a letter and contain only letters, numbers, and underscores");
909
+ process.exit(1);
910
+ }
911
+ const config = loadBotConfig(cwd);
912
+ if (config[stateName]) {
913
+ console.error(`\u274C Error: State "${stateName}" already exists in bot.json`);
914
+ process.exit(1);
915
+ }
916
+ config[stateName] = [];
917
+ saveBotConfig(config, cwd);
918
+ console.log(`\u2705 Added state "${stateName}" to bot.json`);
919
+ await createHandler(stateName, [], cwd);
920
+ updateHandlersIndex(stateName, cwd);
921
+ const paths = getProjectPaths(cwd);
922
+ const typesContent = generateTypes(config);
923
+ fs2.writeFileSync(paths.stateTypesPath, typesContent);
924
+ console.log(`\u{1F4DD} Updated: src/bot-state-types.ts`);
925
+ await generateDiagram(config, cwd);
926
+ console.log(`
927
+ \u2705 State "${stateName}" added successfully!`);
928
+ console.log(`
929
+ Next steps:`);
930
+ console.log(` 1. Edit src/handlers/${stateName}/index.ts to customize the handler`);
931
+ console.log(` 2. Add transitions: telemeister state:transition:add ${stateName} <target-state>`);
932
+ }
933
+ async function stateDelete(stateName) {
934
+ const cwd = process.cwd();
935
+ if (!stateName) {
936
+ console.error("\u274C Error: State name is required");
937
+ console.error("Usage: telemeister state:delete <state-name>");
938
+ process.exit(1);
939
+ }
940
+ const config = loadBotConfig(cwd);
941
+ if (!config[stateName]) {
942
+ console.error(`\u274C Error: State "${stateName}" does not exist in bot.json`);
943
+ process.exit(1);
944
+ }
945
+ if (isHandlerFolderNonEmpty(stateName, cwd)) {
946
+ console.error(`\u274C Error: Cannot delete state "${stateName}" - handler folder is not empty`);
947
+ console.error(` Path: src/handlers/${stateName}/`);
948
+ console.error(` Remove or move the handler files first, then retry.`);
949
+ process.exit(1);
950
+ }
951
+ const outgoing = config[stateName] || [];
952
+ if (outgoing.length > 0) {
953
+ console.error(`\u274C Error: Cannot delete state "${stateName}" - has outgoing transitions:`);
954
+ outgoing.forEach((t) => console.error(` ${stateName} \u2192 ${t}`));
955
+ console.error(` Remove transitions first: telemeister state:transition:delete ${stateName} <target>`);
956
+ process.exit(1);
957
+ }
958
+ const incoming = getIncomingTransitions(config, stateName);
959
+ if (incoming.length > 0) {
960
+ console.error(`\u274C Error: Cannot delete state "${stateName}" - has incoming transitions:`);
961
+ incoming.forEach((f) => console.error(` ${f} \u2192 ${stateName}`));
962
+ console.error(` Remove transitions first: telemeister state:transition:delete <source> ${stateName}`);
963
+ process.exit(1);
964
+ }
965
+ delete config[stateName];
966
+ saveBotConfig(config, cwd);
967
+ console.log(`\u2705 Removed state "${stateName}" from bot.json`);
968
+ removeFromHandlersIndex(stateName, cwd);
969
+ const paths = getProjectPaths(cwd);
970
+ const typesContent = generateTypes(config);
971
+ fs2.writeFileSync(paths.stateTypesPath, typesContent);
972
+ console.log(`\u{1F4DD} Updated: src/bot-state-types.ts`);
973
+ await generateDiagram(config, cwd);
974
+ const handlerDir = path2.join(paths.handlersDir, stateName);
975
+ if (fs2.existsSync(handlerDir)) {
976
+ fs2.rmdirSync(handlerDir);
977
+ console.log(`\u{1F5D1}\uFE0F Removed empty folder: src/handlers/${stateName}/`);
978
+ }
979
+ console.log(`
980
+ \u2705 State "${stateName}" deleted successfully!`);
981
+ }
982
+ async function stateSync() {
983
+ const cwd = process.cwd();
984
+ const config = loadBotConfig(cwd);
985
+ const states = Object.keys(config);
986
+ console.log("\u{1F504} Syncing state types and handlers...\n");
987
+ const paths = getProjectPaths(cwd);
988
+ const typesContent = generateTypes(config);
989
+ fs2.writeFileSync(paths.stateTypesPath, typesContent);
990
+ console.log(`\u{1F4DD} Updated: src/bot-state-types.ts`);
991
+ for (const state of states) {
992
+ if (!handlerExists(state, cwd)) {
993
+ await createHandler(state, config[state] || [], cwd);
994
+ updateHandlersIndex(state, cwd);
995
+ } else {
996
+ console.log(`\u23ED\uFE0F Handler exists: src/handlers/${state}/index.ts`);
997
+ }
998
+ }
999
+ await generateDiagram(config, cwd);
1000
+ console.log("\n\u2705 Sync complete!");
1001
+ }
1002
+ async function transitionAdd(fromState, toState) {
1003
+ const cwd = process.cwd();
1004
+ if (!fromState || !toState) {
1005
+ console.error("\u274C Error: Both source and target state names are required");
1006
+ console.error("Usage: telemeister state:transition:add <from-state> <to-state>");
1007
+ process.exit(1);
1008
+ }
1009
+ const config = loadBotConfig(cwd);
1010
+ if (!config[fromState]) {
1011
+ console.error(`\u274C Error: Source state "${fromState}" does not exist in bot.json`);
1012
+ process.exit(1);
1013
+ }
1014
+ if (!config[toState]) {
1015
+ console.error(`\u274C Error: Target state "${toState}" does not exist in bot.json`);
1016
+ process.exit(1);
1017
+ }
1018
+ if (config[fromState].includes(toState)) {
1019
+ console.error(`\u274C Error: Transition "${fromState}" \u2192 "${toState}" already exists`);
1020
+ process.exit(1);
1021
+ }
1022
+ config[fromState].push(toState);
1023
+ saveBotConfig(config, cwd);
1024
+ console.log(`\u2705 Added transition: ${fromState} \u2192 ${toState}`);
1025
+ const paths = getProjectPaths(cwd);
1026
+ const typesContent = generateTypes(config);
1027
+ fs2.writeFileSync(paths.stateTypesPath, typesContent);
1028
+ console.log(`\u{1F4DD} Updated: src/bot-state-types.ts`);
1029
+ await generateDiagram(config, cwd);
1030
+ }
1031
+ async function transitionDelete(fromState, toState) {
1032
+ const cwd = process.cwd();
1033
+ if (!fromState || !toState) {
1034
+ console.error("\u274C Error: Both source and target state names are required");
1035
+ console.error("Usage: telemeister state:transition:delete <from-state> <to-state>");
1036
+ process.exit(1);
1037
+ }
1038
+ const config = loadBotConfig(cwd);
1039
+ if (!config[fromState]) {
1040
+ console.error(`\u274C Error: Source state "${fromState}" does not exist in bot.json`);
1041
+ process.exit(1);
1042
+ }
1043
+ const index = config[fromState].indexOf(toState);
1044
+ if (index === -1) {
1045
+ console.error(`\u274C Error: Transition "${fromState}" \u2192 "${toState}" does not exist`);
1046
+ process.exit(1);
1047
+ }
1048
+ config[fromState].splice(index, 1);
1049
+ saveBotConfig(config, cwd);
1050
+ console.log(`\u2705 Removed transition: ${fromState} \u2192 ${toState}`);
1051
+ const paths = getProjectPaths(cwd);
1052
+ const typesContent = generateTypes(config);
1053
+ fs2.writeFileSync(paths.stateTypesPath, typesContent);
1054
+ console.log(`\u{1F4DD} Updated: src/bot-state-types.ts`);
1055
+ await generateDiagram(config, cwd);
1056
+ }
1057
+
1058
+ // dist/cli/create-bot.js
1059
+ import * as fs3 from "fs";
1060
+ import * as path3 from "path";
1061
+ import { fileURLToPath as fileURLToPath2 } from "url";
1062
+ import { execSync } from "child_process";
1063
+ var __dirname2 = path3.dirname(fileURLToPath2(import.meta.url));
1064
+ function getPackageRoot2() {
1065
+ const currentDir = __dirname2;
1066
+ const baseName = path3.basename(currentDir);
1067
+ if (baseName === "cli" || baseName === "dist") {
1068
+ return path3.join(currentDir, "..", "..");
1069
+ }
1070
+ return path3.join(currentDir, "..");
1071
+ }
1072
+ function loadTemplate(templateName) {
1073
+ const packageRoot = getPackageRoot2();
1074
+ const templatePath = path3.join(packageRoot, "dist", "templates", templateName);
1075
+ return fs3.readFileSync(templatePath, "utf-8");
1076
+ }
1077
+ function renderTemplate(templateName, data = {}) {
1078
+ const template = loadTemplate(templateName);
1079
+ return ejs_default.render(template, data);
1080
+ }
1081
+ async function createBot(botName) {
1082
+ if (!botName) {
1083
+ console.error("\u274C Error: Bot name is required");
1084
+ console.error("Usage: telemeister create-bot <bot-name>");
1085
+ process.exit(1);
1086
+ }
1087
+ if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(botName)) {
1088
+ console.error("\u274C Error: Bot name must start with a letter and contain only letters, numbers, underscores, and hyphens");
1089
+ process.exit(1);
1090
+ }
1091
+ const targetDir = path3.resolve(process.cwd(), botName);
1092
+ if (fs3.existsSync(targetDir)) {
1093
+ console.error(`\u274C Error: Directory "${botName}" already exists`);
1094
+ process.exit(1);
1095
+ }
1096
+ console.log(`\u{1F680} Creating new bot: ${botName}
1097
+ `);
1098
+ fs3.mkdirSync(targetDir, { recursive: true });
1099
+ fs3.mkdirSync(path3.join(targetDir, "src", "handlers"), { recursive: true });
1100
+ fs3.mkdirSync(path3.join(targetDir, "prisma"), { recursive: true });
1101
+ fs3.writeFileSync(path3.join(targetDir, ".gitignore"), loadTemplate("gitignore.ejs"));
1102
+ fs3.writeFileSync(path3.join(targetDir, "tsconfig.json"), loadTemplate("tsconfig.json.ejs"));
1103
+ fs3.writeFileSync(path3.join(targetDir, ".env.example"), loadTemplate("env.example.ejs"));
1104
+ fs3.writeFileSync(path3.join(targetDir, "bot.json"), loadTemplate("bot.json.ejs"));
1105
+ fs3.writeFileSync(path3.join(targetDir, "src", "index.ts"), loadTemplate("index.ts.ejs"));
1106
+ fs3.writeFileSync(path3.join(targetDir, "prisma", "schema.prisma"), loadTemplate("prisma-schema.prisma.ejs"));
1107
+ fs3.writeFileSync(path3.join(targetDir, "prisma.config.ts"), loadTemplate("prisma.config.ts.ejs"));
1108
+ fs3.mkdirSync(path3.join(targetDir, "src", "lib"), { recursive: true });
1109
+ fs3.writeFileSync(path3.join(targetDir, "src", "lib", "database.ts"), loadTemplate("database.ts.ejs"));
1110
+ fs3.writeFileSync(path3.join(targetDir, "README.md"), renderTemplate("README.md.ejs", { botName }));
1111
+ fs3.writeFileSync(path3.join(targetDir, "package.json"), renderTemplate("package.json.ejs", { botName }));
1112
+ process.chdir(targetDir);
1113
+ await stateSync();
1114
+ console.log("\n\u{1F4E6} Installing dependencies...");
1115
+ try {
1116
+ execSync("npm install", { stdio: "inherit" });
1117
+ console.log("\u2705 Dependencies installed\n");
1118
+ } catch {
1119
+ console.error('\u274C Failed to install dependencies. Please run "npm install" manually.\n');
1120
+ process.exit(1);
1121
+ }
1122
+ const tempDbUrl = "file:./dev.db";
1123
+ console.log("\u{1F5C4}\uFE0F Generating Prisma client...");
1124
+ try {
1125
+ execSync("npm run db:generate", {
1126
+ stdio: "inherit",
1127
+ env: { ...process.env, DATABASE_URL: tempDbUrl }
1128
+ });
1129
+ console.log("\u2705 Prisma client generated\n");
1130
+ } catch {
1131
+ console.error('\u274C Failed to generate Prisma client. Please run "npm run db:generate" manually.\n');
1132
+ process.exit(1);
1133
+ }
1134
+ console.log("\u{1F5C4}\uFE0F Creating initial database migration...");
1135
+ try {
1136
+ execSync("npx prisma migrate dev --name init", {
1137
+ stdio: "inherit",
1138
+ env: { ...process.env, DATABASE_URL: tempDbUrl }
1139
+ });
1140
+ console.log("\u2705 Database migration created\n");
1141
+ } catch {
1142
+ console.error('\u274C Failed to create database migration. Please run "npm run db:migrate" manually.\n');
1143
+ process.exit(1);
1144
+ }
1145
+ console.log(`\u2705 Bot "${botName}" created successfully!
1146
+ `);
1147
+ console.log("Next steps:");
1148
+ console.log(` cd ${botName}`);
1149
+ console.log(" cp .env.example .env # Add your bot token from @BotFather");
1150
+ console.log(" npm run dev");
1151
+ }
1152
+
1153
+ // dist/cli/cli.js
1154
+ var command = process.argv[2];
1155
+ var arg1 = process.argv[3];
1156
+ var arg2 = process.argv[4];
1157
+ async function runCLI() {
1158
+ switch (command) {
1159
+ case "create-bot":
1160
+ await createBot(arg1);
1161
+ break;
1162
+ case "state:add":
1163
+ await stateAdd(arg1);
1164
+ break;
1165
+ case "state:delete":
1166
+ await stateDelete(arg1);
1167
+ break;
1168
+ case "state:sync":
1169
+ await stateSync();
1170
+ break;
1171
+ case "state:transition:add":
1172
+ await transitionAdd(arg1, arg2);
1173
+ break;
1174
+ case "state:transition:delete":
1175
+ await transitionDelete(arg1, arg2);
1176
+ break;
1177
+ default:
1178
+ console.error("\u274C Unknown command:", command);
1179
+ console.error("");
1180
+ console.error("Available commands:");
1181
+ console.error(" create-bot <name> - Create a new bot project");
1182
+ console.error(" state:add <name> - Add a new state + create handler");
1183
+ console.error(" state:delete <name> - Delete a state (with safety checks)");
1184
+ console.error(" state:sync - Sync types and create missing handlers");
1185
+ console.error(" state:transition:add <from> <to> - Add a transition");
1186
+ console.error(" state:transition:delete <from> <to> - Delete a transition");
1187
+ process.exit(1);
1188
+ }
1189
+ }
1190
+ runCLI().catch((err) => {
1191
+ console.error("\u274C Error:", err.message);
1192
+ process.exit(1);
1193
+ });
1194
+ export {
1195
+ runCLI
1196
+ };
1197
+ /*! Bundled license information:
1198
+
1199
+ ejs/lib/esm/ejs.js:
1200
+ (**
1201
+ * @file Embedded JavaScript templating engine. {@link http://ejs.co}
1202
+ * @author Matthew Eernisse <mde@fleegix.org>
1203
+ * @project EJS
1204
+ * @license {@link http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0}
1205
+ *)
1206
+ */