@sdeverywhere/create 0.2.14 → 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/bin/create-sde.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
const currentVersion = process.versions.node
|
|
5
5
|
const requiredMajorVersion = parseInt(currentVersion.split('.')[0], 10)
|
|
6
|
-
const minimumMajorVersion =
|
|
6
|
+
const minimumMajorVersion = 18
|
|
7
7
|
|
|
8
8
|
if (requiredMajorVersion < minimumMajorVersion) {
|
|
9
9
|
console.error(`Node.js v${currentVersion} is not supported by SDEverywhere.`)
|
package/dist/index.cjs
CHANGED
|
@@ -33,19 +33,69 @@ __export(src_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(src_exports);
|
|
35
35
|
var import_path6 = require("path");
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
36
|
+
var import_colors9 = require("kleur/colors");
|
|
37
|
+
var import_ora9 = __toESM(require("ora"), 1);
|
|
38
|
+
var import_prompts9 = __toESM(require("prompts"), 1);
|
|
39
39
|
var import_which_pm_runs = __toESM(require("which-pm-runs"), 1);
|
|
40
40
|
var import_yargs_parser = __toESM(require("yargs-parser"), 1);
|
|
41
41
|
|
|
42
|
+
// src/step-code-format.ts
|
|
43
|
+
var import_colors = require("kleur/colors");
|
|
44
|
+
var import_ora = __toESM(require("ora"), 1);
|
|
45
|
+
var import_prompts = __toESM(require("prompts"), 1);
|
|
46
|
+
var promptMessage = `Would you like your project to use WebAssembly?`;
|
|
47
|
+
var noDesc = `* Choose this if you want to get started using SDEverywhere quickly
|
|
48
|
+
and you don't want to install the Emscripten SDK.
|
|
49
|
+
* This will generate a model that uses JavaScript code only, which
|
|
50
|
+
doesn't require extra build tools, but runs slower than WebAssembly.`;
|
|
51
|
+
var yesDesc = `* Choose this if you want this script to install the Emscripten SDK
|
|
52
|
+
for you, or if you already have it installed.
|
|
53
|
+
* This will generate a model that uses WebAssembly, which requires an
|
|
54
|
+
additional build step, but runs faster than pure JavaScript code.`;
|
|
55
|
+
var FORMATS = [
|
|
56
|
+
{
|
|
57
|
+
title: "No, generate a JavaScript model",
|
|
58
|
+
description: noDesc,
|
|
59
|
+
value: "js"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
title: "Yes, generate a WebAssembly model",
|
|
63
|
+
description: yesDesc,
|
|
64
|
+
value: "c"
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
async function chooseCodeFormat() {
|
|
68
|
+
const options = await (0, import_prompts.default)(
|
|
69
|
+
[
|
|
70
|
+
{
|
|
71
|
+
type: "select",
|
|
72
|
+
name: "format",
|
|
73
|
+
message: promptMessage,
|
|
74
|
+
choices: FORMATS
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
{
|
|
78
|
+
onCancel: () => {
|
|
79
|
+
(0, import_ora.default)().info((0, import_colors.dim)("Operation cancelled."));
|
|
80
|
+
process.exit(0);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
const target = options.format === "c" ? "WebAssembly" : "JavaScript";
|
|
85
|
+
const successMessage = (0, import_colors.green)(
|
|
86
|
+
`Configuring your project to generate ${target}. See "${(0, import_colors.bold)("sde.config.js")}" for details.`
|
|
87
|
+
);
|
|
88
|
+
(0, import_ora.default)(successMessage).succeed();
|
|
89
|
+
return options.format;
|
|
90
|
+
}
|
|
91
|
+
|
|
42
92
|
// src/step-config.ts
|
|
43
93
|
var import_fs = require("fs");
|
|
44
94
|
var import_promises = require("fs/promises");
|
|
45
95
|
var import_path = require("path");
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
var
|
|
96
|
+
var import_colors2 = require("kleur/colors");
|
|
97
|
+
var import_ora2 = __toESM(require("ora"), 1);
|
|
98
|
+
var import_prompts2 = __toESM(require("prompts"), 1);
|
|
49
99
|
var import_yaml = __toESM(require("yaml"), 1);
|
|
50
100
|
var import_compile = require("@sdeverywhere/compile");
|
|
51
101
|
var sampleCheckContent = `# yaml-language-server: $schema=SCHEMA_PATH
|
|
@@ -63,9 +113,10 @@ var sampleCheckContent = `# yaml-language-server: $schema=SCHEMA_PATH
|
|
|
63
113
|
predicates:
|
|
64
114
|
- gt: 0
|
|
65
115
|
`;
|
|
66
|
-
async function updateSdeConfig(projDir, mdlPath) {
|
|
116
|
+
async function updateSdeConfig(projDir, mdlPath, genFormat) {
|
|
67
117
|
const configPath = (0, import_path.join)(projDir, "sde.config.js");
|
|
68
118
|
let configText = await (0, import_promises.readFile)(configPath, "utf8");
|
|
119
|
+
configText = configText.replace(`const genFormat = 'js'`, `const genFormat = '${genFormat}'`);
|
|
69
120
|
configText = configText.replaceAll("MODEL_NAME.mdl", mdlPath);
|
|
70
121
|
await (0, import_promises.writeFile)(configPath, configText);
|
|
71
122
|
}
|
|
@@ -90,8 +141,8 @@ async function chooseGenConfig(projDir, mdlPath) {
|
|
|
90
141
|
mdlVars = await readModelVars(projDir, mdlPath);
|
|
91
142
|
} catch (e) {
|
|
92
143
|
console.log(e);
|
|
93
|
-
(0,
|
|
94
|
-
(0,
|
|
144
|
+
(0, import_ora2.default)(
|
|
145
|
+
(0, import_colors2.yellow)("The mdl file failed to load. We will continue setting things up, and you can diagnose the issue later.")
|
|
95
146
|
).warn();
|
|
96
147
|
return;
|
|
97
148
|
}
|
|
@@ -147,22 +198,22 @@ ${modelCsvLine}
|
|
|
147
198
|
await chooseGenSliderConfig(projDir, validVars);
|
|
148
199
|
}
|
|
149
200
|
async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
150
|
-
const genResponse = await (0,
|
|
201
|
+
const genResponse = await (0, import_prompts2.default)(
|
|
151
202
|
{
|
|
152
203
|
type: "confirm",
|
|
153
204
|
name: "genGraph",
|
|
154
|
-
message: `Would you like to configure a graph to get you started? ${(0,
|
|
205
|
+
message: `Would you like to configure a graph to get you started? ${(0, import_colors2.reset)((0, import_colors2.dim)("(recommended)"))}`,
|
|
155
206
|
initial: true
|
|
156
207
|
},
|
|
157
208
|
{
|
|
158
209
|
onCancel: () => {
|
|
159
|
-
(0,
|
|
210
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)("Operation cancelled."));
|
|
160
211
|
process.exit(0);
|
|
161
212
|
}
|
|
162
213
|
}
|
|
163
214
|
);
|
|
164
215
|
if (!genResponse.genGraph) {
|
|
165
|
-
(0,
|
|
216
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)(`No problem! You can edit the "${(0, import_colors2.cyan)("config/graphs.csv")}" file later.`));
|
|
166
217
|
return;
|
|
167
218
|
}
|
|
168
219
|
const outputVarNames = [];
|
|
@@ -180,7 +231,7 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
|
180
231
|
value: f
|
|
181
232
|
};
|
|
182
233
|
});
|
|
183
|
-
const varsResponse = await (0,
|
|
234
|
+
const varsResponse = await (0, import_prompts2.default)(
|
|
184
235
|
{
|
|
185
236
|
type: "autocompleteMultiselect",
|
|
186
237
|
name: "vars",
|
|
@@ -190,13 +241,13 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
|
190
241
|
},
|
|
191
242
|
{
|
|
192
243
|
onCancel: () => {
|
|
193
|
-
(0,
|
|
244
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)("Operation cancelled."));
|
|
194
245
|
process.exit(0);
|
|
195
246
|
}
|
|
196
247
|
}
|
|
197
248
|
);
|
|
198
249
|
if (varsResponse.vars.length === 0) {
|
|
199
|
-
(0,
|
|
250
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)(`No variables selected. You can edit the "${(0, import_colors2.cyan)("config/graphs.csv")}" file later.`));
|
|
200
251
|
return;
|
|
201
252
|
}
|
|
202
253
|
const graphsCsvFile = (0, import_path.join)(projDir, "config", "graphs.csv");
|
|
@@ -205,8 +256,8 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
|
205
256
|
graphsCsvContent += `${csvLine}
|
|
206
257
|
`;
|
|
207
258
|
await (0, import_promises.writeFile)(graphsCsvFile, graphsCsvContent);
|
|
208
|
-
(0,
|
|
209
|
-
(0,
|
|
259
|
+
(0, import_ora2.default)(
|
|
260
|
+
(0, import_colors2.green)(`Added graph to "${(0, import_colors2.bold)("config/graphs.csv")}". ${(0, import_colors2.dim)("You can configure graphs in that file later.")}`)
|
|
210
261
|
).succeed();
|
|
211
262
|
}
|
|
212
263
|
function graphsCsvLine(outputVarNames) {
|
|
@@ -230,22 +281,22 @@ function graphsCsvLine(outputVarNames) {
|
|
|
230
281
|
return a.join(",");
|
|
231
282
|
}
|
|
232
283
|
async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
233
|
-
const genResponse = await (0,
|
|
284
|
+
const genResponse = await (0, import_prompts2.default)(
|
|
234
285
|
{
|
|
235
286
|
type: "confirm",
|
|
236
287
|
name: "genSliders",
|
|
237
|
-
message: `Would you like to configure a few sliders to get you started? ${(0,
|
|
288
|
+
message: `Would you like to configure a few sliders to get you started? ${(0, import_colors2.reset)((0, import_colors2.dim)("(recommended)"))}`,
|
|
238
289
|
initial: true
|
|
239
290
|
},
|
|
240
291
|
{
|
|
241
292
|
onCancel: () => {
|
|
242
|
-
(0,
|
|
293
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)("Operation cancelled."));
|
|
243
294
|
process.exit(0);
|
|
244
295
|
}
|
|
245
296
|
}
|
|
246
297
|
);
|
|
247
298
|
if (!genResponse.genSliders) {
|
|
248
|
-
(0,
|
|
299
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)(`No problem! You can edit the "${(0, import_colors2.cyan)("config/inputs.csv")}" file later.`));
|
|
249
300
|
return;
|
|
250
301
|
}
|
|
251
302
|
const inputVarNames = [];
|
|
@@ -263,7 +314,7 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
|
263
314
|
value: f
|
|
264
315
|
};
|
|
265
316
|
});
|
|
266
|
-
const varsResponse = await (0,
|
|
317
|
+
const varsResponse = await (0, import_prompts2.default)(
|
|
267
318
|
{
|
|
268
319
|
type: "autocompleteMultiselect",
|
|
269
320
|
name: "vars",
|
|
@@ -273,13 +324,13 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
|
273
324
|
},
|
|
274
325
|
{
|
|
275
326
|
onCancel: () => {
|
|
276
|
-
(0,
|
|
327
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)("Operation cancelled."));
|
|
277
328
|
process.exit(0);
|
|
278
329
|
}
|
|
279
330
|
}
|
|
280
331
|
);
|
|
281
332
|
if (varsResponse.vars.length === 0) {
|
|
282
|
-
(0,
|
|
333
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)(`No variables selected. You can edit the "${(0, import_colors2.cyan)("config/inputs.csv")}" file later.`));
|
|
283
334
|
return;
|
|
284
335
|
}
|
|
285
336
|
const inputsCsvFile = (0, import_path.join)(projDir, "config", "inputs.csv");
|
|
@@ -297,9 +348,9 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
|
297
348
|
}
|
|
298
349
|
await (0, import_promises.writeFile)(inputsCsvFile, inputsCsvContent);
|
|
299
350
|
const slidersText = varsResponse.vars.length > 1 ? "sliders" : "sliders";
|
|
300
|
-
(0,
|
|
301
|
-
(0,
|
|
302
|
-
`Added ${slidersText} to "${(0,
|
|
351
|
+
(0, import_ora2.default)(
|
|
352
|
+
(0, import_colors2.green)(
|
|
353
|
+
`Added ${slidersText} to "${(0, import_colors2.bold)("config/inputs.csv")}". ${(0, import_colors2.dim)("You can configure sliders in that file later.")}`
|
|
303
354
|
)
|
|
304
355
|
).succeed();
|
|
305
356
|
}
|
|
@@ -333,7 +384,7 @@ async function readModelVars(projDir, mdlPath) {
|
|
|
333
384
|
const preprocessed = (0, import_compile.preprocessModel)(
|
|
334
385
|
mdlFile,
|
|
335
386
|
spec,
|
|
336
|
-
"
|
|
387
|
+
"runnable",
|
|
337
388
|
/*writeFiles=*/
|
|
338
389
|
false
|
|
339
390
|
);
|
|
@@ -374,45 +425,45 @@ async function readModelVars(projDir, mdlPath) {
|
|
|
374
425
|
|
|
375
426
|
// src/step-deps.ts
|
|
376
427
|
var import_execa = require("execa");
|
|
377
|
-
var
|
|
378
|
-
var
|
|
379
|
-
var
|
|
428
|
+
var import_colors3 = require("kleur/colors");
|
|
429
|
+
var import_ora3 = __toESM(require("ora"), 1);
|
|
430
|
+
var import_prompts3 = __toESM(require("prompts"), 1);
|
|
380
431
|
async function chooseInstallDeps(projDir, args, pkgManager) {
|
|
381
|
-
const installResponse = await (0,
|
|
432
|
+
const installResponse = await (0, import_prompts3.default)(
|
|
382
433
|
{
|
|
383
434
|
type: "confirm",
|
|
384
435
|
name: "install",
|
|
385
|
-
message: `Would you like to install ${pkgManager} dependencies? ${(0,
|
|
436
|
+
message: `Would you like to install ${pkgManager} dependencies? ${(0, import_colors3.reset)((0, import_colors3.dim)("(recommended)"))}`,
|
|
386
437
|
initial: true
|
|
387
438
|
},
|
|
388
439
|
{
|
|
389
440
|
onCancel: () => {
|
|
390
|
-
(0,
|
|
391
|
-
(0,
|
|
441
|
+
(0, import_ora3.default)().info(
|
|
442
|
+
(0, import_colors3.dim)("Operation cancelled. Your project folder has been created, but no dependencies have been installed.")
|
|
392
443
|
);
|
|
393
444
|
process.exit(0);
|
|
394
445
|
}
|
|
395
446
|
}
|
|
396
447
|
);
|
|
397
448
|
if (args.dryRun) {
|
|
398
|
-
(0,
|
|
449
|
+
(0, import_ora3.default)().info((0, import_colors3.dim)(`--dry-run enabled, skipping.`));
|
|
399
450
|
return;
|
|
400
451
|
} else if (!installResponse.install) {
|
|
401
|
-
(0,
|
|
452
|
+
(0, import_ora3.default)().info((0, import_colors3.dim)(`No problem! Remember to install dependencies after setup.`));
|
|
402
453
|
return;
|
|
403
454
|
}
|
|
404
455
|
const installExec = (0, import_execa.execa)(pkgManager, ["install"], { cwd: projDir });
|
|
405
456
|
const installingPackagesMsg = "Installing packages...";
|
|
406
|
-
const installSpinner = (0,
|
|
457
|
+
const installSpinner = (0, import_ora3.default)(installingPackagesMsg).start();
|
|
407
458
|
try {
|
|
408
459
|
await new Promise((resolve, reject) => {
|
|
409
460
|
installExec.stdout?.on("data", function(data) {
|
|
410
461
|
installSpinner.text = `${installingPackagesMsg}
|
|
411
|
-
${(0,
|
|
462
|
+
${(0, import_colors3.bold)(`[${pkgManager}]`)} ${data}`;
|
|
412
463
|
});
|
|
413
464
|
installExec.stderr?.on("data", function(data) {
|
|
414
465
|
installSpinner.text = `${installingPackagesMsg}
|
|
415
|
-
${(0,
|
|
466
|
+
${(0, import_colors3.bold)(`[${pkgManager}]`)} ${data}`;
|
|
416
467
|
});
|
|
417
468
|
installExec.on("error", (error) => reject(error));
|
|
418
469
|
installExec.on("close", (code) => {
|
|
@@ -423,11 +474,11 @@ ${(0, import_colors2.bold)(`[${pkgManager}]`)} ${data}`;
|
|
|
423
474
|
}
|
|
424
475
|
});
|
|
425
476
|
});
|
|
426
|
-
installSpinner.text = (0,
|
|
477
|
+
installSpinner.text = (0, import_colors3.green)("Packages installed!");
|
|
427
478
|
installSpinner.succeed();
|
|
428
479
|
} catch (e) {
|
|
429
|
-
installSpinner.text = (0,
|
|
430
|
-
`There was an error installing packages. Try running ${(0,
|
|
480
|
+
installSpinner.text = (0, import_colors3.yellow)(
|
|
481
|
+
`There was an error installing packages. Try running ${(0, import_colors3.cyan)(
|
|
431
482
|
`${pkgManager} install`
|
|
432
483
|
)} in your project directory later.`
|
|
433
484
|
);
|
|
@@ -438,9 +489,9 @@ ${(0, import_colors2.bold)(`[${pkgManager}]`)} ${data}`;
|
|
|
438
489
|
// src/step-directory.ts
|
|
439
490
|
var import_fs2 = require("fs");
|
|
440
491
|
var import_path2 = require("path");
|
|
441
|
-
var
|
|
442
|
-
var
|
|
443
|
-
var
|
|
492
|
+
var import_colors4 = require("kleur/colors");
|
|
493
|
+
var import_ora4 = __toESM(require("ora"), 1);
|
|
494
|
+
var import_prompts4 = __toESM(require("prompts"), 1);
|
|
444
495
|
async function chooseProjectDir(args) {
|
|
445
496
|
function isValidDir(dir) {
|
|
446
497
|
const packageJson = (0, import_path2.resolve)(dir, "package.json");
|
|
@@ -448,10 +499,10 @@ async function chooseProjectDir(args) {
|
|
|
448
499
|
return !(0, import_fs2.existsSync)(dir) || !(0, import_fs2.existsSync)(packageJson) && !(0, import_fs2.existsSync)(packagesDir);
|
|
449
500
|
}
|
|
450
501
|
const showValidDirMsg = (dir) => {
|
|
451
|
-
(0,
|
|
502
|
+
(0, import_ora4.default)((0, import_colors4.green)(`Using "${(0, import_colors4.bold)(dir)}" as the project directory.`)).succeed();
|
|
452
503
|
};
|
|
453
504
|
const showInvalidDirMsg = (dir) => {
|
|
454
|
-
(0,
|
|
505
|
+
(0, import_ora4.default)((0, import_colors4.red)(`"${(0, import_colors4.bold)(dir)}" contains existing 'package.json' and/or 'packages' directory, stopping.`)).fail();
|
|
455
506
|
};
|
|
456
507
|
let projDir = args["_"][2];
|
|
457
508
|
if (projDir) {
|
|
@@ -462,7 +513,7 @@ async function chooseProjectDir(args) {
|
|
|
462
513
|
process.exit(0);
|
|
463
514
|
}
|
|
464
515
|
} else {
|
|
465
|
-
const dirResponse = await (0,
|
|
516
|
+
const dirResponse = await (0, import_prompts4.default)(
|
|
466
517
|
{
|
|
467
518
|
type: "text",
|
|
468
519
|
name: "directory",
|
|
@@ -480,7 +531,7 @@ async function chooseProjectDir(args) {
|
|
|
480
531
|
},
|
|
481
532
|
{
|
|
482
533
|
onCancel: () => {
|
|
483
|
-
(0,
|
|
534
|
+
(0, import_ora4.default)().info((0, import_colors4.dim)("Operation cancelled."));
|
|
484
535
|
process.exit(0);
|
|
485
536
|
}
|
|
486
537
|
}
|
|
@@ -503,27 +554,27 @@ async function chooseProjectDir(args) {
|
|
|
503
554
|
var import_fs3 = require("fs");
|
|
504
555
|
var import_path3 = require("path");
|
|
505
556
|
var import_execa2 = require("execa");
|
|
506
|
-
var
|
|
507
|
-
var
|
|
508
|
-
var
|
|
557
|
+
var import_colors5 = require("kleur/colors");
|
|
558
|
+
var import_ora5 = __toESM(require("ora"), 1);
|
|
559
|
+
var import_prompts5 = __toESM(require("prompts"), 1);
|
|
509
560
|
var version = "2.0.34";
|
|
510
561
|
async function chooseInstallEmsdk(projDir, args) {
|
|
511
562
|
const underParentDir = (0, import_path3.resolve)(projDir, "..", "emsdk");
|
|
512
563
|
const underProjDir = (0, import_path3.join)(projDir, "emsdk");
|
|
513
|
-
const installResponse = await (0,
|
|
564
|
+
const installResponse = await (0, import_prompts5.default)(
|
|
514
565
|
{
|
|
515
566
|
type: "select",
|
|
516
567
|
name: "install",
|
|
517
|
-
message: `Would you like to install the Emscripten SDK?`,
|
|
568
|
+
message: `Would you like to install the Emscripten SDK that is used to generate WebAssembly?`,
|
|
518
569
|
choices: [
|
|
519
570
|
// ${reset(dim('(recommended)'))
|
|
520
571
|
{
|
|
521
|
-
title: `Install under parent directory (${(0,
|
|
572
|
+
title: `Install under parent directory (${(0, import_colors5.bold)(underParentDir)})`,
|
|
522
573
|
description: "This is recommended so that it can be shared by multiple projects",
|
|
523
574
|
value: "parent"
|
|
524
575
|
},
|
|
525
576
|
{
|
|
526
|
-
title: `Install under project directory (${(0,
|
|
577
|
+
title: `Install under project directory (${(0, import_colors5.bold)(underProjDir)})"`,
|
|
527
578
|
description: "This is useful for keeping everything under a single project directory",
|
|
528
579
|
value: "project"
|
|
529
580
|
},
|
|
@@ -536,8 +587,8 @@ async function chooseInstallEmsdk(projDir, args) {
|
|
|
536
587
|
},
|
|
537
588
|
{
|
|
538
589
|
onCancel: () => {
|
|
539
|
-
(0,
|
|
540
|
-
(0,
|
|
590
|
+
(0, import_ora5.default)().info(
|
|
591
|
+
(0, import_colors5.dim)(
|
|
541
592
|
"Operation cancelled. Your project folder has been created, but the Emscripten SDK and other dependencies have not been installed."
|
|
542
593
|
)
|
|
543
594
|
);
|
|
@@ -546,12 +597,12 @@ async function chooseInstallEmsdk(projDir, args) {
|
|
|
546
597
|
}
|
|
547
598
|
);
|
|
548
599
|
if (args.dryRun) {
|
|
549
|
-
(0,
|
|
600
|
+
(0, import_ora5.default)().info((0, import_colors5.dim)(`--dry-run enabled, skipping.`));
|
|
550
601
|
return;
|
|
551
602
|
} else if (installResponse.install === "skip") {
|
|
552
|
-
(0,
|
|
553
|
-
(0,
|
|
554
|
-
`No problem! Be sure to install the Emscripten SDK and configure it in "${(0,
|
|
603
|
+
(0, import_ora5.default)().info(
|
|
604
|
+
(0, import_colors5.dim)(
|
|
605
|
+
`No problem! Be sure to install the Emscripten SDK and configure it in "${(0, import_colors5.cyan)("sde.config.js")}" after setup.`
|
|
555
606
|
)
|
|
556
607
|
);
|
|
557
608
|
return;
|
|
@@ -560,10 +611,10 @@ async function chooseInstallEmsdk(projDir, args) {
|
|
|
560
611
|
try {
|
|
561
612
|
await installEmscripten(installDir);
|
|
562
613
|
} catch (e) {
|
|
563
|
-
(0,
|
|
614
|
+
(0, import_ora5.default)((0, import_colors5.red)(`Failed to install Emscripten SDK: ${e.message}`)).fail();
|
|
564
615
|
process.exit(0);
|
|
565
616
|
}
|
|
566
|
-
(0,
|
|
617
|
+
(0, import_ora5.default)((0, import_colors5.green)(`Installed the Emscripten SDK in "${(0, import_colors5.bold)(installDir)}"`)).succeed();
|
|
567
618
|
}
|
|
568
619
|
async function installEmscripten(emsdkDir) {
|
|
569
620
|
if (!(0, import_fs3.existsSync)(emsdkDir)) {
|
|
@@ -590,38 +641,38 @@ async function installEmscripten(emsdkDir) {
|
|
|
590
641
|
|
|
591
642
|
// src/step-git.ts
|
|
592
643
|
var import_execa3 = require("execa");
|
|
593
|
-
var
|
|
594
|
-
var
|
|
595
|
-
var
|
|
644
|
+
var import_colors6 = require("kleur/colors");
|
|
645
|
+
var import_ora6 = __toESM(require("ora"), 1);
|
|
646
|
+
var import_prompts6 = __toESM(require("prompts"), 1);
|
|
596
647
|
async function chooseGitInit(projDir, args) {
|
|
597
|
-
const gitResponse = await (0,
|
|
648
|
+
const gitResponse = await (0, import_prompts6.default)(
|
|
598
649
|
{
|
|
599
650
|
type: "confirm",
|
|
600
651
|
name: "git",
|
|
601
|
-
message: `Would you like to initialize a new git repository? ${(0,
|
|
652
|
+
message: `Would you like to initialize a new git repository? ${(0, import_colors6.reset)((0, import_colors6.dim)("(optional)"))}`,
|
|
602
653
|
initial: true
|
|
603
654
|
},
|
|
604
655
|
{
|
|
605
656
|
onCancel: () => {
|
|
606
|
-
(0,
|
|
657
|
+
(0, import_ora6.default)().info((0, import_colors6.dim)("Operation cancelled. Your project folder has already been created."));
|
|
607
658
|
process.exit(0);
|
|
608
659
|
}
|
|
609
660
|
}
|
|
610
661
|
);
|
|
611
662
|
if (args.dryRun) {
|
|
612
|
-
(0,
|
|
663
|
+
(0, import_ora6.default)().info((0, import_colors6.dim)(`--dry-run enabled, skipping.`));
|
|
613
664
|
return;
|
|
614
665
|
} else if (!gitResponse.git) {
|
|
615
|
-
(0,
|
|
666
|
+
(0, import_ora6.default)().info((0, import_colors6.dim)(`No problem! You can come back and run ${(0, import_colors6.cyan)(`git init`)} later.`));
|
|
616
667
|
return;
|
|
617
668
|
}
|
|
618
669
|
try {
|
|
619
670
|
await (0, import_execa3.execaCommand)("git init", { cwd: projDir });
|
|
620
|
-
(0,
|
|
671
|
+
(0, import_ora6.default)().succeed((0, import_colors6.green)("Git repository initialized!"));
|
|
621
672
|
} catch (e) {
|
|
622
|
-
(0,
|
|
623
|
-
(0,
|
|
624
|
-
`There was a problem initializing the Git repository, but no problem, you can run ${(0,
|
|
673
|
+
(0, import_ora6.default)().warn(
|
|
674
|
+
(0, import_colors6.yellow)(
|
|
675
|
+
`There was a problem initializing the Git repository, but no problem, you can run ${(0, import_colors6.cyan)(`git init`)} later.`
|
|
625
676
|
)
|
|
626
677
|
);
|
|
627
678
|
}
|
|
@@ -630,9 +681,9 @@ async function chooseGitInit(projDir, args) {
|
|
|
630
681
|
// src/step-mdl.ts
|
|
631
682
|
var import_promises2 = require("fs/promises");
|
|
632
683
|
var import_path4 = require("path");
|
|
633
|
-
var
|
|
634
|
-
var
|
|
635
|
-
var
|
|
684
|
+
var import_colors7 = require("kleur/colors");
|
|
685
|
+
var import_ora7 = __toESM(require("ora"), 1);
|
|
686
|
+
var import_prompts7 = __toESM(require("prompts"), 1);
|
|
636
687
|
var sampleMdlContent = `{UTF-8}
|
|
637
688
|
|
|
638
689
|
X = TIME
|
|
@@ -674,19 +725,19 @@ async function chooseMdlFile(projDir) {
|
|
|
674
725
|
if (mdlFiles.length === 0) {
|
|
675
726
|
const sampleMdlFile = (0, import_path4.join)(projDir, "sample.mdl");
|
|
676
727
|
await (0, import_promises2.writeFile)(sampleMdlFile, sampleMdlContent);
|
|
677
|
-
(0,
|
|
678
|
-
(0,
|
|
679
|
-
`No mdl files were found in "${projDir}". A "${(0,
|
|
728
|
+
(0, import_ora7.default)(
|
|
729
|
+
(0, import_colors7.yellow)(
|
|
730
|
+
`No mdl files were found in "${projDir}". A "${(0, import_colors7.cyan)(
|
|
680
731
|
"sample.mdl"
|
|
681
732
|
)}" file has been added to the project to get you started.`
|
|
682
733
|
)
|
|
683
734
|
).warn();
|
|
684
735
|
mdlFile = "sample.mdl";
|
|
685
736
|
} else if (mdlFiles.length === 1) {
|
|
686
|
-
(0,
|
|
737
|
+
(0, import_ora7.default)().succeed(`Found "${mdlFiles[0]}", will configure the project to use that mdl file.`);
|
|
687
738
|
mdlFile = mdlFiles[0];
|
|
688
739
|
} else {
|
|
689
|
-
const options = await (0,
|
|
740
|
+
const options = await (0, import_prompts7.default)(
|
|
690
741
|
[
|
|
691
742
|
{
|
|
692
743
|
type: "select",
|
|
@@ -697,14 +748,14 @@ async function chooseMdlFile(projDir) {
|
|
|
697
748
|
],
|
|
698
749
|
{
|
|
699
750
|
onCancel: () => {
|
|
700
|
-
(0,
|
|
751
|
+
(0, import_ora7.default)().info((0, import_colors7.dim)("Operation cancelled."));
|
|
701
752
|
process.exit(0);
|
|
702
753
|
}
|
|
703
754
|
}
|
|
704
755
|
);
|
|
705
756
|
mdlFile = options.mdlFile;
|
|
706
757
|
}
|
|
707
|
-
(0,
|
|
758
|
+
(0, import_ora7.default)((0, import_colors7.green)(`Using "${(0, import_colors7.bold)(mdlFile)}" as the model for the project.`)).succeed();
|
|
708
759
|
return mdlFile;
|
|
709
760
|
}
|
|
710
761
|
|
|
@@ -715,9 +766,9 @@ var import_fs_extra = require("fs-extra");
|
|
|
715
766
|
var import_os = require("os");
|
|
716
767
|
var import_path5 = require("path");
|
|
717
768
|
var import_giget = require("giget");
|
|
718
|
-
var
|
|
719
|
-
var
|
|
720
|
-
var
|
|
769
|
+
var import_colors8 = require("kleur/colors");
|
|
770
|
+
var import_ora8 = __toESM(require("ora"), 1);
|
|
771
|
+
var import_prompts8 = __toESM(require("prompts"), 1);
|
|
721
772
|
var TEMPLATES = [
|
|
722
773
|
{
|
|
723
774
|
title: "Default project",
|
|
@@ -731,7 +782,7 @@ var TEMPLATES = [
|
|
|
731
782
|
}
|
|
732
783
|
];
|
|
733
784
|
async function chooseTemplate(projDir, args, pkgManager) {
|
|
734
|
-
const options = await (0,
|
|
785
|
+
const options = await (0, import_prompts8.default)(
|
|
735
786
|
[
|
|
736
787
|
{
|
|
737
788
|
type: "select",
|
|
@@ -742,21 +793,21 @@ async function chooseTemplate(projDir, args, pkgManager) {
|
|
|
742
793
|
],
|
|
743
794
|
{
|
|
744
795
|
onCancel: () => {
|
|
745
|
-
(0,
|
|
796
|
+
(0, import_ora8.default)().info((0, import_colors8.dim)("Operation cancelled."));
|
|
746
797
|
process.exit(0);
|
|
747
798
|
}
|
|
748
799
|
}
|
|
749
800
|
);
|
|
750
801
|
if (args.dryRun) {
|
|
751
|
-
(0,
|
|
802
|
+
(0, import_ora8.default)().info((0, import_colors8.dim)(`--dry-run enabled, skipping.`));
|
|
752
803
|
return;
|
|
753
804
|
}
|
|
754
805
|
const defaultRev = "main";
|
|
755
806
|
const commit = args.commit || defaultRev;
|
|
756
807
|
const templateTarget = `climateinteractive/SDEverywhere/examples/${options.template}#${commit}`;
|
|
757
|
-
const templateSpinner = (0,
|
|
808
|
+
const templateSpinner = (0, import_ora8.default)("Copying project files...").start();
|
|
758
809
|
await copyTemplate(templateTarget, projDir, templateSpinner);
|
|
759
|
-
templateSpinner.text = (0,
|
|
810
|
+
templateSpinner.text = (0, import_colors8.green)("Template copied!");
|
|
760
811
|
templateSpinner.succeed();
|
|
761
812
|
if (options.template === "template-default" && pkgManager === "pnpm") {
|
|
762
813
|
const workspaceFile = (0, import_path5.join)(projDir, "pnpm-workspace.yaml");
|
|
@@ -785,10 +836,10 @@ async function copyTemplate(templateTarget, dstDir, spinner) {
|
|
|
785
836
|
(0, import_fs4.rmSync)(tmpDir, { recursive: true, force: true });
|
|
786
837
|
} catch (e) {
|
|
787
838
|
spinner.fail();
|
|
788
|
-
console.error((0,
|
|
789
|
-
console.error((0,
|
|
839
|
+
console.error((0, import_colors8.red)(e.message));
|
|
840
|
+
console.error((0, import_colors8.yellow)("\nThere was a problem copying the template."));
|
|
790
841
|
console.error(
|
|
791
|
-
(0,
|
|
842
|
+
(0, import_colors8.yellow)(
|
|
792
843
|
"Please start a new discussion thread and include the command output so that we can help:\n https://github.com/climateinteractive/SDEverywhere/discussions/categories/q-a\n"
|
|
793
844
|
)
|
|
794
845
|
);
|
|
@@ -800,9 +851,9 @@ async function copyTemplate(templateTarget, dstDir, spinner) {
|
|
|
800
851
|
async function main() {
|
|
801
852
|
const pkgManager = (0, import_which_pm_runs.default)()?.name || "npm";
|
|
802
853
|
const args = (0, import_yargs_parser.default)(process.argv);
|
|
803
|
-
|
|
854
|
+
import_prompts9.default.override(args);
|
|
804
855
|
console.log(`
|
|
805
|
-
${(0,
|
|
856
|
+
${(0, import_colors9.bold)("Welcome to SDEverywhere!")}`);
|
|
806
857
|
console.log(`Let's create a new SDEverywhere project for your model.
|
|
807
858
|
`);
|
|
808
859
|
const projDir = await chooseProjectDir(args);
|
|
@@ -810,29 +861,36 @@ ${(0, import_colors8.bold)("Welcome to SDEverywhere!")}`);
|
|
|
810
861
|
const templateName = await chooseTemplate(projDir, args, pkgManager);
|
|
811
862
|
console.log();
|
|
812
863
|
const mdlPath = await chooseMdlFile(projDir);
|
|
813
|
-
await updateSdeConfig(projDir, mdlPath);
|
|
814
|
-
await generateCheckYaml(projDir, mdlPath);
|
|
815
864
|
console.log();
|
|
865
|
+
const genFormat = await chooseCodeFormat();
|
|
866
|
+
console.log();
|
|
867
|
+
if (!args.dryRun) {
|
|
868
|
+
await updateSdeConfig(projDir, mdlPath, genFormat);
|
|
869
|
+
await generateCheckYaml(projDir, mdlPath);
|
|
870
|
+
console.log();
|
|
871
|
+
}
|
|
816
872
|
if (templateName === "template-default" && !args.dryRun) {
|
|
817
873
|
await chooseGenConfig(projDir, mdlPath);
|
|
818
874
|
console.log();
|
|
819
875
|
}
|
|
820
|
-
|
|
821
|
-
|
|
876
|
+
if (genFormat === "c") {
|
|
877
|
+
await chooseInstallEmsdk(projDir, args);
|
|
878
|
+
console.log();
|
|
879
|
+
}
|
|
822
880
|
await chooseInstallDeps(projDir, args, pkgManager);
|
|
823
881
|
console.log();
|
|
824
882
|
await chooseGitInit(projDir, args);
|
|
825
883
|
console.log();
|
|
826
|
-
(0,
|
|
884
|
+
(0, import_ora9.default)((0, import_colors9.green)("Setup complete!")).succeed();
|
|
827
885
|
console.log(`
|
|
828
|
-
${(0,
|
|
886
|
+
${(0, import_colors9.bgCyan)((0, import_colors9.black)(" Next steps "))}
|
|
829
887
|
`);
|
|
830
888
|
const relProjDir = (0, import_path6.relative)(process.cwd(), projDir);
|
|
831
889
|
const devCmd = pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`;
|
|
832
890
|
if (relProjDir !== "") {
|
|
833
|
-
console.log(`You can now ${(0,
|
|
891
|
+
console.log(`You can now ${(0, import_colors9.bold)((0, import_colors9.cyan)("cd"))} into the ${(0, import_colors9.bold)((0, import_colors9.cyan)(relProjDir))} project directory.`);
|
|
834
892
|
}
|
|
835
|
-
console.log(`Run ${(0,
|
|
893
|
+
console.log(`Run ${(0, import_colors9.bold)((0, import_colors9.cyan)(devCmd))} to start the local dev server. ${(0, import_colors9.bold)((0, import_colors9.cyan)("CTRL-C"))} to close.`);
|
|
836
894
|
console.log("");
|
|
837
895
|
}
|
|
838
896
|
// Annotate the CommonJS export names for ESM import in node:
|