@sdeverywhere/create 0.1.0 → 0.1.2

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/dist/index.cjs CHANGED
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/index.ts
@@ -83,7 +86,9 @@ async function chooseGenConfig(projDir, mdlPath) {
83
86
  mdlVars = await readModelVars(projDir, mdlPath);
84
87
  } catch (e) {
85
88
  console.log(e);
86
- (0, import_ora.default)((0, import_colors.yellow)("The mdl file failed to load. We will continue setting things up, and you can diagnose the issue later.")).warn();
89
+ (0, import_ora.default)(
90
+ (0, import_colors.yellow)("The mdl file failed to load. We will continue setting things up, and you can diagnose the issue later.")
91
+ ).warn();
87
92
  return;
88
93
  }
89
94
  let initialTime;
@@ -138,17 +143,20 @@ ${modelCsvLine}
138
143
  await chooseGenSliderConfig(projDir, validVars);
139
144
  }
140
145
  async function chooseGenGraphConfig(projDir, mdlVars) {
141
- const genResponse = await (0, import_prompts.default)({
142
- type: "confirm",
143
- name: "genGraph",
144
- message: `Would you like to configure a graph to get you started? ${(0, import_colors.reset)((0, import_colors.dim)("(recommended)"))}`,
145
- initial: true
146
- }, {
147
- onCancel: () => {
148
- (0, import_ora.default)().info((0, import_colors.dim)("Operation cancelled."));
149
- process.exit(0);
146
+ const genResponse = await (0, import_prompts.default)(
147
+ {
148
+ type: "confirm",
149
+ name: "genGraph",
150
+ message: `Would you like to configure a graph to get you started? ${(0, import_colors.reset)((0, import_colors.dim)("(recommended)"))}`,
151
+ initial: true
152
+ },
153
+ {
154
+ onCancel: () => {
155
+ (0, import_ora.default)().info((0, import_colors.dim)("Operation cancelled."));
156
+ process.exit(0);
157
+ }
150
158
  }
151
- });
159
+ );
152
160
  if (!genResponse.genGraph) {
153
161
  (0, import_ora.default)().info((0, import_colors.dim)(`No problem! You can edit the "${(0, import_colors.cyan)("config/graphs.csv")}" file later.`));
154
162
  return;
@@ -168,18 +176,21 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
168
176
  value: f
169
177
  };
170
178
  });
