@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.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
|
}
|
|
@@ -137,7 +188,10 @@ async function chooseGenConfig(projDir, mdlPath) {
|
|
|
137
188
|
const modelCsvFile = (0, import_path.join)(projDir, "config", "model.csv");
|
|
138
189
|
const origModelCsvContent = await (0, import_promises.readFile)(modelCsvFile, "utf8");
|
|
139
190
|
const modelCsvHeader = origModelCsvContent.split("\n")[0];
|
|
140
|
-
const
|
|
191
|
+
const bundleListing = "false";
|
|
192
|
+
const customLookups = "false";
|
|
193
|
+
const customOutputs = "false";
|
|
194
|
+
const modelCsvLine = `${initialTime},${finalTime},${datPart},${bundleListing},${customLookups},${customOutputs}`;
|
|
141
195
|
const newModelCsvContent = `${modelCsvHeader}
|
|
142
196
|
${modelCsvLine}
|
|
143
197
|
`;
|
|
@@ -147,22 +201,22 @@ ${modelCsvLine}
|
|
|
147
201
|
await chooseGenSliderConfig(projDir, validVars);
|
|
148
202
|
}
|
|
149
203
|
async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
150
|
-
const genResponse = await (0,
|
|
204
|
+
const genResponse = await (0, import_prompts2.default)(
|
|
151
205
|
{
|
|
152
206
|
type: "confirm",
|
|
153
207
|
name: "genGraph",
|
|
154
|
-
message: `Would you like to configure a graph to get you started? ${(0,
|
|
208
|
+
message: `Would you like to configure a graph to get you started? ${(0, import_colors2.reset)((0, import_colors2.dim)("(recommended)"))}`,
|
|
155
209
|
initial: true
|
|
156
210
|
},
|
|
157
211
|
{
|
|
158
212
|
onCancel: () => {
|
|
159
|
-
(0,
|
|
213
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)("Operation cancelled."));
|
|
160
214
|
process.exit(0);
|
|
161
215
|
}
|
|
162
216
|
}
|
|
163
217
|
);
|
|
164
218
|
if (!genResponse.genGraph) {
|
|
165
|
-
(0,
|
|
219
|
+
(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
220
|
return;
|
|
167
221
|
}
|
|
168
222
|
const outputVarNames = [];
|
|
@@ -180,7 +234,7 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
|
180
234
|
value: f
|
|
181
235
|
};
|
|
182
236
|
});
|
|
183
|
-
const varsResponse = await (0,
|
|
237
|
+
const varsResponse = await (0, import_prompts2.default)(
|
|
184
238
|
{
|
|
185
239
|
type: "autocompleteMultiselect",
|
|
186
240
|
name: "vars",
|
|
@@ -190,13 +244,13 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
|
190
244
|
},
|
|
191
245
|
{
|
|
192
246
|
onCancel: () => {
|
|
193
|
-
(0,
|
|
247
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)("Operation cancelled."));
|
|
194
248
|
process.exit(0);
|
|
195
249
|
}
|
|
196
250
|
}
|
|
197
251
|
);
|
|
198
252
|
if (varsResponse.vars.length === 0) {
|
|
199
|
-
(0,
|
|
253
|
+
(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
254
|
return;
|
|
201
255
|
}
|
|
202
256
|
const graphsCsvFile = (0, import_path.join)(projDir, "config", "graphs.csv");
|
|
@@ -205,8 +259,8 @@ async function chooseGenGraphConfig(projDir, mdlVars) {
|
|
|
205
259
|
graphsCsvContent += `${csvLine}
|
|
206
260
|
`;
|
|
207
261
|
await (0, import_promises.writeFile)(graphsCsvFile, graphsCsvContent);
|
|
208
|
-
(0,
|
|
209
|
-
(0,
|
|
262
|
+
(0, import_ora2.default)(
|
|
263
|
+
(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
264
|
).succeed();
|
|
211
265
|
}
|
|
212
266
|
function graphsCsvLine(outputVarNames) {
|
|
@@ -230,22 +284,22 @@ function graphsCsvLine(outputVarNames) {
|
|
|
230
284
|
return a.join(",");
|
|
231
285
|
}
|
|
232
286
|
async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
233
|
-
const genResponse = await (0,
|
|
287
|
+
const genResponse = await (0, import_prompts2.default)(
|
|
234
288
|
{
|
|
235
289
|
type: "confirm",
|
|
236
290
|
name: "genSliders",
|
|
237
|
-
message: `Would you like to configure a few sliders to get you started? ${(0,
|
|
291
|
+
message: `Would you like to configure a few sliders to get you started? ${(0, import_colors2.reset)((0, import_colors2.dim)("(recommended)"))}`,
|
|
238
292
|
initial: true
|
|
239
293
|
},
|
|
240
294
|
{
|
|
241
295
|
onCancel: () => {
|
|
242
|
-
(0,
|
|
296
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)("Operation cancelled."));
|
|
243
297
|
process.exit(0);
|
|
244
298
|
}
|
|
245
299
|
}
|
|
246
300
|
);
|
|
247
301
|
if (!genResponse.genSliders) {
|
|
248
|
-
(0,
|
|
302
|
+
(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
303
|
return;
|
|
250
304
|
}
|
|
251
305
|
const inputVarNames = [];
|
|
@@ -263,7 +317,7 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
|
263
317
|
value: f
|
|
264
318
|
};
|
|
265
319
|
});
|
|
266
|
-
const varsResponse = await (0,
|
|
320
|
+
const varsResponse = await (0, import_prompts2.default)(
|
|
267
321
|
{
|
|
268
322
|
type: "autocompleteMultiselect",
|
|
269
323
|
name: "vars",
|
|
@@ -273,13 +327,13 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
|
273
327
|
},
|
|
274
328
|
{
|
|
275
329
|
onCancel: () => {
|
|
276
|
-
(0,
|
|
330
|
+
(0, import_ora2.default)().info((0, import_colors2.dim)("Operation cancelled."));
|
|
277
331
|
process.exit(0);
|
|
278
332
|
}
|
|
279
333
|
}
|
|
280
334
|
);
|
|
281
335
|
if (varsResponse.vars.length === 0) {
|
|
282
|
-
(0,
|
|
336
|
+
(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
337
|
return;
|
|
284
338
|
}
|
|
285
339
|
const inputsCsvFile = (0, import_path.join)(projDir, "config", "inputs.csv");
|
|
@@ -297,9 +351,9 @@ async function chooseGenSliderConfig(projDir, mdlVars) {
|
|
|
297
351
|
}
|
|
298
352
|
await (0, import_promises.writeFile)(inputsCsvFile, inputsCsvContent);
|
|
299
353
|
const slidersText = varsResponse.vars.length > 1 ? "sliders" : "sliders";
|
|
300
|
-
(0,
|
|
301
|
-
(0,
|
|
302
|
-
`Added ${slidersText} to "${(0,
|
|
354
|
+
(0, import_ora2.default)(
|
|
355
|
+
(0, import_colors2.green)(
|
|
356
|
+
`Added ${slidersText} to "${(0, import_colors2.bold)("config/inputs.csv")}". ${(0, import_colors2.dim)("You can configure sliders in that file later.")}`
|
|
303
357
|
)
|
|
304
358
|
).succeed();
|
|
305
359
|
}
|
|
@@ -333,7 +387,7 @@ async function readModelVars(projDir, mdlPath) {
|
|
|
333
387
|
const preprocessed = (0, import_compile.preprocessModel)(
|
|
334
388
|
mdlFile,
|
|
335
389
|
spec,
|
|
336
|
-
"
|
|
390
|
+
"runnable",
|
|
337
391
|
/*writeFiles=*/
|
|
338
392
|
false
|
|
339
393
|
);
|
|
@@ -374,45 +428,45 @@ async function readModelVars(projDir, mdlPath) {
|
|
|
374
428
|
|
|
375
429
|
// src/step-deps.ts
|
|
376
430
|
var import_execa = require("execa");
|
|
377
|
-
var
|
|
378
|
-
var
|
|
379
|
-
var
|
|
431
|
+
var import_colors3 = require("kleur/colors");
|
|
432
|
+
var import_ora3 = __toESM(require("ora"), 1);
|
|
433
|
+
var import_prompts3 = __toESM(require("prompts"), 1);
|
|
380
434
|
async function chooseInstallDeps(projDir, args, pkgManager) {
|
|
381
|
-
const installResponse = await (0,
|
|
435
|
+
const installResponse = await (0, import_prompts3.default)(
|
|
382
436
|
{
|
|
383
437
|
type: "confirm",
|
|
384
438
|
name: "install",
|
|
385
|
-
message: `Would you like to install ${pkgManager} dependencies? ${(0,
|
|
439
|
+
message: `Would you like to install ${pkgManager} dependencies? ${(0, import_colors3.reset)((0, import_colors3.dim)("(recommended)"))}`,
|
|
386
440
|
initial: true
|
|
387
441
|
},
|
|
388
442
|
{
|
|
389
443
|
onCancel: () => {
|
|
390
|
-
(0,
|
|
391
|
-
(0,
|
|
444
|
+
(0, import_ora3.default)().info(
|
|
445
|
+
(0, import_colors3.dim)("Operation cancelled. Your project folder has been created, but no dependencies have been installed.")
|
|
392
446
|
);
|
|
393
447
|
process.exit(0);
|
|
394
448
|
}
|
|
395
449
|
}
|
|
396
450
|
);
|
|
397
451
|
if (args.dryRun) {
|
|
398
|
-
(0,
|
|
452
|
+
(0, import_ora3.default)().info((0, import_colors3.dim)(`--dry-run enabled, skipping.`));
|
|
399
453
|
return;
|
|
400
454
|
} else if (!installResponse.install) {
|
|
401
|
-
(0,
|
|
455
|
+
(0, import_ora3.default)().info((0, import_colors3.dim)(`No problem! Remember to install dependencies after setup.`));
|
|
402
456
|
return;
|
|
403
457
|
}
|
|
404
458
|
const installExec = (0, import_execa.execa)(pkgManager, ["install"], { cwd: projDir });
|
|
405
459
|
const installingPackagesMsg = "Installing packages...";
|
|
406
|
-
const installSpinner = (0,
|
|
460
|
+
const installSpinner = (0, import_ora3.default)(installingPackagesMsg).start();
|
|
407
461
|
try {
|
|
408
462
|
await new Promise((resolve, reject) => {
|
|
409
463
|
installExec.stdout?.on("data", function(data) {
|
|
410
464
|
installSpinner.text = `${installingPackagesMsg}
|
|
411
|
-
${(0,
|
|
465
|
+
${(0, import_colors3.bold)(`[${pkgManager}]`)} ${data}`;
|
|
412
466
|
});
|
|
413
467
|
installExec.stderr?.on("data", function(data) {
|
|
414
468
|
installSpinner.text = `${installingPackagesMsg}
|
|
415
|
-
${(0,
|
|
469
|
+
${(0, import_colors3.bold)(`[${pkgManager}]`)} ${data}`;
|
|
416
470
|
});
|
|
417
471
|
installExec.on("error", (error) => reject(error));
|
|
418
472
|
installExec.on("close", (code) => {
|
|
@@ -423,11 +477,11 @@ ${(0, import_colors2.bold)(`[${pkgManager}]`)} ${data}`;
|
|
|
423
477
|
}
|
|
424
478
|
});
|
|
425
479
|
});
|
|
426
|
-
installSpinner.text = (0,
|
|
480
|
+
installSpinner.text = (0, import_colors3.green)("Packages installed!");
|
|
427
481
|
installSpinner.succeed();
|
|
428
482
|
} catch (e) {
|
|
429
|
-
installSpinner.text = (0,
|
|
430
|
-
`There was an error installing packages. Try running ${(0,
|
|
483
|
+
installSpinner.text = (0, import_colors3.yellow)(
|
|
484
|
+
`There was an error installing packages. Try running ${(0, import_colors3.cyan)(
|
|
431
485
|
`${pkgManager} install`
|
|
432
486
|
)} in your project directory later.`
|
|
433
487
|
);
|
|
@@ -438,9 +492,9 @@ ${(0, import_colors2.bold)(`[${pkgManager}]`)} ${data}`;
|
|
|
438
492
|
// src/step-directory.ts
|
|
439
493
|
var import_fs2 = require("fs");
|
|
440
494
|
var import_path2 = require("path");
|
|
441
|
-
var
|
|
442
|
-
var
|
|
443
|
-
var
|
|
495
|
+
var import_colors4 = require("kleur/colors");
|
|
496
|
+
var import_ora4 = __toESM(require("ora"), 1);
|
|
497
|
+
var import_prompts4 = __toESM(require("prompts"), 1);
|
|
444
498
|
async function chooseProjectDir(args) {
|
|
445
499
|
function isValidDir(dir) {
|
|
446
500
|
const packageJson = (0, import_path2.resolve)(dir, "package.json");
|
|
@@ -448,10 +502,10 @@ async function chooseProjectDir(args) {
|
|
|
448
502
|
return !(0, import_fs2.existsSync)(dir) || !(0, import_fs2.existsSync)(packageJson) && !(0, import_fs2.existsSync)(packagesDir);
|
|
449
503
|
}
|
|
450
504
|
const showValidDirMsg = (dir) => {
|
|
451
|
-
(0,
|
|
505
|
+
(0, import_ora4.default)((0, import_colors4.green)(`Using "${(0, import_colors4.bold)(dir)}" as the project directory.`)).succeed();
|
|
452
506
|
};
|
|
453
507
|
const showInvalidDirMsg = (dir) => {
|
|
454
|
-
(0,
|
|
508
|
+
(0, import_ora4.default)((0, import_colors4.red)(`"${(0, import_colors4.bold)(dir)}" contains existing 'package.json' and/or 'packages' directory, stopping.`)).fail();
|
|
455
509
|
};
|
|
456
510
|
let projDir = args["_"][2];
|
|
457
511
|
if (projDir) {
|
|
@@ -462,7 +516,7 @@ async function chooseProjectDir(args) {
|
|
|
462
516
|
process.exit(0);
|
|
463
517
|
}
|
|
464
518
|
} else {
|
|
465
|
-
const dirResponse = await (0,
|
|
519
|
+
const dirResponse = await (0, import_prompts4.default)(
|
|
466
520
|
{
|
|
467
521
|
type: "text",
|
|
468
522
|
name: "directory",
|
|
@@ -480,7 +534,7 @@ async function chooseProjectDir(args) {
|
|
|
480
534
|
},
|
|
481
535
|
{
|
|
482
536
|
onCancel: () => {
|
|
483
|
-
(0,
|
|
537
|
+
(0, import_ora4.default)().info((0, import_colors4.dim)("Operation cancelled."));
|
|
484
538
|
process.exit(0);
|
|
485
539
|
}
|
|
486
540
|
}
|
|
@@ -503,27 +557,27 @@ async function chooseProjectDir(args) {
|
|
|
503
557
|
var import_fs3 = require("fs");
|
|
504
558
|
var import_path3 = require("path");
|
|
505
559
|
var import_execa2 = require("execa");
|
|
506
|
-
var
|
|
507
|
-
var
|
|
508
|
-
var
|
|
560
|
+
var import_colors5 = require("kleur/colors");
|
|
561
|
+
var import_ora5 = __toESM(require("ora"), 1);
|
|
562
|
+
var import_prompts5 = __toESM(require("prompts"), 1);
|
|
509
563
|
var version = "2.0.34";
|
|
510
564
|
async function chooseInstallEmsdk(projDir, args) {
|
|
511
565
|
const underParentDir = (0, import_path3.resolve)(projDir, "..", "emsdk");
|
|
512
566
|
const underProjDir = (0, import_path3.join)(projDir, "emsdk");
|
|
513
|
-
const installResponse = await (0,
|
|
567
|
+
const installResponse = await (0, import_prompts5.default)(
|
|
514
568
|
{
|
|
515
569
|
type: "select",
|
|
516
570
|
name: "install",
|
|
517
|
-
message: `Would you like to install the Emscripten SDK?`,
|
|
571
|
+
message: `Would you like to install the Emscripten SDK that is used to generate WebAssembly?`,
|
|
518
572
|
choices: [
|
|
519
573
|
// ${reset(dim('(recommended)'))
|
|
520
574
|
{
|
|
521
|
-
title: `Install under parent directory (${(0,
|
|
575
|
+
title: `Install under parent directory (${(0, import_colors5.bold)(underParentDir)})`,
|
|
522
576
|
description: "This is recommended so that it can be shared by multiple projects",
|
|
523
577
|
value: "parent"
|
|
524
578
|
},
|
|
525
579
|
{
|
|
526
|
-
title: `Install under project directory (${(0,
|
|
580
|
+
title: `Install under project directory (${(0, import_colors5.bold)(underProjDir)})"`,
|
|
527
581
|
description: "This is useful for keeping everything under a single project directory",
|
|
528
582
|
value: "project"
|
|
529
583
|
},
|
|
@@ -536,8 +590,8 @@ async function chooseInstallEmsdk(projDir, args) {
|
|
|
536
590
|
},
|
|
537
591
|
{
|
|
538
592
|
onCancel: () => {
|
|
539
|
-
(0,
|
|
540
|
-
(0,
|
|
593
|
+
(0, import_ora5.default)().info(
|
|
594
|
+
(0, import_colors5.dim)(
|
|
541
595
|
"Operation cancelled. Your project folder has been created, but the Emscripten SDK and other dependencies have not been installed."
|
|
542
596
|
)
|
|
543
597
|
);
|
|
@@ -546,12 +600,12 @@ async function chooseInstallEmsdk(projDir, args) {
|
|
|
546
600
|
}
|
|
547
601
|
);
|
|
548
602
|
if (args.dryRun) {
|
|
549
|
-
(0,
|
|
603
|
+
(0, import_ora5.default)().info((0, import_colors5.dim)(`--dry-run enabled, skipping.`));
|
|
550
604
|
return;
|
|
551
605
|
} else if (installResponse.install === "skip") {
|
|
552
|
-
(0,
|
|
553
|
-
(0,
|
|
554
|
-
`No problem! Be sure to install the Emscripten SDK and configure it in "${(0,
|
|
606
|
+
(0, import_ora5.default)().info(
|
|
607
|
+
(0, import_colors5.dim)(
|
|
608
|
+
`No problem! Be sure to install the Emscripten SDK and configure it in "${(0, import_colors5.cyan)("sde.config.js")}" after setup.`
|
|
555
609
|
)
|
|
556
610
|
);
|
|
557
611
|
return;
|
|
@@ -560,10 +614,10 @@ async function chooseInstallEmsdk(projDir, args) {
|
|
|
560
614
|
try {
|
|
561
615
|
await installEmscripten(installDir);
|
|
562
616
|
} catch (e) {
|
|
563
|
-
(0,
|
|
617
|
+
(0, import_ora5.default)((0, import_colors5.red)(`Failed to install Emscripten SDK: ${e.message}`)).fail();
|
|
564
618
|
process.exit(0);
|
|
565
619
|
}
|
|
566
|
-
(0,
|
|
620
|
+
(0, import_ora5.default)((0, import_colors5.green)(`Installed the Emscripten SDK in "${(0, import_colors5.bold)(installDir)}"`)).succeed();
|
|
567
621
|
}
|
|
568
622
|
async function installEmscripten(emsdkDir) {
|
|
569
623
|
if (!(0, import_fs3.existsSync)(emsdkDir)) {
|
|
@@ -590,38 +644,38 @@ async function installEmscripten(emsdkDir) {
|
|
|
590
644
|
|
|
591
645
|
// src/step-git.ts
|
|
592
646
|
var import_execa3 = require("execa");
|
|
593
|
-
var
|
|
594
|
-
var
|
|
595
|
-
var
|
|
647
|
+
var import_colors6 = require("kleur/colors");
|
|
648
|
+
var import_ora6 = __toESM(require("ora"), 1);
|
|
649
|
+
var import_prompts6 = __toESM(require("prompts"), 1);
|
|
596
650
|
async function chooseGitInit(projDir, args) {
|
|
597
|
-
const gitResponse = await (0,
|
|
651
|
+
const gitResponse = await (0, import_prompts6.default)(
|
|
598
652
|
{
|
|
599
653
|
type: "confirm",
|
|
600
654
|
name: "git",
|
|
601
|
-
message: `Would you like to initialize a new git repository? ${(0,
|
|
655
|
+
message: `Would you like to initialize a new git repository? ${(0, import_colors6.reset)((0, import_colors6.dim)("(optional)"))}`,
|
|
602
656
|
initial: true
|
|
603
657
|
},
|
|
604
658
|
{
|
|
605
659
|
onCancel: () => {
|
|
606
|
-
(0,
|
|
660
|
+
(0, import_ora6.default)().info((0, import_colors6.dim)("Operation cancelled. Your project folder has already been created."));
|
|
607
661
|
process.exit(0);
|
|
608
662
|
}
|
|
609
663
|
}
|
|
610
664
|
);
|
|
611
665
|
if (args.dryRun) {
|
|
612
|
-
(0,
|
|
666
|
+
(0, import_ora6.default)().info((0, import_colors6.dim)(`--dry-run enabled, skipping.`));
|
|
613
667
|
return;
|
|
614
668
|
} else if (!gitResponse.git) {
|
|
615
|
-
(0,
|
|
669
|
+
(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
670
|
return;
|
|
617
671
|
}
|
|
618
672
|
try {
|
|
619
673
|
await (0, import_execa3.execaCommand)("git init", { cwd: projDir });
|
|
620
|
-
(0,
|
|
674
|
+
(0, import_ora6.default)().succeed((0, import_colors6.green)("Git repository initialized!"));
|
|
621
675
|
} catch (e) {
|
|
622
|
-
(0,
|
|
623
|
-
(0,
|
|
624
|
-
`There was a problem initializing the Git repository, but no problem, you can run ${(0,
|
|
676
|
+
(0, import_ora6.default)().warn(
|
|
677
|
+
(0, import_colors6.yellow)(
|
|
678
|
+
`There was a problem initializing the Git repository, but no problem, you can run ${(0, import_colors6.cyan)(`git init`)} later.`
|
|
625
679
|
)
|
|
626
680
|
);
|
|
627
681
|
}
|
|
@@ -630,9 +684,9 @@ async function chooseGitInit(projDir, args) {
|
|
|
630
684
|
// src/step-mdl.ts
|
|
631
685
|
var import_promises2 = require("fs/promises");
|
|
632
686
|
var import_path4 = require("path");
|
|
633
|
-
var
|
|
634
|
-
var
|
|
635
|
-
var
|
|
687
|
+
var import_colors7 = require("kleur/colors");
|
|
688
|
+
var import_ora7 = __toESM(require("ora"), 1);
|
|
689
|
+
var import_prompts7 = __toESM(require("prompts"), 1);
|
|
636
690
|
var sampleMdlContent = `{UTF-8}
|
|
637
691
|
|
|
638
692
|
X = TIME
|
|
@@ -674,19 +728,19 @@ async function chooseMdlFile(projDir) {
|
|
|
674
728
|
if (mdlFiles.length === 0) {
|
|
675
729
|
const sampleMdlFile = (0, import_path4.join)(projDir, "sample.mdl");
|
|
676
730
|
await (0, import_promises2.writeFile)(sampleMdlFile, sampleMdlContent);
|
|
677
|
-
(0,
|
|
678
|
-
(0,
|
|
679
|
-
`No mdl files were found in "${projDir}". A "${(0,
|
|
731
|
+
(0, import_ora7.default)(
|
|
732
|
+
(0, import_colors7.yellow)(
|
|
733
|
+
`No mdl files were found in "${projDir}". A "${(0, import_colors7.cyan)(
|
|
680
734
|
"sample.mdl"
|
|
681
735
|
)}" file has been added to the project to get you started.`
|
|
682
736
|
)
|
|
683
737
|
).warn();
|
|
684
738
|
mdlFile = "sample.mdl";
|
|
685
739
|
} else if (mdlFiles.length === 1) {
|
|
686
|
-
(0,
|
|
740
|
+
(0, import_ora7.default)().succeed(`Found "${mdlFiles[0]}", will configure the project to use that mdl file.`);
|
|
687
741
|
mdlFile = mdlFiles[0];
|
|
688
742
|
} else {
|
|
689
|
-
const options = await (0,
|
|
743
|
+
const options = await (0, import_prompts7.default)(
|
|
690
744
|
[
|
|
691
745
|
{
|
|
692
746
|
type: "select",
|
|
@@ -697,14 +751,14 @@ async function chooseMdlFile(projDir) {
|
|
|
697
751
|
],
|
|
698
752
|
{
|
|
699
753
|
onCancel: () => {
|
|
700
|
-
(0,
|
|
754
|
+
(0, import_ora7.default)().info((0, import_colors7.dim)("Operation cancelled."));
|
|
701
755
|
process.exit(0);
|
|
702
756
|
}
|
|
703
757
|
}
|
|
704
758
|
);
|
|
705
759
|
mdlFile = options.mdlFile;
|
|
706
760
|
}
|
|
707
|
-
(0,
|
|
761
|
+
(0, import_ora7.default)((0, import_colors7.green)(`Using "${(0, import_colors7.bold)(mdlFile)}" as the model for the project.`)).succeed();
|
|
708
762
|
return mdlFile;
|
|
709
763
|
}
|
|
710
764
|
|
|
@@ -715,9 +769,9 @@ var import_fs_extra = require("fs-extra");
|
|
|
715
769
|
var import_os = require("os");
|
|
716
770
|
var import_path5 = require("path");
|
|
717
771
|
var import_giget = require("giget");
|
|
718
|
-
var
|
|
719
|
-
var
|
|
720
|
-
var
|
|
772
|
+
var import_colors8 = require("kleur/colors");
|
|
773
|
+
var import_ora8 = __toESM(require("ora"), 1);
|
|
774
|
+
var import_prompts8 = __toESM(require("prompts"), 1);
|
|
721
775
|
var TEMPLATES = [
|
|
722
776
|
{
|
|
723
777
|
title: "Default project",
|
|
@@ -731,7 +785,7 @@ var TEMPLATES = [
|
|
|
731
785
|
}
|
|
732
786
|
];
|
|
733
787
|
async function chooseTemplate(projDir, args, pkgManager) {
|
|
734
|
-
const options = await (0,
|
|
788
|
+
const options = await (0, import_prompts8.default)(
|
|
735
789
|
[
|
|
736
790
|
{
|
|
737
791
|
type: "select",
|
|
@@ -742,21 +796,21 @@ async function chooseTemplate(projDir, args, pkgManager) {
|
|
|
742
796
|
],
|
|
743
797
|
{
|
|
744
798
|
onCancel: () => {
|
|
745
|
-
(0,
|
|
799
|
+
(0, import_ora8.default)().info((0, import_colors8.dim)("Operation cancelled."));
|
|
746
800
|
process.exit(0);
|
|
747
801
|
}
|
|
748
802
|
}
|
|
749
803
|
);
|
|
750
804
|
if (args.dryRun) {
|
|
751
|
-
(0,
|
|
805
|
+
(0, import_ora8.default)().info((0, import_colors8.dim)(`--dry-run enabled, skipping.`));
|
|
752
806
|
return;
|
|
753
807
|
}
|
|
754
808
|
const defaultRev = "main";
|
|
755
809
|
const commit = args.commit || defaultRev;
|
|
756
810
|
const templateTarget = `climateinteractive/SDEverywhere/examples/${options.template}#${commit}`;
|
|
757
|
-
const templateSpinner = (0,
|
|
811
|
+
const templateSpinner = (0, import_ora8.default)("Copying project files...").start();
|
|
758
812
|
await copyTemplate(templateTarget, projDir, templateSpinner);
|
|
759
|
-
templateSpinner.text = (0,
|
|
813
|
+
templateSpinner.text = (0, import_colors8.green)("Template copied!");
|
|
760
814
|
templateSpinner.succeed();
|
|
761
815
|
if (options.template === "template-default" && pkgManager === "pnpm") {
|
|
762
816
|
const workspaceFile = (0, import_path5.join)(projDir, "pnpm-workspace.yaml");
|
|
@@ -785,10 +839,10 @@ async function copyTemplate(templateTarget, dstDir, spinner) {
|
|
|
785
839
|
(0, import_fs4.rmSync)(tmpDir, { recursive: true, force: true });
|
|
786
840
|
} catch (e) {
|
|
787
841
|
spinner.fail();
|
|
788
|
-
console.error((0,
|
|
789
|
-
console.error((0,
|
|
842
|
+
console.error((0, import_colors8.red)(e.message));
|
|
843
|
+
console.error((0, import_colors8.yellow)("\nThere was a problem copying the template."));
|
|
790
844
|
console.error(
|
|
791
|
-
(0,
|
|
845
|
+
(0, import_colors8.yellow)(
|
|
792
846
|
"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
847
|
)
|
|
794
848
|
);
|
|
@@ -800,9 +854,9 @@ async function copyTemplate(templateTarget, dstDir, spinner) {
|
|
|
800
854
|
async function main() {
|
|
801
855
|
const pkgManager = (0, import_which_pm_runs.default)()?.name || "npm";
|
|
802
856
|
const args = (0, import_yargs_parser.default)(process.argv);
|
|
803
|
-
|
|
857
|
+
import_prompts9.default.override(args);
|
|
804
858
|
console.log(`
|
|
805
|
-
${(0,
|
|
859
|
+
${(0, import_colors9.bold)("Welcome to SDEverywhere!")}`);
|
|
806
860
|
console.log(`Let's create a new SDEverywhere project for your model.
|
|
807
861
|
`);
|
|
808
862
|
const projDir = await chooseProjectDir(args);
|
|
@@ -810,29 +864,35 @@ ${(0, import_colors8.bold)("Welcome to SDEverywhere!")}`);
|
|
|
810
864
|
const templateName = await chooseTemplate(projDir, args, pkgManager);
|
|
811
865
|
console.log();
|
|
812
866
|
const mdlPath = await chooseMdlFile(projDir);
|
|
813
|
-
|
|
814
|
-
await
|
|
867
|
+
console.log();
|
|
868
|
+
const genFormat = await chooseCodeFormat();
|
|
869
|
+
if (!args.dryRun) {
|
|
870
|
+
await updateSdeConfig(projDir, mdlPath, genFormat);
|
|
871
|
+
await generateCheckYaml(projDir, mdlPath);
|
|
872
|
+
}
|
|
815
873
|
console.log();
|
|
816
874
|
if (templateName === "template-default" && !args.dryRun) {
|
|
817
875
|
await chooseGenConfig(projDir, mdlPath);
|
|
818
876
|
console.log();
|
|
819
877
|
}
|
|
820
|
-
|
|
821
|
-
|
|
878
|
+
if (genFormat === "c") {
|
|
879
|
+
await chooseInstallEmsdk(projDir, args);
|
|
880
|
+
console.log();
|
|
881
|
+
}
|
|
822
882
|
await chooseInstallDeps(projDir, args, pkgManager);
|
|
823
883
|
console.log();
|
|
824
884
|
await chooseGitInit(projDir, args);
|
|
825
885
|
console.log();
|
|
826
|
-
(0,
|
|
886
|
+
(0, import_ora9.default)((0, import_colors9.green)("Setup complete!")).succeed();
|
|
827
887
|
console.log(`
|
|
828
|
-
${(0,
|
|
888
|
+
${(0, import_colors9.bgCyan)((0, import_colors9.black)(" Next steps "))}
|
|
829
889
|
`);
|
|
830
890
|
const relProjDir = (0, import_path6.relative)(process.cwd(), projDir);
|
|
831
891
|
const devCmd = pkgManager === "npm" ? "npm run dev" : `${pkgManager} dev`;
|
|
832
892
|
if (relProjDir !== "") {
|
|
833
|
-
console.log(`You can now ${(0,
|
|
893
|
+
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
894
|
}
|
|
835
|
-
console.log(`Run ${(0,
|
|
895
|
+
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
896
|
console.log("");
|
|
837
897
|
}
|
|
838
898
|
// Annotate the CommonJS export names for ESM import in node:
|