@sdeverywhere/create 0.2.13 → 0.2.15
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/bin/create-sde.js +1 -1
- package/dist/index.cjs +167 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +155 -97
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,18 +1,68 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { relative as relative3 } from "path";
|
|
3
|
-
import { bgCyan, black, bold as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import { bgCyan, black, bold as bold7, cyan as cyan6, green as green9 } from "kleur/colors";
|
|
4
|
+
import ora9 from "ora";
|
|
5
|
+
import prompts9 from "prompts";
|
|
6
6
|
import detectPackageManager from "which-pm-runs";
|
|
7
7
|
import yargs from "yargs-parser";
|
|
8
8
|
|
|
9
|
+
// src/step-code-format.ts
|
|
10
|
+
import { bold, dim, green } from "kleur/colors";
|
|
11
|
+
import ora from "ora";
|
|
12
|
+
import prompts from "prompts";
|
|
13
|
+
var promptMessage = `Would you like your project to use WebAssembly?`;
|
|
14
|
+
var noDesc = `* Choose this if you want to get started using SDEverywhere quickly
|
|
15
|
+
and you don't want to install the Emscripten SDK.
|
|
16
|
+
* This will generate a model that uses JavaScript code only, which
|
|
17
|
+
doesn't require extra build tools, but runs slower than WebAssembly.`;
|
|
18
|
+
var yesDesc = `* Choose this if you want this script to install the Emscripten SDK
|
|
19
|
+
for you, or if you already have it installed.
|
|
20
|
+
* This will generate a model that uses WebAssembly, which requires an
|
|
21
|
+
additional build step, but runs faster than pure JavaScript code.`;
|
|
22
|
+
var FORMATS = [
|
|
23
|
+
{
|
|
24
|
+
title: "No, generate a JavaScript model",
|
|
25
|
+
description: noDesc,
|
|
26
|
+
value: "js"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
title: "Yes, generate a WebAssembly model",
|
|
30
|
+
description: yesDesc,
|
|
31
|
+
value: "c"
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
async function chooseCodeFormat() {
|
|
35
|
+
const options = await prompts(
|
|
36
|
+
[
|
|
37
|
+
{
|
|
38
|
+
type: "select",
|
|
39
|
+
name: "format",
|
|
40
|
+
message: promptMessage,
|
|
41
|
+
choices: FORMATS
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
{
|
|
45
|
+
onCancel: () => {
|
|
46
|
+
ora().info(dim("Operation cancelled."));
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
const target = options.format === "c" ? "WebAssembly" : "JavaScript";
|
|
52
|
+
const successMessage = green(
|
|
53
|
+
`Configuring your project to generate ${target}. See "${bold("sde.config.js")}" for details.`
|
|
54
|
+
);
|
|
55
|
+
ora(successMessage).succeed();
|
|
56
|
+
return options.format;
|
|
57
|
+
}
|
|
58
|
+
|
|
9
59
|
// src/step-config.ts
|
|
10
60
|
import { existsSync } from "fs";
|
|
11
61
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
12
62
|
import { dirname, join as joinPath, parse as parsePath, relative, resolve as resolvePath } from "path";
|
|
13
|
-
import { bold, cyan, dim, green, reset, yellow } from "kleur/colors";
|
|
14
|
-
import
|
|
15
|
-
import
|
|
63
|
+
import { bold as bold2, cyan, dim as dim2, green as green2, reset, yellow } from "kleur/colors";
|
|
64
|
+
import ora2 from "ora";
|
|
65
|
+
import prompts2 from "prompts";
|
|
16
66
|
import yaml from "yaml";
|
|
17
67
|
import { parseAndGenerate, preprocessModel } from "@sdeverywhere/compile";
|
|
18
68
|
var sampleCheckContent = `# yaml-language-server: $schema=SCHEMA_PATH
|
|
@@ -30,9 +80,10 @@ var sampleCheckContent = `# yaml-language-server: $schema=SCHEMA_PATH
|
|
|
30
80
|
predicates:
|
|
31
81
|
- gt: 0
|
|
32
82
|
`;
|
|
33
|
-
async function updateSdeConfig(projDir, mdlPath) {
|
|
83
|
+
async function updateSdeConfig(projDir, mdlPath, genFormat) {
|
|
34
84
|
const configPath = joinPath(projDir, "sde.config.js");
|
|
35
85
|
let configText = await readFile(configPath, "utf8");
|
|
86
|
+
configText = configText.replace(`const genFormat = 'js'`, `const genFormat = '${genFormat}'`);
|
|
36
87
|
configText = configText.replaceAll("MODEL_NAME.mdl", mdlPath);
|
|
37
88
|
await writeFile(configPath, configText);
|
|
38
89
|
}
|
|
@@ -57,7 +108,7 @@ async function chooseGenConfig(projDir, mdlPath) {
|
|
|
57
108
|
mdlVars = await readModelVars(projDir, mdlPath);
|
|
58
109
|
} catch (e) {
|
|
59
110
|
console.log(e);
|
|
60
|
-
|
|
111
|
+
ora2(
|
|
61
112
|
yellow("The mdl file failed to load. We will continue setting things up, and you can diagnose the issue later.")
|
|
62
113
|
).warn();
|
|
63
114
|
return;
|
|
@@ -114,22 +165,22 @@ ${modelCsvLine}
|
|
|
114
165
|
await chooseGenSliderConfig(projDir, validVars);
|
|
115
166
|
}
|
|
116
167
|
async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
117
|
-
const genResponse = await
|
|
168
|
+
const genResponse = await prompts2(
|
|
118
169
|
{
|
|
119
170
|
type: "confirm",
|
|
120
171
|
name: "genGraph",
|
|
121
|
-
message: `Would you like to configure a graph to get you started? ${reset(
|
|
172
|
+
message: `Would you like to configure a graph to get you started? ${reset(dim2("(recommended)"))}`,
|
|
122
173
|
initial: true
|
|
123
174
|
},
|
|
124
175
|
{
|
|
125
176
|
onCancel: () => {
|
|
126
|
-
|
|
177
|
+
ora2().info(dim2("Operation cancelled."));
|
|
127
178
|
process.exit(0);
|
|
128
179
|
}
|
|
129
180
|
}
|
|
130
181
|
);
|
|
131
182
|
if (!genResponse.genGraph) {
|
|
132
|
-
|
|
183
|
+
ora2().info(dim2(`No problem! You can edit the "${cyan("config/graphs.csv")}" file later.`));
|
|
133
184
|
return;
|
|
134
185
|
}
|
|
135
186
|
const outputVarNames = [];
|
|
@@ -147,7 +198,7 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
|
147
198
|
value: f
|
|
148
199
|
};
|
|
149
200
|
});
|
|
150
|
-
const varsResponse = await
|
|
201
|
+
const varsResponse = await prompts2(
|
|
151
202
|
{
|
|
152
203
|
type: "autocompleteMultiselect",
|
|
153
204
|
name: "vars",
|
|
@@ -157,13 +208,13 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
|
157
208
|
},
|
|
158
209
|
{
|
|
159
210
|
onCancel: () => {
|
|
160
|
-
|
|
211
|
+
ora2().info(dim2("Operation cancelled."));
|
|
161
212
|
process.exit(0);
|
|
162
213
|
}
|
|
163
214
|
}
|
|
164
215
|
);
|
|
165
216
|
if (varsResponse.vars.length === 0) {
|
|
166
|
-
|
|
217
|
+
ora2().info(dim2(`No variables selected. You can edit the "${cyan("config/graphs.csv")}" file later.`));
|
|
167
218
|
return;
|
|
168
219
|
}
|
|
169
220
|
const graphsCsvFile = joinPath(projDir, "config", "graphs.csv");
|
|
@@ -172,8 +223,8 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
|
172
223
|
graphsCsvContent += `${csvLine}
|
|
173
224
|
`;
|
|
174
225
|
await writeFile(graphsCsvFile, graphsCsvContent);
|
|
175
|
-
|
|
176
|
-
|
|
226
|
+
ora2(
|
|
227
|
+
green2(`Added graph to "${bold2("config/graphs.csv")}". ${dim2("You can configure graphs in that file later.")}`)
|
|
177
228
|
).succeed();
|
|
178
229
|
}
|
|
179
230
|
function graphsCsvLine(outputVarNames) {
|
|
@@ -197,22 +248,22 @@ function graphsCsvLine(outputVarNames) {
|
|
|
197
248
|
return a.join(",");
|
|
198
249
|
}
|
|
199
250
|
async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
200
|
-
const genResponse = await
|
|
251
|
+
const genResponse = await prompts2(
|
|
201
252
|
{
|
|
202
253
|
type: "confirm",
|
|
203
254
|
name: "genSliders",
|
|
204
|
-
message: `Would you like to configure a few sliders to get you started? ${reset(
|
|
255
|
+
message: `Would you like to configure a few sliders to get you started? ${reset(dim2("(recommended)"))}`,
|
|
205
256
|
initial: true
|
|
206
257
|
},
|
|
207
258
|
{
|
|
208
259
|
onCancel: () => {
|
|
209
|
-
|
|
260
|
+
ora2().info(dim2("Operation cancelled."));
|
|
210
261
|
process.exit(0);
|
|
211
262
|
}
|
|
212
263
|
}
|
|
213
264
|
);
|
|
214
265
|
if (!genResponse.genSliders) {
|
|
215
|
-
|
|
266
|
+
ora2().info(dim2(`No problem! You can edit the "${cyan("config/inputs.csv")}" file later.`));
|
|
216
267
|
return;
|
|
217
268
|
}
|
|
218
269
|
const inputVarNames = [];
|
|
@@ -230,7 +281,7 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
|
230
281
|
value: f
|
|
231
282
|
};
|
|
232
283
|
});
|
|
233
|
-
const varsResponse = await
|
|
284
|
+
const varsResponse = await prompts2(
|
|
234
285
|
{
|
|
235
286
|
type: "autocompleteMultiselect",
|
|
236
287
|
name: "vars",
|
|
@@ -240,13 +291,13 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
|
240
291
|
},
|
|
241
292
|
{
|
|
242
293
|
onCancel: () => {
|
|
243
|
-
|
|
294
|
+
ora2().info(dim2("Operation cancelled."));
|
|
244
295
|
process.exit(0);
|
|
245
296
|
}
|
|
246
297
|
}
|
|
247
298
|
);
|
|
248
299
|
if (varsResponse.vars.length === 0) {
|
|
249
|
-
|
|
300
|
+
ora2().info(dim2(`No variables selected. You can edit the "${cyan("config/inputs.csv")}" file later.`));
|
|
250
301
|
return;
|
|
251
302
|
}
|
|
252
303
|
const inputsCsvFile = joinPath(projDir, "config", "inputs.csv");
|
|
@@ -264,9 +315,9 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
|
264
315
|
}
|
|
265
316
|
await writeFile(inputsCsvFile, inputsCsvContent);
|
|
266
317
|
const slidersText = varsResponse.vars.length > 1 ? "sliders" : "sliders";
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
`Added ${slidersText} to "${
|
|
318
|
+
ora2(
|
|
319
|
+
green2(
|
|
320
|
+
`Added ${slidersText} to "${bold2("config/inputs.csv")}". ${dim2("You can configure sliders in that file later.")}`
|
|
270
321
|
)
|
|
271
322
|
).succeed();
|
|
272
323
|
}
|
|
@@ -300,7 +351,7 @@ async function readModelVars(projDir, mdlPath) {
|
|
|
300
351
|
const preprocessed = preprocessModel(
|
|
301
352
|
mdlFile,
|
|
302
353
|
spec,
|
|
303
|
-
"
|
|
354
|
+
"runnable",
|
|
304
355
|
/*writeFiles=*/
|
|
305
356
|
false
|
|
306
357
|
);
|
|
@@ -341,45 +392,45 @@ async function readModelVars(projDir, mdlPath) {
|
|
|
341
392
|
|
|
342
393
|
// src/step-deps.ts
|
|
343
394
|
import { execa } from "execa";
|
|
344
|
-
import { bold as
|
|
345
|
-
import
|
|
346
|
-
import
|
|
395
|
+
import { bold as bold3, cyan as cyan2, dim as dim3, green as green3, reset as reset2, yellow as yellow2 } from "kleur/colors";
|
|
396
|
+
import ora3 from "ora";
|
|
397
|
+
import prompts3 from "prompts";
|
|
347
398
|
async function chooseInstallDeps(projDir, args, pkgManager) {
|
|
348
|
-
const installResponse = await
|
|
399
|
+
const installResponse = await prompts3(
|
|
349
400
|
{
|
|
350
401
|
type: "confirm",
|
|
351
402
|
name: "install",
|
|
352
|
-
message: `Would you like to install ${pkgManager} dependencies? ${reset2(
|
|
403
|
+
message: `Would you like to install ${pkgManager} dependencies? ${reset2(dim3("(recommended)"))}`,
|
|
353
404
|
initial: true
|
|
354
405
|
},
|
|
355
406
|
{
|
|
356
407
|
onCancel: () => {
|
|
357
|
-
|
|
358
|
-
|
|
408
|
+
ora3().info(
|
|
409
|
+
dim3("Operation cancelled. Your project folder has been created, but no dependencies have been installed.")
|
|
359
410
|
);
|
|
360
411
|
process.exit(0);
|
|
361
412
|
}
|
|
362
413
|
}
|
|
363
414
|
);
|
|
364
415
|
if (args.dryRun) {
|
|
365
|
-
|
|
416
|
+
ora3().info(dim3(`--dry-run enabled, skipping.`));
|
|
366
417
|
return;
|
|
367
418
|
} else if (!installResponse.install) {
|
|
368
|
-
|
|
419
|
+
ora3().info(dim3(`No problem! Remember to install dependencies after setup.`));
|
|
369
420
|
return;
|
|
370
421
|
}
|
|
371
422
|
const installExec = execa(pkgManager, ["install"], { cwd: projDir });
|
|
372
423
|
const installingPackagesMsg = "Installing packages...";
|
|
373
|
-
const installSpinner =
|
|
424
|
+
const installSpinner = ora3(installingPackagesMsg).start();
|
|
374
425
|
try {
|
|
375
426
|
await new Promise((resolve, reject) => {
|
|
376
427
|
installExec.stdout?.on("data", function(data) {
|
|
377
428
|
installSpinner.text = `${installingPackagesMsg}
|
|
378
|
-
${
|
|
429
|
+
${bold3(`[${pkgManager}]`)} ${data}`;
|
|
379
430
|
});
|
|
380
431
|
installExec.stderr?.on("data", function(data) {
|
|
381
432
|
installSpinner.text = `${installingPackagesMsg}
|
|
382
|
-
${
|
|
433
|
+
${bold3(`[${pkgManager}]`)} ${data}`;
|
|
383
434
|
});
|
|
384
435
|
installExec.on("error", (error) => reject(error));
|
|
385
436
|
installExec.on("close", (code) => {
|
|
@@ -390,7 +441,7 @@ ${bold2(`[${pkgManager}]`)} ${data}`;
|
|
|
390
441
|
}
|
|
391
442
|
});
|
|
392
443
|
});
|
|
393
|
-
installSpinner.text =
|
|
444
|
+
installSpinner.text = green3("Packages installed!");
|
|
394
445
|
installSpinner.succeed();
|
|
395
446
|
} catch (e) {
|
|
396
447
|
installSpinner.text = yellow2(
|
|
@@ -405,9 +456,9 @@ ${bold2(`[${pkgManager}]`)} ${data}`;
|
|
|
405
456
|
// src/step-directory.ts
|
|
406
457
|
import { existsSync as existsSync2 } from "fs";
|
|
407
458
|
import { resolve as resolvePath2 } from "path";
|
|
408
|
-
import { bold as
|
|
409
|
-
import
|
|
410
|
-
import
|
|
459
|
+
import { bold as bold4, dim as dim4, green as green4, red } from "kleur/colors";
|
|
460
|
+
import ora4 from "ora";
|
|
461
|
+
import prompts4 from "prompts";
|
|
411
462
|
async function chooseProjectDir(args) {
|
|
412
463
|
function isValidDir(dir) {
|
|
413
464
|
const packageJson = resolvePath2(dir, "package.json");
|
|
@@ -415,10 +466,10 @@ async function chooseProjectDir(args) {
|
|
|
415
466
|
return !existsSync2(dir) || !existsSync2(packageJson) && !existsSync2(packagesDir);
|
|
416
467
|
}
|
|
417
468
|
const showValidDirMsg = (dir) => {
|
|
418
|
-
|
|
469
|
+
ora4(green4(`Using "${bold4(dir)}" as the project directory.`)).succeed();
|
|
419
470
|
};
|
|
420
471
|
const showInvalidDirMsg = (dir) => {
|
|
421
|
-
|
|
472
|
+
ora4(red(`"${bold4(dir)}" contains existing 'package.json' and/or 'packages' directory, stopping.`)).fail();
|
|
422
473
|
};
|
|
423
474
|
let projDir = args["_"][2];
|
|
424
475
|
if (projDir) {
|
|
@@ -429,7 +480,7 @@ async function chooseProjectDir(args) {
|
|
|
429
480
|
process.exit(0);
|
|
430
481
|
}
|
|
431
482
|
} else {
|
|
432
|
-
const dirResponse = await
|
|
483
|
+
const dirResponse = await prompts4(
|
|
433
484
|
{
|
|
434
485
|
type: "text",
|
|
435
486
|
name: "directory",
|
|
@@ -447,7 +498,7 @@ async function chooseProjectDir(args) {
|
|
|
447
498
|
},
|
|
448
499
|
{
|
|
449
500
|
onCancel: () => {
|
|
450
|
-
|
|
501
|
+
ora4().info(dim4("Operation cancelled."));
|
|
451
502
|
process.exit(0);
|
|
452
503
|
}
|
|
453
504
|
}
|
|
@@ -470,27 +521,27 @@ async function chooseProjectDir(args) {
|
|
|
470
521
|
import { existsSync as existsSync3, rmSync } from "fs";
|
|
471
522
|
import { join as joinPath2, resolve as resolvePath3 } from "path";
|
|
472
523
|
import { execa as execa2 } from "execa";
|
|
473
|
-
import { bold as
|
|
474
|
-
import
|
|
475
|
-
import
|
|
524
|
+
import { bold as bold5, cyan as cyan3, dim as dim5, green as green5, red as red2 } from "kleur/colors";
|
|
525
|
+
import ora5 from "ora";
|
|
526
|
+
import prompts5 from "prompts";
|
|
476
527
|
var version = "2.0.34";
|
|
477
528
|
async function chooseInstallEmsdk(projDir, args) {
|
|
478
529
|
const underParentDir = resolvePath3(projDir, "..", "emsdk");
|
|
479
530
|
const underProjDir = joinPath2(projDir, "emsdk");
|
|
480
|
-
const installResponse = await
|
|
531
|
+
const installResponse = await prompts5(
|
|
481
532
|
{
|
|
482
533
|
type: "select",
|
|
483
534
|
name: "install",
|
|
484
|
-
message: `Would you like to install the Emscripten SDK?`,
|
|
535
|
+
message: `Would you like to install the Emscripten SDK that is used to generate WebAssembly?`,
|
|
485
536
|
choices: [
|
|
486
537
|
// ${reset(dim('(recommended)'))
|
|
487
538
|
{
|
|
488
|
-
title: `Install under parent directory (${
|
|
539
|
+
title: `Install under parent directory (${bold5(underParentDir)})`,
|
|
489
540
|
description: "This is recommended so that it can be shared by multiple projects",
|
|
490
541
|
value: "parent"
|
|
491
542
|
},
|
|
492
543
|
{
|
|
493
|
-
title: `Install under project directory (${
|
|
544
|
+
title: `Install under project directory (${bold5(underProjDir)})"`,
|
|
494
545
|
description: "This is useful for keeping everything under a single project directory",
|
|
495
546
|
value: "project"
|
|
496
547
|
},
|
|
@@ -503,8 +554,8 @@ async function chooseInstallEmsdk(projDir, args) {
|
|
|
503
554
|
},
|
|
504
555
|
{
|
|
505
556
|
onCancel: () => {
|
|
506
|
-
|
|
507
|
-
|
|
557
|
+
ora5().info(
|
|
558
|
+
dim5(
|
|
508
559
|
"Operation cancelled. Your project folder has been created, but the Emscripten SDK and other dependencies have not been installed."
|
|
509
560
|
)
|
|
510
561
|
);
|
|
@@ -513,11 +564,11 @@ async function chooseInstallEmsdk(projDir, args) {
|
|
|
513
564
|
}
|
|
514
565
|
);
|
|
515
566
|
if (args.dryRun) {
|
|
516
|
-
|
|
567
|
+
ora5().info(dim5(`--dry-run enabled, skipping.`));
|
|
517
568
|
return;
|
|
518
569
|
} else if (installResponse.install === "skip") {
|
|
519
|
-
|
|
520
|
-
|
|
570
|
+
ora5().info(
|
|
571
|
+
dim5(
|
|
521
572
|
`No problem! Be sure to install the Emscripten SDK and configure it in "${cyan3("sde.config.js")}" after setup.`
|
|
522
573
|
)
|
|
523
574
|
);
|
|
@@ -527,10 +578,10 @@ async function chooseInstallEmsdk(projDir, args) {
|
|
|
527
578
|
try {
|
|
528
579
|
await installEmscripten(installDir);
|
|
529
580
|
} catch (e) {
|
|
530
|
-
|
|
581
|
+
ora5(red2(`Failed to install Emscripten SDK: ${e.message}`)).fail();
|
|
531
582
|
process.exit(0);
|
|
532
583
|
}
|
|
533
|
-
|
|
584
|
+
ora5(green5(`Installed the Emscripten SDK in "${bold5(installDir)}"`)).succeed();
|
|
534
585
|
}
|
|
535
586
|
async function installEmscripten(emsdkDir) {
|
|
536
587
|
if (!existsSync3(emsdkDir)) {
|
|
@@ -557,36 +608,36 @@ async function installEmscripten(emsdkDir) {
|
|
|
557
608
|
|
|
558
609
|
// src/step-git.ts
|
|
559
610
|
import { execaCommand } from "execa";
|
|
560
|
-
import { cyan as cyan4, dim as
|
|
561
|
-
import
|
|
562
|
-
import
|
|
611
|
+
import { cyan as cyan4, dim as dim6, green as green6, reset as reset3, yellow as yellow3 } from "kleur/colors";
|
|
612
|
+
import ora6 from "ora";
|
|
613
|
+
import prompts6 from "prompts";
|
|
563
614
|
async function chooseGitInit(projDir, args) {
|
|
564
|
-
const gitResponse = await
|
|
615
|
+
const gitResponse = await prompts6(
|
|
565
616
|
{
|
|
566
617
|
type: "confirm",
|
|
567
618
|
name: "git",
|
|
568
|
-
message: `Would you like to initialize a new git repository? ${reset3(
|
|
619
|
+
message: `Would you like to initialize a new git repository? ${reset3(dim6("(optional)"))}`,
|
|
569
620
|
initial: true
|
|
570
621
|
},
|
|
571
622
|
{
|
|
572
623
|
onCancel: () => {
|
|
573
|
-
|
|
624
|
+
ora6().info(dim6("Operation cancelled. Your project folder has already been created."));
|
|
574
625
|
process.exit(0);
|
|
575
626
|
}
|
|
576
627
|
}
|
|
577
628
|
);
|
|
578
629
|
if (args.dryRun) {
|
|
579
|
-
|
|
630
|
+
ora6().info(dim6(`--dry-run enabled, skipping.`));
|
|
580
631
|
return;
|
|
581
632
|
} else if (!gitResponse.git) {
|
|
582
|
-
|
|
633
|
+
ora6().info(dim6(`No problem! You can come back and run ${cyan4(`git init`)} later.`));
|
|
583
634
|
return;
|
|
584
635
|
}
|
|
585
636
|
try {
|
|
586
637
|
await execaCommand("git init", { cwd: projDir });
|
|
587
|
-
|
|
638
|
+
ora6().succeed(green6("Git repository initialized!"));
|
|
588
639
|
} catch (e) {
|
|
589
|
-
|
|
640
|
+
ora6().warn(
|
|
590
641
|
yellow3(
|
|
591
642
|
`There was a problem initializing the Git repository, but no problem, you can run ${cyan4(`git init`)} later.`
|
|
592
643
|
)
|
|
@@ -597,9 +648,9 @@ async function chooseGitInit(projDir, args) {
|
|
|
597
648
|
// src/step-mdl.ts
|
|
598
649
|
import { readdir, writeFile as writeFile2 } from "fs/promises";
|
|
599
650
|
import { join as joinPath3, relative as relative2, resolve as resolvePath4 } from "path";
|
|
600
|
-
import { bold as
|
|
601
|
-
import
|
|
602
|
-
import
|
|
651
|
+
import { bold as bold6, cyan as cyan5, dim as dim7, green as green7, yellow as yellow4 } from "kleur/colors";
|
|
652
|
+
import ora7 from "ora";
|
|
653
|
+
import prompts7 from "prompts";
|
|
603
654
|
var sampleMdlContent = `{UTF-8}
|
|
604
655
|
|
|
605
656
|
X = TIME
|
|
@@ -641,7 +692,7 @@ async function chooseMdlFile(projDir) {
|
|
|
641
692
|
if (mdlFiles.length === 0) {
|
|
642
693
|
const sampleMdlFile = joinPath3(projDir, "sample.mdl");
|
|
643
694
|
await writeFile2(sampleMdlFile, sampleMdlContent);
|
|
644
|
-
|
|
695
|
+
ora7(
|
|
645
696
|
yellow4(
|
|
646
697
|
`No mdl files were found in "${projDir}". A "${cyan5(
|
|
647
698
|
"sample.mdl"
|
|
@@ -650,10 +701,10 @@ async function chooseMdlFile(projDir) {
|
|
|
650
701
|
).warn();
|
|
651
702
|
mdlFile = "sample.mdl";
|
|
652
703
|
} else if (mdlFiles.length === 1) {
|
|
653
|
-
|
|
704
|
+
ora7().succeed(`Found "${mdlFiles[0]}", will configure the project to use that mdl file.`);
|
|
654
705
|
mdlFile = mdlFiles[0];
|
|
655
706
|
} else {
|
|
656
|
-
const options = await
|
|
707
|
+
const options = await prompts7(
|
|
657
708
|
[
|
|
658
709
|
{
|
|
659
710
|
type: "select",
|
|
@@ -664,14 +715,14 @@ async function chooseMdlFile(projDir) {
|
|
|
664
715
|
],
|
|
665
716
|
{
|
|
666
717
|
onCancel: () => {
|
|
667
|
-
|
|
718
|
+
ora7().info(dim7("Operation cancelled."));
|
|
668
719
|
process.exit(0);
|
|
669
720
|
}
|
|
670
721
|
}
|
|
671
722
|
);
|
|
672
723
|
mdlFile = options.mdlFile;
|
|
673
724
|
}
|
|
674
|
-
|
|
725
|
+
ora7(green7(`Using "${bold6(mdlFile)}" as the model for the project.`)).succeed();
|
|
675
726
|
return mdlFile;
|
|
676
727
|
}
|
|
677
728
|
|
|
@@ -682,9 +733,9 @@ import { copy } from "fs-extra";
|
|
|
682
733
|
import { tmpdir } from "os";
|
|
683
734
|
import { join as joinPath4 } from "path";
|
|
684
735
|
import { downloadTemplate } from "giget";
|
|
685
|
-
import { dim as
|
|
686
|
-
import
|
|
687
|
-
import
|
|
736
|
+
import { dim as dim8, green as green8, red as red3, yellow as yellow5 } from "kleur/colors";
|
|
737
|
+
import ora8 from "ora";
|
|
738
|
+
import prompts8 from "prompts";
|
|
688
739
|
var TEMPLATES = [
|
|
689
740
|
{
|
|
690
741
|
title: "Default project",
|
|
@@ -698,7 +749,7 @@ var TEMPLATES = [
|
|
|
698
749
|
}
|
|
699
750
|
];
|
|
700
751
|
async function chooseTemplate(projDir, args, pkgManager) {
|
|
701
|
-
const options = await
|
|
752
|
+
const options = await prompts8(
|
|
702
753
|
[
|
|
703
754
|
{
|
|
704
755
|
type: "select",
|
|
@@ -709,21 +760,21 @@ async function chooseTemplate(projDir, args, pkgManager) {
|
|
|
709
760
|
],
|
|
710
761
|
{
|
|
711
762
|
onCancel: () => {
|
|
712
|
-
|
|
763
|
+
ora8().info(dim8("Operation cancelled."));
|
|
713
764
|
process.exit(0);
|
|
714
765
|
}
|
|
715
766
|
}
|
|
716
767
|
);
|
|
717
768
|
if (args.dryRun) {
|
|
718
|
-
|
|
769
|
+
ora8().info(dim8(`--dry-run enabled, skipping.`));
|
|
719
770
|
return;
|
|
720
771
|
}
|
|
721
772
|
const defaultRev = "main";
|
|
722
773
|
const commit = args.commit || defaultRev;
|
|
723
774
|
const templateTarget = `climateinteractive/SDEverywhere/examples/${options.template}#${commit}`;
|
|
724
|
-
const templateSpinner =
|
|
775
|
+
const templateSpinner = ora8("Copying project files...").start();
|
|
725
776
|
await copyTemplate(templateTarget, projDir, templateSpinner);
|
|
726
|
-
templateSpinner.text =
|
|
777
|
+
templateSpinner.text = green8("Template copied!");
|
|
727
778
|
templateSpinner.succeed();
|
|
728
779
|
if (options.template === "template-default" && pkgManager === "pnpm") {
|
|
729
780
|
const workspaceFile = joinPath4(projDir, "pnpm-workspace.yaml");
|
|
@@ -767,9 +818,9 @@ async function copyTemplate(templateTarget, dstDir, spinner) {
|
|
|
767
818
|
async function main() {
|
|
768
819
|
const pkgManager = detectPackageManager()?.name || "npm";
|
|
769
820
|
const args = yargs(process.argv);
|
|
770
|
-
|
|
821
|
+
prompts9.override(args);
|
|
771
822
|
console.log(`
|
|
772
|
-
${
|
|
823
|
+
${bold7("Welcome to SDEverywhere!")}`);
|
|
773
824
|
console.log(`Let's create a new SDEverywhere project for your model.
|
|
774
825
|
`);
|
|
775
826
|
const projDir = await chooseProjectDir(args);
|
|
@@ -777,29 +828,36 @@ ${bold6("Welcome to SDEverywhere!")}`);
|
|
|
777
828
|
const templateName = await chooseTemplate(projDir, args, pkgManager);
|
|
778
829
|
console.log();
|
|
779
830
|
const mdlPath = await chooseMdlFile(projDir);
|
|
780
|
-
await updateSdeConfig(projDir, mdlPath);
|
|
781
|
-
await generateCheckYaml(projDir, mdlPath);
|
|
782
831
|
console.log();
|
|
832
|
+
const genFormat = await chooseCodeFormat();
|
|
833
|
+
console.log();
|
|
834
|
+
if (!args.dryRun) {
|
|
835
|
+
await updateSdeConfig(projDir, mdlPath, genFormat);
|
|
836
|
+
await generateCheckYaml(projDir, mdlPath);
|
|
837
|
+
console.log();
|
|
838
|
+
}
|
|
783
839
|
if (templateName === "template-default" && !args.dryRun) {
|
|
784
840
|
await chooseGenConfig(projDir, mdlPath);
|
|
785
841
|
console.log();
|
|
786
842
|
}
|
|
787
|
-
|
|
788
|
-
|
|
843
|
+
if (genFormat === "c") {
|
|
844
|
+
await chooseInstallEmsdk(projDir, args);
|
|
845
|
+
console.log();
|
|
846
|
+
}
|
|
789
847
|
await chooseInstallDeps(projDir, args, pkgManager);
|
|
790
848
|
console.log();
|
|
791
849
|
await chooseGitInit(projDir, args);
|
|
792
850
|
console.log();
|
|
793
|
-
|
|
851
|
+
ora9(green9("Setup complete!")).succeed();
|
|
794
852
|
console.log(`
|
|
795
853
|
${bgCyan(black(" Next steps "))}
|
|
796
854
|
`);
|
|
797
855
|
const relProjDir = relative3(process.cwd(), projDir);
|
|
798
856
|
const devCmd = pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`;
|
|
799
857
|
if (relProjDir !== "") {
|
|
800
|
-
console.log(`You can now ${
|
|
858
|
+
console.log(`You can now ${bold7(cyan6("cd"))} into the ${bold7(cyan6(relProjDir))} project directory.`);
|
|
801
859
|
}
|
|
802
|
-
console.log(`Run ${
|
|
860
|
+
console.log(`Run ${bold7(cyan6(devCmd))} to start the local dev server. ${bold7(cyan6("CTRL-C"))} to close.`);
|
|
803
861
|
console.log("");
|
|
804
862
|
}
|
|
805
863
|
export {
|