@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.js CHANGED
@@ -57,7 +57,9 @@ async function chooseGenConfig(projDir, mdlPath) {
57
57
  mdlVars = await readModelVars(projDir, mdlPath);
58
58
  } catch (e) {
59
59
  console.log(e);
60
- ora(yellow("The mdl file failed to load. We will continue setting things up, and you can diagnose the issue later.")).warn();
60
+ ora(
61
+ yellow("The mdl file failed to load. We will continue setting things up, and you can diagnose the issue later.")
62
+ ).warn();
61
63
  return;
62
64
  }
63
65
  let initialTime;
@@ -112,17 +114,20 @@ ${modelCsvLine}
112
114
  await chooseGenSliderConfig(projDir, validVars);
113
115
  }
114
116
  async function chooseGenGraphConfig(projDir, mdlVars) {
115
- const genResponse = await prompts({
116
- type: "confirm",
117
- name: "genGraph",
118
- message: `Would you like to configure a graph to get you started? ${reset(dim("(recommended)"))}`,
119
- initial: true
120
- }, {
121
- onCancel: () => {
122
- ora().info(dim("Operation cancelled."));
123
- process.exit(0);
117
+ const genResponse = await prompts(
118
+ {
119
+ type: "confirm",
120
+ name: "genGraph",
121
+ message: `Would you like to configure a graph to get you started? ${reset(dim("(recommended)"))}`,
122
+ initial: true
123
+ },
124
+ {
125
+ onCancel: () => {
126
+ ora().info(dim("Operation cancelled."));
127
+ process.exit(0);
128
+ }
124
129
  }
125
- });
130
+ );
126
131
  if (!genResponse.genGraph) {
127
132
  ora().info(dim(`No problem! You can edit the "${cyan("config/graphs.csv")}" file later.`));
128
133
  return;
@@ -142,18 +147,21 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
142
147
  value: f
143
148
  };
144
149
  });
