@pega/dx-component-builder-sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/util.js CHANGED
@@ -20,11 +20,23 @@ import {
20
20
  FIELD_PATH,
21
21
  WIDGET_PATH,
22
22
  TEMPLATE_PATH,
23
+ FORMS_PATH,
24
+ TEMPLATES_PATH,
25
+ WIDGETS_PATH,
26
+ DSE_PATH,
27
+ INFRA_PATH,
23
28
  COMPONENT_PREFIX_FIELD_PATH,
24
29
  COMPONENT_PREFIX_TEMPLATE_PATH,
25
- COMPONENT_PREFIX_WIDGET_PATH
30
+ COMPONENT_PREFIX_WIDGET_PATH,
31
+ COMPONENT_PREFIX_FORMS_PATH,
32
+ COMPONENT_PREFIX_TEMPLATES_PATH,
33
+ COMPONENT_PREFIX_WIDGETS_PATH,
34
+ COMPONENT_PREFIX_DSE_PATH,
35
+ COMPONENT_PREFIX_INFRA_PATH
26
36
  } from './constants.js';
27
37
 
38
+
39
+
28
40
  const access = promisify(fs.access);
29
41
 
30
42
  export const checkPathAccess = async (path, options = {}) => {
@@ -59,12 +71,15 @@ export const deleteLocalComponent = async (componentKey, category = "custom") =>
59
71
 
60
72
  const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
61
73
 
62
- fs.rmdir(directory, { recursive: true }, err => {
74
+ //fs.rmdir(directory, { recursive: true }, err => {
75
+ fs.rm(directory, { recursive: true }, err => {
63
76
  if (err) {
64
77
  throw err;
65
78
  }
66
79
 
67
80
  console.log(`${chalk.red.bold(componentKey)} is deleted from Local`);
81
+
82
+
68
83
  });
69
84
  };
70
85
 
@@ -122,29 +137,71 @@ export const getComponents = async (showSeparator = false, category = "custom")
122
137
  process.exit(1);
123
138
  }
124
139
 
140
+
125
141
  const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory);
142
+ let compList = new Array();
126
143
 
127
- const fieldComps = await getSubComponents(directory, FIELD_PATH);
128
- const templateComps = await getSubComponents(directory, TEMPLATE_PATH);
129
- const widgetComps = await getSubComponents(directory, WIDGET_PATH);
144
+ switch (category) {
145
+ case "custom":
146
+ const fieldComps = await getSubComponents(directory, FIELD_PATH);
147
+ const templateComps = await getSubComponents(directory, TEMPLATE_PATH);
148
+ const widgetComps = await getSubComponents(directory, WIDGET_PATH);
130
149
 
131
- let compList = new Array();
132
150
 
133
- if (fieldComps.length > 0) {
134
- if (showSeparator) compList.push(new inquirer.Separator("---- fields ----"));
135
- compList.push(...fieldComps);
136
- }
137
151
 
138
- if (templateComps.length > 0) {
139
- if (showSeparator) compList.push(new inquirer.Separator("---- templates ----"));
140
- compList.push(...templateComps);
141
- }
152
+ if (fieldComps.length > 0) {
153
+ if (showSeparator) compList.push(new inquirer.Separator("---- fields ----"));
154
+ compList.push(...fieldComps);
155
+ }
156
+
157
+ if (templateComps.length > 0) {
158
+ if (showSeparator) compList.push(new inquirer.Separator("---- templates ----"));
159
+ compList.push(...templateComps);
160
+ }
161
+
162
+ if (widgetComps.length > 0) {
163
+ if (showSeparator) compList.push(new inquirer.Separator("---- widgets ----"));
164
+ compList.push(...widgetComps);
165
+ }
166
+ break;
167
+ case "override":
168
+ const formsComps = await getSubComponents(directory, FORMS_PATH);
169
+ const templatesComps = await getSubComponents(directory, TEMPLATES_PATH);
170
+ const widgetsComps = await getSubComponents(directory, WIDGETS_PATH);
171
+ const dseComps = await getSubComponents(directory, DSE_PATH);
172
+ const infraComps = await getSubComponents(directory, INFRA_PATH);
173
+
174
+ if (formsComps.length > 0) {
175
+ if (showSeparator) compList.push(new inquirer.Separator("---- forms (fields) ----"));
176
+ compList.push(...formsComps);
177
+ }
142
178
 
143
- if (widgetComps.length > 0) {
144
- if (showSeparator) compList.push(new inquirer.Separator("---- widgets ----"));
145
- compList.push(...widgetComps);
179
+ if (templatesComps.length > 0) {
180
+ if (showSeparator) compList.push(new inquirer.Separator("---- templates ----"));
181
+ compList.push(...templatesComps);
182
+ }
183
+
184
+ if (widgetsComps.length > 0) {
185
+ if (showSeparator) compList.push(new inquirer.Separator("---- widgets ----"));
186
+ compList.push(...widgetsComps);
187
+ }
188
+
189
+ if (dseComps.length > 0) {
190
+ if (showSeparator) compList.push(new inquirer.Separator("---- design system extensions ----"));
191
+ compList.push(...dseComps);
192
+ }
193
+
194
+ if (infraComps.length > 0) {
195
+ if (showSeparator) compList.push(new inquirer.Separator("---- infrastructure ----"));
196
+ compList.push(...infraComps);
197
+ }
198
+ break;
146
199
  }
147
200
 
201
+
202
+
203
+
204
+
148
205
  return compList;
149
206
 
150
207
  };
