@aventusjs/cli 0.0.14 → 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.
@@ -40,6 +40,8 @@ declare type TemplateInfo = {
40
40
  tags?: string[],
41
41
  /** Determine if the template is a project or a template */
42
42
  isProject?: boolean,
43
+ /** Determine if the template is global */
44
+ isGlobal?: boolean,
43
45
  /** Determine where to install the template */
44
46
  installationFolder?: string,
45
47
  /** Documentation link for the package */
@@ -64,9 +66,12 @@ declare abstract class AventusTemplate {
64
66
  protected blocks: {
65
67
  [key: string]: BlockInfo;
66
68
  };
69
+ protected ifs: { [key: string]: boolean };
67
70
  protected destination: string;
68
71
  protected workspacePath: string;
69
72
  protected templatePath: string;
73
+ private _isAllowed;
74
+ protected isAllowed(): boolean;
70
75
  private _run;
71
76
  private defaultBlocks(): void;
72
77
  protected abstract run(destination: string): Promise<void>;
@@ -85,6 +90,8 @@ declare abstract class AventusTemplate {
85
90
  protected registerVar<T extends string>(name: T & (T extends ReservedVariables ? never : {}), value: string | null | undefined): void;
86
91
  /** Register a block that you can use later as #{{block}} #{{block/}} */
87
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;
88
95
  /** Prevent writing default files/folders */
89
96
  protected defaultWriteDeny(info: WriteInfo, denyDir?: string[], denyFile?: string[]): boolean
90
97
  /** Start writing process */
@@ -93,6 +100,8 @@ declare abstract class AventusTemplate {
93
100
  protected replaceVariables(ctx: string): string;
94
101
  /** Replace #{{block}} #{{block/}} inside the content */
95
102
  protected replaceBlocks(ctx: string): string;
103
+ /** Replace #if{{block}} #end{{block}} inside the content */
104
+ protected replaceIfs(ctx: string): void;
96
105
  /** Add \\t before each line */
97
106
  protected addIndent(text: string): string;
98
107
  /** Remove \\t before each line */
@@ -43,6 +43,7 @@ export type TemplateInfo = {
43
43
  organization?: string,
44
44
  tags?: string[],
45
45
  isProject?: boolean,
46
+ isGlobal?: boolean,
46
47
  installationFolder?: string
47
48
  documentation?: string,
48
49
  repository?: string,
@@ -83,9 +84,17 @@ export const AventusExtension = {
83
84
 
84
85
  export abstract class AventusTemplate {
85
86
  private basicInfo() {
87
+ let hasIsAllow = false;
88
+ try {
89
+ hasIsAllow = this.isAllowed() != 'default';
90
+ }
91
+ catch {
92
+ hasIsAllow = true;
93
+ }
86
94
  const defaultValues = {
87
95
  description: "",
88
- version: "1.0.0"
96
+ version: "1.0.0",
97
+ hasIsAllow
89
98
  }
90
99
  const values = { ...defaultValues, ...this.meta() };
91
100
  return JSON.stringify(values);
@@ -93,6 +102,7 @@ export abstract class AventusTemplate {
93
102
  protected abstract meta(): TemplateInfo;
94
103
 
95
104
  protected variables: { [key: string]: string | null | undefined } = {}
105
+ protected ifs: { [key: string]: boolean } = {}
96
106
  protected blocks: {
97
107
  [key: string]: BlockInfo
98
108
  } = {}
@@ -126,6 +136,16 @@ export abstract class AventusTemplate {
126
136
  })
127
137
  }
128
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
+
129
149
  protected defaultBlocks() {
130
150
  this.registerBlock("namespace", {
131
151
  before: () => {
@@ -202,6 +222,9 @@ export abstract class AventusTemplate {
202
222
  protected registerVar<T extends string>(name: T & (T extends ReservedVariables ? never : {}), value: string | null | undefined) {
203
223
  this.variables[name] = value;
204
224
  }
225
+ protected registerIf<T extends string>(name: T & (T extends ReservedVariables ? never : {}), value: boolean) {
226
+ this.ifs[name] = value;
227
+ }
205
228
 
206
229
  protected registerBlock(name: string, block: Partial<BlockInfo>) {
207
230
  const defaultBlock: BlockInfo = {
@@ -270,6 +293,7 @@ export abstract class AventusTemplate {
270
293
  this.variables["namespace"] = await this.runCommandWithAnswer("getNamespace", exportPath);
271
294
  let ctx = this.replaceVariables(rawCtx);
272
295
  ctx = this.replaceBlocks(ctx);
296
+ ctx = this.replaceIfs(ctx);
273
297
  const writeInfo: WriteInfo = {
274
298
  content: ctx,
275
299
  isDir: false,
@@ -337,7 +361,24 @@ export abstract class AventusTemplate {
337
361
  }
338
362
 
339
363
 
340
-
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
+ }
341
382
  protected replaceBlocks(ctx: string) {
342
383
  for (let blockName in this.blocks) {
343
384
  const regex = new RegExp('#\\{\\{' + blockName + '\\}\\}((\\s|\\S)*)#\\{\\{' + blockName + '\\/\\}\\}', 'gm');