@doyuli/create-vue 0.0.1-beta.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.
Files changed (34) hide show
  1. package/bin/index.js +2 -0
  2. package/dist/index.js +1034 -0
  3. package/package.json +31 -0
  4. package/template/base/.editorconfig +8 -0
  5. package/template/base/.gitattributes +1 -0
  6. package/template/base/.prettierrc.json +7 -0
  7. package/template/base/.vscode/extensions.json +3 -0
  8. package/template/base/index.html +14 -0
  9. package/template/base/package.json +32 -0
  10. package/template/base/public/favicon.ico +0 -0
  11. package/template/base/src/App.vue +26 -0
  12. package/template/base/src/layouts/DefaultLayout.vue +11 -0
  13. package/template/base/src/main.ts +14 -0
  14. package/template/base/src/pages/about/index.vue +43 -0
  15. package/template/base/src/pages/home/index.vue +38 -0
  16. package/template/base/src/stores/counter.ts +12 -0
  17. package/template/base/types/env.d.ts.ejs +12 -0
  18. package/template/base/unocss.config.ts +21 -0
  19. package/template/base/vite.config.ts.ejs +42 -0
  20. package/template/eslint/eslint.config.ts +8 -0
  21. package/template/eslint/package.json +12 -0
  22. package/template/git-hooks/package.json +17 -0
  23. package/template/git-hooks/scripts/verify-commit.js +29 -0
  24. package/template/router/default/package.json +6 -0
  25. package/template/router/default/src/router/index.ts +19 -0
  26. package/template/router/unplugin/package.json +9 -0
  27. package/template/router/unplugin/src/router/index.ts +13 -0
  28. package/template/tsconfig/tsconfig.app.json +20 -0
  29. package/template/tsconfig/tsconfig.node.json +19 -0
  30. package/template/vitest/.vscode/extensions.json +3 -0
  31. package/template/vitest/package.json +14 -0
  32. package/template/vitest/src/components/__tests__/HelloWorld.spec.js +11 -0
  33. package/template/vitest/tsconfig.vitest.json +11 -0
  34. package/template/vitest/vitest.config.js +14 -0