@@ -176,53 +233,132 @@ export const getComponentsObj = async (showSeparator = false, category = "custom
176
233
  }
177
234
 
178
235
  const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory);
236
+ let compList = new Array();
179
237
 
180
- const fieldComps = await getSubComponents(directory, FIELD_PATH);
181
- const templateComps = await getSubComponents(directory, TEMPLATE_PATH);
182
- const widgetComps = await getSubComponents(directory, WIDGET_PATH);
238
+ switch (category) {
239
+ case "custom":
240
+ const fieldComps = await getSubComponents(directory, FIELD_PATH);
241
+ const templateComps = await getSubComponents(directory, TEMPLATE_PATH);
242
+ const widgetComps = await getSubComponents(directory, WIDGET_PATH);
183
243
 
184
- let compList = new Array();
244
+ if (fieldComps.length > 0) {
245
+ if (showSeparator) compList.push(new inquirer.Separator("---- fields ----"));
185
246
 
186
- if (fieldComps.length > 0) {
187
- if (showSeparator) compList.push(new inquirer.Separator("---- fields ----"));
247
+ compList.push(...fieldComps.map(
248
+ name => {
249
+ const container = {};
250
+ container.name = name;
251
+ container.value = COMPONENT_PREFIX_FIELD_PATH + name;
188
252
 
189
- compList.push(...fieldComps.map(
190
- name => {
191
- const container = {};
192
- container.name = name;
193
- container.value = COMPONENT_PREFIX_FIELD_PATH + name;
253
+ return container;
254
+ }
255
+ ));
256
+ }
194
257
 
195
- return container;
258
+ if (templateComps.length > 0) {
259
+ if (showSeparator) compList.push(new inquirer.Separator("---- templates ----"));
260
+ compList.push(...templateComps.map(
261
+ name => {
262
+ const container = {};
263
+ container.name = name;
264
+ container.value = COMPONENT_PREFIX_TEMPLATE_PATH + name;
265
+
266
+ return container;
267
+ }
268
+ ));
196
269
  }
197
- ));
198
- }
199
270
 
200
- if (templateComps.length > 0) {
201
- if (showSeparator) compList.push(new inquirer.Separator("---- templates ----"));
202
- compList.push(...templateComps.map(
203
- name => {
204
- const container = {};
205
- container.name = name;
206
- container.value = COMPONENT_PREFIX_TEMPLATE_PATH + name;
271
+ if (widgetComps.length > 0) {
272
+ if (showSeparator) compList.push(new inquirer.Separator("---- widgets ----"));
273
+ compList.push(...widgetComps.map(
274
+ name => {
275
+ const container = {};
276
+ container.name = name;
277
+ container.value = COMPONENT_PREFIX_WIDGET_PATH + name;
207
278
 
208
- return container;
279
+ return container;
280
+ }
281
+ ));
282
+ }
283
+ break;
284
+ case "override":
285
+ const formsComps = await getSubComponents(directory, FORMS_PATH);
286
+ const templatesComps = await getSubComponents(directory, TEMPLATES_PATH);
287
+ const widgetsComps = await getSubComponents(directory, WIDGETS_PATH);
288
+ const dseComps = await getSubComponents(directory, DSE_PATH);
289
+ const infraComps = await getSubComponents(directory, INFRA_PATH);
290
+
291
+ if (formsComps.length > 0) {
292
+ if (showSeparator) compList.push(new inquirer.Separator("---- forms (fields) ----"));
293
+
294
+ compList.push(...formsComps.map(
295
+ name => {
296
+ const container = {};
297
+ container.name = name;
298
+ container.value = COMPONENT_PREFIX_FORMS_PATH + name;
299
+
300
+ return container;
301
+ }
302
+ ));
209
303
  }
210
- ));
211
- }
212
304
 
213
- if (widgetComps.length > 0) {
214
- if (showSeparator) compList.push(new inquirer.Separator("---- widgets ----"));
215
- compList.push(...widgetComps.map(
216
- name => {
217
- const container = {};
218
- container.name = name;
219
- container.value = COMPONENT_PREFIX_WIDGET_PATH + name;
305
+ if (templatesComps.length > 0) {
306
+ if (showSeparator) compList.push(new inquirer.Separator("---- templates ----"));
307
+ compList.push(...templatesComps.map(
308
+ name => {
309
+ const container = {};
310
+ container.name = name;
311
+ container.value = COMPONENT_PREFIX_TEMPLATES_PATH + name;
220
312
 
221
- return container;
313
+ return container;
314
+ }
315
+ ));
222
316
  }
223
- ));
317
+
318
+ if (widgetsComps.length > 0) {
319
+ if (showSeparator) compList.push(new inquirer.Separator("---- widgets ----"));
320
+ compList.push(...widgetsComps.map(
321
+ name => {
322
+ const container = {};
323
+ container.name = name;
324
+ container.value = COMPONENT_PREFIX_WIDGETS_PATH + name;
325
+
326
+ return container;
327
+ }
328
+ ));
329
+ }
330
+
331
+ if (dseComps.length > 0) {
332
+ if (showSeparator) compList.push(new inquirer.Separator("---- designSystemExtensions ----"));
333
+ compList.push(...dseComps.map(
334
+ name => {
335
+ const container = {};
336
+ container.name = name;
337
+ container.value = COMPONENT_PREFIX_DSE_PATH + name;
338
+
339
+ return container;
340
+ }
341
+ ));
342
+ }
343
+
344
+ if (infraComps.length > 0) {
345
+ if (showSeparator) compList.push(new inquirer.Separator("---- infrastructure ----"));
346
+ compList.push(...infraComps.map(
347
+ name => {
348
+ const container = {};
349
+ container.name = name;
350
+ container.value = COMPONENT_PREFIX_INFRA_PATH + name;
351
+
352
+ return container;
353
+ }
354
+ ));
355
+ }
356
+
357
+ break;
224
358
  }
225
359
 
360
+
361
+
226
362
  return compList;
227
363
  }
228
364
 
@@ -279,6 +415,21 @@ export const removeComponentPrefix = (componentName) => {
279
415
  else if (componentName.indexOf(COMPONENT_PREFIX_WIDGET_PATH) == 0) {
280
416
  componentName = componentName.substring(COMPONENT_PREFIX_WIDGET_PATH.length);
281
417
  }
418
+ else if (componentName.indexOf(COMPONENT_PREFIX_FORMS_PATH) == 0) {
419
+ componentName = componentName.substring(COMPONENT_PREFIX_FORMS_PATH.length);
420
+ }
421
+ else if (componentName.indexOf(COMPONENT_PREFIX_TEMPLATES_PATH) == 0) {
422
+ componentName = componentName.substring(COMPONENT_PREFIX_TEMPLATES_PATH.length);
423
+ }
424
+ else if (componentName.indexOf(COMPONENT_PREFIX_WIDGETS_PATH) == 0) {
425
+ componentName = componentName.substring(COMPONENT_PREFIX_WIDGETS_PATH.length);
426
+ }
427
+ else if (componentName.indexOf(COMPONENT_PREFIX_DSE_PATH) == 0) {
428
+ componentName = componentName.substring(COMPONENT_PREFIX_DSE_PATH.length);
429
+ }
430
+ else if (componentName.indexOf(COMPONENT_PREFIX_INFRA_PATH) == 0) {
431
+ componentName = componentName.substring(COMPONENT_PREFIX_INFRA_PATH.length);
432
+ }
282
433
 
283
434
  return componentName;
284
435
  }
@@ -326,6 +477,7 @@ export const getComponentDirectoryPath = async (componentKey, category = "custom
326
477
  return join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
327
478
  };
328
479
 
480
+
329
481
  export const compileMustacheTemplate = (file, data) => {
330
482
  const content = fs.readFileSync(file, 'utf8');
331
483
  return mustache.render(content, data);