145
- const varsResponse = await prompts({
146
- type: "autocompleteMultiselect",
147
- name: "vars",
148
- message: "Choose up to three output variables to display in the graph",
149
- choices,
150
- max: 3
151
- }, {
152
- onCancel: () => {
153
- ora().info(dim("Operation cancelled."));
154
- process.exit(0);
150
+ const varsResponse = await prompts(
151
+ {
152
+ type: "autocompleteMultiselect",
153
+ name: "vars",
154
+ message: "Choose up to three output variables to display in the graph",
155
+ choices,
156
+ max: 3
157
+ },
158
+ {
159
+ onCancel: () => {
160
+ ora().info(dim("Operation cancelled."));
161
+ process.exit(0);
162
+ }
155
163
  }
156
- });
164
+ );
157
165
  if (varsResponse.vars.length === 0) {
158
166
  ora().info(dim(`No variables selected. You can edit the "${cyan("config/graphs.csv")}" file later.`));
159
167
  return;
@@ -164,7 +172,9 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
164
172
  graphsCsvContent += `${csvLine}
165
173
  `;
166
174
  await writeFile(graphsCsvFile, graphsCsvContent);
167
- ora(green(`Added graph to "${bold("config/graphs.csv")}". ${dim("You can configure graphs in that file later.")}`)).succeed();
175
+ ora(
176
+ green(`Added graph to "${bold("config/graphs.csv")}". ${dim("You can configure graphs in that file later.")}`)
177
+ ).succeed();
168
178
  }
169
179
  function graphsCsvLine(outputVarNames) {
170
180
  const colors = ["blue", "red", "green"];
@@ -187,17 +197,20 @@ function graphsCsvLine(outputVarNames) {
187
197
  return a.join(",");
188
198
  }
189
199
  async function chooseGenSliderConfig(projDir, mdlVars) {
190
- const genResponse = await prompts({
191
- type: "confirm",
192
- name: "genSliders",
193
- message: `Would you like to configure a few sliders to get you started? ${reset(dim("(recommended)"))}`,
194
- initial: true
195
- }, {
196
- onCancel: () => {
197
- ora().info(dim("Operation cancelled."));
198
- process.exit(0);
200
+ const genResponse = await prompts(
201
+ {
202
+ type: "confirm",
203
+ name: "genSliders",
204
+ message: `Would you like to configure a few sliders to get you started? ${reset(dim("(recommended)"))}`,
205
+ initial: true
206
+ },
207
+ {
208
+ onCancel: () => {
209
+ ora().info(dim("Operation cancelled."));
210
+ process.exit(0);
211
+ }
199
212
  }
200
- });
213
+ );
201
214
  if (!genResponse.genSliders) {
202
215
  ora().info(dim(`No problem! You can edit the "${cyan("config/inputs.csv")}" file later.`));
203
216
  return;
@@ -217,18 +230,21 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
217
230
  value: f
218
231
  };
219
232
  });
220
- const varsResponse = await prompts({
221
- type: "autocompleteMultiselect",
222
- name: "vars",
223
- message: "Choose up to three input variables to control with sliders",
224
- choices,
225
- max: 3
226
- }, {
227
- onCancel: () => {
228
- ora().info(dim("Operation cancelled."));
229
- process.exit(0);
233
+ const varsResponse = await prompts(
234
+ {
235
+ type: "autocompleteMultiselect",
236
+ name: "vars",
237
+ message: "Choose up to three input variables to control with sliders",
238
+ choices,
239
+ max: 3
240
+ },
241
+ {
242
+ onCancel: () => {
243
+ ora().info(dim("Operation cancelled."));
244
+ process.exit(0);
245
+ }
230
246
  }
231
- });
247
+ );
232
248
  if (varsResponse.vars.length === 0) {
233
249
  ora().info(dim(`No variables selected. You can edit the "${cyan("config/inputs.csv")}" file later.`));
234
250
  return;
@@ -248,7 +264,11 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
248
264
  }
249
265
  await writeFile(inputsCsvFile, inputsCsvContent);
250
266
  const slidersText = varsResponse.vars.length > 1 ? "sliders" : "sliders";
251
- ora(green(`Added ${slidersText} to "${bold("config/inputs.csv")}". ${dim("You can configure sliders in that file later.")}`)).succeed();
267
+ ora(
268
+ green(
269
+ `Added ${slidersText} to "${bold("config/inputs.csv")}". ${dim("You can configure sliders in that file later.")}`
270
+ )
271
+ ).succeed();
252
272
  }
253
273
  function inputsCsvLine(inputVarName, defaultValue, id) {
254
274
  const escapedName = escapeCsvField(inputVarName);
@@ -319,17 +339,22 @@ import { bold as bold2, cyan as cyan2, dim as dim2, green as green2, reset as re
319
339
  import ora2 from "ora";
320
340
  import prompts2 from "prompts";
321
341
  async function chooseInstallDeps(projDir, args, pkgManager) {
322
- const installResponse = await prompts2({
323
- type: "confirm",
324
- name: "install",
325
- message: `Would you like to install ${pkgManager} dependencies? ${reset2(dim2("(recommended)"))}`,
326
- initial: true
327
- }, {
328
- onCancel: () => {
329
- ora2().info(dim2("Operation cancelled. Your project folder has been created, but no dependencies have been installed."));
330
- process.exit(0);
342
+ const installResponse = await prompts2(
343
+ {
344
+ type: "confirm",
345
+ name: "install",
346
+ message: `Would you like to install ${pkgManager} dependencies? ${reset2(dim2("(recommended)"))}`,
347
+ initial: true
348
+ },
349
+ {
350
+ onCancel: () => {
351
+ ora2().info(
352
+ dim2("Operation cancelled. Your project folder has been created, but no dependencies have been installed.")
353
+ );
354
+ process.exit(0);
355
+ }
331
356
  }
332
- });
357
+ );
333
358
  if (args.dryRun) {
334
359
  ora2().info(dim2(`--dry-run enabled, skipping.`));
335
360
  return;
@@ -352,13 +377,22 @@ ${bold2(`[${pkgManager}]`)} ${data}`;
352
377
  ${bold2(`[${pkgManager}]`)} ${data}`;
353
378
  });
354
379
  installExec.on("error", (error) => reject(error));
355
- installExec.on("exit", (code) => reject(`Install failed (code=${code})`));
356
- installExec.on("close", () => resolve());
380
+ installExec.on("close", (code) => {
381
+ if (code !== 0) {
382
+ reject(`Install failed (code=${code})`);
383
+ } else {
384
+ resolve();
385
+ }
386
+ });
357
387
  });
358
388
  installSpinner.text = green2("Packages installed!");
359
389
  installSpinner.succeed();
360
390
  } catch (e) {
361
- installSpinner.text = yellow2(`There was an error installing packages. Try running ${cyan2(`${pkgManager} install`)} in your project directory later.`);
391
+ installSpinner.text = yellow2(
392
+ `There was an error installing packages. Try running ${cyan2(
393
+ `${pkgManager} install`
394
+ )} in your project directory later.`
395
+ );
362
396
  installSpinner.warn();
363
397
  }
364
398
  }
@@ -390,17 +424,20 @@ async function chooseProjectDir(args) {
390
424
  process.exit(0);
391
425
  }
392
426
  } else {
393
- const dirResponse = await prompts3({
394
- type: "text",
395
- name: "directory",
396
- message: "Where would you like to create your new project?",
397
- initial: "<current directory>"
398
- }, {
399
- onCancel: () => {
400
- ora3().info(dim3("Operation cancelled."));
401
- process.exit(0);
427
+ const dirResponse = await prompts3(
428
+ {
429
+ type: "text",
430
+ name: "directory",
431
+ message: "Where would you like to create your new project?",
432
+ initial: "<current directory>"
433
+ },
434
+ {
435
+ onCancel: () => {
436
+ ora3().info(dim3("Operation cancelled."));
437
+ process.exit(0);
438
+ }
402
439
  }
403
- });
440
+ );
404
441
  projDir = dirResponse.directory;
405
442
  if (projDir === "<current directory>") {
406
443
  projDir = process.cwd();
@@ -426,38 +463,49 @@ var version = "2.0.34";
426
463
  async function chooseInstallEmsdk(projDir, args) {
427
464
  const underParentDir = resolvePath3(projDir, "..", "emsdk");
428
465
  const underProjDir = joinPath2(projDir, "emsdk");
429
- const installResponse = await prompts4({
430
- type: "select",
431
- name: "install",
432
- message: `Would you like to install the Emscripten SDK?`,
433
- choices: [
434
- {
435
- title: `Install under parent directory (${bold4(underParentDir)})`,
436
- description: "This is recommended so that it can be shared by multiple projects",
437
- value: "parent"
438
- },
439
- {
440
- title: `Install under project directory (${bold4(underProjDir)})"`,
441
- description: "This is useful for keeping everything under a single project directory",
442
- value: "project"
443
- },
444
- {
445
- title: `Don't install`,
446
- description: `It's OK, you can install it later`,
447
- value: "skip"
466
+ const installResponse = await prompts4(
467
+ {
468
+ type: "select",
469
+ name: "install",
470
+ message: `Would you like to install the Emscripten SDK?`,
471
+ choices: [
472
+ {
473
+ title: `Install under parent directory (${bold4(underParentDir)})`,
474
+ description: "This is recommended so that it can be shared by multiple projects",
475
+ value: "parent"
476
+ },
477
+ {
478
+ title: `Install under project directory (${bold4(underProjDir)})"`,
479
+ description: "This is useful for keeping everything under a single project directory",
480
+ value: "project"
481
+ },
482
+ {
483
+ title: `Don't install`,
484
+ description: `It's OK, you can install it later`,
485
+ value: "skip"
486
+ }
487
+ ]
488
+ },
489
+ {
490
+ onCancel: () => {
491
+ ora4().info(
492
+ dim4(
493
+ "Operation cancelled. Your project folder has been created, but the Emscripten SDK and other dependencies have not been installed."
494
+ )
495
+ );
496
+ process.exit(0);
448
497
  }
449
- ]
450
- }, {
451
- onCancel: () => {
452
- ora4().info(dim4("Operation cancelled. Your project folder has been created, but the Emscripten SDK and other dependencies have not been installed."));
453
- process.exit(0);
454
498
  }
455
- });
499
+ );
456
500
  if (args.dryRun) {
457
501
  ora4().info(dim4(`--dry-run enabled, skipping.`));
458
502
  return;
459
503
  } else if (installResponse.install === "skip") {
460
- ora4().info(dim4(`No problem! Be sure to install the Emscripten SDK and configure it in "${cyan3("sde.config.js")}" after setup.`));
504
+ ora4().info(
505
+ dim4(
506
+ `No problem! Be sure to install the Emscripten SDK and configure it in "${cyan3("sde.config.js")}" after setup.`
507
+ )
508
+ );
461
509
  return;
462
510
  }
463
511
  const installDir = installResponse.install === "parent" ? underParentDir : underProjDir;
@@ -498,17 +546,20 @@ import { cyan as cyan4, dim as dim5, green as green5, reset as reset3 } from "kl
498
546
  import ora5 from "ora";
499
547
  import prompts5 from "prompts";
500
548
  async function chooseGitInit(projDir, args) {
501
- const gitResponse = await prompts5({
502
- type: "confirm",
503
- name: "git",
504
- message: `Would you like to initialize a new git repository? ${reset3(dim5("(optional)"))}`,
505
- initial: true
506
- }, {
507
- onCancel: () => {
508
- ora5().info(dim5("Operation cancelled. Your project folder has already been created."));
509
- process.exit(0);
549
+ const gitResponse = await prompts5(
550
+ {
551
+ type: "confirm",
552
+ name: "git",
553
+ message: `Would you like to initialize a new git repository? ${reset3(dim5("(optional)"))}`,
554
+ initial: true
555
+ },
556
+ {
557
+ onCancel: () => {
558
+ ora5().info(dim5("Operation cancelled. Your project folder has already been created."));
559
+ process.exit(0);
560
+ }
510
561
  }
511
- });
562
+ );
512
563
  if (args.dryRun) {
513
564
  ora5().info(dim5(`--dry-run enabled, skipping.`));
514
565
  return;
@@ -547,10 +598,12 @@ SAVEPER = TIME STEP ~~|
547
598
  async function chooseMdlFile(projDir) {
548
599
  async function getFiles(dir) {
549
600
  const dirents = await readdir(dir, { withFileTypes: true });
550
- const files = await Promise.all(dirents.map((dirent) => {
551
- const res = resolvePath4(dir, dirent.name);
552
- return dirent.isDirectory() ? getFiles(res) : res;
553
- }));
601
+ const files = await Promise.all(
602
+ dirents.map((dirent) => {
603
+ const res = resolvePath4(dir, dirent.name);
604
+ return dirent.isDirectory() ? getFiles(res) : res;
605
+ })
606
+ );
554
607
  return files.flat();
555
608
  }
556
609
  const allFiles = await getFiles(projDir);
@@ -565,25 +618,34 @@ async function chooseMdlFile(projDir) {
565
618
  if (mdlFiles.length === 0) {
566
619
  const sampleMdlFile = joinPath3(projDir, "sample.mdl");
567
620
  await writeFile2(sampleMdlFile, sampleMdlContent);
568
- ora6(yellow3(`No mdl files were found in "${projDir}". A "${cyan5("sample.mdl")}" file has been added to the project to get you started.`)).warn();
621
+ ora6(
622
+ yellow3(
623
+ `No mdl files were found in "${projDir}". A "${cyan5(
624
+ "sample.mdl"
625
+ )}" file has been added to the project to get you started.`
626
+ )
627
+ ).warn();
569
628
  mdlFile = "sample.mdl";
570
629
  } else if (mdlFiles.length === 1) {
571
630
  ora6().succeed(`Found "${mdlFiles[0]}", will configure the project to use that mdl file.`);
572
631
  mdlFile = mdlFiles[0];
573
632
  } else {
574
- const options = await prompts6([
633
+ const options = await prompts6(
634
+ [
635
+ {
636
+ type: "select",
637
+ name: "mdlFile",
638
+ message: "It looks like there are multiple mdl files. Which one would you like to use?",
639
+ choices: mdlChoices
640
+ }
641
+ ],
575
642
  {
576
- type: "select",
577
- name: "mdlFile",
578
- message: "It looks like there are multiple mdl files. Which one would you like to use?",
579
- choices: mdlChoices
580
- }
581
- ], {
582
- onCancel: () => {
583
- ora6().info(dim6("Operation cancelled."));
584
- process.exit(0);
643
+ onCancel: () => {
644
+ ora6().info(dim6("Operation cancelled."));
645
+ process.exit(0);
646
+ }
585
647
  }
586
- });
648
+ );
587
649
  mdlFile = options.mdlFile;
588
650
  }
589
651
  ora6(green6(`Using "${bold5(mdlFile)}" as the model for the project.`)).succeed();
@@ -613,19 +675,22 @@ var TEMPLATES = [
613
675
  }
614
676
  ];
615
677
  async function chooseTemplate(projDir, args, pkgManager) {
616
- const options = await prompts7([
678
+ const options = await prompts7(
679
+ [
680
+ {
681
+ type: "select",
682
+ name: "template",
683
+ message: "Which template would you like to use?",
684
+ choices: TEMPLATES
685
+ }
686
+ ],
617
687
  {
618
- type: "select",
619
- name: "template",
620
- message: "Which template would you like to use?",
621
- choices: TEMPLATES
622
- }
623
- ], {
624
- onCancel: () => {
625
- ora7().info(dim7("Operation cancelled."));
626
- process.exit(0);
688
+ onCancel: () => {
689
+ ora7().info(dim7("Operation cancelled."));
690
+ process.exit(0);
691
+ }
627
692
  }
628
- });
693
+ );
629
694
  if (args.dryRun) {
630
695
  ora7().info(dim7(`--dry-run enabled, skipping.`));
631
696
  return;
@@ -674,7 +739,11 @@ async function runDegit(templateTarget, hash, dstDir, args, spinner) {
674
739
  spinner.fail();
675
740
  console.error(red3(e.message));
676
741
  console.error(yellow4("There was a problem copying the template."));
677
- console.error(yellow4("Please file a new issue with the command output here: https://github.com/climateinteractive/sdeverywhere/issues"));
742
+ console.error(
743
+ yellow4(
744
+ "Please file a new issue with the command output here: https://github.com/climateinteractive/sdeverywhere/issues"
745
+ )
746
+ );
678
747
  process.exit(0);
679
748
  }
680
749
  }