@hardkas/artifacts 0.7.4-alpha → 0.7.5-alpha

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.
Files changed (2) hide show
  1. package/dist/index.js +23 -2
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "@hardkas/artifacts",
4
- version: "0.7.4-alpha",
4
+ version: "0.7.5-alpha",
5
5
  type: "module",
6
6
  license: "MIT",
7
7
  author: "Javier Rodriguez",
@@ -1362,8 +1362,29 @@ import path from "path";
1362
1362
  import { writeFileAtomic } from "@hardkas/core";
1363
1363
  var bigIntReplacer = (_key, value) => typeof value === "bigint" ? value.toString() : value;
1364
1364
  async function writeArtifact(filePath, artifact) {
1365
+ let targetPath = filePath;
1366
+ try {
1367
+ const stats = await fs2.stat(filePath);
1368
+ if (stats.isDirectory()) {
1369
+ const artifactObj = typeof artifact === "string" ? JSON.parse(artifact) : artifact;
1370
+ const id = artifactObj.planId || artifactObj.signedId || artifactObj.txId || Date.now().toString(36);
1371
+ const prefix = artifactObj.schema ? artifactObj.schema.split(".")[1] || "artifact" : "artifact";
1372
+ targetPath = path.join(filePath, `${prefix}-${id}.json`);
1373
+ console.log(`
1374
+ Note: Provided path is a directory. Auto-generating artifact filename: ${path.basename(targetPath)}`);
1375
+ }
1376
+ } catch (e) {
1377
+ if (filePath.endsWith("/") || filePath.endsWith("\\")) {
1378
+ const artifactObj = typeof artifact === "string" ? JSON.parse(artifact) : artifact;
1379
+ const id = artifactObj.planId || artifactObj.signedId || artifactObj.txId || Date.now().toString(36);
1380
+ const prefix = artifactObj.schema ? artifactObj.schema.split(".")[1] || "artifact" : "artifact";
1381
+ targetPath = path.join(filePath, `${prefix}-${id}.json`);
1382
+ console.log(`
1383
+ Note: Provided path is a directory. Auto-generating artifact filename: ${path.basename(targetPath)}`);
1384
+ }
1385
+ }
1365
1386
  const content = typeof artifact === "string" ? artifact : JSON.stringify(artifact, bigIntReplacer, 2) + "\n";
1366
- await writeFileAtomic(filePath, content);
1387
+ await writeFileAtomic(targetPath, content);
1367
1388
  }
1368
1389
  function getDefaultReceiptPath(txId, cwd = process.cwd()) {
1369
1390
  return path.join(cwd, "artifacts", "receipts", `${txId}.json`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardkas/artifacts",
3
- "version": "0.7.4-alpha",
3
+ "version": "0.7.5-alpha",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Javier Rodriguez",
@@ -24,8 +24,8 @@
24
24
  "types": "./dist/index.d.ts",
25
25
  "dependencies": {
26
26
  "zod": "^3.24.1",
27
- "@hardkas/tx-builder": "0.7.4-alpha",
28
- "@hardkas/core": "0.7.4-alpha"
27
+ "@hardkas/core": "0.7.5-alpha",
28
+ "@hardkas/tx-builder": "0.7.5-alpha"
29
29
  },
30
30
  "devDependencies": {
31
31
  "tsup": "^8.3.5",