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