@pd4castr/cli 1.13.0 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +51 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -339,7 +339,7 @@ __name(getEnv, "getEnv");
|
|
|
339
339
|
// package.json
|
|
340
340
|
var package_default = {
|
|
341
341
|
name: "@pd4castr/cli",
|
|
342
|
-
version: "1.13.
|
|
342
|
+
version: "1.13.1",
|
|
343
343
|
description: "CLI tool for creating, testing, and publishing pd4castr models",
|
|
344
344
|
license: "MIT",
|
|
345
345
|
main: "dist/index.js",
|
|
@@ -537,6 +537,8 @@ function registerFetchCommand(program2) {
|
|
|
537
537
|
__name(registerFetchCommand, "registerFetchCommand");
|
|
538
538
|
|
|
539
539
|
// src/commands/init/handle-action.ts
|
|
540
|
+
import fs6 from "fs/promises";
|
|
541
|
+
import os2 from "os";
|
|
540
542
|
import path6 from "path";
|
|
541
543
|
import * as inquirer from "@inquirer/prompts";
|
|
542
544
|
import ora2 from "ora";
|
|
@@ -618,7 +620,32 @@ async function fetchTemplate(template, projectName) {
|
|
|
618
620
|
force: true
|
|
619
621
|
});
|
|
620
622
|
const destination = path6.join(process.cwd(), projectName);
|
|
621
|
-
|
|
623
|
+
const originalCwd = process.cwd();
|
|
624
|
+
let tmpDir;
|
|
625
|
+
try {
|
|
626
|
+
const tmpBase = os2.tmpdir();
|
|
627
|
+
await fs6.mkdir(tmpBase, {
|
|
628
|
+
recursive: true
|
|
629
|
+
});
|
|
630
|
+
tmpDir = await fs6.mkdtemp(path6.join(tmpBase, "pd4castr-init-"));
|
|
631
|
+
process.chdir(tmpDir);
|
|
632
|
+
} catch {
|
|
633
|
+
}
|
|
634
|
+
try {
|
|
635
|
+
await fetcher.clone(destination);
|
|
636
|
+
} finally {
|
|
637
|
+
try {
|
|
638
|
+
process.chdir(originalCwd);
|
|
639
|
+
} catch {
|
|
640
|
+
}
|
|
641
|
+
if (tmpDir) {
|
|
642
|
+
await fs6.rm(tmpDir, {
|
|
643
|
+
recursive: true,
|
|
644
|
+
force: true
|
|
645
|
+
}).catch(() => {
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
}
|
|
622
649
|
}
|
|
623
650
|
__name(fetchTemplate, "fetchTemplate");
|
|
624
651
|
function isDegitError(error) {
|
|
@@ -648,15 +675,15 @@ import ora3 from "ora";
|
|
|
648
675
|
import { ZodError as ZodError3 } from "zod";
|
|
649
676
|
|
|
650
677
|
// src/config/update-global-config.ts
|
|
651
|
-
import
|
|
652
|
-
import
|
|
678
|
+
import fs7 from "fs/promises";
|
|
679
|
+
import os3 from "os";
|
|
653
680
|
import path7 from "path";
|
|
654
681
|
import { produce } from "immer";
|
|
655
682
|
async function updateGlobalConfig(updateFn) {
|
|
656
683
|
const globalConfig = await loadGlobalConfig();
|
|
657
684
|
const updatedConfig = produce(globalConfig, updateFn);
|
|
658
|
-
const configPath = path7.join(
|
|
659
|
-
await
|
|
685
|
+
const configPath = path7.join(os3.homedir(), GLOBAL_CONFIG_FILE);
|
|
686
|
+
await fs7.writeFile(configPath, JSON.stringify(updatedConfig, void 0, 2));
|
|
660
687
|
}
|
|
661
688
|
__name(updateGlobalConfig, "updateGlobalConfig");
|
|
662
689
|
|
|
@@ -879,14 +906,14 @@ async function triggerModelRun(modelId, authCtx) {
|
|
|
879
906
|
__name(triggerModelRun, "triggerModelRun");
|
|
880
907
|
|
|
881
908
|
// src/config/update-project-config.ts
|
|
882
|
-
import
|
|
909
|
+
import fs8 from "fs/promises";
|
|
883
910
|
import path8 from "path";
|
|
884
911
|
import { produce as produce2 } from "immer";
|
|
885
912
|
async function updateProjectConfig(updateFn, configPath) {
|
|
886
913
|
const projectConfig = await loadProjectContext(configPath);
|
|
887
914
|
const updatedConfig = produce2(projectConfig.config, updateFn);
|
|
888
915
|
const resolvedConfigPath = configPath ? path8.resolve(configPath) : path8.join(projectConfig.projectRoot, PROJECT_CONFIG_FILE);
|
|
889
|
-
await
|
|
916
|
+
await fs8.writeFile(resolvedConfigPath, JSON.stringify(updatedConfig, void 0, 2));
|
|
890
917
|
}
|
|
891
918
|
__name(updateProjectConfig, "updateProjectConfig");
|
|
892
919
|
|
|
@@ -968,7 +995,7 @@ function getDockerImage(ctx) {
|
|
|
968
995
|
__name(getDockerImage, "getDockerImage");
|
|
969
996
|
|
|
970
997
|
// src/utils/get-model-config-from-project-config.ts
|
|
971
|
-
import
|
|
998
|
+
import fs9 from "fs/promises";
|
|
972
999
|
import path9 from "path";
|
|
973
1000
|
async function getModelConfigFromProjectConfig(ctx) {
|
|
974
1001
|
const inputs = await getInputsWithInlinedSQL(ctx);
|
|
@@ -1002,8 +1029,8 @@ async function getInputsWithInlinedSQL(ctx) {
|
|
|
1002
1029
|
const fetchQueryPath = path9.resolve(ctx.projectRoot, input2.fetcher.config.fetchQuery);
|
|
1003
1030
|
const checkQueryPath = path9.resolve(ctx.projectRoot, input2.fetcher.config.checkQuery);
|
|
1004
1031
|
const [fetchQuerySQL, checkQuerySQL] = await Promise.all([
|
|
1005
|
-
|
|
1006
|
-
|
|
1032
|
+
fs9.readFile(fetchQueryPath, "utf8"),
|
|
1033
|
+
fs9.readFile(checkQueryPath, "utf8")
|
|
1007
1034
|
]);
|
|
1008
1035
|
const inputWithSQL = {
|
|
1009
1036
|
...input2,
|
|
@@ -1027,7 +1054,7 @@ async function getSensitivitiesWithInlinedSQL(ctx) {
|
|
|
1027
1054
|
for (const sensitivity of sensitivities) {
|
|
1028
1055
|
const queryPath = path9.resolve(ctx.projectRoot, sensitivity.query);
|
|
1029
1056
|
try {
|
|
1030
|
-
const sql = await
|
|
1057
|
+
const sql = await fs9.readFile(queryPath, "utf8");
|
|
1031
1058
|
sensitivitiesWithSQL.push({
|
|
1032
1059
|
...sensitivity,
|
|
1033
1060
|
query: sql
|
|
@@ -1044,7 +1071,7 @@ async function getInputAggregationsWithInlinedSQL(ctx) {
|
|
|
1044
1071
|
for (const inputAggregation of ctx.config.inputAggregations) {
|
|
1045
1072
|
const queryPath = path9.resolve(ctx.projectRoot, inputAggregation.query);
|
|
1046
1073
|
try {
|
|
1047
|
-
const sql = await
|
|
1074
|
+
const sql = await fs9.readFile(queryPath, "utf8");
|
|
1048
1075
|
inputAggregationsWithSQL.push({
|
|
1049
1076
|
...inputAggregation,
|
|
1050
1077
|
query: sql
|
|
@@ -1062,7 +1089,7 @@ async function getrunDatetimeQuerySQL(ctx) {
|
|
|
1062
1089
|
}
|
|
1063
1090
|
const queryPath = path9.resolve(ctx.projectRoot, ctx.config.runDatetimeQuery);
|
|
1064
1091
|
try {
|
|
1065
|
-
const sql = await
|
|
1092
|
+
const sql = await fs9.readFile(queryPath, "utf8");
|
|
1066
1093
|
return sql;
|
|
1067
1094
|
} catch {
|
|
1068
1095
|
throw new Error(`Run datetime query file not found (${ctx.config.runDatetimeQuery})`);
|
|
@@ -1158,7 +1185,7 @@ function getInputType(input2) {
|
|
|
1158
1185
|
__name(getInputType, "getInputType");
|
|
1159
1186
|
|
|
1160
1187
|
// src/docker/run-model-container.ts
|
|
1161
|
-
import
|
|
1188
|
+
import os4 from "os";
|
|
1162
1189
|
import { execa as execa4 } from "execa";
|
|
1163
1190
|
|
|
1164
1191
|
// src/docker/utils/get-input-env.ts
|
|
@@ -1210,7 +1237,7 @@ async function runModelContainer(dockerImage, webserverPort, ctx) {
|
|
|
1210
1237
|
__name(runModelContainer, "runModelContainer");
|
|
1211
1238
|
function getWSLMachineIP() {
|
|
1212
1239
|
const env = getEnv();
|
|
1213
|
-
const interfaces =
|
|
1240
|
+
const interfaces = os4.networkInterfaces();
|
|
1214
1241
|
const interfaceInfo = interfaces[env.wslNetworkInterface]?.[0];
|
|
1215
1242
|
if (!interfaceInfo) {
|
|
1216
1243
|
throw new Error(`WSL machine IP not found for interface \`${env.wslNetworkInterface}\``);
|
|
@@ -1276,18 +1303,18 @@ function createInputHandler(inputFilesPath, modelIOChecks, ctx) {
|
|
|
1276
1303
|
__name(createInputHandler, "createInputHandler");
|
|
1277
1304
|
|
|
1278
1305
|
// src/model-io-checks/utils/create-output-handler.ts
|
|
1279
|
-
import
|
|
1306
|
+
import fs10 from "fs/promises";
|
|
1280
1307
|
import path13 from "path";
|
|
1281
1308
|
function createOutputHandler(modelIOChecks, ctx) {
|
|
1282
1309
|
return async (req, res) => {
|
|
1283
1310
|
modelIOChecks.trackOutputHandled();
|
|
1284
1311
|
const outputPath = path13.join(ctx.projectRoot, TEST_OUTPUT_DATA_DIR);
|
|
1285
|
-
await
|
|
1312
|
+
await fs10.mkdir(outputPath, {
|
|
1286
1313
|
recursive: true
|
|
1287
1314
|
});
|
|
1288
1315
|
const outputFilePath = path13.join(outputPath, TEST_OUTPUT_FILENAME);
|
|
1289
1316
|
const outputData = JSON.stringify(req.body, null, 2);
|
|
1290
|
-
await
|
|
1317
|
+
await fs10.writeFile(outputFilePath, outputData, "utf8");
|
|
1291
1318
|
return res.status(200).json({
|
|
1292
1319
|
success: true
|
|
1293
1320
|
});
|
|
@@ -1331,7 +1358,7 @@ async function runModelIOTests(dockerImage, options, app, ctx) {
|
|
|
1331
1358
|
__name(runModelIOTests, "runModelIOTests");
|
|
1332
1359
|
|
|
1333
1360
|
// src/commands/publish/utils/upload-static-inputs.ts
|
|
1334
|
-
import
|
|
1361
|
+
import fs11 from "fs";
|
|
1335
1362
|
import path15 from "path";
|
|
1336
1363
|
import ky3, { isHTTPError } from "ky";
|
|
1337
1364
|
import promiseRetry from "promise-retry";
|
|
@@ -1395,8 +1422,8 @@ var RETRY_LIMIT = 3;
|
|
|
1395
1422
|
var RETRY_DELAY_MS = 250;
|
|
1396
1423
|
async function uploadWithRetry(filePath, signedUploadURL) {
|
|
1397
1424
|
const upload = /* @__PURE__ */ __name(async (retry) => {
|
|
1398
|
-
const { size } =
|
|
1399
|
-
const body =
|
|
1425
|
+
const { size } = fs11.statSync(filePath);
|
|
1426
|
+
const body = fs11.createReadStream(filePath);
|
|
1400
1427
|
try {
|
|
1401
1428
|
const response = await ky3.put(signedUploadURL, {
|
|
1402
1429
|
body,
|
|
@@ -1541,7 +1568,7 @@ import * as inquirer3 from "@inquirer/prompts";
|
|
|
1541
1568
|
import chalk4 from "chalk";
|
|
1542
1569
|
|
|
1543
1570
|
// src/utils/migrate-config.ts
|
|
1544
|
-
import
|
|
1571
|
+
import fs12 from "fs/promises";
|
|
1545
1572
|
import invariant4 from "tiny-invariant";
|
|
1546
1573
|
|
|
1547
1574
|
// src/migrations/01-backfill-output-variable-keys.ts
|
|
@@ -1653,7 +1680,7 @@ async function migrateConfig(ctx, migrationCtx) {
|
|
|
1653
1680
|
$$configVersion: lastMigration.version
|
|
1654
1681
|
};
|
|
1655
1682
|
ctx.config = config;
|
|
1656
|
-
await
|
|
1683
|
+
await fs12.writeFile(ctx.configPath, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
1657
1684
|
}
|
|
1658
1685
|
__name(migrateConfig, "migrateConfig");
|
|
1659
1686
|
|