@uniformdev/cli 19.42.1-alpha.7 → 19.45.0

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 +13 -216
  2. package/package.json +8 -12
package/dist/index.mjs CHANGED
@@ -411,9 +411,7 @@ async function syncEngine({
411
411
  whatIf = false,
412
412
  // eslint-disable-next-line @typescript-eslint/no-empty-function
413
413
  log = () => {
414
- },
415
- onBeforeCompareObjects,
416
- onBeforeWriteObject
414
+ }
417
415
  }) {
418
416
  var _a, _b;
419
417
  const targetItems = /* @__PURE__ */ new Map();
@@ -447,20 +445,18 @@ async function syncEngine({
447
445
  }
448
446
  const actions = [];
449
447
  let sourceHasItems = false;
450
- for await (let sourceObject of source.objects) {
448
+ for await (const sourceObject of source.objects) {
451
449
  sourceHasItems = true;
452
450
  const ids = Array.isArray(sourceObject.id) ? sourceObject.id : [sourceObject.id];
453
451
  const targetObject = targetItems.get(ids[0]);
454
452
  const invalidTargetObjects = ids.map((i) => targetItems.get(i)).filter((o) => (o == null ? void 0 : o.object) !== (targetObject == null ? void 0 : targetObject.object));
455
453
  if (targetObject && invalidTargetObjects.length == 0) {
456
- sourceObject = onBeforeCompareObjects ? await onBeforeCompareObjects(sourceObject, targetObject) : sourceObject;
457
454
  if (!compareContents(sourceObject, targetObject)) {
458
455
  if (mode === "createOrUpdate" || mode === "mirror") {
459
456
  const process2 = async (sourceObject2, targetObject2) => {
460
457
  if (!whatIf) {
461
458
  try {
462
- const finalSourceObject = onBeforeWriteObject ? await onBeforeWriteObject(sourceObject2, targetObject2) : sourceObject2;
463
- await target.writeObject(finalSourceObject, targetObject2);
459
+ await target.writeObject(sourceObject2, targetObject2);
464
460
  } catch (e) {
465
461
  throw new SyncEngineError(e, sourceObject2);
466
462
  }
@@ -482,8 +478,7 @@ async function syncEngine({
482
478
  const process2 = async (sourceObject2, id) => {
483
479
  if (!whatIf) {
484
480
  try {
485
- const finalSourceObject = onBeforeWriteObject ? await onBeforeWriteObject(sourceObject2) : sourceObject2;
486
- await target.writeObject(finalSourceObject);
481
+ await target.writeObject(sourceObject2);
487
482
  } catch (e) {
488
483
  throw new SyncEngineError(e, sourceObject2);
489
484
  }
@@ -1461,180 +1456,6 @@ var CompositionPublishModule = {
1461
1456
 
1462
1457
  // src/commands/canvas/commands/composition/pull.ts
1463
1458
  import { UncachedCanvasClient as UncachedCanvasClient10 } from "@uniformdev/canvas";
1464
-
1465
- // src/files/index.ts
1466
- import { preferredType } from "@thi.ng/mime";
1467
- import { FILE_READY_STATE, getFileNameFromUrl } from "@uniformdev/files-sdk";
1468
- import { createHash } from "crypto";
1469
- import fsj from "fs-jetpack";
1470
- import sizeOf from "image-size";
1471
- import PQueue from "p-queue";
1472
- import { join as join2 } from "path";
1473
- var FILES_DIRECTORY_NAME = "files";
1474
- var urlToHash = (url) => {
1475
- const hash = createHash("sha256");
1476
- hash.update(url);
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) : "";
1483
- return `${fileName}${fileExtension ? `.${fileExtension}` : ""}`;
1484
- };
1485
- var extractAndDownloadUniformFilesForObject = async (object, options) => {
1486
- const objectAsString = JSON.stringify(object);
1487
- const uniformFileUrlMatches = objectAsString.matchAll(
1488
- /"(https:\/\/(.*)?img\.uniform\.(rocks|global)\/(.*?))"/g
1489
- );
1490
- if (uniformFileUrlMatches) {
1491
- const fileDownloadQueue = new PQueue({ concurrency: 10 });
1492
- for (const match of uniformFileUrlMatches) {
1493
- const url = match[1];
1494
- fileDownloadQueue.add(async () => {
1495
- try {
1496
- const fileName = urlToFileName(url);
1497
- const fileAlreadyExists = await fsj.existsAsync(
1498
- join2(options.directory, FILES_DIRECTORY_NAME, fileName)
1499
- );
1500
- if (fileAlreadyExists) {
1501
- return;
1502
- }
1503
- const response = await fetch(url);
1504
- if (!response.ok) {
1505
- return;
1506
- }
1507
- const fileBuffer = await response.arrayBuffer();
1508
- await fsj.writeAsync(
1509
- join2(options.directory, FILES_DIRECTORY_NAME, fileName),
1510
- Buffer.from(fileBuffer)
1511
- );
1512
- } catch {
1513
- console.warn(`Failed to download file ${url}`);
1514
- }
1515
- });
1516
- }
1517
- await fileDownloadQueue.onIdle();
1518
- }
1519
- return object;
1520
- };
1521
- var extractAndUploadUniformFilesForObject = async (object, options) => {
1522
- let objectAsString = JSON.stringify(object);
1523
- const uniformFileUrlMatches = objectAsString.matchAll(
1524
- /"(https:\/\/(.*)?img\.uniform\.(rocks|global)\/(.*?))"/g
1525
- );
1526
- if (uniformFileUrlMatches) {
1527
- const fileUploadQueue = new PQueue({ concurrency: 3 });
1528
- for (const match of uniformFileUrlMatches) {
1529
- const url = match[1];
1530
- const hash = urlToHash(url);
1531
- fileUploadQueue.add(async () => {
1532
- try {
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)) {
1538
- return;
1539
- }
1540
- const localFileName = urlToFileName(url);
1541
- const fileExistsLocally = await fsj.existsAsync(
1542
- join2(options.directory, FILES_DIRECTORY_NAME, localFileName)
1543
- );
1544
- if (!fileExistsLocally) {
1545
- console.warn(`Skipping file ${url} as we couldn't find a local copy`);
1546
- return;
1547
- }
1548
- const fileBuffer = await fsj.readAsync(
1549
- join2(options.directory, FILES_DIRECTORY_NAME, localFileName),
1550
- "buffer"
1551
- );
1552
- if (!fileBuffer) {
1553
- console.warn(`Skipping file ${url} as we couldn't read it`);
1554
- return;
1555
- }
1556
- const fileName = getFileNameFromUrl(url);
1557
- const { width, height } = (() => {
1558
- try {
1559
- return sizeOf(fileBuffer);
1560
- } catch {
1561
- return {
1562
- width: void 0,
1563
- height: void 0
1564
- };
1565
- }
1566
- })();
1567
- const { id, method, uploadUrl } = await options.fileClient.createNewProjectFile({
1568
- name: fileName,
1569
- mediaType: preferredType(url.split(".").at(-1) ?? ""),
1570
- size: fileBuffer.length,
1571
- width,
1572
- height,
1573
- projectId: options.projectId,
1574
- sourceId: hash
1575
- });
1576
- const uploadResponse = await fetch(uploadUrl, {
1577
- method,
1578
- body: fileBuffer
1579
- });
1580
- if (!uploadResponse.ok) {
1581
- console.warn(`Failed to upload file ${url}`);
1582
- return;
1583
- }
1584
- const checkForFile = async () => {
1585
- const file = await options.fileClient.getFile({ id });
1586
- if (!file || file.state !== FILE_READY_STATE) {
1587
- await new Promise((resolve) => setTimeout(resolve, 500));
1588
- return checkForFile();
1589
- }
1590
- return file.url;
1591
- };
1592
- const abortTimeout = setTimeout(() => {
1593
- throw new Error(`Failed to upload file ${url}`);
1594
- }, 1e4);
1595
- const uploadedFileUrl = await checkForFile();
1596
- clearTimeout(abortTimeout);
1597
- objectAsString = objectAsString.replaceAll(`"${url}"`, `"${uploadedFileUrl}"`);
1598
- } catch {
1599
- console.warn(`Failed to upload file ${url}`);
1600
- }
1601
- });
1602
- }
1603
- await fileUploadQueue.onIdle();
1604
- }
1605
- return JSON.parse(objectAsString);
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
- };
1636
-
1637
- // src/commands/canvas/commands/composition/pull.ts
1638
1459
  var CompositionPullModule = {
1639
1460
  command: "pull <directory>",
1640
1461
  describe: "Pulls all compositions to local files in a directory",
@@ -1721,19 +1542,13 @@ var CompositionPullModule = {
1721
1542
  target,
1722
1543
  mode,
1723
1544
  whatIf,
1724
- log: createSyncEngineConsoleLogger({ diffMode }),
1725
- onBeforeWriteObject: async (sourceObject) => {
1726
- return extractAndDownloadUniformFilesForObject(sourceObject, {
1727
- directory
1728
- });
1729
- }
1545
+ log: createSyncEngineConsoleLogger({ diffMode })
1730
1546
  });
1731
1547
  }
1732
1548
  };
1733
1549
 
1734
1550
  // src/commands/canvas/commands/composition/push.ts
1735
1551
  import { UncachedCanvasClient as UncachedCanvasClient11 } from "@uniformdev/canvas";
1736
- import { FileClient as FileClient2 } from "@uniformdev/files-sdk";
1737
1552
  var CompositionPushModule = {
1738
1553
  command: "push <directory>",
1739
1554
  describe: "Pushes all compositions from files in a directory to Uniform Canvas",
@@ -1803,26 +1618,12 @@ var CompositionPushModule = {
1803
1618
  });
1804
1619
  }
1805
1620
  const target = createComponentInstanceEngineDataSource({ client, state, onlyCompositions, onlyPatterns });
1806
- const fileClient = new FileClient2({ apiKey, apiHost, fetch: fetch3, projectId });
1807
1621
  await syncEngine({
1808
1622
  source,
1809
1623
  target,
1810
1624
  mode,
1811
1625
  whatIf,
1812
- log: createSyncEngineConsoleLogger({ diffMode }),
1813
- onBeforeCompareObjects: async (sourceObject) => {
1814
- return swapOutUniformFileUrlsForTargetProject(sourceObject, {
1815
- fileClient,
1816
- projectId
1817
- });
1818
- },
1819
- onBeforeWriteObject: async (sourceObject) => {
1820
- return extractAndUploadUniformFilesForObject(sourceObject, {
1821
- directory,
1822
- fileClient,
1823
- projectId
1824
- });
1825
- }
1626
+ log: createSyncEngineConsoleLogger({ diffMode })
1826
1627
  });
1827
1628
  }
1828
1629
  };
@@ -3974,7 +3775,7 @@ import { PostHog } from "posthog-node";
3974
3775
  // package.json
3975
3776
  var package_default = {
3976
3777
  name: "@uniformdev/cli",
3977
- version: "19.42.0",
3778
+ version: "19.45.0",
3978
3779
  description: "Uniform command line interface tool",
3979
3780
  license: "SEE LICENSE IN LICENSE.txt",
3980
3781
  main: "./cli.js",
@@ -3990,10 +3791,8 @@ var package_default = {
3990
3791
  format: 'prettier --write "src/**/*.{js,ts,tsx}"'
3991
3792
  },
3992
3793
  dependencies: {
3993
- "@thi.ng/mime": "^2.2.23",
3994
3794
  "@uniformdev/canvas": "workspace:*",
3995
3795
  "@uniformdev/context": "workspace:*",
3996
- "@uniformdev/files-sdk": "workspace:*",
3997
3796
  "@uniformdev/project-map": "workspace:*",
3998
3797
  "@uniformdev/redirect": "workspace:*",
3999
3798
  colorette: "2.0.20",
@@ -4006,8 +3805,7 @@ var package_default = {
4006
3805
  graphql: "16.7.1",
4007
3806
  "graphql-request": "6.1.0",
4008
3807
  "https-proxy-agent": "^7.0.0",
4009
- "image-size": "^1.0.2",
4010
- inquirer: "9.2.9",
3808
+ inquirer: "9.2.10",
4011
3809
  "isomorphic-git": "1.24.5",
4012
3810
  "isomorphic-unfetch": "^3.1.0",
4013
3811
  "js-yaml": "^4.1.0",
@@ -4015,7 +3813,6 @@ var package_default = {
4015
3813
  "lodash.isequalwith": "^4.4.0",
4016
3814
  open: "9.1.0",
4017
3815
  ora: "6.3.1",
4018
- "p-queue": "7.3.4",
4019
3816
  "posthog-node": "3.1.1",
4020
3817
  slugify: "1.6.6",
4021
3818
  "update-check": "^1.5.4",
@@ -4028,7 +3825,7 @@ var package_default = {
4028
3825
  "@types/js-yaml": "4.0.5",
4029
3826
  "@types/jsonwebtoken": "9.0.2",
4030
3827
  "@types/lodash.isequalwith": "4.4.7",
4031
- "@types/node": "18.17.1",
3828
+ "@types/node": "18.17.5",
4032
3829
  "@types/yargs": "17.0.24"
4033
3830
  },
4034
3831
  bin: {
@@ -4353,7 +4150,7 @@ ${err.message}`);
4353
4150
  // src/projects/cloneStarter.ts
4354
4151
  import crypto2 from "crypto";
4355
4152
  import fs3 from "fs";
4356
- import fsj2 from "fs-jetpack";
4153
+ import fsj from "fs-jetpack";
4357
4154
  import * as git from "isomorphic-git";
4358
4155
  import * as http from "isomorphic-git/http/node/index.js";
4359
4156
  import os from "os";
@@ -4384,7 +4181,7 @@ async function cloneStarter({
4384
4181
  throw new Error(`"${targetDir}" is not empty`);
4385
4182
  }
4386
4183
  const starterDir = path.join(cloneDir, ...pathSegments);
4387
- fsj2.copy(starterDir, targetDir, { overwrite: true });
4184
+ fsj.copy(starterDir, targetDir, { overwrite: true });
4388
4185
  if (dotEnvFile) {
4389
4186
  fs3.writeFileSync(path.resolve(targetDir, ".env"), dotEnvFile, "utf-8");
4390
4187
  }
@@ -6288,7 +6085,7 @@ async function checkForUpdateMiddleware() {
6288
6085
 
6289
6086
  // src/middleware/checkLocalDepsVersionsMiddleware.ts
6290
6087
  import { magenta, red as red6 } from "colorette";
6291
- import { join as join3 } from "path";
6088
+ import { join as join2 } from "path";
6292
6089
 
6293
6090
  // src/fs.ts
6294
6091
  import { promises as fs5 } from "fs";
@@ -6327,7 +6124,7 @@ var checkLocalDepsVersions = async (args) => {
6327
6124
  try {
6328
6125
  let isOutside = false;
6329
6126
  let warning = `${magenta("Warning:")} Installed Uniform packages should be the same version`;
6330
- const localPackages = await tryReadJSON(join3(process.cwd(), "package.json"));
6127
+ const localPackages = await tryReadJSON(join2(process.cwd(), "package.json"));
6331
6128
  if (!localPackages)
6332
6129
  return;
6333
6130
  let firstVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/cli",
3
- "version": "19.42.1-alpha.7+1380aadd7",
3
+ "version": "19.45.0",
4
4
  "description": "Uniform command line interface tool",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./cli.js",
@@ -16,12 +16,10 @@
16
16
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\""
17
17
  },
18
18
  "dependencies": {
19
- "@thi.ng/mime": "^2.2.23",
20
- "@uniformdev/canvas": "19.42.1-alpha.7+1380aadd7",
21
- "@uniformdev/context": "19.42.1-alpha.7+1380aadd7",
22
- "@uniformdev/files-sdk": "19.37.0",
23
- "@uniformdev/project-map": "19.42.1-alpha.7+1380aadd7",
24
- "@uniformdev/redirect": "19.42.1-alpha.7+1380aadd7",
19
+ "@uniformdev/canvas": "19.45.0",
20
+ "@uniformdev/context": "19.45.0",
21
+ "@uniformdev/project-map": "19.45.0",
22
+ "@uniformdev/redirect": "19.45.0",
25
23
  "colorette": "2.0.20",
26
24
  "cosmiconfig": "8.2.0",
27
25
  "cosmiconfig-typescript-loader": "5.0.0",
@@ -32,8 +30,7 @@
32
30
  "graphql": "16.7.1",
33
31
  "graphql-request": "6.1.0",
34
32
  "https-proxy-agent": "^7.0.0",
35
- "image-size": "^1.0.2",
36
- "inquirer": "9.2.9",
33
+ "inquirer": "9.2.10",
37
34
  "isomorphic-git": "1.24.5",
38
35
  "isomorphic-unfetch": "^3.1.0",
39
36
  "js-yaml": "^4.1.0",
@@ -41,7 +38,6 @@
41
38
  "lodash.isequalwith": "^4.4.0",
42
39
  "open": "9.1.0",
43
40
  "ora": "6.3.1",
44
- "p-queue": "7.3.4",
45
41
  "posthog-node": "3.1.1",
46
42
  "slugify": "1.6.6",
47
43
  "update-check": "^1.5.4",
@@ -54,7 +50,7 @@
54
50
  "@types/js-yaml": "4.0.5",
55
51
  "@types/jsonwebtoken": "9.0.2",
56
52
  "@types/lodash.isequalwith": "4.4.7",
57
- "@types/node": "18.17.1",
53
+ "@types/node": "18.17.5",
58
54
  "@types/yargs": "17.0.24"
59
55
  },
60
56
  "bin": {
@@ -66,5 +62,5 @@
66
62
  "publishConfig": {
67
63
  "access": "public"
68
64
  },
69
- "gitHead": "1380aadd7c71f6f120f933a40e73e113518e3716"
65
+ "gitHead": "ff90cd6bd6d9db14f0d3a2ba8bd4db538b66548c"
70
66
  }