171
- const varsResponse = await (0, import_prompts.default)({
172
- type: "autocompleteMultiselect",
173
- name: "vars",
174
- message: "Choose up to three output variables to display in the graph",
175
- choices,
176
- max: 3
177
- }, {
178
- onCancel: () => {
179
- (0, import_ora.default)().info((0, import_colors.dim)("Operation cancelled."));
180
- process.exit(0);
179
+ const varsResponse = await (0, import_prompts.default)(
180
+ {
181
+ type: "autocompleteMultiselect",
182
+ name: "vars",
183
+ message: "Choose up to three output variables to display in the graph",
184
+ choices,
185
+ max: 3
186
+ },
187
+ {
188
+ onCancel: () => {
189
+ (0, import_ora.default)().info((0, import_colors.dim)("Operation cancelled."));
190
+ process.exit(0);
191
+ }
181
192
  }
182
- });
193
+ );
183
194
  if (varsResponse.vars.length === 0) {
184
195
  (0, import_ora.default)().info((0, import_colors.dim)(`No variables selected. You can edit the "${(0, import_colors.cyan)("config/graphs.csv")}" file later.`));
185
196
  return;
@@ -190,7 +201,9 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
190
201
  graphsCsvContent += `${csvLine}
191
202
  `;
192
203
  await (0, import_promises.writeFile)(graphsCsvFile, graphsCsvContent);
193
- (0, import_ora.default)((0, import_colors.green)(`Added graph to "${(0, import_colors.bold)("config/graphs.csv")}". ${(0, import_colors.dim)("You can configure graphs in that file later.")}`)).succeed();
204
+ (0, import_ora.default)(
205
+ (0, import_colors.green)(`Added graph to "${(0, import_colors.bold)("config/graphs.csv")}". ${(0, import_colors.dim)("You can configure graphs in that file later.")}`)
206
+ ).succeed();
194
207
  }
195
208
  function graphsCsvLine(outputVarNames) {
196
209
  const colors = ["blue", "red", "green"];
@@ -213,17 +226,20 @@ function graphsCsvLine(outputVarNames) {
213
226
  return a.join(",");
214
227
  }
215
228
  async function chooseGenSliderConfig(projDir, mdlVars) {
216
- const genResponse = await (0, import_prompts.default)({
217
- type: "confirm",
218
- name: "genSliders",
219
- message: `Would you like to configure a few sliders to get you started? ${(0, import_colors.reset)((0, import_colors.dim)("(recommended)"))}`,
220
- initial: true
221
- }, {
222
- onCancel: () => {
223
- (0, import_ora.default)().info((0, import_colors.dim)("Operation cancelled."));
224
- process.exit(0);
229
+ const genResponse = await (0, import_prompts.default)(
230
+ {
231
+ type: "confirm",
232
+ name: "genSliders",
233
+ message: `Would you like to configure a few sliders to get you started? ${(0, import_colors.reset)((0, import_colors.dim)("(recommended)"))}`,
234
+ initial: true
235
+ },
236
+ {
237
+ onCancel: () => {
238
+ (0, import_ora.default)().info((0, import_colors.dim)("Operation cancelled."));
239
+ process.exit(0);
240
+ }
225
241
  }
226
- });
242
+ );
227
243
  if (!genResponse.genSliders) {
228
244
  (0, import_ora.default)().info((0, import_colors.dim)(`No problem! You can edit the "${(0, import_colors.cyan)("config/inputs.csv")}" file later.`));
229
245
  return;
@@ -243,18 +259,21 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
243
259
  value: f
244
260
  };
245
261
  });
246
- const varsResponse = await (0, import_prompts.default)({
247
- type: "autocompleteMultiselect",
248
- name: "vars",
249
- message: "Choose up to three input variables to control with sliders",
250
- choices,
251
- max: 3
252
- }, {
253
- onCancel: () => {
254
- (0, import_ora.default)().info((0, import_colors.dim)("Operation cancelled."));
255
- process.exit(0);
262
+ const varsResponse = await (0, import_prompts.default)(
263
+ {
264
+ type: "autocompleteMultiselect",
265
+ name: "vars",
266
+ message: "Choose up to three input variables to control with sliders",
267
+ choices,
268
+ max: 3
269
+ },
270
+ {
271
+ onCancel: () => {
272
+ (0, import_ora.default)().info((0, import_colors.dim)("Operation cancelled."));
273
+ process.exit(0);
274
+ }
256
275
  }
257
- });
276
+ );
258
277
  if (varsResponse.vars.length === 0) {
259
278
  (0, import_ora.default)().info((0, import_colors.dim)(`No variables selected. You can edit the "${(0, import_colors.cyan)("config/inputs.csv")}" file later.`));
260
279
  return;
@@ -274,7 +293,11 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
274
293
  }
275
294
  await (0, import_promises.writeFile)(inputsCsvFile, inputsCsvContent);
276
295
  const slidersText = varsResponse.vars.length > 1 ? "sliders" : "sliders";
277
- (0, import_ora.default)((0, import_colors.green)(`Added ${slidersText} to "${(0, import_colors.bold)("config/inputs.csv")}". ${(0, import_colors.dim)("You can configure sliders in that file later.")}`)).succeed();
296
+ (0, import_ora.default)(
297
+ (0, import_colors.green)(
298
+ `Added ${slidersText} to "${(0, import_colors.bold)("config/inputs.csv")}". ${(0, import_colors.dim)("You can configure sliders in that file later.")}`
299
+ )
300
+ ).succeed();
278
301
  }
279
302
  function inputsCsvLine(inputVarName, defaultValue, id) {
280
303
  const escapedName = escapeCsvField(inputVarName);
@@ -345,17 +368,22 @@ var import_colors2 = require("kleur/colors");
345
368
  var import_ora2 = __toESM(require("ora"), 1);
346
369
  var import_prompts2 = __toESM(require("prompts"), 1);
347
370
  async function chooseInstallDeps(projDir, args, pkgManager) {
348
- const installResponse = await (0, import_prompts2.default)({
349
- type: "confirm",
350
- name: "install",
351
- message: `Would you like to install ${pkgManager} dependencies? ${(0, import_colors2.reset)((0, import_colors2.dim)("(recommended)"))}`,
352
- initial: true
353
- }, {
354
- onCancel: () => {
355
- (0, import_ora2.default)().info((0, import_colors2.dim)("Operation cancelled. Your project folder has been created, but no dependencies have been installed."));
356
- process.exit(0);
371
+ const installResponse = await (0, import_prompts2.default)(
372
+ {
373
+ type: "confirm",
374
+ name: "install",
375
+ message: `Would you like to install ${pkgManager} dependencies? ${(0, import_colors2.reset)((0, import_colors2.dim)("(recommended)"))}`,
376
+ initial: true
377
+ },
378
+ {
379
+ onCancel: () => {
380
+ (0, import_ora2.default)().info(
381
+ (0, import_colors2.dim)("Operation cancelled. Your project folder has been created, but no dependencies have been installed.")
382
+ );
383
+ process.exit(0);
384
+ }
357
385
  }
358
- });
386
+ );
359
387
  if (args.dryRun) {
360
388
  (0, import_ora2.default)().info((0, import_colors2.dim)(`--dry-run enabled, skipping.`));
361
389
  return;
@@ -378,13 +406,22 @@ ${(0, import_colors2.bold)(`[${pkgManager}]`)} ${data}`;
378
406
  ${(0, import_colors2.bold)(`[${pkgManager}]`)} ${data}`;
379
407
  });
380
408
  installExec.on("error", (error) => reject(error));
381
- installExec.on("exit", (code) => reject(`Install failed (code=${code})`));
382
- installExec.on("close", () => resolve());
409
+ installExec.on("close", (code) => {
410
+ if (code !== 0) {
411
+ reject(`Install failed (code=${code})`);
412
+ } else {
413
+ resolve();
414
+ }
415
+ });
383
416
  });
384
417
  installSpinner.text = (0, import_colors2.green)("Packages installed!");
385
418
  installSpinner.succeed();
386
419
  } catch (e) {
387
- installSpinner.text = (0, import_colors2.yellow)(`There was an error installing packages. Try running ${(0, import_colors2.cyan)(`${pkgManager} install`)} in your project directory later.`);
420
+ installSpinner.text = (0, import_colors2.yellow)(
421
+ `There was an error installing packages. Try running ${(0, import_colors2.cyan)(
422
+ `${pkgManager} install`
423
+ )} in your project directory later.`
424
+ );
388
425
  installSpinner.warn();
389
426
  }
390
427
  }
