@aventusjs/cli 0.0.13 → 0.0.15

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 (76) hide show
  1. package/lib/Aventus@I18n.package.avt +72 -0
  2. package/lib/Aventus@Main.package.avt +2318 -1926
  3. package/lib/Aventus@Php.package.avt +455 -0
  4. package/lib/Aventus@Sharp.package.avt +805 -644
  5. package/lib/Aventus@UI.package.avt +2587 -296
  6. package/lib/Avonis.package.avt +58 -0
  7. package/lib/aventusjs-rules.md +750 -0
  8. package/lib/emmet/aventus.json +7 -0
  9. package/lib/templateScript/AventusTemplate.d.ts +127 -0
  10. package/lib/templateScript/AventusTemplate.ts +461 -0
  11. package/out/RealInteraction.js +4 -1
  12. package/out/RealServer.js +497 -341
  13. package/out/cli.js +1 -1
  14. package/package.json +4 -3
  15. package/tsconfig.tsbuildinfo +1 -0
  16. package/lib/bin/CSharpToTypescript/AventusSharp.dll +0 -0
  17. package/lib/bin/CSharpToTypescript/AventusSharp.pdb +0 -0
  18. package/lib/bin/CSharpToTypescript/AventusSharp.xml +0 -2151
  19. package/lib/bin/CSharpToTypescript/BouncyCastle.Cryptography.dll +0 -0
  20. package/lib/bin/CSharpToTypescript/CSharpToTypescript.deps.json +0 -885
  21. package/lib/bin/CSharpToTypescript/CSharpToTypescript.dll +0 -0
  22. package/lib/bin/CSharpToTypescript/CSharpToTypescript.dll.config +0 -707
  23. package/lib/bin/CSharpToTypescript/CSharpToTypescript.exe +0 -0
  24. package/lib/bin/CSharpToTypescript/CSharpToTypescript.pdb +0 -0
  25. package/lib/bin/CSharpToTypescript/CSharpToTypescript.runtimeconfig.json +0 -19
  26. package/lib/bin/CSharpToTypescript/Google.Protobuf.dll +0 -0
  27. package/lib/bin/CSharpToTypescript/HttpMultipartParser.dll +0 -0
  28. package/lib/bin/CSharpToTypescript/Humanizer.dll +0 -0
  29. package/lib/bin/CSharpToTypescript/K4os.Compression.LZ4.Streams.dll +0 -0
  30. package/lib/bin/CSharpToTypescript/K4os.Compression.LZ4.dll +0 -0
  31. package/lib/bin/CSharpToTypescript/K4os.Hash.xxHash.dll +0 -0
  32. package/lib/bin/CSharpToTypescript/Microsoft.Bcl.AsyncInterfaces.dll +0 -0
  33. package/lib/bin/CSharpToTypescript/Microsoft.Build.Locator.dll +0 -0
  34. package/lib/bin/CSharpToTypescript/Microsoft.CodeAnalysis.CSharp.Workspaces.dll +0 -0
  35. package/lib/bin/CSharpToTypescript/Microsoft.CodeAnalysis.CSharp.dll +0 -0
  36. package/lib/bin/CSharpToTypescript/Microsoft.CodeAnalysis.Workspaces.MSBuild.dll +0 -0
  37. package/lib/bin/CSharpToTypescript/Microsoft.CodeAnalysis.Workspaces.dll +0 -0
  38. package/lib/bin/CSharpToTypescript/Microsoft.CodeAnalysis.dll +0 -0
  39. package/lib/bin/CSharpToTypescript/Microsoft.IO.RecyclableMemoryStream.dll +0 -0
  40. package/lib/bin/CSharpToTypescript/Microsoft.Win32.SystemEvents.dll +0 -0
  41. package/lib/bin/CSharpToTypescript/MySql.Data.dll +0 -0
  42. package/lib/bin/CSharpToTypescript/Newtonsoft.Json.dll +0 -0
  43. package/lib/bin/CSharpToTypescript/Scriban.dll +0 -0
  44. package/lib/bin/CSharpToTypescript/System.Collections.Immutable.dll +0 -0
  45. package/lib/bin/CSharpToTypescript/System.Composition.AttributedModel.dll +0 -0
  46. package/lib/bin/CSharpToTypescript/System.Composition.Convention.dll +0 -0
  47. package/lib/bin/CSharpToTypescript/System.Composition.Hosting.dll +0 -0
  48. package/lib/bin/CSharpToTypescript/System.Composition.Runtime.dll +0 -0
  49. package/lib/bin/CSharpToTypescript/System.Composition.TypedParts.dll +0 -0
  50. package/lib/bin/CSharpToTypescript/System.Configuration.ConfigurationManager.dll +0 -0
  51. package/lib/bin/CSharpToTypescript/System.Drawing.Common.dll +0 -0
  52. package/lib/bin/CSharpToTypescript/System.IO.Pipelines.dll +0 -0
  53. package/lib/bin/CSharpToTypescript/System.Reflection.Metadata.dll +0 -0
  54. package/lib/bin/CSharpToTypescript/System.Security.Cryptography.ProtectedData.dll +0 -0
  55. package/lib/bin/CSharpToTypescript/System.Security.Permissions.dll +0 -0
  56. package/lib/bin/CSharpToTypescript/System.Text.Encoding.CodePages.dll +0 -0
  57. package/lib/bin/CSharpToTypescript/System.Text.Encodings.Web.dll +0 -0
  58. package/lib/bin/CSharpToTypescript/System.Text.Json.dll +0 -0
  59. package/lib/bin/CSharpToTypescript/System.Threading.Channels.dll +0 -0
  60. package/lib/bin/CSharpToTypescript/System.Windows.Extensions.dll +0 -0
  61. package/lib/bin/CSharpToTypescript/ZstdSharp.dll +0 -0
  62. package/lib/bin/CSharpToTypescript/package.json +0 -6
  63. package/lib/bin/CSharpToTypescript/runtimes/browser/lib/net6.0/System.Text.Encodings.Web.dll +0 -0
  64. package/lib/bin/CSharpToTypescript/runtimes/win/lib/net6.0/Microsoft.Win32.SystemEvents.dll +0 -0
  65. package/lib/bin/CSharpToTypescript/runtimes/win/lib/net6.0/System.Drawing.Common.dll +0 -0
  66. package/lib/bin/CSharpToTypescript/runtimes/win/lib/net6.0/System.Security.Cryptography.ProtectedData.dll +0 -0
  67. package/lib/bin/CSharpToTypescript/runtimes/win/lib/net6.0/System.Text.Encoding.CodePages.dll +0 -0
  68. package/lib/bin/CSharpToTypescript/runtimes/win/lib/net6.0/System.Windows.Extensions.dll +0 -0
  69. package/lib/bin/CSharpToTypescript/runtimes/win/lib/net7.0/System.Security.Cryptography.ProtectedData.dll +0 -0
  70. package/lib/bin/CSharpToTypescript/runtimes/win/lib/net7.0/System.Windows.Extensions.dll +0 -0
  71. package/lib/bin/CSharpToTypescript/runtimes/win/lib/net8.0/Microsoft.Win32.SystemEvents.dll +0 -0
  72. package/lib/bin/CSharpToTypescript/runtimes/win-x64/native/comerr64.dll +0 -0
  73. package/lib/bin/CSharpToTypescript/runtimes/win-x64/native/gssapi64.dll +0 -0
  74. package/lib/bin/CSharpToTypescript/runtimes/win-x64/native/k5sprt64.dll +0 -0
  75. package/lib/bin/CSharpToTypescript/runtimes/win-x64/native/krb5_64.dll +0 -0
  76. package/lib/bin/CSharpToTypescript/runtimes/win-x64/native/krbcc64.dll +0 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "html": {
3
+ "snippets": {
4
+ "block": "<block name=\"${1}\">${2}<block>"
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,127 @@
1
+ declare type Version = `${number}.${number}.${number}`;
2
+ declare interface InputOptions {
3
+ title?: string;
4
+ value?: string;
5
+ placeHolder?: string,
6
+ validations?: {
7
+ regex: string;
8
+ message: string;
9
+ }[];
10
+ }
11
+ declare interface SelectOptions {
12
+ placeHolder?: string;
13
+ title?: string;
14
+ }
15
+ declare interface SelectItem {
16
+ label: string;
17
+ detail?: string;
18
+ picked?: boolean;
19
+ }
20
+ declare type WriteInfo = {
21
+ templatePath: string;
22
+ writePath: string;
23
+ relativePath: string;
24
+ rawContent: string;
25
+ content: string;
26
+ isDir: boolean;
27
+ };
28
+ declare type TemplateInfo = {
29
+ /** Determine the name of your template. Each dot will be a group */
30
+ name: string,
31
+ /** Short description to help user */
32
+ description?: string,
33
+ /** Version of your template */
34
+ version?: Version,
35
+ /** Determine if the template can be use without right click */
36
+ allowQuick?: boolean,
37
+ /** Organization from which your template will be published on the store */
38
+ organization?: string,
39
+ /** List of tags to find your template on the store */
40
+ tags?: string[],
41
+ /** Determine if the template is a project or a template */
42
+ isProject?: boolean,
43
+ /** Determine if the template is global */
44
+ isGlobal?: boolean,
45
+ /** Determine where to install the template */
46
+ installationFolder?: string,
47
+ /** Documentation link for the package */
48
+ documentation?: string,
49
+ /** Repository link for the package */
50
+ repository?: string,
51
+ }
52
+
53
+ declare type WriteCallback = (info: WriteInfo) => void | boolean;
54
+ declare type ReservedVariables = "module" | "namespace";
55
+ declare type BlockInfo = {
56
+ before: () => string;
57
+ after: () => string;
58
+ custom: (txt: string) => string;
59
+ };
60
+ declare abstract class AventusTemplate {
61
+ protected abstract meta(): TemplateInfo;
62
+ private basicInfo;
63
+ protected variables: {
64
+ [key: string]: string | null | undefined;
65
+ };
66
+ protected blocks: {
67
+ [key: string]: BlockInfo;
68
+ };
69
+ protected ifs: { [key: string]: boolean };
70
+ protected destination: string;
71
+ protected workspacePath: string;
72
+ protected templatePath: string;
73
+ private _isAllowed;
74
+ protected isAllowed(): boolean;
75
+ private _run;
76
+ private defaultBlocks(): void;
77
+ protected abstract run(destination: string): Promise<void>;
78
+ /** Ask user with a input */
79
+ protected input(config: InputOptions): Promise<string | null>;
80
+ /** Ask user with a select */
81
+ protected select(items: SelectItem[], options: SelectOptions): Promise<SelectItem | null>;
82
+ /** Ask user with a select with mulitple choices */
83
+ protected selectMultiple(items: SelectItem[], options: SelectOptions): Promise<SelectItem[] | null>;
84
+ private waitingResponse: {
85
+ [cmd: string]: (response: string | null) => void;
86
+ };
87
+ private runCommandWithAnswer;
88
+ private runCommand;
89
+ /** Register a variable that you can use later as ${{var}} */
90
+ protected registerVar<T extends string>(name: T & (T extends ReservedVariables ? never : {}), value: string | null | undefined): void;
91
+ /** Register a block that you can use later as #{{block}} #{{block/}} */
92
+ protected registerBlock(name: string, block: Partial<BlockInfo>): void;
93
+ /** Register a if that you can use later as #if{{block}} #end{{block}} */
94
+ protected registerIf<T extends string>(name: T & (T extends ReservedVariables ? never : {}), value: boolean): void;
95
+ /** Prevent writing default files/folders */
96
+ protected defaultWriteDeny(info: WriteInfo, denyDir?: string[], denyFile?: string[]): boolean
97
+ /** Start writing process */
98
+ protected writeFile(cb?: WriteCallback): Promise<void>;
99
+ /** Replace ${{var}} inside the content */
100
+ protected replaceVariables(ctx: string): string;
101
+ /** Replace #{{block}} #{{block/}} inside the content */
102
+ protected replaceBlocks(ctx: string): string;
103
+ /** Replace #if{{block}} #end{{block}} inside the content */
104
+ protected replaceIfs(ctx: string): void;
105
+ /** Add \\t before each line */
106
+ protected addIndent(text: string): string;
107
+ /** Remove \\t before each line */
108
+ protected removeIndent(text: string): string;
109
+ /** Exec a command. For example: "npm i" */
110
+ protected exec(cmd: string, asAdmin?: boolean): Promise<void>;
111
+ /** Show an error message inside the IDE */
112
+ protected showErrorMessage(msg: string): void;
113
+ /** Show a warning message inside the IDE */
114
+ protected showWarningMessage(msg: string): void;
115
+ /** Show an information message inside the IDE */
116
+ protected showInformationMessage(msg: string): void;
117
+ /** Show a progress bar inside the IDE */
118
+ protected showProgress(txt: string): Promise<string>;
119
+ /** Hide the progress bar inside the IDE */
120
+ protected hideProgress(uuid: string): Promise<void>;
121
+ /** Helper to show then hide a progress bar */
122
+ protected runWithProgress(txt: string, cb: () => Promise<void>): Promise<void>;
123
+ /** Open file. You must define the relative path from the template.avt.ts */
124
+ protected openFile(name: string | string[]): void;
125
+ /** Helper to wait x ms */
126
+ protected sleep(ms: number): Promise<void>;
127
+ }
@@ -0,0 +1,461 @@
1
+ import { mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'fs'
2
+ import { join, normalize, sep } from 'path'
3
+
4
+ export type Version = `${number}.${number}.${number}`
5
+ export interface InputOptions {
6
+ title: string,
7
+ value?: string,
8
+ validations?: { regex: string, message: string }[]
9
+ }
10
+ export interface SelectOptions {
11
+ placeHolder?: string,
12
+ title?: string,
13
+ }
14
+
15
+ export interface SelectItem {
16
+ label: string,
17
+ detail?: string,
18
+ picked?: boolean,
19
+ }
20
+ export type WriteInfo = {
21
+ templatePath: string,
22
+ writePath: string,
23
+ relativePath: string,
24
+ rawContent: string,
25
+ content: string,
26
+ isDir: boolean
27
+ }
28
+ export type WriteCallback = (info: WriteInfo) => void | boolean;
29
+
30
+ export type ReservedVariables = "module" | "namespace";
31
+
32
+ export type BlockInfo = {
33
+ before: () => string,
34
+ after: () => string,
35
+ custom: (txt: string) => string
36
+ }
37
+
38
+ export type TemplateInfo = {
39
+ name: string,
40
+ description?: string,
41
+ version?: Version,
42
+ allowQuick?: boolean,
43
+ organization?: string,
44
+ tags?: string[],
45
+ isProject?: boolean,
46
+ isGlobal?: boolean,
47
+ installationFolder?: string
48
+ documentation?: string,
49
+ repository?: string,
50
+ }
51
+
52
+ const trueLog = console.log;
53
+
54
+ console.log = (message?: any, ...optionalParams: any[]) => {
55
+ trueLog(JSON.stringify({ cmd: "log", config: message }));
56
+ }
57
+
58
+ export function log(message?: any, ...optionalParams: any[]) {
59
+ trueLog(message, ...optionalParams);
60
+ }
61
+
62
+ export const AventusExtension = {
63
+ Base: ".avt",
64
+ Config: "aventus.conf.avt",
65
+ CsharpConfig: "aventus.sharp.avt",
66
+ PhpConfig: "aventus.php.avt",
67
+ ComponentLogic: ".wcl.avt",
68
+ ComponentView: ".wcv.avt",
69
+ ComponentStyle: ".wcs.avt",
70
+ Component: ".wc.avt",
71
+ GlobalStyle: ".gs.avt",
72
+ Data: ".data.avt",
73
+ Lib: ".lib.avt",
74
+ RAM: ".ram.avt",
75
+ State: ".state.avt",
76
+ Static: ".static.avt",
77
+ Definition: ".def.avt",
78
+ DefinitionNpm: ".defnpm.avt",
79
+ Template: "template.avt.ts",
80
+ ConfigTemplate: "!aventus.conf.avt",
81
+ Package: ".package.avt",
82
+ I18n: ".i18n.avt",
83
+ } as const;
84
+
85
+ export abstract class AventusTemplate {
86
+ private basicInfo() {
87
+ let hasIsAllow = false;
88
+ try {
89
+ hasIsAllow = this.isAllowed() != 'default';
90
+ }
91
+ catch {
92
+ hasIsAllow = true;
93
+ }
94
+ const defaultValues = {
95
+ description: "",
96
+ version: "1.0.0",
97
+ hasIsAllow
98
+ }
99
+ const values = { ...defaultValues, ...this.meta() };
100
+ return JSON.stringify(values);
101
+ }
102
+ protected abstract meta(): TemplateInfo;
103
+
104
+ protected variables: { [key: string]: string | null | undefined } = {}
105
+ protected ifs: { [key: string]: boolean } = {}
106
+ protected blocks: {
107
+ [key: string]: BlockInfo
108
+ } = {}
109
+ protected destination: string = "";
110
+ protected workspacePath: string = "";
111
+ protected templatePath: string = "";
112
+ private _run(templatePath: string, destination: string, workspacePath: string) {
113
+ return new Promise<void>((resolve) => {
114
+ this.destination = destination;
115
+ this.templatePath = templatePath;
116
+ this.workspacePath = workspacePath;
117
+ this.defaultBlocks();
118
+ process.stdin.on("data", (data) => {
119
+ try {
120
+ const txt = data.toString().trim();
121
+ const payload: { cmd: string, result: string | null } = JSON.parse(txt);
122
+ if (payload.result == 'NULL') {
123
+ payload.result = null;
124
+ }
125
+ if (this.waitingResponse[payload.cmd]) {
126
+ this.waitingResponse[payload.cmd](payload.result);
127
+ }
128
+ }
129
+ catch (e) {
130
+ this.runCommand("error", e);
131
+ }
132
+ })
133
+ this.run(destination).then(() => {
134
+ process.exit();
135
+ })
136
+ })
137
+ }
138
+
139
+ private _isAllowed(templatePath: string, destination: string, workspacePath: string): boolean | 'default' {
140
+ this.destination = destination;
141
+ this.templatePath = templatePath;
142
+ this.workspacePath = workspacePath;
143
+ return this.isAllowed();
144
+ }
145
+ protected isAllowed(): boolean | 'default' {
146
+ return 'default';
147
+ }
148
+
149
+ protected defaultBlocks() {
150
+ this.registerBlock("namespace", {
151
+ before: () => {
152
+ if (this.variables["namespace"]) {
153
+ return `namespace ${this.variables["namespace"]} {`;
154
+ }
155
+ return "";
156
+ },
157
+ after: () => {
158
+ if (this.variables["namespace"]) {
159
+ return `}`;
160
+ }
161
+ return "";
162
+ },
163
+ custom: (v) => {
164
+ if (this.variables["namespace"]) {
165
+ return v;
166
+ }
167
+ v = this.removeIndent(v);
168
+ return v.trim()
169
+ }
170
+ })
171
+ }
172
+
173
+ protected abstract run(destination: string): Promise<void>;
174
+
175
+ protected async input(config: InputOptions): Promise<string | null> {
176
+ let response = await this.runCommandWithAnswer('input', config);
177
+ return response;
178
+ }
179
+
180
+ protected async select(items: SelectItem[], options: SelectOptions): Promise<SelectItem | null> {
181
+
182
+ let response = await this.runCommandWithAnswer('select', { items, options });
183
+ if (response == null) return null;
184
+ const temp = JSON.parse(response) as SelectItem;
185
+ for (let item of items) {
186
+ if (item.label == temp.label) {
187
+ return item;
188
+ }
189
+ }
190
+ return null;
191
+ }
192
+
193
+ protected async selectMultiple(items: SelectItem[], options: SelectOptions): Promise<SelectItem[] | null> {
194
+ let response = await this.runCommandWithAnswer('selectMultiple', { items, options });
195
+ if (response == null) return null;
196
+ const optionsResult = JSON.parse(response) as SelectItem[];
197
+ const result: SelectItem[] = [];
198
+ for (let item of items) {
199
+ for (let opt of optionsResult) {
200
+ if (item.label == opt.label) {
201
+ result.push(item);
202
+ }
203
+ }
204
+ }
205
+ return result;
206
+ }
207
+
208
+ protected waitingResponse: { [cmd: string]: (response: string | null) => void } = {};
209
+ private runCommandWithAnswer(cmd: string, config?: any): Promise<string | null> {
210
+ return new Promise<string | null>((resolve) => {
211
+ this.waitingResponse[cmd] = (response: string | null) => {
212
+ delete this.waitingResponse[cmd];
213
+ resolve(response);
214
+ }
215
+ log(JSON.stringify({ cmd, config }));
216
+ })
217
+ }
218
+ private runCommand(cmd: string, config?: any): void {
219
+ log(JSON.stringify({ cmd, config }));
220
+ }
221
+
222
+ protected registerVar<T extends string>(name: T & (T extends ReservedVariables ? never : {}), value: string | null | undefined) {
223
+ this.variables[name] = value;
224
+ }
225
+ protected registerIf<T extends string>(name: T & (T extends ReservedVariables ? never : {}), value: boolean) {
226
+ this.ifs[name] = value;
227
+ }
228
+
229
+ protected registerBlock(name: string, block: Partial<BlockInfo>) {
230
+ const defaultBlock: BlockInfo = {
231
+ before: () => "",
232
+ after: () => "",
233
+ custom: (v) => v
234
+ }
235
+ this.blocks[name] = { ...defaultBlock, ...block };
236
+ }
237
+
238
+ protected defaultWriteDeny(info: WriteInfo, denyDir?: string[], denyFile?: string[]): boolean {
239
+ if (!denyDir) {
240
+ denyDir = [".git"]
241
+ }
242
+ if (!denyFile) {
243
+ denyFile = [".empty"]
244
+ }
245
+ const deny = info.isDir ? denyDir : denyFile;
246
+ for (let key of deny) {
247
+ if (info.templatePath.endsWith(sep + key))
248
+ return false;
249
+ }
250
+
251
+ return true;
252
+ }
253
+ protected async writeFile(cb?: WriteCallback) {
254
+ if (!cb) {
255
+ cb = this.defaultWriteDeny
256
+ }
257
+ let configFiles: { [path: string]: string } = {};
258
+ const configPattern: string[] = [
259
+ AventusExtension.Config,
260
+ AventusExtension.ConfigTemplate
261
+ ]
262
+ let filesPath: string[] = [];
263
+ const _internalLoop = async (currentPath) => {
264
+ try {
265
+ let files = readdirSync(currentPath);
266
+ for (let file of files) {
267
+ let templatePath = currentPath + sep + file;
268
+ let relativePath = templatePath.replace(this.templatePath, "");
269
+ let exportPath = templatePath.replace(this.templatePath, this.destination);
270
+ exportPath = this.replaceVariables(exportPath);
271
+ exportPath = normalize(exportPath);
272
+
273
+
274
+ if (statSync(templatePath).isDirectory()) {
275
+ const writeInfo: WriteInfo = {
276
+ content: '',
277
+ isDir: true,
278
+ rawContent: '',
279
+ templatePath: templatePath,
280
+ writePath: exportPath,
281
+ relativePath: relativePath
282
+ }
283
+ const result = cb(writeInfo)
284
+ if (result === false) continue;
285
+ mkdirSync(exportPath, { recursive: true });
286
+ await _internalLoop(templatePath);
287
+ }
288
+ else {
289
+ if (templatePath == this.templatePath + sep + AventusExtension.Template) {
290
+ continue;
291
+ }
292
+ let rawCtx = readFileSync(templatePath, 'utf-8');
293
+ this.variables["namespace"] = await this.runCommandWithAnswer("getNamespace", exportPath);
294
+ let ctx = this.replaceVariables(rawCtx);
295
+ ctx = this.replaceBlocks(ctx);
296
+ ctx = this.replaceIfs(ctx);
297
+ const writeInfo: WriteInfo = {
298
+ content: ctx,
299
+ isDir: false,
300
+ rawContent: rawCtx,
301
+ templatePath: templatePath,
302
+ writePath: exportPath,
303
+ relativePath: relativePath
304
+ }
305
+ const result = cb(writeInfo)
306
+
307
+ if (result === false) continue;
308
+ if (!configPattern.includes(file)) {
309
+ writeFileSync(exportPath, writeInfo.content);
310
+ if (exportPath.endsWith(".avt")) {
311
+ filesPath.push(writeInfo.writePath);
312
+ }
313
+ }
314
+ else {
315
+ if (file == AventusExtension.ConfigTemplate) {
316
+ exportPath = exportPath.replace(AventusExtension.ConfigTemplate, AventusExtension.Config)
317
+ }
318
+ configFiles[exportPath] = writeInfo.content;
319
+ }
320
+ }
321
+ }
322
+ } catch (e) {
323
+ console.log(e);
324
+ }
325
+ }
326
+
327
+ await _internalLoop(this.templatePath);
328
+ // Force config to be written at the end
329
+ for (let configPath in configFiles) {
330
+ writeFileSync(configPath, configFiles[configPath]);
331
+ filesPath.push(configPath);
332
+ }
333
+
334
+
335
+
336
+ if (filesPath.length > 0) {
337
+ this.runCommand("registerFile", filesPath);
338
+ }
339
+ }
340
+ protected replaceVariables(ctx: string) {
341
+ for (let varName in this.variables) {
342
+ const regex = new RegExp('\\$\\{\\{' + varName + '\\}\\}', 'gm');
343
+ const value = this.variables[varName] ?? ''
344
+ ctx = ctx.replace(regex, value);
345
+ }
346
+ return ctx;
347
+ }
348
+ protected openFile(name: string | string[]) {
349
+
350
+ if (!Array.isArray(name)) {
351
+ name = [name];
352
+ }
353
+
354
+ const result: string[] = [];
355
+ for (let n of name) {
356
+ result.push(normalize(join(this.destination, n)));
357
+ }
358
+
359
+ this.runCommand("openFile", result)
360
+
361
+ }
362
+
363
+
364
+ protected replaceIfs(ctx: string) {
365
+ for (let ifName in this.ifs) {
366
+ const regex = new RegExp('#if\\{\\{' + ifName + '\\}\\}((\\s|\\S)*)#end\\{\\{' + ifName + '\\}\\}', 'gm');
367
+ if (this.ifs[ifName]) {
368
+ let m: RegExpExecArray | null;
369
+ while ((m = regex.exec(ctx)) !== null) {
370
+ if (m.index === regex.lastIndex) {
371
+ regex.lastIndex++;
372
+ }
373
+ ctx = ctx.replace(m[0], m[1]);
374
+ }
375
+ }
376
+ else {
377
+ ctx = ctx.replace(regex, "");
378
+ }
379
+ }
380
+ return ctx;
381
+ }
382
+ protected replaceBlocks(ctx: string) {
383
+ for (let blockName in this.blocks) {
384
+ const regex = new RegExp('#\\{\\{' + blockName + '\\}\\}((\\s|\\S)*)#\\{\\{' + blockName + '\\/\\}\\}', 'gm');
385
+ const block = this.blocks[blockName];
386
+ const contentBefore = block.before();
387
+ const contentAfter = block.after();
388
+
389
+ let m: RegExpExecArray | null;
390
+ while ((m = regex.exec(ctx)) !== null) {
391
+ // This is necessary to avoid infinite loops with zero-width matches
392
+ if (m.index === regex.lastIndex) {
393
+ regex.lastIndex++;
394
+ }
395
+
396
+ let main = m[0];
397
+
398
+ const replaceStart = new RegExp('#\\{\\{' + blockName + '\\}\\}', 'gm');
399
+ main = main.replace(replaceStart, contentBefore);
400
+
401
+ const replaceEnd = new RegExp('#\\{\\{' + blockName + '\\/\\}\\}', 'gm');
402
+ main = main.replace(replaceEnd, contentAfter);
403
+
404
+ main = block.custom(main);
405
+ ctx = ctx.replace(m[0], main);
406
+ }
407
+
408
+ }
409
+ return ctx;
410
+ }
411
+
412
+ protected addIndent(text: string) {
413
+ text = "\t" + text.split('\n').join("\n\t");
414
+ return text;
415
+ }
416
+ protected removeIndent(text: string) {
417
+ return text.split('\n').map(line => line.startsWith('\t') ? line.slice(1) : line).join('\n');
418
+ }
419
+
420
+ protected async exec(cmd: string, asAdmin: boolean = false): Promise<void> {
421
+ if (asAdmin) {
422
+ await this.runCommand("execAdmin", cmd);
423
+ }
424
+ else {
425
+ await this.runCommand("exec", cmd);
426
+ }
427
+ }
428
+
429
+ protected showErrorMessage(msg: string): void {
430
+ return this.runCommand("showErrorMessage", msg);
431
+ }
432
+ protected showWarningMessage(msg: string): void {
433
+ return this.runCommand("showWarningMessage", msg);
434
+ }
435
+ protected showInformationMessage(msg: string): void {
436
+ return this.runCommand("showErrorMessage", msg);
437
+ }
438
+ protected async showProgress(txt: string): Promise<string> {
439
+ return await this.runCommandWithAnswer("progressStart", txt);
440
+ }
441
+ protected async hideProgress(uuid: string): Promise<void> {
442
+ await this.runCommand("progressStop", uuid);
443
+ }
444
+ protected async runWithProgress(txt: string, cb: () => Promise<void>) {
445
+ let uuid = await this.showProgress(txt);
446
+ await cb();
447
+ if (uuid) {
448
+ await this.hideProgress(uuid);
449
+ }
450
+ }
451
+
452
+ protected sleep(ms: number): Promise<void> {
453
+ return new Promise((resolve) => {
454
+ setTimeout(() => {
455
+ resolve()
456
+ }, ms);
457
+ })
458
+ }
459
+ }
460
+
461
+ (global as any).AventusTemplate = AventusTemplate;