@uniformdev/cli 19.82.1-alpha.5 → 19.82.2-alpha.19

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.d.mts CHANGED
@@ -31,4 +31,4 @@ type CLIConfiguration = {
31
31
  serialization: UserDefinedSerializationConfiguration;
32
32
  };
33
33
 
34
- export { CLIConfiguration };
34
+ export type { CLIConfiguration };
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
7
7
  throw Error('Dynamic require of "' + x + '" is not supported');
8
8
  });
9
9
 
10
- // ../../node_modules/.pnpm/tsup@7.2.0_postcss@8.4.31_ts-node@10.9.1_typescript@5.2.2/node_modules/tsup/assets/esm_shims.js
10
+ // ../../node_modules/.pnpm/tsup@8.0.1_@microsoft+api-extractor@7.36.3_postcss@8.4.31_typescript@5.2.2/node_modules/tsup/assets/esm_shims.js
11
11
  import { fileURLToPath } from "url";
12
12
  import path from "path";
13
13
  var getFilename = () => fileURLToPath(import.meta.url);
@@ -669,62 +669,30 @@ var AssetListModule = {
669
669
 
670
670
  // src/commands/canvas/commands/asset/pull.ts
671
671
  import { UncachedAssetClient as UncachedAssetClient3 } from "@uniformdev/assets";
672
- import { UncachedFileClient } from "@uniformdev/files";
673
672
 
674
673
  // src/files/index.ts
675
674
  import { preferredType } from "@thi.ng/mime";
676
675
  import { FILE_READY_STATE, getFileNameFromUrl } from "@uniformdev/files";
676
+ import { createHash } from "crypto";
677
677
  import fsj from "fs-jetpack";
678
678
  import sizeOf from "image-size";
679
679
  import PQueue from "p-queue";
680
680
  import { dirname as dirname2, join as join2 } from "path";
681
681
  var FILES_DIRECTORY_NAME = "files";
682
- var escapeRegExp = (string) => {
683
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
684
- };
685
682
  var urlToHash = (url) => {
686
- return Buffer.from(
687
- // We take only the first 64 characters of the pathname as
688
- // that's enough to guarantee uniqueness
689
- new URL(url).pathname.substring(0, 64)
690
- ).toString("base64");
691
- };
692
- var hashToPartialPathname = (hash) => {
693
- try {
694
- return Buffer.from(hash, "base64").toString("utf8");
695
- } catch {
696
- return null;
697
- }
698
- };
699
- var findUrlMatchingPartialPathname = (source, pathname) => {
700
- const escapedPathname = escapeRegExp(pathname);
701
- const regex = new RegExp(`"(https://([^"]*?)?img.uniform.(rocks|global)${escapedPathname}([^"]*?))"`);
702
- const match = source.match(regex);
703
- if (match && match[1]) {
704
- return match[1];
705
- }
706
- return null;
683
+ const hash = createHash("sha256");
684
+ hash.update(url);
685
+ return hash.digest("hex");
707
686
  };
708
- var urlToFileName = (url, hash) => {
709
- const fileName = hash ?? urlToHash(url);
687
+ var urlToFileName = (url) => {
688
+ const fileName = urlToHash(url);
710
689
  const fileNameChunks = url.split(".");
711
690
  const fileExtension = fileNameChunks.length > 1 ? fileNameChunks.at(-1) : "";
712
691
  return `${fileName}${fileExtension ? `.${fileExtension}` : ""}`;
713
692
  };
714
- var getFilesDirectory = (directory) => {
715
- const isPackage = isPathAPackageFile(directory);
716
- return isPackage ? dirname2(directory) : (
717
- // If we are syncing to a directory, we want to write all files into a
718
- // top-lvl folder. That way any entities that contain files will sync to the
719
- // same directory, so there is no duplication
720
- join2(directory, "..")
721
- );
722
- };
723
- var getUniformFileUrlMatches = (string) => {
724
- return string.matchAll(/"(https:\/\/(.*?)?img\.uniform\.(rocks|global)\/(.*?))"/g);
725
- };
726
693
  var deleteDownloadedFileByUrl = async (url, options) => {
727
- const writeDirectory = getFilesDirectory(options.directory);
694
+ const isPackage = isPathAPackageFile(options.directory);
695
+ const writeDirectory = isPackage ? dirname2(options.directory) : options.directory;
728
696
  const fileName = urlToFileName(url);
729
697
  const fileToDelete = join2(writeDirectory, FILES_DIRECTORY_NAME, fileName);
730
698
  try {
@@ -735,14 +703,18 @@ var deleteDownloadedFileByUrl = async (url, options) => {
735
703
  };
736
704
  var extractAndDownloadUniformFilesForObject = async (object, options) => {
737
705
  const objectAsString = JSON.stringify(object);
738
- const uniformFileUrlMatches = getUniformFileUrlMatches(objectAsString);
739
- const writeDirectory = getFilesDirectory(options.directory);
706
+ const uniformFileUrlMatches = objectAsString.matchAll(
707
+ /"(https:\/\/(.*)?img\.uniform\.(rocks|global)\/(.*?))"/g
708
+ );
709
+ const isPackage = isPathAPackageFile(options.directory);
710
+ const writeDirectory = isPackage ? dirname2(options.directory) : options.directory;
740
711
  if (uniformFileUrlMatches) {
741
712
  const fileDownloadQueue = new PQueue({ concurrency: 10 });
742
713
  for (const match of uniformFileUrlMatches) {
743
714
  const url = new URL(match[1]);
744
715
  fileDownloadQueue.add(async () => {
745
716
  try {
717
+ const fetchUrl = `${url.origin}${url.pathname}?format=original`;
746
718
  const fileName = urlToFileName(url.toString());
747
719
  const fileAlreadyExists = await fsj.existsAsync(
748
720
  join2(writeDirectory, FILES_DIRECTORY_NAME, fileName)
@@ -750,20 +722,6 @@ var extractAndDownloadUniformFilesForObject = async (object, options) => {
750
722
  if (fileAlreadyExists) {
751
723
  return;
752
724
  }
753
- const file = await options.fileClient.get({ url: url.toString() }).catch(() => null);
754
- if (!file) {
755
- console.warn(`Skipping file ${url} as it does not exist in the project anymore`);
756
- return;
757
- }
758
- if (file.sourceId) {
759
- const hashAlreadyExists = await fsj.findAsync(join2(writeDirectory, FILES_DIRECTORY_NAME), {
760
- matching: [file.sourceId, `${file.sourceId}.*`]
761
- });
762
- if (hashAlreadyExists.length > 0) {
763
- return;
764
- }
765
- }
766
- const fetchUrl = `${url.origin}${url.pathname}?format=original`;
767
725
  const response = await fetch(fetchUrl);
768
726
  if (!response.ok) {
769
727
  return;
@@ -781,8 +739,11 @@ var extractAndDownloadUniformFilesForObject = async (object, options) => {
781
739
  };
782
740
  var extractAndUploadUniformFilesForObject = async (object, options) => {
783
741
  let objectAsString = JSON.stringify(object);
784
- const uniformFileUrlMatches = getUniformFileUrlMatches(objectAsString);
785
- const writeDirectory = getFilesDirectory(options.directory);
742
+ const uniformFileUrlMatches = objectAsString.matchAll(
743
+ /"(https:\/\/(.*)?img\.uniform\.(rocks|global)\/(.*?))"/g
744
+ );
745
+ const isPackage = isPathAPackageFile(options.directory);
746
+ const writeDirectory = isPackage ? dirname2(options.directory) : options.directory;
786
747
  if (uniformFileUrlMatches) {
787
748
  const fileUploadQueue = new PQueue({ concurrency: 3 });
788
749
  for (const match of uniformFileUrlMatches) {
@@ -870,7 +831,9 @@ var extractAndUploadUniformFilesForObject = async (object, options) => {
870
831
  };
871
832
  var swapOutUniformFileUrlsForTargetProject = async (object, options) => {
872
833
  let objectAsString = JSON.stringify(object);
873
- const uniformFileUrlMatches = getUniformFileUrlMatches(objectAsString);
834
+ const uniformFileUrlMatches = objectAsString.matchAll(
835
+ /"(https:\/\/(.*)?img\.uniform\.(rocks|global)\/(.*?))"/g
836
+ );
874
837
  if (uniformFileUrlMatches) {
875
838
  const fileUrlReplacementQueue = new PQueue({ concurrency: 3 });
876
839
  for (const match of uniformFileUrlMatches) {
@@ -895,45 +858,6 @@ var swapOutUniformFileUrlsForTargetProject = async (object, options) => {
895
858
  }
896
859
  return JSON.parse(objectAsString);
897
860
  };
898
- var replaceRemoteUrlsWithLocalReferences = async (sourceObject, targetObject, options) => {
899
- let sourceObjectAsString = JSON.stringify(sourceObject);
900
- const targetObjectAsString = JSON.stringify(targetObject);
901
- const uniformFileUrlMatches = getUniformFileUrlMatches(sourceObjectAsString);
902
- const writeDirectory = getFilesDirectory(options.directory);
903
- if (uniformFileUrlMatches) {
904
- const fileUrlReplacementQueue = new PQueue({ concurrency: 3 });
905
- for (const match of uniformFileUrlMatches) {
906
- const url = match[1];
907
- fileUrlReplacementQueue.add(async () => {
908
- try {
909
- const localFileName = urlToFileName(url);
910
- const fileExistsLocally = await fsj.existsAsync(
911
- join2(writeDirectory, FILES_DIRECTORY_NAME, localFileName)
912
- );
913
- if (fileExistsLocally) {
914
- return;
915
- }
916
- const file = await options.fileClient.get({ url }).catch(() => null);
917
- if (!file || !file.sourceId) {
918
- return;
919
- }
920
- const originalPartialPath = hashToPartialPathname(file.sourceId);
921
- if (!originalPartialPath) {
922
- return;
923
- }
924
- const originalUrl = findUrlMatchingPartialPathname(targetObjectAsString, originalPartialPath);
925
- if (!originalUrl) {
926
- return;
927
- }
928
- sourceObjectAsString = sourceObjectAsString.replaceAll(`"${url}"`, `"${originalUrl}"`);
929
- } catch {
930
- }
931
- });
932
- }
933
- await fileUrlReplacementQueue.onIdle();
934
- }
935
- return JSON.parse(sourceObjectAsString);
936
- };
937
861
  var updateAssetFileIdBasedOnUrl = async (asset, options) => {
938
862
  var _a, _b, _c;
939
863
  const fileUrl = (_b = (_a = asset.asset.fields) == null ? void 0 : _a.url) == null ? void 0 : _b.value;
@@ -1085,7 +1009,6 @@ var AssetPullModule = {
1085
1009
  fetch: fetch3,
1086
1010
  projectId
1087
1011
  });
1088
- const fileClient = new UncachedFileClient({ apiKey, apiHost, fetch: fetch3, projectId });
1089
1012
  const source = createAssetEngineDataSource({ client });
1090
1013
  let target;
1091
1014
  const isPackage = isPathAPackageFile(directory);
@@ -1127,27 +1050,14 @@ var AssetPullModule = {
1127
1050
  whatIf,
1128
1051
  allowEmptySource: true,
1129
1052
  log: createSyncEngineConsoleLogger({ diffMode }),
1130
- onBeforeCompareObjects: async (sourceObject, targetObject) => {
1131
- var _a, _b;
1053
+ onBeforeCompareObjects: async (sourceObject) => {
1132
1054
  delete sourceObject.object.asset._author;
1133
- const sourceObjectWithPotentiallySwappedUrl = await replaceRemoteUrlsWithLocalReferences(
1134
- sourceObject,
1135
- targetObject,
1136
- {
1137
- directory,
1138
- fileClient
1139
- }
1140
- );
1141
- if (((_a = sourceObjectWithPotentiallySwappedUrl.object.asset.fields) == null ? void 0 : _a.url) && ((_b = targetObject.object.asset.fields) == null ? void 0 : _b.url) && sourceObjectWithPotentiallySwappedUrl.object.asset.fields.url.value === targetObject.object.asset.fields.url.value) {
1142
- targetObject.object.asset.fields.file = sourceObjectWithPotentiallySwappedUrl.object.asset.fields.file;
1143
- }
1144
- return sourceObjectWithPotentiallySwappedUrl;
1055
+ return sourceObject;
1145
1056
  },
1146
1057
  onBeforeWriteObject: async (sourceObject) => {
1147
1058
  delete sourceObject.object.asset._author;
1148
1059
  return extractAndDownloadUniformFilesForObject(sourceObject, {
1149
- directory,
1150
- fileClient
1060
+ directory
1151
1061
  });
1152
1062
  }
1153
1063
  });
@@ -1156,7 +1066,7 @@ var AssetPullModule = {
1156
1066
 
1157
1067
  // src/commands/canvas/commands/asset/push.ts
1158
1068
  import { UncachedAssetClient as UncachedAssetClient4 } from "@uniformdev/assets";
1159
- import { UncachedFileClient as UncachedFileClient2 } from "@uniformdev/files";
1069
+ import { UncachedFileClient } from "@uniformdev/files";
1160
1070
  var AssetPushModule = {
1161
1071
  command: "push <directory>",
1162
1072
  describe: "Pushes all assets from files in a directory to Uniform",
@@ -1217,7 +1127,7 @@ var AssetPushModule = {
1217
1127
  });
1218
1128
  }
1219
1129
  const target = createAssetEngineDataSource({ client });
1220
- const fileClient = new UncachedFileClient2({ apiKey, apiHost, fetch: fetch3, projectId });
1130
+ const fileClient = new UncachedFileClient({ apiKey, apiHost, fetch: fetch3, projectId });
1221
1131
  await syncEngine({
1222
1132
  source,
1223
1133
  target,
@@ -1240,15 +1150,10 @@ var AssetPushModule = {
1240
1150
  return sourceObjectWithNewFileUrls;
1241
1151
  },
1242
1152
  onBeforeWriteObject: async (sourceObject) => {
1243
- const sourceObjectWithNewFileUrls = await swapOutUniformFileUrlsForTargetProject(
1244
- await extractAndUploadUniformFilesForObject(sourceObject, {
1245
- directory,
1246
- fileClient
1247
- }),
1248
- {
1249
- fileClient
1250
- }
1251
- );
1153
+ const sourceObjectWithNewFileUrls = await extractAndUploadUniformFilesForObject(sourceObject, {
1154
+ directory,
1155
+ fileClient
1156
+ });
1252
1157
  sourceObjectWithNewFileUrls.object = await updateAssetFileIdBasedOnUrl(
1253
1158
  sourceObjectWithNewFileUrls.object,
1254
1159
  {
@@ -2184,7 +2089,6 @@ var CompositionPublishModule = {
2184
2089
 
2185
2090
  // src/commands/canvas/commands/composition/pull.ts
2186
2091
  import { UncachedCanvasClient as UncachedCanvasClient10 } from "@uniformdev/canvas";
2187
- import { UncachedFileClient as UncachedFileClient3 } from "@uniformdev/files";
2188
2092
  var CompositionPullModule = {
2189
2093
  command: "pull <directory>",
2190
2094
  describe: "Pulls all compositions to local files in a directory",
@@ -2244,7 +2148,6 @@ var CompositionPullModule = {
2244
2148
  }) => {
2245
2149
  const fetch3 = nodeFetchProxy(proxy);
2246
2150
  const client = new UncachedCanvasClient10({ apiKey, apiHost, fetch: fetch3, projectId });
2247
- const fileClient = new UncachedFileClient3({ apiKey, apiHost, fetch: fetch3, projectId });
2248
2151
  const source = createComponentInstanceEngineDataSource({ client, state, onlyCompositions, onlyPatterns });
2249
2152
  const isPackage = isPathAPackageFile(directory);
2250
2153
  let target;
@@ -2274,16 +2177,9 @@ var CompositionPullModule = {
2274
2177
  whatIf,
2275
2178
  allowEmptySource: true,
2276
2179
  log: createSyncEngineConsoleLogger({ diffMode }),
2277
- onBeforeCompareObjects: async (sourceObject, targetObject) => {
2278
- return replaceRemoteUrlsWithLocalReferences(sourceObject, targetObject, {
2279
- directory,
2280
- fileClient
2281
- });
2282
- },
2283
2180
  onBeforeWriteObject: async (sourceObject) => {
2284
2181
  return extractAndDownloadUniformFilesForObject(sourceObject, {
2285
- directory,
2286
- fileClient
2182
+ directory
2287
2183
  });
2288
2184
  }
2289
2185
  });
@@ -2292,7 +2188,7 @@ var CompositionPullModule = {
2292
2188
 
2293
2189
  // src/commands/canvas/commands/composition/push.ts
2294
2190
  import { UncachedCanvasClient as UncachedCanvasClient11 } from "@uniformdev/canvas";
2295
- import { UncachedFileClient as UncachedFileClient4 } from "@uniformdev/files";
2191
+ import { UncachedFileClient as UncachedFileClient2 } from "@uniformdev/files";
2296
2192
  var CompositionPushModule = {
2297
2193
  command: "push <directory>",
2298
2194
  describe: "Pushes all compositions from files in a directory to Uniform Canvas",
@@ -2362,7 +2258,7 @@ var CompositionPushModule = {
2362
2258
  });
2363
2259
  }
2364
2260
  const target = createComponentInstanceEngineDataSource({ client, state, onlyCompositions, onlyPatterns });
2365
- const fileClient = new UncachedFileClient4({ apiKey, apiHost, fetch: fetch3, projectId });
2261
+ const fileClient = new UncachedFileClient2({ apiKey, apiHost, fetch: fetch3, projectId });
2366
2262
  await syncEngine({
2367
2263
  source,
2368
2264
  target,
@@ -3165,7 +3061,6 @@ var EntryListModule = {
3165
3061
 
3166
3062
  // src/commands/canvas/commands/entry/pull.ts
3167
3063
  import { ContentClient as ContentClient10 } from "@uniformdev/canvas";
3168
- import { UncachedFileClient as UncachedFileClient5 } from "@uniformdev/files";
3169
3064
 
3170
3065
  // src/commands/canvas/entryEngineDataSource.ts
3171
3066
  import { convertEntryToPutEntry } from "@uniformdev/canvas";
@@ -3265,7 +3160,6 @@ var EntryPullModule = {
3265
3160
  projectId,
3266
3161
  bypassCache: true
3267
3162
  });
3268
- const fileClient = new UncachedFileClient5({ apiKey, apiHost, fetch: fetch3, projectId });
3269
3163
  const source = createEntryEngineDataSource({ client, state });
3270
3164
  let target;
3271
3165
  const isPackage = isPathAPackageFile(directory);
@@ -3294,26 +3188,13 @@ var EntryPullModule = {
3294
3188
  mode,
3295
3189
  whatIf,
3296
3190
  allowEmptySource: true,
3297
- log: createSyncEngineConsoleLogger({ diffMode }),
3298
- onBeforeCompareObjects: async (sourceObject, targetObject) => {
3299
- return replaceRemoteUrlsWithLocalReferences(sourceObject, targetObject, {
3300
- directory,
3301
- fileClient
3302
- });
3303
- },
3304
- onBeforeWriteObject: async (sourceObject) => {
3305
- return extractAndDownloadUniformFilesForObject(sourceObject, {
3306
- directory,
3307
- fileClient
3308
- });
3309
- }
3191
+ log: createSyncEngineConsoleLogger({ diffMode })
3310
3192
  });
3311
3193
  }
3312
3194
  };
3313
3195
 
3314
3196
  // src/commands/canvas/commands/entry/push.ts
3315
3197
  import { ContentClient as ContentClient11 } from "@uniformdev/canvas";
3316
- import { UncachedFileClient as UncachedFileClient6 } from "@uniformdev/files";
3317
3198
  var EntryPushModule = {
3318
3199
  command: "push <directory>",
3319
3200
  describe: "Pushes all entries from files in a directory to Uniform",
@@ -3378,24 +3259,12 @@ var EntryPushModule = {
3378
3259
  });
3379
3260
  }
3380
3261
  const target = createEntryEngineDataSource({ client, state });
3381
- const fileClient = new UncachedFileClient6({ apiKey, apiHost, fetch: fetch3, projectId });
3382
3262
  await syncEngine({
3383
3263
  source,
3384
3264
  target,
3385
3265
  mode,
3386
3266
  whatIf,
3387
- log: createSyncEngineConsoleLogger({ diffMode }),
3388
- onBeforeCompareObjects: async (sourceObject) => {
3389
- return swapOutUniformFileUrlsForTargetProject(sourceObject, {
3390
- fileClient
3391
- });
3392
- },
3393
- onBeforeWriteObject: async (sourceObject) => {
3394
- return extractAndUploadUniformFilesForObject(sourceObject, {
3395
- directory,
3396
- fileClient
3397
- });
3398
- }
3267
+ log: createSyncEngineConsoleLogger({ diffMode })
3399
3268
  });
3400
3269
  }
3401
3270
  };
@@ -5586,7 +5455,7 @@ import { PostHog } from "posthog-node";
5586
5455
  // package.json
5587
5456
  var package_default = {
5588
5457
  name: "@uniformdev/cli",
5589
- version: "19.82.0",
5458
+ version: "19.82.1",
5590
5459
  description: "Uniform command line interface tool",
5591
5460
  license: "SEE LICENSE IN LICENSE.txt",
5592
5461
  main: "./cli.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/cli",
3
- "version": "19.82.1-alpha.5+7af3d5cdf",
3
+ "version": "19.82.2-alpha.19+6199510dc",
4
4
  "description": "Uniform command line interface tool",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./cli.js",
@@ -17,12 +17,12 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@thi.ng/mime": "^2.2.23",
20
- "@uniformdev/assets": "19.82.1-alpha.5+7af3d5cdf",
21
- "@uniformdev/canvas": "19.82.1-alpha.5+7af3d5cdf",
22
- "@uniformdev/context": "19.82.1-alpha.5+7af3d5cdf",
23
- "@uniformdev/files": "19.82.1-alpha.5+7af3d5cdf",
24
- "@uniformdev/project-map": "19.82.1-alpha.5+7af3d5cdf",
25
- "@uniformdev/redirect": "19.82.1-alpha.5+7af3d5cdf",
20
+ "@uniformdev/assets": "19.82.2-alpha.19+6199510dc",
21
+ "@uniformdev/canvas": "19.82.2-alpha.19+6199510dc",
22
+ "@uniformdev/context": "19.82.2-alpha.19+6199510dc",
23
+ "@uniformdev/files": "19.82.2-alpha.19+6199510dc",
24
+ "@uniformdev/project-map": "19.82.2-alpha.19+6199510dc",
25
+ "@uniformdev/redirect": "19.82.2-alpha.19+6199510dc",
26
26
  "call-bind": "^1.0.2",
27
27
  "colorette": "2.0.20",
28
28
  "cosmiconfig": "8.3.6",
@@ -69,5 +69,5 @@
69
69
  "publishConfig": {
70
70
  "access": "public"
71
71
  },
72
- "gitHead": "7af3d5cdfabfe24f8a0d55b430cb2c196d5934d8"
72
+ "gitHead": "6199510dc30be5eb343702326180ea178087d524"
73
73
  }