@@ -416,17 +453,20 @@ async function chooseProjectDir(args) {
416
453
  process.exit(0);
417
454
  }
418
455
  } else {
419
- const dirResponse = await (0, import_prompts3.default)({
420
- type: "text",
421
- name: "directory",
422
- message: "Where would you like to create your new project?",
423
- initial: "<current directory>"
424
- }, {
425
- onCancel: () => {
426
- (0, import_ora3.default)().info((0, import_colors3.dim)("Operation cancelled."));
427
- process.exit(0);
456
+ const dirResponse = await (0, import_prompts3.default)(
457
+ {
458
+ type: "text",
459
+ name: "directory",
460
+ message: "Where would you like to create your new project?",
461
+ initial: "<current directory>"
462
+ },
463
+ {
464
+ onCancel: () => {
465
+ (0, import_ora3.default)().info((0, import_colors3.dim)("Operation cancelled."));
466
+ process.exit(0);
467
+ }
428
468
  }
429
- });
469
+ );
430
470
  projDir = dirResponse.directory;
431
471
  if (projDir === "<current directory>") {
432
472
  projDir = process.cwd();
@@ -452,38 +492,49 @@ var version = "2.0.34";
452
492
  async function chooseInstallEmsdk(projDir, args) {
453
493
  const underParentDir = (0, import_path3.resolve)(projDir, "..", "emsdk");
454
494
  const underProjDir = (0, import_path3.join)(projDir, "emsdk");
455
- const installResponse = await (0, import_prompts4.default)({
456
- type: "select",
457
- name: "install",
458
- message: `Would you like to install the Emscripten SDK?`,
459
- choices: [
460
- {
461
- title: `Install under parent directory (${(0, import_colors4.bold)(underParentDir)})`,
462
- description: "This is recommended so that it can be shared by multiple projects",
463
- value: "parent"
464
- },
465
- {
466
- title: `Install under project directory (${(0, import_colors4.bold)(underProjDir)})"`,
467
- description: "This is useful for keeping everything under a single project directory",
468
- value: "project"
469
- },
470
- {
471
- title: `Don't install`,
472
- description: `It's OK, you can install it later`,
473
- value: "skip"
495
+ const installResponse = await (0, import_prompts4.default)(
496
+ {
497
+ type: "select",
498
+ name: "install",
499
+ message: `Would you like to install the Emscripten SDK?`,
500
+ choices: [
501
+ {
502
+ title: `Install under parent directory (${(0, import_colors4.bold)(underParentDir)})`,
503
+ description: "This is recommended so that it can be shared by multiple projects",
504
+ value: "parent"
505
+ },
506
+ {
507
+ title: `Install under project directory (${(0, import_colors4.bold)(underProjDir)})"`,
508
+ description: "This is useful for keeping everything under a single project directory",
509
+ value: "project"
510
+ },
511
+ {
512
+ title: `Don't install`,
513
+ description: `It's OK, you can install it later`,
514
+ value: "skip"
515
+ }
516
+ ]
517
+ },
518
+ {
519
+ onCancel: () => {
520
+ (0, import_ora4.default)().info(
521
+ (0, import_colors4.dim)(
522
+ "Operation cancelled. Your project folder has been created, but the Emscripten SDK and other dependencies have not been installed."
523
+ )
524
+ );
525
+ process.exit(0);
474
526
  }
475
- ]
476
- }, {
477
- onCancel: () => {
478
- (0, import_ora4.default)().info((0, import_colors4.dim)("Operation cancelled. Your project folder has been created, but the Emscripten SDK and other dependencies have not been installed."));
479
- process.exit(0);
480
527
  }
481
- });
528
+ );
482
529
  if (args.dryRun) {
483
530
  (0, import_ora4.default)().info((0, import_colors4.dim)(`--dry-run enabled, skipping.`));
484
531
  return;
485
532
  } else if (installResponse.install === "skip") {
486
- (0, import_ora4.default)().info((0, import_colors4.dim)(`No problem! Be sure to install the Emscripten SDK and configure it in "${(0, import_colors4.cyan)("sde.config.js")}" after setup.`));
533
+ (0, import_ora4.default)().info(
534
+ (0, import_colors4.dim)(
535
+ `No problem! Be sure to install the Emscripten SDK and configure it in "${(0, import_colors4.cyan)("sde.config.js")}" after setup.`
536
+ )
537
+ );
487
538
  return;
488
539
  }
489
540
  const installDir = installResponse.install === "parent" ? underParentDir : underProjDir;
@@ -524,17 +575,20 @@ var import_colors5 = require("kleur/colors");
524
575
  var import_ora5 = __toESM(require("ora"), 1);
525
576
  var import_prompts5 = __toESM(require("prompts"), 1);
526
577
  async function chooseGitInit(projDir, args) {
527
- const gitResponse = await (0, import_prompts5.default)({
528
- type: "confirm",
529
- name: "git",
530
- message: `Would you like to initialize a new git repository? ${(0, import_colors5.reset)((0, import_colors5.dim)("(optional)"))}`,
531
- initial: true
532
- }, {
533
- onCancel: () => {
534
- (0, import_ora5.default)().info((0, import_colors5.dim)("Operation cancelled. Your project folder has already been created."));
535
- process.exit(0);
578
+ const gitResponse = await (0, import_prompts5.default)(
579
+ {
580
+ type: "confirm",
581
+ name: "git",
582
+ message: `Would you like to initialize a new git repository? ${(0, import_colors5.reset)((0, import_colors5.dim)("(optional)"))}`,
583
+ initial: true
584
+ },
585
+ {
586
+ onCancel: () => {
587
+ (0, import_ora5.default)().info((0, import_colors5.dim)("Operation cancelled. Your project folder has already been created."));
588
+ process.exit(0);
589
+ }
536
590
  }
537
- });
591
+ );
538
592
  if (args.dryRun) {
539
593
  (0, import_ora5.default)().info((0, import_colors5.dim)(`--dry-run enabled, skipping.`));
540
594
  return;
@@ -573,10 +627,12 @@ SAVEPER = TIME STEP ~~|
573
627
  async function chooseMdlFile(projDir) {
574
628
  async function getFiles(dir) {
575
629
  const dirents = await (0, import_promises2.readdir)(dir, { withFileTypes: true });
576
- const files = await Promise.all(dirents.map((dirent) => {
577
- const res = (0, import_path4.resolve)(dir, dirent.name);
578
- return dirent.isDirectory() ? getFiles(res) : res;
579
- }));
630
+ const files = await Promise.all(
631
+ dirents.map((dirent) => {
632
+ const res = (0, import_path4.resolve)(dir, dirent.name);
633
+ return dirent.isDirectory() ? getFiles(res) : res;
634
+ })
635
+ );
580
636
  return files.flat();
581
637
  }
582
638
  const allFiles = await getFiles(projDir);
@@ -591,25 +647,34 @@ async function chooseMdlFile(projDir) {
591
647
  if (mdlFiles.length === 0) {
592
648
  const sampleMdlFile = (0, import_path4.join)(projDir, "sample.mdl");
593
649
  await (0, import_promises2.writeFile)(sampleMdlFile, sampleMdlContent);
594
- (0, import_ora6.default)((0, import_colors6.yellow)(`No mdl files were found in "${projDir}". A "${(0, import_colors6.cyan)("sample.mdl")}" file has been added to the project to get you started.`)).warn();
650
+ (0, import_ora6.default)(
651
+ (0, import_colors6.yellow)(
652
+ `No mdl files were found in "${projDir}". A "${(0, import_colors6.cyan)(
653
+ "sample.mdl"
654
+ )}" file has been added to the project to get you started.`
655
+ )
656
+ ).warn();
595
657
  mdlFile = "sample.mdl";
596
658
  } else if (mdlFiles.length === 1) {
597
659
  (0, import_ora6.default)().succeed(`Found "${mdlFiles[0]}", will configure the project to use that mdl file.`);
598
660
  mdlFile = mdlFiles[0];
599
661
  } else {
600
- const options = await (0, import_prompts6.default)([
662
+ const options = await (0, import_prompts6.default)(
663
+ [
664
+ {
665
+ type: "select",
666
+ name: "mdlFile",
667
+ message: "It looks like there are multiple mdl files. Which one would you like to use?",
668
+ choices: mdlChoices
669
+ }
670
+ ],
601
671
  {
602
- type: "select",
603
- name: "mdlFile",
604
- message: "It looks like there are multiple mdl files. Which one would you like to use?",
605
- choices: mdlChoices
606
- }
607
- ], {
608
- onCancel: () => {
609
- (0, import_ora6.default)().info((0, import_colors6.dim)("Operation cancelled."));
610
- process.exit(0);
672
+ onCancel: () => {
673
+ (0, import_ora6.default)().info((0, import_colors6.dim)("Operation cancelled."));
674
+ process.exit(0);
675
+ }
611
676
  }
612
- });
677
+ );
613
678
  mdlFile = options.mdlFile;
614
679
  }
615
680
  (0, import_ora6.default)((0, import_colors6.green)(`Using "${(0, import_colors6.bold)(mdlFile)}" as the model for the project.`)).succeed();
@@ -639,19 +704,22 @@ var TEMPLATES = [
639
704
  }
640
705
  ];
641
706
  async function chooseTemplate(projDir, args, pkgManager) {
642
- const options = await (0, import_prompts7.default)([
707
+ const options = await (0, import_prompts7.default)(
708
+ [
709
+ {
710
+ type: "select",
711
+ name: "template",
712
+ message: "Which template would you like to use?",
713
+ choices: TEMPLATES
714
+ }
715
+ ],
643
716
  {
644
- type: "select",
645
- name: "template",
646
- message: "Which template would you like to use?",
647
- choices: TEMPLATES
648
- }
649
- ], {
650
- onCancel: () => {
651
- (0, import_ora7.default)().info((0, import_colors7.dim)("Operation cancelled."));
652
- process.exit(0);
717
+ onCancel: () => {
718
+ (0, import_ora7.default)().info((0, import_colors7.dim)("Operation cancelled."));
719
+ process.exit(0);
720
+ }
653
721
  }
654
- });
722
+ );
655
723
  if (args.dryRun) {
656
724
  (0, import_ora7.default)().info((0, import_colors7.dim)(`--dry-run enabled, skipping.`));
657
725
  return;
@@ -700,7 +768,11 @@ async function runDegit(templateTarget, hash, dstDir, args, spinner) {
700
768
  spinner.fail();
701
769
  console.error((0, import_colors7.red)(e.message));
702
770
  console.error((0, import_colors7.yellow)("There was a problem copying the template."));
703
- console.error((0, import_colors7.yellow)("Please file a new issue with the command output here: https://github.com/climateinteractive/sdeverywhere/issues"));
771
+ console.error(
772
+ (0, import_colors7.yellow)(
773
+ "Please file a new issue with the command output here: https://github.com/climateinteractive/sdeverywhere/issues"
774
+ )
775
+ );
704
776
  process.exit(0);
705
777
  }
706
778
  }