create-awesome-node-app 0.0.0 → 0.1.0

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 (3) hide show
  1. package/dist/index.cjs +123 -37
  2. package/dist/index.js +123 -37
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -3441,30 +3441,53 @@ var getTemplateData = async () => {
3441
3441
  templateDataMap.set(TEMPLATE_DATA_FILE_URL, templateData);
3442
3442
  return templateData;
3443
3443
  };
3444
- var getBaseTemplates = async () => {
3444
+ var getTemplateCategories = async () => {
3445
3445
  const templateData = await getTemplateData();
3446
- return templateData.templates;
3446
+ const categories = /* @__PURE__ */ new Set();
3447
+ templateData.templates.forEach((template) => {
3448
+ categories.add(template.category);
3449
+ });
3450
+ return Array.from(categories);
3451
+ };
3452
+ var getTemplatesForCategory = async (category) => {
3453
+ const templateData = await getTemplateData();
3454
+ const templates = templateData.templates.filter(
3455
+ (template) => template.category === category
3456
+ );
3457
+ return templates;
3447
3458
  };
3448
- var getCnaExtensions = async (appType) => {
3459
+ var getExtensionsGroupedByCategory = async (type) => {
3449
3460
  const templateData = await getTemplateData();
3450
- return templateData.extensions.filter(
3451
- (extension) => extension.type === appType
3461
+ const extensions = templateData.extensions.filter(
3462
+ (extension) => extension.type === type
3452
3463
  );
3464
+ const extensionsGroupedByCategory = extensions.reduce((acc, extension) => {
3465
+ const category = extension.category;
3466
+ if (!acc[category]) {
3467
+ acc[category] = [];
3468
+ }
3469
+ acc[category].push(extension);
3470
+ return acc;
3471
+ }, {});
3472
+ return extensionsGroupedByCategory;
3453
3473
  };
3454
3474
 
3455
3475
  // src/options.ts
3456
3476
  import_prompts.default.override(import_yargs.default.argv);
3457
3477
  var getCnaOptions = async (options) => {
3458
3478
  var _a;
3459
- const templates = await getBaseTemplates();
3460
- const appTypeOptions = templates.map((template) => {
3461
- var _a2;
3462
- return {
3463
- title: template.name,
3464
- value: template.type,
3465
- description: template.description + " - " + ((_a2 = template.labels) == null ? void 0 : _a2.join(", "))
3466
- };
3467
- });
3479
+ const categories = await getTemplateCategories();
3480
+ const categoriesOptions = [
3481
+ ...categories.map((category) => ({
3482
+ title: category,
3483
+ value: category
3484
+ })),
3485
+ {
3486
+ title: "None of the above",
3487
+ value: "custom",
3488
+ description: "I have my own template"
3489
+ }
3490
+ ];
3468
3491
  const baseInput = await (0, import_prompts.default)([
3469
3492
  {
3470
3493
  type: "text",
@@ -3482,19 +3505,45 @@ var getCnaOptions = async (options) => {
3482
3505
  },
3483
3506
  {
3484
3507
  type: "select",
3485
- name: "appType",
3508
+ name: "category",
3486
3509
  message: "What type of app do you want to create?",
3487
- choices: appTypeOptions,
3510
+ choices: categoriesOptions,
3488
3511
  initial: 0
3489
- },
3490
- {
3491
- type: "text",
3492
- name: "template",
3493
- message: "Template to use to bootstrap application. e.g: https://github.com/username/repository/tree/main/subdir",
3494
- initial: ""
3495
3512
  }
3496
3513
  ]);
3497
- const extensions = await getCnaExtensions(baseInput.appType);
3514
+ const templates = await getTemplatesForCategory(baseInput.category);
3515
+ const templateOptions = templates.map((template) => {
3516
+ var _a2;
3517
+ return {
3518
+ title: template.name,
3519
+ value: template.type,
3520
+ description: template.description + " Keywords: " + ((_a2 = template.labels) == null ? void 0 : _a2.join(", "))
3521
+ };
3522
+ });
3523
+ const templateInput = await (0, import_prompts.default)(
3524
+ baseInput.category === "custom" ? [
3525
+ {
3526
+ type: "text",
3527
+ name: "template",
3528
+ message: "Enter the URL of your template. e.g: https://github.com/username/repository/tree/main/subdir",
3529
+ initial: "",
3530
+ validate: (value) => {
3531
+ if (!value) {
3532
+ return "Template URL is required";
3533
+ }
3534
+ return true;
3535
+ }
3536
+ }
3537
+ ] : [
3538
+ {
3539
+ type: "select",
3540
+ name: "template",
3541
+ message: "Select a template",
3542
+ choices: templateOptions,
3543
+ initial: 0
3544
+ }
3545
+ ]
3546
+ );
3498
3547
  const defaultSrcDir = options.srcDir;
3499
3548
  const appConfig = await (0, import_prompts.default)([
3500
3549
  {
@@ -3509,34 +3558,71 @@ var getCnaOptions = async (options) => {
3509
3558
  message: "Import alias to use for the project, e.g. `@`",
3510
3559
  initial: options.alias
3511
3560
  },
3561
+ // The following prompts are placeholders for future inputs
3512
3562
  {
3513
- type: "multiselect",
3563
+ type: null,
3514
3564
  name: "addons",
3515
- message: `Select extensions to extend your ${baseInput.appType} project`,
3516
- hint: "- Space to select. Return to submit",
3517
- choices: extensions.map((option) => {
3565
+ message: "Select extensions",
3566
+ initial: 0
3567
+ },
3568
+ {
3569
+ type: null,
3570
+ name: "extend",
3571
+ message: "Enter extra extensions",
3572
+ initial: 0
3573
+ }
3574
+ ]);
3575
+ appConfig.addons = [];
3576
+ appConfig.extend = [];
3577
+ const extensionsGroupedByCategory = await getExtensionsGroupedByCategory(
3578
+ templateInput.template
3579
+ );
3580
+ for (const [category, extensions] of Object.entries(
3581
+ extensionsGroupedByCategory
3582
+ )) {
3583
+ const { selected } = await (0, import_prompts.default)({
3584
+ type: "multiselect",
3585
+ name: "selected",
3586
+ message: `Select extensions for ${category}`,
3587
+ choices: extensions.map((extension) => {
3518
3588
  var _a2;
3519
3589
  return {
3520
- title: option.name,
3521
- value: option.url,
3522
- description: option.description + " - " + ((_a2 = option.labels) == null ? void 0 : _a2.join(", "))
3590
+ title: extension.name,
3591
+ value: extension.url,
3592
+ description: extension.description + " Keywords: " + ((_a2 = extension.labels) == null ? void 0 : _a2.join(", "))
3523
3593
  };
3524
- })
3525
- },
3594
+ }),
3595
+ initial: 0
3596
+ });
3597
+ appConfig.addons = appConfig.addons ? [...appConfig.addons, ...selected] : [];
3598
+ }
3599
+ const askForExtend = await (0, import_prompts.default)([
3526
3600
  {
3527
- type: "list",
3601
+ type: "confirm",
3528
3602
  name: "extend",
3529
- message: "Enter extra extensions separater by comma. e.g: https://github.com/username/repository/tree/main/extension1,https://github.com/username/repository/tree/main/extension2",
3530
- initial: "",
3531
- separator: ","
3603
+ message: "Do you want to extend the app with more extensions?",
3604
+ initial: false
3532
3605
  }
3533
3606
  ]);
3607
+ if (askForExtend.extend) {
3608
+ const { extend } = await (0, import_prompts.default)([
3609
+ {
3610
+ type: "list",
3611
+ name: "extend",
3612
+ message: "Enter extra extensions separater by comma. e.g: https://github.com/username/repository/tree/main/extension1,https://github.com/username/repository/tree/main/extension2",
3613
+ initial: "",
3614
+ separator: ","
3615
+ }
3616
+ ]);
3617
+ appConfig.extend = extend;
3618
+ }
3534
3619
  const { ...nextAppOptions } = {
3535
3620
  ...options,
3536
3621
  ...baseInput,
3622
+ ...templateInput,
3537
3623
  ...appConfig
3538
3624
  };
3539
- const templateAddon = baseInput.template || ((_a = templates.find((template) => template.type === nextAppOptions.appType)) == null ? void 0 : _a.url);
3625
+ const templateAddon = baseInput.category === "custom" ? templateInput.template : (_a = templates.find((template) => template.type === templateInput.template)) == null ? void 0 : _a.url;
3540
3626
  const addons = [
3541
3627
  templateAddon,
3542
3628
  ...nextAppOptions.addons,
package/dist/index.js CHANGED
@@ -3447,30 +3447,53 @@ var getTemplateData = async () => {
3447
3447
  templateDataMap.set(TEMPLATE_DATA_FILE_URL, templateData);
3448
3448
  return templateData;
3449
3449
  };
3450
- var getBaseTemplates = async () => {
3450
+ var getTemplateCategories = async () => {
3451
3451
  const templateData = await getTemplateData();
3452
- return templateData.templates;
3452
+ const categories = /* @__PURE__ */ new Set();
3453
+ templateData.templates.forEach((template) => {
3454
+ categories.add(template.category);
3455
+ });
3456
+ return Array.from(categories);
3457
+ };
3458
+ var getTemplatesForCategory = async (category) => {
3459
+ const templateData = await getTemplateData();
3460
+ const templates = templateData.templates.filter(
3461
+ (template) => template.category === category
3462
+ );
3463
+ return templates;
3453
3464
  };
3454
- var getCnaExtensions = async (appType) => {
3465
+ var getExtensionsGroupedByCategory = async (type) => {
3455
3466
  const templateData = await getTemplateData();
3456
- return templateData.extensions.filter(
3457
- (extension) => extension.type === appType
3467
+ const extensions = templateData.extensions.filter(
3468
+ (extension) => extension.type === type
3458
3469
  );
3470
+ const extensionsGroupedByCategory = extensions.reduce((acc, extension) => {
3471
+ const category = extension.category;
3472
+ if (!acc[category]) {
3473
+ acc[category] = [];
3474
+ }
3475
+ acc[category].push(extension);
3476
+ return acc;
3477
+ }, {});
3478
+ return extensionsGroupedByCategory;
3459
3479
  };
3460
3480
 
3461
3481
  // src/options.ts
3462
3482
  prompts.override(yargs.argv);
3463
3483
  var getCnaOptions = async (options) => {
3464
3484
  var _a;
3465
- const templates = await getBaseTemplates();
3466
- const appTypeOptions = templates.map((template) => {
3467
- var _a2;
3468
- return {
3469
- title: template.name,
3470
- value: template.type,
3471
- description: template.description + " - " + ((_a2 = template.labels) == null ? void 0 : _a2.join(", "))
3472
- };
3473
- });
3485
+ const categories = await getTemplateCategories();
3486
+ const categoriesOptions = [
3487
+ ...categories.map((category) => ({
3488
+ title: category,
3489
+ value: category
3490
+ })),
3491
+ {
3492
+ title: "None of the above",
3493
+ value: "custom",
3494
+ description: "I have my own template"
3495
+ }
3496
+ ];
3474
3497
  const baseInput = await prompts([
3475
3498
  {
3476
3499
  type: "text",
@@ -3488,19 +3511,45 @@ var getCnaOptions = async (options) => {
3488
3511
  },
3489
3512
  {
3490
3513
  type: "select",
3491
- name: "appType",
3514
+ name: "category",
3492
3515
  message: "What type of app do you want to create?",
3493
- choices: appTypeOptions,
3516
+ choices: categoriesOptions,
3494
3517
  initial: 0
3495
- },
3496
- {
3497
- type: "text",
3498
- name: "template",
3499
- message: "Template to use to bootstrap application. e.g: https://github.com/username/repository/tree/main/subdir",
3500
- initial: ""
3501
3518
  }
3502
3519
  ]);
3503
- const extensions = await getCnaExtensions(baseInput.appType);
3520
+ const templates = await getTemplatesForCategory(baseInput.category);
3521
+ const templateOptions = templates.map((template) => {
3522
+ var _a2;
3523
+ return {
3524
+ title: template.name,
3525
+ value: template.type,
3526
+ description: template.description + " Keywords: " + ((_a2 = template.labels) == null ? void 0 : _a2.join(", "))
3527
+ };
3528
+ });
3529
+ const templateInput = await prompts(
3530
+ baseInput.category === "custom" ? [
3531
+ {
3532
+ type: "text",
3533
+ name: "template",
3534
+ message: "Enter the URL of your template. e.g: https://github.com/username/repository/tree/main/subdir",
3535
+ initial: "",
3536
+ validate: (value) => {
3537
+ if (!value) {
3538
+ return "Template URL is required";
3539
+ }
3540
+ return true;
3541
+ }
3542
+ }
3543
+ ] : [
3544
+ {
3545
+ type: "select",
3546
+ name: "template",
3547
+ message: "Select a template",
3548
+ choices: templateOptions,
3549
+ initial: 0
3550
+ }
3551
+ ]
3552
+ );
3504
3553
  const defaultSrcDir = options.srcDir;
3505
3554
  const appConfig = await prompts([
3506
3555
  {
@@ -3515,34 +3564,71 @@ var getCnaOptions = async (options) => {
3515
3564
  message: "Import alias to use for the project, e.g. `@`",
3516
3565
  initial: options.alias
3517
3566
  },
3567
+ // The following prompts are placeholders for future inputs
3518
3568
  {
3519
- type: "multiselect",
3569
+ type: null,
3520
3570
  name: "addons",
3521
- message: `Select extensions to extend your ${baseInput.appType} project`,
3522
- hint: "- Space to select. Return to submit",
3523
- choices: extensions.map((option) => {
3571
+ message: "Select extensions",
3572
+ initial: 0
3573
+ },
3574
+ {
3575
+ type: null,
3576
+ name: "extend",
3577
+ message: "Enter extra extensions",
3578
+ initial: 0
3579
+ }
3580
+ ]);
3581
+ appConfig.addons = [];
3582
+ appConfig.extend = [];
3583
+ const extensionsGroupedByCategory = await getExtensionsGroupedByCategory(
3584
+ templateInput.template
3585
+ );
3586
+ for (const [category, extensions] of Object.entries(
3587
+ extensionsGroupedByCategory
3588
+ )) {
3589
+ const { selected } = await prompts({
3590
+ type: "multiselect",
3591
+ name: "selected",
3592
+ message: `Select extensions for ${category}`,
3593
+ choices: extensions.map((extension) => {
3524
3594
  var _a2;
3525
3595
  return {
3526
- title: option.name,
3527
- value: option.url,
3528
- description: option.description + " - " + ((_a2 = option.labels) == null ? void 0 : _a2.join(", "))
3596
+ title: extension.name,
3597
+ value: extension.url,
3598
+ description: extension.description + " Keywords: " + ((_a2 = extension.labels) == null ? void 0 : _a2.join(", "))
3529
3599
  };
3530
- })
3531
- },
3600
+ }),
3601
+ initial: 0
3602
+ });
3603
+ appConfig.addons = appConfig.addons ? [...appConfig.addons, ...selected] : [];
3604
+ }
3605
+ const askForExtend = await prompts([
3532
3606
  {
3533
- type: "list",
3607
+ type: "confirm",
3534
3608
  name: "extend",
3535
- message: "Enter extra extensions separater by comma. e.g: https://github.com/username/repository/tree/main/extension1,https://github.com/username/repository/tree/main/extension2",
3536
- initial: "",
3537
- separator: ","
3609
+ message: "Do you want to extend the app with more extensions?",
3610
+ initial: false
3538
3611
  }
3539
3612
  ]);
3613
+ if (askForExtend.extend) {
3614
+ const { extend } = await prompts([
3615
+ {
3616
+ type: "list",
3617
+ name: "extend",
3618
+ message: "Enter extra extensions separater by comma. e.g: https://github.com/username/repository/tree/main/extension1,https://github.com/username/repository/tree/main/extension2",
3619
+ initial: "",
3620
+ separator: ","
3621
+ }
3622
+ ]);
3623
+ appConfig.extend = extend;
3624
+ }
3540
3625
  const { ...nextAppOptions } = {
3541
3626
  ...options,
3542
3627
  ...baseInput,
3628
+ ...templateInput,
3543
3629
  ...appConfig
3544
3630
  };
3545
- const templateAddon = baseInput.template || ((_a = templates.find((template) => template.type === nextAppOptions.appType)) == null ? void 0 : _a.url);
3631
+ const templateAddon = baseInput.category === "custom" ? templateInput.template : (_a = templates.find((template) => template.type === templateInput.template)) == null ? void 0 : _a.url;
3546
3632
  const addons = [
3547
3633
  templateAddon,
3548
3634
  ...nextAppOptions.addons,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-awesome-node-app",
3
- "version": "0.0.0",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "description": "Command line tool to create Node apps with a lot of different addons.",
6
6
  "license": "MIT",