@ixon-cdk/core 1.13.0-next.1 → 1.13.0-next.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ixon-cdk/core",
3
- "version": "1.13.0-next.1",
3
+ "version": "1.13.0-next.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "",
@@ -183,22 +183,35 @@ module.exports = class TemplateService {
183
183
  });
184
184
  }
185
185
 
186
- async add(componentName, componentPrefix) {
186
+ async add(componentName, componentPrefix, templateName, variantName) {
187
187
  let schema;
188
188
 
189
- const result = await prompts({
190
- type: 'select',
191
- name: 'templateName',
192
- message: 'Pick a template',
193
- choices: Object.keys(this._schemas).map(key => ({
194
- title: this._schemas[key].name,
195
- value: key,
196
- })),
197
- initial: 0,
198
- });
189
+ if (templateName) {
190
+ const result = Object.keys(this._schemas).find(
191
+ key => this._schemas[key].name === templateName,
192
+ );
193
+
194
+ if (result) {
195
+ schema = this._schemas[result];
196
+ console.log(`Using template: ${schema.name}`);
197
+ }
198
+ }
199
+
200
+ if (!schema) {
201
+ const result = await prompts({
202
+ type: 'select',
203
+ name: 'templateName',
204
+ message: 'Pick a template',
205
+ choices: Object.keys(this._schemas).map(key => ({
206
+ title: this._schemas[key].name,
207
+ value: key,
208
+ })),
209
+ initial: 0,
210
+ });
199
211
 
200
- if (result) {
201
- schema = this._schemas[result.templateName];
212
+ if (result) {
213
+ schema = this._schemas[result.templateName];
214
+ }
202
215
  }
203
216
 
204
217
  if (schema) {
@@ -209,19 +222,26 @@ module.exports = class TemplateService {
209
222
  let variantIdx = null;
210
223
 
211
224
  if (schema.variants) {
212
- const _result = await prompts({
213
- type: 'select',
214
- name: 'variantIdx',
215
- message: 'Pick a variant',
216
- choices: schema.variants.map((variant, index) => ({
217
- title: variant.name,
218
- value: index,
219
- })),
220
- initial: 0,
221
- });
225
+ if (variantName) {
226
+ variantIdx = schema.variants.findIndex(v => v.name === variantName);
227
+ console.log(`Using variant: ${schema.variants[variantIdx].name}`);
228
+ }
229
+
230
+ if (variantIdx < 0) {
231
+ const _result = await prompts({
232
+ type: 'select',
233
+ name: 'variantIdx',
234
+ message: 'Pick a variant',
235
+ choices: schema.variants.map((variant, index) => ({
236
+ title: variant.name,
237
+ value: index,
238
+ })),
239
+ initial: 0,
240
+ });
222
241
 
223
- if (_result) {
224
- variantIdx = _result.variantIdx;
242
+ if (_result) {
243
+ variantIdx = _result.variantIdx;
244
+ }
225
245
  }
226
246
 
227
247
  if (variantIdx === undefined) {