package/dist/index.js ADDED
@@ -0,0 +1,1034 @@
1
+ import { createRequire } from "node:module";
2
+ import * as fs from "node:fs";
3
+ import * as path from "node:path";
4
+ import process from "node:process";
5
+ import { fileURLToPath } from "node:url";
6
+ import { parseArgs } from "node:util";
7
+ import { cancel, confirm, intro, multiselect, outro, text } from "@clack/prompts";
8
+ import { canSkipEmptying, emptyDir, getOutroMessage, preOrderDirectoryTraverse, renderFile, renderTemplate, unwrapPrompt } from "@doyuli/kits-core";
9
+ import pico from "picocolors";
10
+
11
+ //#region rolldown:runtime
12
+ var __create = Object.create;
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
16
+ var __getProtoOf = Object.getPrototypeOf;
17
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
18
+ var __commonJS = (cb, mod) => function() {
19
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
23
+ key = keys[i];
24
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
25
+ get: ((k) => from[k]).bind(null, key),
26
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
27
+ });
28
+ }
29
+ return to;
30
+ };
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
32
+ value: mod,
33
+ enumerable: true
34
+ }) : target, mod));
35
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
36
+
37
+ //#endregion
38
+ //#region ../../node_modules/.pnpm/ejs@3.1.10/node_modules/ejs/lib/utils.js
39
+ var require_utils = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/ejs@3.1.10/node_modules/ejs/lib/utils.js": ((exports) => {
40
+ var regExpChars = /[|\\{}()[\]^$+*?.]/g;
41
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
42
+ var hasOwn = function(obj, key) {
43
+ return hasOwnProperty.apply(obj, [key]);
44
+ };
45
+ /**
46
+ * Escape characters reserved in regular expressions.
47
+ *
48
+ * If `string` is `undefined` or `null`, the empty string is returned.
49
+ *
50
+ * @param {String} string Input string
51
+ * @return {String} Escaped string
52
+ * @static
53
+ * @private
54
+ */
55
+ exports.escapeRegExpChars = function(string) {
56
+ // istanbul ignore if
57
+ if (!string) return "";
58
+ return String(string).replace(regExpChars, "\\$&");
59
+ };
60
+ var _ENCODE_HTML_RULES = {
61
+ "&": "&amp;",
62
+ "<": "&lt;",
63
+ ">": "&gt;",
64
+ "\"": "&#34;",
65
+ "'": "&#39;"
66
+ };
67
+ var _MATCH_HTML = /[&<>'"]/g;
68
+ function encode_char(c) {
69
+ return _ENCODE_HTML_RULES[c] || c;
70
+ }
71
+ /**
72
+ * Stringified version of constants used by {@link module:utils.escapeXML}.
73
+ *
74
+ * It is used in the process of generating {@link ClientFunction}s.
75
+ *
76
+ * @readonly
77
+ * @type {String}
78
+ */
79
+ var escapeFuncStr = "var _ENCODE_HTML_RULES = {\n \"&\": \"&amp;\"\n , \"<\": \"&lt;\"\n , \">\": \"&gt;\"\n , '\"': \"&#34;\"\n , \"'\": \"&#39;\"\n }\n , _MATCH_HTML = /[&<>'\"]/g;\nfunction encode_char(c) {\n return _ENCODE_HTML_RULES[c] || c;\n};\n";
80
+ /**
81
+ * Escape characters reserved in XML.
82
+ *
83
+ * If `markup` is `undefined` or `null`, the empty string is returned.
84
+ *
85
+ * @implements {EscapeCallback}
86
+ * @param {String} markup Input string
87
+ * @return {String} Escaped string
88
+ * @static
89
+ * @private
90
+ */
91
+ exports.escapeXML = function(markup) {
92
+ return markup == void 0 ? "" : String(markup).replace(_MATCH_HTML, encode_char);
93
+ };
94
+ function escapeXMLToString() {
95
+ return Function.prototype.toString.call(this) + ";\n" + escapeFuncStr;
96
+ }
97
+ try {
98
+ if (typeof Object.defineProperty === "function") Object.defineProperty(exports.escapeXML, "toString", { value: escapeXMLToString });
99
+ else exports.escapeXML.toString = escapeXMLToString;
100
+ } catch (err) {
101
+ console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)");
102
+ }
103
+ /**
104
+ * Naive copy of properties from one object to another.
105
+ * Does not recurse into non-scalar properties
106
+ * Does not check to see if the property has a value before copying
107
+ *
108
+ * @param {Object} to Destination object
109
+ * @param {Object} from Source object
110
+ * @return {Object} Destination object
111
+ * @static
112
+ * @private
113
+ */
114
+ exports.shallowCopy = function(to, from) {
115
+ from = from || {};
116
+ if (to !== null && to !== void 0) for (var p in from) {
117
+ if (!hasOwn(from, p)) continue;
118
+ if (p === "__proto__" || p === "constructor") continue;
119
+ to[p] = from[p];
120
+ }
121
+ return to;
122
+ };
123
+ /**
124
+ * Naive copy of a list of key names, from one object to another.
125
+ * Only copies property if it is actually defined
126
+ * Does not recurse into non-scalar properties
127
+ *
128
+ * @param {Object} to Destination object
129
+ * @param {Object} from Source object
130
+ * @param {Array} list List of properties to copy
131
+ * @return {Object} Destination object
132
+ * @static
133
+ * @private
134
+ */
135
+ exports.shallowCopyFromList = function(to, from, list) {
136
+ list = list || [];
137
+ from = from || {};
138
+ if (to !== null && to !== void 0) for (var i = 0; i < list.length; i++) {
139
+ var p = list[i];
140
+ if (typeof from[p] != "undefined") {
141
+ if (!hasOwn(from, p)) continue;
142
+ if (p === "__proto__" || p === "constructor") continue;
143
+ to[p] = from[p];
144
+ }
145
+ }
146
+ return to;
147
+ };
148
+ /**
149
+ * Simple in-process cache implementation. Does not implement limits of any
150
+ * sort.
151
+ *
152
+ * @implements {Cache}
153
+ * @static
154
+ * @private
155
+ */
156
+ exports.cache = {
157
+ _data: {},
158
+ set: function(key, val) {
159
+ this._data[key] = val;
160
+ },
161
+ get: function(key) {
162
+ return this._data[key];
163
+ },
164
+ remove: function(key) {
165
+ delete this._data[key];
166
+ },
167
+ reset: function() {
168
+ this._data = {};
169
+ }
170
+ };
171
+ /**
172
+ * Transforms hyphen case variable into camel case.
173
+ *
174
+ * @param {String} string Hyphen case string
175
+ * @return {String} Camel case string
176
+ * @static
177
+ * @private
178
+ */
179
+ exports.hyphenToCamel = function(str) {
180
+ return str.replace(/-[a-z]/g, function(match) {
181
+ return match[1].toUpperCase();
182
+ });
183
+ };
184
+ /**
185
+ * Returns a null-prototype object in runtimes that support it
186
+ *
187
+ * @return {Object} Object, prototype will be set to null where possible
188
+ * @static
189
+ * @private
190
+ */
191
+ exports.createNullProtoObjWherePossible = (function() {
192
+ if (typeof Object.create == "function") return function() {
193
+ return Object.create(null);
194
+ };
195
+ return function() {
196
+ return {};
197
+ };
198
+ })();
199
+ exports.hasOwnOnlyObject = function(obj) {
200
+ var o = exports.createNullProtoObjWherePossible();
201
+ for (var p in obj) if (hasOwn(obj, p)) o[p] = obj[p];
202
+ return o;
203
+ };
204
+ }) });
205
+
206
+ //#endregion
207
+ //#region ../../node_modules/.pnpm/ejs@3.1.10/node_modules/ejs/package.json
208
+ var require_package = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/ejs@3.1.10/node_modules/ejs/package.json": ((exports, module) => {
209
+ module.exports = {
210
+ "name": "ejs",
211
+ "description": "Embedded JavaScript templates",
212
+ "keywords": [
213
+ "template",
214
+ "engine",
215
+ "ejs"
216
+ ],
217
+ "version": "3.1.10",
218
+ "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
219
+ "license": "Apache-2.0",
220
+ "bin": { "ejs": "./bin/cli.js" },
221
+ "main": "./lib/ejs.js",
222
+ "jsdelivr": "ejs.min.js",
223
+ "unpkg": "ejs.min.js",
224
+ "repository": {
225
+ "type": "git",
226
+ "url": "git://github.com/mde/ejs.git"
227
+ },
228
+ "bugs": "https://github.com/mde/ejs/issues",
229
+ "homepage": "https://github.com/mde/ejs",
230
+ "dependencies": { "jake": "^10.8.5" },
231
+ "devDependencies": {
232
+ "browserify": "^16.5.1",
233
+ "eslint": "^6.8.0",
234
+ "git-directory-deploy": "^1.5.1",
235
+ "jsdoc": "^4.0.2",
236
+ "lru-cache": "^4.0.1",
237
+ "mocha": "^10.2.0",
238
+ "uglify-js": "^3.3.16"
239
+ },
240
+ "engines": { "node": ">=0.10.0" },
241
+ "scripts": { "test": "npx jake test" }
242
+ };
243
+ }) });
244
+
245
+ //#endregion
246
+ //#region ../../node_modules/.pnpm/ejs@3.1.10/node_modules/ejs/lib/ejs.js
247
+ var require_ejs = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/ejs@3.1.10/node_modules/ejs/lib/ejs.js": ((exports) => {
248
+ /**
249
+ * @file Embedded JavaScript templating engine. {@link http://ejs.co}
250
+ * @author Matthew Eernisse <mde@fleegix.org>
251
+ * @author Tiancheng "Timothy" Gu <timothygu99@gmail.com>
252
+ * @project EJS
253
+ * @license {@link http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0}
254
+ */
255
+ /**
256
+ * EJS internal functions.
257
+ *
258
+ * Technically this "module" lies in the same file as {@link module:ejs}, for
259
+ * the sake of organization all the private functions re grouped into this
260
+ * module.
261
+ *
262
+ * @module ejs-internal
263
+ * @private
264
+ */
265
+ /**
266
+ * Embedded JavaScript templating engine.
267
+ *
268
+ * @module ejs
269
+ * @public
270
+ */
271
+ var fs$1 = __require("fs");
272
+ var path$1 = __require("path");
273
+ var utils = require_utils();
274
+ var scopeOptionWarned = false;
275
+ /** @type {string} */
276
+ var _VERSION_STRING = require_package().version;
277
+ var _DEFAULT_OPEN_DELIMITER = "<";
278
+ var _DEFAULT_CLOSE_DELIMITER = ">";
279
+ var _DEFAULT_DELIMITER = "%";
280
+ var _DEFAULT_LOCALS_NAME = "locals";
281
+ var _NAME = "ejs";
282
+ var _REGEX_STRING = "(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)";
283
+ var _OPTS_PASSABLE_WITH_DATA = [
284
+ "delimiter",
285
+ "scope",
286
+ "context",
287
+ "debug",
288
+ "compileDebug",
289
+ "client",
290
+ "_with",
291
+ "rmWhitespace",
292
+ "strict",
293
+ "filename",
294
+ "async"
295
+ ];
296
+ var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat("cache");
297
+ var _BOM = /^\uFEFF/;
298
+ var _JS_IDENTIFIER = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
299
+ /**
300
+ * EJS template function cache. This can be a LRU object from lru-cache NPM
301
+ * module. By default, it is {@link module:utils.cache}, a simple in-process
302
+ * cache that grows continuously.
303
+ *
304
+ * @type {Cache}
305
+ */
306
+ exports.cache = utils.cache;
307
+ /**
308
+ * Custom file loader. Useful for template preprocessing or restricting access
309
+ * to a certain part of the filesystem.
310
+ *
311
+ * @type {fileLoader}
312
+ */
313
+ exports.fileLoader = fs$1.readFileSync;
314
+ /**
315
+ * Name of the object containing the locals.
316
+ *
317
+ * This variable is overridden by {@link Options}`.localsName` if it is not
318
+ * `undefined`.
319
+ *
320
+ * @type {String}
321
+ * @public
322
+ */
323
+ exports.localsName = _DEFAULT_LOCALS_NAME;
324
+ /**
325
+ * Promise implementation -- defaults to the native implementation if available
326
+ * This is mostly just for testability
327
+ *
328
+ * @type {PromiseConstructorLike}
329
+ * @public
330
+ */
331
+ exports.promiseImpl = new Function("return this;")().Promise;
332
+ /**
333
+ * Get the path to the included file from the parent file path and the
334
+ * specified path.
335
+ *
336
+ * @param {String} name specified path
337
+ * @param {String} filename parent file path
338
+ * @param {Boolean} [isDir=false] whether the parent file path is a directory
339
+ * @return {String}
340
+ */
341
+ exports.resolveInclude = function(name, filename, isDir) {
342
+ var dirname = path$1.dirname;
343
+ var extname = path$1.extname;
344
+ var resolve = path$1.resolve;
345
+ var includePath = resolve(isDir ? filename : dirname(filename), name);
346
+ if (!extname(name)) includePath += ".ejs";
347
+ return includePath;
348
+ };
349
+ /**
350
+ * Try to resolve file path on multiple directories
351
+ *
352
+ * @param {String} name specified path
353
+ * @param {Array<String>} paths list of possible parent directory paths
354
+ * @return {String}
355
+ */
356
+ function resolvePaths(name, paths) {
357
+ var filePath;
358
+ if (paths.some(function(v) {
359
+ filePath = exports.resolveInclude(name, v, true);
360
+ return fs$1.existsSync(filePath);
361
+ })) return filePath;
362
+ }
363
+ /**
364
+ * Get the path to the included file by Options
365
+ *
366
+ * @param {String} path specified path
367
+ * @param {Options} options compilation options
368
+ * @return {String}
369
+ */
370
+ function getIncludePath(path$2, options) {
371
+ var includePath;
372
+ var filePath;
373
+ var views = options.views;
374
+ var match = /^[A-Za-z]+:\\|^\//.exec(path$2);
375
+ if (match && match.length) {
376
+ path$2 = path$2.replace(/^\/*/, "");
377
+ if (Array.isArray(options.root)) includePath = resolvePaths(path$2, options.root);
378
+ else includePath = exports.resolveInclude(path$2, options.root || "/", true);
379
+ } else {
380
+ if (options.filename) {
381
+ filePath = exports.resolveInclude(path$2, options.filename);
382
+ if (fs$1.existsSync(filePath)) includePath = filePath;
383
+ }
384
+ if (!includePath && Array.isArray(views)) includePath = resolvePaths(path$2, views);
385
+ if (!includePath && typeof options.includer !== "function") throw new Error("Could not find the include file \"" + options.escapeFunction(path$2) + "\"");
386
+ }
387
+ return includePath;
388
+ }
389
+ /**
390
+ * Get the template from a string or a file, either compiled on-the-fly or
391
+ * read from cache (if enabled), and cache the template if needed.
392
+ *
393
+ * If `template` is not set, the file specified in `options.filename` will be
394
+ * read.
395
+ *
396
+ * If `options.cache` is true, this function reads the file from
397
+ * `options.filename` so it must be set prior to calling this function.
398
+ *
399
+ * @memberof module:ejs-internal
400
+ * @param {Options} options compilation options
401
+ * @param {String} [template] template source
402
+ * @return {(TemplateFunction|ClientFunction)}
403
+ * Depending on the value of `options.client`, either type might be returned.
404
+ * @static
405
+ */
406
+ function handleCache(options, template) {
407
+ var func;
408
+ var filename = options.filename;
409
+ var hasTemplate = arguments.length > 1;
410
+ if (options.cache) {
411
+ if (!filename) throw new Error("cache option requires a filename");
412
+ func = exports.cache.get(filename);
413
+ if (func) return func;
414
+ if (!hasTemplate) template = fileLoader(filename).toString().replace(_BOM, "");
415
+ } else if (!hasTemplate) {
416
+ // istanbul ignore if: should not happen at all
417
+ if (!filename) throw new Error("Internal EJS error: no file name or template provided");
418
+ template = fileLoader(filename).toString().replace(_BOM, "");
419
+ }
420
+ func = exports.compile(template, options);
421
+ if (options.cache) exports.cache.set(filename, func);
422
+ return func;
423
+ }
424
+ /**
425
+ * Try calling handleCache with the given options and data and call the
426
+ * callback with the result. If an error occurs, call the callback with
427
+ * the error. Used by renderFile().
428
+ *
429
+ * @memberof module:ejs-internal
430
+ * @param {Options} options compilation options
431
+ * @param {Object} data template data
432
+ * @param {RenderFileCallback} cb callback
433
+ * @static
434
+ */
435
+ function tryHandleCache(options, data, cb) {
436
+ var result;
437
+ if (!cb) if (typeof exports.promiseImpl == "function") return new exports.promiseImpl(function(resolve, reject) {
438
+ try {
439
+ result = handleCache(options)(data);
440
+ resolve(result);
441
+ } catch (err) {
442
+ reject(err);
443
+ }
444
+ });
445
+ else throw new Error("Please provide a callback function");
446
+ else {
447
+ try {
448
+ result = handleCache(options)(data);
449
+ } catch (err) {
450
+ return cb(err);
451
+ }
452
+ cb(null, result);
453
+ }
454
+ }
455
+ /**
456
+ * fileLoader is independent
457
+ *
458
+ * @param {String} filePath ejs file path.
459
+ * @return {String} The contents of the specified file.
460
+ * @static
461
+ */
462
+ function fileLoader(filePath) {
463
+ return exports.fileLoader(filePath);
464
+ }
465
+ /**
466
+ * Get the template function.
467
+ *
468
+ * If `options.cache` is `true`, then the template is cached.
469
+ *
470
+ * @memberof module:ejs-internal
471
+ * @param {String} path path for the specified file
472
+ * @param {Options} options compilation options
473
+ * @return {(TemplateFunction|ClientFunction)}
474
+ * Depending on the value of `options.client`, either type might be returned
475
+ * @static
476
+ */
477
+ function includeFile(path$2, options) {
478
+ var opts = utils.shallowCopy(utils.createNullProtoObjWherePossible(), options);
479
+ opts.filename = getIncludePath(path$2, opts);
480
+ if (typeof options.includer === "function") {
481
+ var includerResult = options.includer(path$2, opts.filename);
482
+ if (includerResult) {
483
+ if (includerResult.filename) opts.filename = includerResult.filename;
484
+ if (includerResult.template) return handleCache(opts, includerResult.template);
485
+ }
486
+ }
487
+ return handleCache(opts);
488
+ }
489
+ /**
490
+ * Re-throw the given `err` in context to the `str` of ejs, `filename`, and
491
+ * `lineno`.
492
+ *
493
+ * @implements {RethrowCallback}
494
+ * @memberof module:ejs-internal
495
+ * @param {Error} err Error object
496
+ * @param {String} str EJS source
497
+ * @param {String} flnm file name of the EJS file
498
+ * @param {Number} lineno line number of the error
499
+ * @param {EscapeCallback} esc
500
+ * @static
501
+ */
502
+ function rethrow(err, str, flnm, lineno, esc) {
503
+ var lines = str.split("\n");
504
+ var start = Math.max(lineno - 3, 0);
505
+ var end = Math.min(lines.length, lineno + 3);
506
+ var filename = esc(flnm);
507
+ var context = lines.slice(start, end).map(function(line, i) {
508
+ var curr = i + start + 1;
509
+ return (curr == lineno ? " >> " : " ") + curr + "| " + line;
510
+ }).join("\n");
511
+ err.path = filename;
512
+ err.message = (filename || "ejs") + ":" + lineno + "\n" + context + "\n\n" + err.message;
513
+ throw err;
514
+ }
515
+ function stripSemi(str) {
516
+ return str.replace(/;(\s*$)/, "$1");
517
+ }
518
+ /**
519
+ * Compile the given `str` of ejs into a template function.
520
+ *
521
+ * @param {String} template EJS template
522
+ *
523
+ * @param {Options} [opts] compilation options
524
+ *
525
+ * @return {(TemplateFunction|ClientFunction)}
526
+ * Depending on the value of `opts.client`, either type might be returned.
527
+ * Note that the return type of the function also depends on the value of `opts.async`.
528
+ * @public
529
+ */
530
+ exports.compile = function compile(template, opts) {
531
+ var templ;
532
+ if (opts && opts.scope) {
533
+ if (!scopeOptionWarned) {
534
+ console.warn("`scope` option is deprecated and will be removed in EJS 3");
535
+ scopeOptionWarned = true;
536
+ }
537
+ if (!opts.context) opts.context = opts.scope;
538
+ delete opts.scope;
539
+ }
540
+ templ = new Template(template, opts);
541
+ return templ.compile();
542
+ };
543
+ /**
544
+ * Render the given `template` of ejs.
545
+ *
546
+ * If you would like to include options but not data, you need to explicitly
547
+ * call this function with `data` being an empty object or `null`.
548
+ *
549
+ * @param {String} template EJS template
550
+ * @param {Object} [data={}] template data
551
+ * @param {Options} [opts={}] compilation and rendering options
552
+ * @return {(String|Promise<String>)}
553
+ * Return value type depends on `opts.async`.
554
+ * @public
555
+ */
556
+ exports.render = function(template, d, o) {
557
+ var data = d || utils.createNullProtoObjWherePossible();
558
+ var opts = o || utils.createNullProtoObjWherePossible();
559
+ if (arguments.length == 2) utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
560
+ return handleCache(opts, template)(data);
561
+ };
562
+ /**
563
+ * Render an EJS file at the given `path` and callback `cb(err, str)`.
564
+ *
565
+ * If you would like to include options but not data, you need to explicitly
566
+ * call this function with `data` being an empty object or `null`.
567
+ *
568
+ * @param {String} path path to the EJS file
569
+ * @param {Object} [data={}] template data
570
+ * @param {Options} [opts={}] compilation and rendering options
571
+ * @param {RenderFileCallback} cb callback
572
+ * @public
573
+ */
574
+ exports.renderFile = function() {
575
+ var args = Array.prototype.slice.call(arguments);
576
+ var filename = args.shift();
577
+ var cb;
578
+ var opts = { filename };
579
+ var data;
580
+ var viewOpts;
581
+ if (typeof arguments[arguments.length - 1] == "function") cb = args.pop();
582
+ if (args.length) {
583
+ data = args.shift();
584
+ if (args.length) utils.shallowCopy(opts, args.pop());
585
+ else {
586
+ if (data.settings) {
587
+ if (data.settings.views) opts.views = data.settings.views;
588
+ if (data.settings["view cache"]) opts.cache = true;
589
+ viewOpts = data.settings["view options"];
590
+ if (viewOpts) utils.shallowCopy(opts, viewOpts);
591
+ }
592
+ utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
593
+ }
594
+ opts.filename = filename;
595
+ } else data = utils.createNullProtoObjWherePossible();
596
+ return tryHandleCache(opts, data, cb);
597
+ };
598
+ /**
599
+ * Clear intermediate JavaScript cache. Calls {@link Cache#reset}.
600
+ * @public
601
+ */
602
+ /**
603
+ * EJS template class
604
+ * @public
605
+ */
606
+ exports.Template = Template;
607
+ exports.clearCache = function() {
608
+ exports.cache.reset();
609
+ };
610
+ function Template(text$1, optsParam) {
611
+ var opts = utils.hasOwnOnlyObject(optsParam);
612
+ var options = utils.createNullProtoObjWherePossible();
613
+ this.templateText = text$1;
614
+ /** @type {string | null} */
615
+ this.mode = null;
616
+ this.truncate = false;
617
+ this.currentLine = 1;
618
+ this.source = "";
619
+ options.client = opts.client || false;
620
+ options.escapeFunction = opts.escape || opts.escapeFunction || utils.escapeXML;
621
+ options.compileDebug = opts.compileDebug !== false;
622
+ options.debug = !!opts.debug;
623
+ options.filename = opts.filename;
624
+ options.openDelimiter = opts.openDelimiter || exports.openDelimiter || _DEFAULT_OPEN_DELIMITER;
625
+ options.closeDelimiter = opts.closeDelimiter || exports.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
626
+ options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
627
+ options.strict = opts.strict || false;
628
+ options.context = opts.context;
629
+ options.cache = opts.cache || false;
630
+ options.rmWhitespace = opts.rmWhitespace;
631
+ options.root = opts.root;
632
+ options.includer = opts.includer;
633
+ options.outputFunctionName = opts.outputFunctionName;
634
+ options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
635
+ options.views = opts.views;
636
+ options.async = opts.async;
637
+ options.destructuredLocals = opts.destructuredLocals;
638
+ options.legacyInclude = typeof opts.legacyInclude != "undefined" ? !!opts.legacyInclude : true;
639
+ if (options.strict) options._with = false;
640
+ else options._with = typeof opts._with != "undefined" ? opts._with : true;
641
+ this.opts = options;
642
+ this.regex = this.createRegex();
643
+ }
644
+ Template.modes = {
645
+ EVAL: "eval",
646
+ ESCAPED: "escaped",
647
+ RAW: "raw",
648
+ COMMENT: "comment",
649
+ LITERAL: "literal"
650
+ };
651
+ Template.prototype = {
652
+ createRegex: function() {
653
+ var str = _REGEX_STRING;
654
+ var delim = utils.escapeRegExpChars(this.opts.delimiter);
655
+ var open = utils.escapeRegExpChars(this.opts.openDelimiter);
656
+ var close = utils.escapeRegExpChars(this.opts.closeDelimiter);
657
+ str = str.replace(/%/g, delim).replace(/</g, open).replace(/>/g, close);
658
+ return new RegExp(str);
659
+ },
660
+ compile: function() {
661
+ /** @type {string} */
662
+ var src;
663
+ /** @type {ClientFunction} */
664
+ var fn;
665
+ var opts = this.opts;
666
+ var prepended = "";
667
+ var appended = "";
668
+ /** @type {EscapeCallback} */
669
+ var escapeFn = opts.escapeFunction;
670
+ /** @type {FunctionConstructor} */
671
+ var ctor;
672
+ /** @type {string} */
673
+ var sanitizedFilename = opts.filename ? JSON.stringify(opts.filename) : "undefined";
674
+ if (!this.source) {
675
+ this.generateSource();
676
+ prepended += " var __output = \"\";\n function __append(s) { if (s !== undefined && s !== null) __output += s }\n";
677
+ if (opts.outputFunctionName) {
678
+ if (!_JS_IDENTIFIER.test(opts.outputFunctionName)) throw new Error("outputFunctionName is not a valid JS identifier.");
679
+ prepended += " var " + opts.outputFunctionName + " = __append;\n";
680
+ }
681
+ if (opts.localsName && !_JS_IDENTIFIER.test(opts.localsName)) throw new Error("localsName is not a valid JS identifier.");
682
+ if (opts.destructuredLocals && opts.destructuredLocals.length) {
683
+ var destructuring = " var __locals = (" + opts.localsName + " || {}),\n";
684
+ for (var i = 0; i < opts.destructuredLocals.length; i++) {
685
+ var name = opts.destructuredLocals[i];
686
+ if (!_JS_IDENTIFIER.test(name)) throw new Error("destructuredLocals[" + i + "] is not a valid JS identifier.");
687
+ if (i > 0) destructuring += ",\n ";
688
+ destructuring += name + " = __locals." + name;
689
+ }
690
+ prepended += destructuring + ";\n";
691
+ }
692
+ if (opts._with !== false) {
693
+ prepended += " with (" + opts.localsName + " || {}) {\n";
694
+ appended += " }\n";
695
+ }
696
+ appended += " return __output;\n";
697
+ this.source = prepended + this.source + appended;
698
+ }
699
+ if (opts.compileDebug) 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";
700
+ else src = this.source;
701
+ if (opts.client) {
702
+ src = "escapeFn = escapeFn || " + escapeFn.toString() + ";\n" + src;
703
+ if (opts.compileDebug) src = "rethrow = rethrow || " + rethrow.toString() + ";\n" + src;
704
+ }
705
+ if (opts.strict) src = "\"use strict\";\n" + src;
706
+ if (opts.debug) console.log(src);
707
+ if (opts.compileDebug && opts.filename) src = src + "\n//# sourceURL=" + sanitizedFilename + "\n";
708
+ try {
709
+ if (opts.async) try {
710
+ ctor = new Function("return (async function(){}).constructor;")();
711
+ } catch (e) {
712
+ if (e instanceof SyntaxError) throw new Error("This environment does not support async/await");
713
+ else throw e;
714
+ }
715
+ else ctor = Function;
716
+ fn = new ctor(opts.localsName + ", escapeFn, include, rethrow", src);
717
+ } catch (e) {
718
+ // istanbul ignore else
719
+ if (e instanceof SyntaxError) {
720
+ if (opts.filename) e.message += " in " + opts.filename;
721
+ e.message += " while compiling ejs\n\n";
722
+ e.message += "If the above error is not helpful, you may want to try EJS-Lint:\n";
723
+ e.message += "https://github.com/RyanZim/EJS-Lint";
724
+ if (!opts.async) {
725
+ e.message += "\n";
726
+ e.message += "Or, if you meant to create an async function, pass `async: true` as an option.";
727
+ }
728
+ }
729
+ throw e;
730
+ }
731
+ var returnedFn = opts.client ? fn : function anonymous(data) {
732
+ var include = function(path$2, includeData) {
733
+ var d = utils.shallowCopy(utils.createNullProtoObjWherePossible(), data);
734
+ if (includeData) d = utils.shallowCopy(d, includeData);
735
+ return includeFile(path$2, opts)(d);
736
+ };
737
+ return fn.apply(opts.context, [
738
+ data || utils.createNullProtoObjWherePossible(),
739
+ escapeFn,
740
+ include,
741
+ rethrow
742
+ ]);
743
+ };
744
+ if (opts.filename && typeof Object.defineProperty === "function") {
745
+ var filename = opts.filename;
746
+ var basename = path$1.basename(filename, path$1.extname(filename));
747
+ try {
748
+ Object.defineProperty(returnedFn, "name", {
749
+ value: basename,
750
+ writable: false,
751
+ enumerable: false,
752
+ configurable: true
753
+ });
754
+ } catch (e) {}
755
+ }
756
+ return returnedFn;
757
+ },
758
+ generateSource: function() {
759
+ if (this.opts.rmWhitespace) this.templateText = this.templateText.replace(/[\r\n]+/g, "\n").replace(/^\s+|\s+$/gm, "");
760
+ this.templateText = this.templateText.replace(/[ \t]*<%_/gm, "<%_").replace(/_%>[ \t]*/gm, "_%>");
761
+ var self = this;
762
+ var matches = this.parseTemplateText();
763
+ var d = this.opts.delimiter;
764
+ var o = this.opts.openDelimiter;
765
+ var c = this.opts.closeDelimiter;
766
+ if (matches && matches.length) matches.forEach(function(line, index) {
767
+ var closing;
768
+ if (line.indexOf(o + d) === 0 && line.indexOf(o + d + d) !== 0) {
769
+ closing = matches[index + 2];
770
+ if (!(closing == d + c || closing == "-" + d + c || closing == "_" + d + c)) throw new Error("Could not find matching close tag for \"" + line + "\".");
771
+ }
772
+ self.scanLine(line);
773
+ });
774
+ },
775
+ parseTemplateText: function() {
776
+ var str = this.templateText;
777
+ var pat = this.regex;
778
+ var result = pat.exec(str);
779
+ var arr = [];
780
+ var firstPos;
781
+ while (result) {
782
+ firstPos = result.index;
783
+ if (firstPos !== 0) {
784
+ arr.push(str.substring(0, firstPos));
785
+ str = str.slice(firstPos);
786
+ }
787
+ arr.push(result[0]);
788
+ str = str.slice(result[0].length);
789
+ result = pat.exec(str);
790
+ }
791
+ if (str) arr.push(str);
792
+ return arr;
793
+ },
794
+ _addOutput: function(line) {
795
+ if (this.truncate) {
796
+ line = line.replace(/^(?:\r\n|\r|\n)/, "");
797
+ this.truncate = false;
798
+ }
799
+ if (!line) return line;
800
+ line = line.replace(/\\/g, "\\\\");
801
+ line = line.replace(/\n/g, "\\n");
802
+ line = line.replace(/\r/g, "\\r");
803
+ line = line.replace(/"/g, "\\\"");
804
+ this.source += " ; __append(\"" + line + "\")\n";
805
+ },
806
+ scanLine: function(line) {
807
+ var self = this;
808
+ var d = this.opts.delimiter;
809
+ var o = this.opts.openDelimiter;
810
+ var c = this.opts.closeDelimiter;
811
+ var newLineCount = 0;
812
+ newLineCount = line.split("\n").length - 1;
813
+ switch (line) {
814
+ case o + d:
815
+ case o + d + "_":
816
+ this.mode = Template.modes.EVAL;
817
+ break;
818
+ case o + d + "=":
819
+ this.mode = Template.modes.ESCAPED;
820
+ break;
821
+ case o + d + "-":
822
+ this.mode = Template.modes.RAW;
823
+ break;
824
+ case o + d + "#":
825
+ this.mode = Template.modes.COMMENT;
826
+ break;
827
+ case o + d + d:
828
+ this.mode = Template.modes.LITERAL;
829
+ this.source += " ; __append(\"" + line.replace(o + d + d, o + d) + "\")\n";
830
+ break;
831
+ case d + d + c:
832
+ this.mode = Template.modes.LITERAL;
833
+ this.source += " ; __append(\"" + line.replace(d + d + c, d + c) + "\")\n";
834
+ break;
835
+ case d + c:
836
+ case "-" + d + c:
837
+ case "_" + d + c:
838
+ if (this.mode == Template.modes.LITERAL) this._addOutput(line);
839
+ this.mode = null;
840
+ this.truncate = line.indexOf("-") === 0 || line.indexOf("_") === 0;
841
+ break;
842
+ default: if (this.mode) {
843
+ switch (this.mode) {
844
+ case Template.modes.EVAL:
845
+ case Template.modes.ESCAPED:
846
+ case Template.modes.RAW: if (line.lastIndexOf("//") > line.lastIndexOf("\n")) line += "\n";
847
+ }
848
+ switch (this.mode) {
849
+ case Template.modes.EVAL:
850
+ this.source += " ; " + line + "\n";
851
+ break;
852
+ case Template.modes.ESCAPED:
853
+ this.source += " ; __append(escapeFn(" + stripSemi(line) + "))\n";
854
+ break;
855
+ case Template.modes.RAW:
856
+ this.source += " ; __append(" + stripSemi(line) + ")\n";
857
+ break;
858
+ case Template.modes.COMMENT: break;
859
+ case Template.modes.LITERAL:
860
+ this._addOutput(line);
861
+ break;
862
+ }
863
+ } else this._addOutput(line);
864
+ }
865
+ if (self.opts.compileDebug && newLineCount) {
866
+ this.currentLine += newLineCount;
867
+ this.source += " ; __line = " + this.currentLine + "\n";
868
+ }
869
+ }
870
+ };
871
+ /**
872
+ * Escape characters reserved in XML.
873
+ *
874
+ * This is simply an export of {@link module:utils.escapeXML}.
875
+ *
876
+ * If `markup` is `undefined` or `null`, the empty string is returned.
877
+ *
878
+ * @param {String} markup Input string
879
+ * @return {String} Escaped string
880
+ * @public
881
+ * @func
882
+ * */
883
+ exports.escapeXML = utils.escapeXML;
884
+ /**
885
+ * Express.js support.
886
+ *
887
+ * This is an alias for {@link module:ejs.renderFile}, in order to support
888
+ * Express.js out-of-the-box.
889
+ *
890
+ * @func
891
+ */
892
+ exports.__express = exports.renderFile;
893
+ /**
894
+ * Version of EJS.
895
+ *
896
+ * @readonly
897
+ * @type {String}
898
+ * @public
899
+ */
900
+ exports.VERSION = _VERSION_STRING;
901
+ /**
902
+ * Name for detection of EJS.
903
+ *
904
+ * @readonly
905
+ * @type {String}
906
+ * @public
907
+ */
908
+ exports.name = _NAME;
909
+ /* istanbul ignore if */
910
+ if (typeof window != "undefined") window.ejs = exports;
911
+ }) });
912
+
913
+ //#endregion
914
+ //#region src/constants.ts
915
+ var import_ejs = /* @__PURE__ */ __toESM(require_ejs(), 1);
916
+ const DEFAULT_BANNER = "Template-Kits - 快速生成你的模板代码";
917
+ const FEATURE_OPTIONS = [
918
+ {
919
+ value: "unplugin-vue-router",
920
+ label: "Unplugin Vue Router(约定式路由)"
921
+ },
922
+ {
923
+ value: "simple-git-hooks",
924
+ label: "Simple Git Hooks(Git Commit 检查)"
925
+ },
926
+ {
927
+ value: "vitest",
928
+ label: "Vitest(单元测试)"
929
+ }
930
+ ];
931
+
932
+ //#endregion
933
+ //#region src/index.ts
934
+ async function promptUser() {
935
+ const { positionals } = parseArgs({
936
+ strict: true,
937
+ allowPositionals: true
938
+ });
939
+ let targetDir = positionals[0];
940
+ const defaultProjectName = targetDir || "Template-Kits";
941
+ const result = {
942
+ projectName: defaultProjectName,
943
+ packageName: defaultProjectName,
944
+ shouldOverwrite: false,
945
+ features: []
946
+ };
947
+ if (!targetDir) targetDir = result.projectName = result.packageName = (await unwrapPrompt(text({
948
+ message: "请输入项目名称:",
949
+ placeholder: defaultProjectName,
950
+ defaultValue: "",
951
+ validate: (value) => value.trim().length === 0 ? "不能为空" : ""
952
+ }))).trim();
953
+ if (!canSkipEmptying(targetDir)) {
954
+ result.shouldOverwrite = await unwrapPrompt(confirm({
955
+ message: `${targetDir === "." ? "当前目录" : `目标文件夹 "${targetDir}"`} 非空,是否覆盖?`,
956
+ initialValue: false
957
+ }));
958
+ if (!result.shouldOverwrite) {
959
+ cancel(`${pico.red("✖")} 操作取消`);
960
+ process.exit(0);
961
+ }
962
+ }
963
+ result.features = await unwrapPrompt(multiselect({
964
+ message: `请选择要包含的功能: ${pico.dim("(↑/↓ 切换,空格选择,a 全选,回车确认)")}`,
965
+ options: FEATURE_OPTIONS,
966
+ required: false
967
+ }));
968
+ return {
969
+ result,
970
+ targetDir
971
+ };
972
+ }
973
+ function setupProjectDir(cwd, result, targetDir) {
974
+ const root = path.join(cwd, targetDir);
975
+ if (fs.existsSync(root) && result.shouldOverwrite) emptyDir(root);
976
+ else if (!fs.existsSync(root)) fs.mkdirSync(root);
977
+ console.log(`\n正在初始化项目 ${root}...`);
978
+ const pkg = {
979
+ name: result.packageName,
980
+ version: "0.0.0"
981
+ };
982
+ renderFile(root, "tsconfig.json", JSON.stringify(pkg, null, 2));
983
+ return root;
984
+ }
985
+ function renderTemplates(root, result) {
986
+ const { features = [] } = result;
987
+ const needsAutoRouter = features.includes("unplugin-vue-router");
988
+ const needsGitHooks = features.includes("simple-git-hooks");
989
+ const needsVitest = features.includes("vitest");
990
+ const templateRoot = fileURLToPath(new URL("../template", import.meta.url));
991
+ const callbacks = [];
992
+ const render = (templateName) => {
993
+ const templateDir = path.resolve(templateRoot, templateName);
994
+ renderTemplate(templateDir, root, callbacks);
995
+ };
996
+ render("base");
997
+ render("eslint");
998
+ render("tsconfig");
999
+ render(needsAutoRouter ? "router/unplugin" : "router/default");
1000
+ if (needsGitHooks) render("git-hooks");
1001
+ const rootTsConfig = {
1002
+ files: [],
1003
+ references: [{ path: "./tsconfig.node.json" }, { path: "./tsconfig.app.json" }]
1004
+ };
1005
+ if (needsVitest) {
1006
+ render("vitest");
1007
+ rootTsConfig.references.push({ path: "./tsconfig.vitest.json" });
1008
+ }
1009
+ renderFile(root, "tsconfig.json", `${JSON.stringify(rootTsConfig, null, 2)}\n`);
1010
+ renderFile(root, ".env", `VITE_APP_TITLE = ${result.packageName}\n`);
1011
+ preOrderDirectoryTraverse(root, () => {}, (filepath) => {
1012
+ if (filepath.endsWith(".ejs")) {
1013
+ const template = fs.readFileSync(filepath, "utf-8");
1014
+ const dest = filepath.replace(/\.ejs$/, "");
1015
+ const content = import_ejs.render(template, {
1016
+ needsAutoRouter,
1017
+ needsGitHooks
1018
+ });
1019
+ fs.writeFileSync(dest, content);
1020
+ fs.unlinkSync(filepath);
1021
+ }
1022
+ });
1023
+ }
1024
+ (async function() {
1025
+ const cwd = process.cwd();
1026
+ intro(pico.magenta(DEFAULT_BANNER));
1027
+ const { result, targetDir } = await promptUser();
1028
+ const root = setupProjectDir(cwd, result, targetDir);
1029
+ renderTemplates(root, result);
1030
+ outro(getOutroMessage(root, cwd));
1031
+ })();
1032
+
1033
+ //#endregion
1034
+ export { };