@uniformdev/cli 19.42.1-alpha.6 → 19.42.1-alpha.7

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.mjs +57 -9
  2. package/package.json +6 -6
package/dist/index.mjs CHANGED
@@ -412,6 +412,7 @@ async function syncEngine({
412
412
  // eslint-disable-next-line @typescript-eslint/no-empty-function
413
413
  log = () => {
414
414
  },
415
+ onBeforeCompareObjects,
415
416
  onBeforeWriteObject
416
417
  }) {
417
418
  var _a, _b;
@@ -446,12 +447,13 @@ async function syncEngine({
446
447
  }
447
448
  const actions = [];
448
449
  let sourceHasItems = false;
449
- for await (const sourceObject of source.objects) {
450
+ for await (let sourceObject of source.objects) {
450
451
  sourceHasItems = true;
451
452
  const ids = Array.isArray(sourceObject.id) ? sourceObject.id : [sourceObject.id];
452
453
  const targetObject = targetItems.get(ids[0]);
453
454
  const invalidTargetObjects = ids.map((i) => targetItems.get(i)).filter((o) => (o == null ? void 0 : o.object) !== (targetObject == null ? void 0 : targetObject.object));
454
455
  if (targetObject && invalidTargetObjects.length == 0) {
456
+ sourceObject = onBeforeCompareObjects ? await onBeforeCompareObjects(sourceObject, targetObject) : sourceObject;
455
457
  if (!compareContents(sourceObject, targetObject)) {
456
458
  if (mode === "createOrUpdate" || mode === "mirror") {
457
459
  const process2 = async (sourceObject2, targetObject2) => {
@@ -1469,11 +1471,15 @@ import sizeOf from "image-size";
1469
1471
  import PQueue from "p-queue";
1470
1472
  import { join as join2 } from "path";
1471
1473
  var FILES_DIRECTORY_NAME = "files";
1472
- var urlToFileName = (url) => {
1474
+ var urlToHash = (url) => {
1473
1475
  const hash = createHash("sha256");
1474
1476
  hash.update(url);
1475
- const fileName = hash.digest("hex");
1476
- const fileExtension = url.split(".").pop();
1477
+ return hash.digest("hex");
1478
+ };
1479
+ var urlToFileName = (url) => {
1480
+ const fileName = urlToHash(url);
1481
+ const fileNameChunks = url.split(".");
1482
+ const fileExtension = fileNameChunks.length > 1 ? fileNameChunks.at(-1) : "";
1477
1483
  return `${fileName}${fileExtension ? `.${fileExtension}` : ""}`;
1478
1484
  };
1479
1485
  var extractAndDownloadUniformFilesForObject = async (object, options) => {
@@ -1518,13 +1524,17 @@ var extractAndUploadUniformFilesForObject = async (object, options) => {
1518
1524
  /"(https:\/\/(.*)?img\.uniform\.(rocks|global)\/(.*?))"/g
1519
1525
  );
1520
1526
  if (uniformFileUrlMatches) {
1521
- const fileUploadQueue = new PQueue({ concurrency: 5 });
1527
+ const fileUploadQueue = new PQueue({ concurrency: 3 });
1522
1528
  for (const match of uniformFileUrlMatches) {
1523
1529
  const url = match[1];
1530
+ const hash = urlToHash(url);
1524
1531
  fileUploadQueue.add(async () => {
1525
1532
  try {
1526
- const fileAlreadyExists = await options.fileClient.getFile({ url }).catch(() => null);
1527
- if (fileAlreadyExists) {
1533
+ const fileAlreadyExistsChecks = await Promise.all([
1534
+ options.fileClient.getFile({ projectId: options.projectId, url }).catch(() => null),
1535
+ options.fileClient.getFile({ projectId: options.projectId, sourceId: hash }).catch(() => null)
1536
+ ]);
1537
+ if (fileAlreadyExistsChecks.some((check) => check !== null)) {
1528
1538
  return;
1529
1539
  }
1530
1540
  const localFileName = urlToFileName(url);
@@ -1559,7 +1569,9 @@ var extractAndUploadUniformFilesForObject = async (object, options) => {
1559
1569
  mediaType: preferredType(url.split(".").at(-1) ?? ""),
1560
1570
  size: fileBuffer.length,
1561
1571
  width,
1562
- height
1572
+ height,
1573
+ projectId: options.projectId,
1574
+ sourceId: hash
1563
1575
  });
1564
1576
  const uploadResponse = await fetch(uploadUrl, {
1565
1577
  method,
@@ -1592,6 +1604,35 @@ var extractAndUploadUniformFilesForObject = async (object, options) => {
1592
1604
  }
1593
1605
  return JSON.parse(objectAsString);
1594
1606
  };
1607
+ var swapOutUniformFileUrlsForTargetProject = async (object, options) => {
1608
+ let objectAsString = JSON.stringify(object);
1609
+ const uniformFileUrlMatches = objectAsString.matchAll(
1610
+ /"(https:\/\/(.*)?img\.uniform\.(rocks|global)\/(.*?))"/g
1611
+ );
1612
+ if (uniformFileUrlMatches) {
1613
+ const fileUrlReplacementQueue = new PQueue({ concurrency: 3 });
1614
+ for (const match of uniformFileUrlMatches) {
1615
+ const url = match[1];
1616
+ const hash = urlToHash(url);
1617
+ fileUrlReplacementQueue.add(async () => {
1618
+ try {
1619
+ const fileAlreadyExistsChecks = await Promise.all([
1620
+ options.fileClient.getFile({ projectId: options.projectId, url }).catch(() => null),
1621
+ options.fileClient.getFile({ projectId: options.projectId, sourceId: hash }).catch(() => null)
1622
+ ]);
1623
+ const file = fileAlreadyExistsChecks.find((check) => check !== null);
1624
+ if (!file) {
1625
+ return;
1626
+ }
1627
+ objectAsString = objectAsString.replaceAll(`"${url}"`, `"${file.url}"`);
1628
+ } catch {
1629
+ }
1630
+ });
1631
+ }
1632
+ await fileUrlReplacementQueue.onIdle();
1633
+ }
1634
+ return JSON.parse(objectAsString);
1635
+ };
1595
1636
 
1596
1637
  // src/commands/canvas/commands/composition/pull.ts
1597
1638
  var CompositionPullModule = {
@@ -1769,10 +1810,17 @@ var CompositionPushModule = {
1769
1810
  mode,
1770
1811
  whatIf,
1771
1812
  log: createSyncEngineConsoleLogger({ diffMode }),
1813
+ onBeforeCompareObjects: async (sourceObject) => {
1814
+ return swapOutUniformFileUrlsForTargetProject(sourceObject, {
1815
+ fileClient,
1816
+ projectId
1817
+ });
1818
+ },
1772
1819
  onBeforeWriteObject: async (sourceObject) => {
1773
1820
  return extractAndUploadUniformFilesForObject(sourceObject, {
1774
1821
  directory,
1775
- fileClient
1822
+ fileClient,
1823
+ projectId
1776
1824
  });
1777
1825
  }
1778
1826
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/cli",
3
- "version": "19.42.1-alpha.6+8511a0877",
3
+ "version": "19.42.1-alpha.7+1380aadd7",
4
4
  "description": "Uniform command line interface tool",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./cli.js",
@@ -17,11 +17,11 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@thi.ng/mime": "^2.2.23",
20
- "@uniformdev/canvas": "19.42.1-alpha.6+8511a0877",
21
- "@uniformdev/context": "19.42.1-alpha.6+8511a0877",
20
+ "@uniformdev/canvas": "19.42.1-alpha.7+1380aadd7",
21
+ "@uniformdev/context": "19.42.1-alpha.7+1380aadd7",
22
22
  "@uniformdev/files-sdk": "19.37.0",
23
- "@uniformdev/project-map": "19.42.1-alpha.6+8511a0877",
24
- "@uniformdev/redirect": "19.42.1-alpha.6+8511a0877",
23
+ "@uniformdev/project-map": "19.42.1-alpha.7+1380aadd7",
24
+ "@uniformdev/redirect": "19.42.1-alpha.7+1380aadd7",
25
25
  "colorette": "2.0.20",
26
26
  "cosmiconfig": "8.2.0",
27
27
  "cosmiconfig-typescript-loader": "5.0.0",
@@ -66,5 +66,5 @@
66
66
  "publishConfig": {
67
67
  "access": "public"
68
68
  },
69
- "gitHead": "8511a0877200b169973a40ab7c7684e6744f3d2f"
69
+ "gitHead": "1380aadd7c71f6f120f933a40e73e113518e3716"
70
70
  }