@uniformdev/cli 19.42.0 → 19.42.1-alpha.6
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.mjs +164 -9
- package/package.json +10 -6
package/dist/index.mjs
CHANGED
|
@@ -411,7 +411,8 @@ async function syncEngine({
|
|
|
411
411
|
whatIf = false,
|
|
412
412
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
413
413
|
log = () => {
|
|
414
|
-
}
|
|
414
|
+
},
|
|
415
|
+
onBeforeWriteObject
|
|
415
416
|
}) {
|
|
416
417
|
var _a, _b;
|
|
417
418
|
const targetItems = /* @__PURE__ */ new Map();
|
|
@@ -456,7 +457,8 @@ async function syncEngine({
|
|
|
456
457
|
const process2 = async (sourceObject2, targetObject2) => {
|
|
457
458
|
if (!whatIf) {
|
|
458
459
|
try {
|
|
459
|
-
await
|
|
460
|
+
const finalSourceObject = onBeforeWriteObject ? await onBeforeWriteObject(sourceObject2, targetObject2) : sourceObject2;
|
|
461
|
+
await target.writeObject(finalSourceObject, targetObject2);
|
|
460
462
|
} catch (e) {
|
|
461
463
|
throw new SyncEngineError(e, sourceObject2);
|
|
462
464
|
}
|
|
@@ -478,7 +480,8 @@ async function syncEngine({
|
|
|
478
480
|
const process2 = async (sourceObject2, id) => {
|
|
479
481
|
if (!whatIf) {
|
|
480
482
|
try {
|
|
481
|
-
await
|
|
483
|
+
const finalSourceObject = onBeforeWriteObject ? await onBeforeWriteObject(sourceObject2) : sourceObject2;
|
|
484
|
+
await target.writeObject(finalSourceObject);
|
|
482
485
|
} catch (e) {
|
|
483
486
|
throw new SyncEngineError(e, sourceObject2);
|
|
484
487
|
}
|
|
@@ -1456,6 +1459,141 @@ var CompositionPublishModule = {
|
|
|
1456
1459
|
|
|
1457
1460
|
// src/commands/canvas/commands/composition/pull.ts
|
|
1458
1461
|
import { UncachedCanvasClient as UncachedCanvasClient10 } from "@uniformdev/canvas";
|
|
1462
|
+
|
|
1463
|
+
// src/files/index.ts
|
|
1464
|
+
import { preferredType } from "@thi.ng/mime";
|
|
1465
|
+
import { FILE_READY_STATE, getFileNameFromUrl } from "@uniformdev/files-sdk";
|
|
1466
|
+
import { createHash } from "crypto";
|
|
1467
|
+
import fsj from "fs-jetpack";
|
|
1468
|
+
import sizeOf from "image-size";
|
|
1469
|
+
import PQueue from "p-queue";
|
|
1470
|
+
import { join as join2 } from "path";
|
|
1471
|
+
var FILES_DIRECTORY_NAME = "files";
|
|
1472
|
+
var urlToFileName = (url) => {
|
|
1473
|
+
const hash = createHash("sha256");
|
|
1474
|
+
hash.update(url);
|
|
1475
|
+
const fileName = hash.digest("hex");
|
|
1476
|
+
const fileExtension = url.split(".").pop();
|
|
1477
|
+
return `${fileName}${fileExtension ? `.${fileExtension}` : ""}`;
|
|
1478
|
+
};
|
|
1479
|
+
var extractAndDownloadUniformFilesForObject = async (object, options) => {
|
|
1480
|
+
const objectAsString = JSON.stringify(object);
|
|
1481
|
+
const uniformFileUrlMatches = objectAsString.matchAll(
|
|
1482
|
+
/"(https:\/\/(.*)?img\.uniform\.(rocks|global)\/(.*?))"/g
|
|
1483
|
+
);
|
|
1484
|
+
if (uniformFileUrlMatches) {
|
|
1485
|
+
const fileDownloadQueue = new PQueue({ concurrency: 10 });
|
|
1486
|
+
for (const match of uniformFileUrlMatches) {
|
|
1487
|
+
const url = match[1];
|
|
1488
|
+
fileDownloadQueue.add(async () => {
|
|
1489
|
+
try {
|
|
1490
|
+
const fileName = urlToFileName(url);
|
|
1491
|
+
const fileAlreadyExists = await fsj.existsAsync(
|
|
1492
|
+
join2(options.directory, FILES_DIRECTORY_NAME, fileName)
|
|
1493
|
+
);
|
|
1494
|
+
if (fileAlreadyExists) {
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
const response = await fetch(url);
|
|
1498
|
+
if (!response.ok) {
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
const fileBuffer = await response.arrayBuffer();
|
|
1502
|
+
await fsj.writeAsync(
|
|
1503
|
+
join2(options.directory, FILES_DIRECTORY_NAME, fileName),
|
|
1504
|
+
Buffer.from(fileBuffer)
|
|
1505
|
+
);
|
|
1506
|
+
} catch {
|
|
1507
|
+
console.warn(`Failed to download file ${url}`);
|
|
1508
|
+
}
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
await fileDownloadQueue.onIdle();
|
|
1512
|
+
}
|
|
1513
|
+
return object;
|
|
1514
|
+
};
|
|
1515
|
+
var extractAndUploadUniformFilesForObject = async (object, options) => {
|
|
1516
|
+
let objectAsString = JSON.stringify(object);
|
|
1517
|
+
const uniformFileUrlMatches = objectAsString.matchAll(
|
|
1518
|
+
/"(https:\/\/(.*)?img\.uniform\.(rocks|global)\/(.*?))"/g
|
|
1519
|
+
);
|
|
1520
|
+
if (uniformFileUrlMatches) {
|
|
1521
|
+
const fileUploadQueue = new PQueue({ concurrency: 5 });
|
|
1522
|
+
for (const match of uniformFileUrlMatches) {
|
|
1523
|
+
const url = match[1];
|
|
1524
|
+
fileUploadQueue.add(async () => {
|
|
1525
|
+
try {
|
|
1526
|
+
const fileAlreadyExists = await options.fileClient.getFile({ url }).catch(() => null);
|
|
1527
|
+
if (fileAlreadyExists) {
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1530
|
+
const localFileName = urlToFileName(url);
|
|
1531
|
+
const fileExistsLocally = await fsj.existsAsync(
|
|
1532
|
+
join2(options.directory, FILES_DIRECTORY_NAME, localFileName)
|
|
1533
|
+
);
|
|
1534
|
+
if (!fileExistsLocally) {
|
|
1535
|
+
console.warn(`Skipping file ${url} as we couldn't find a local copy`);
|
|
1536
|
+
return;
|
|
1537
|
+
}
|
|
1538
|
+
const fileBuffer = await fsj.readAsync(
|
|
1539
|
+
join2(options.directory, FILES_DIRECTORY_NAME, localFileName),
|
|
1540
|
+
"buffer"
|
|
1541
|
+
);
|
|
1542
|
+
if (!fileBuffer) {
|
|
1543
|
+
console.warn(`Skipping file ${url} as we couldn't read it`);
|
|
1544
|
+
return;
|
|
1545
|
+
}
|
|
1546
|
+
const fileName = getFileNameFromUrl(url);
|
|
1547
|
+
const { width, height } = (() => {
|
|
1548
|
+
try {
|
|
1549
|
+
return sizeOf(fileBuffer);
|
|
1550
|
+
} catch {
|
|
1551
|
+
return {
|
|
1552
|
+
width: void 0,
|
|
1553
|
+
height: void 0
|
|
1554
|
+
};
|
|
1555
|
+
}
|
|
1556
|
+
})();
|
|
1557
|
+
const { id, method, uploadUrl } = await options.fileClient.createNewProjectFile({
|
|
1558
|
+
name: fileName,
|
|
1559
|
+
mediaType: preferredType(url.split(".").at(-1) ?? ""),
|
|
1560
|
+
size: fileBuffer.length,
|
|
1561
|
+
width,
|
|
1562
|
+
height
|
|
1563
|
+
});
|
|
1564
|
+
const uploadResponse = await fetch(uploadUrl, {
|
|
1565
|
+
method,
|
|
1566
|
+
body: fileBuffer
|
|
1567
|
+
});
|
|
1568
|
+
if (!uploadResponse.ok) {
|
|
1569
|
+
console.warn(`Failed to upload file ${url}`);
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
const checkForFile = async () => {
|
|
1573
|
+
const file = await options.fileClient.getFile({ id });
|
|
1574
|
+
if (!file || file.state !== FILE_READY_STATE) {
|
|
1575
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1576
|
+
return checkForFile();
|
|
1577
|
+
}
|
|
1578
|
+
return file.url;
|
|
1579
|
+
};
|
|
1580
|
+
const abortTimeout = setTimeout(() => {
|
|
1581
|
+
throw new Error(`Failed to upload file ${url}`);
|
|
1582
|
+
}, 1e4);
|
|
1583
|
+
const uploadedFileUrl = await checkForFile();
|
|
1584
|
+
clearTimeout(abortTimeout);
|
|
1585
|
+
objectAsString = objectAsString.replaceAll(`"${url}"`, `"${uploadedFileUrl}"`);
|
|
1586
|
+
} catch {
|
|
1587
|
+
console.warn(`Failed to upload file ${url}`);
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
await fileUploadQueue.onIdle();
|
|
1592
|
+
}
|
|
1593
|
+
return JSON.parse(objectAsString);
|
|
1594
|
+
};
|
|
1595
|
+
|
|
1596
|
+
// src/commands/canvas/commands/composition/pull.ts
|
|
1459
1597
|
var CompositionPullModule = {
|
|
1460
1598
|
command: "pull <directory>",
|
|
1461
1599
|
describe: "Pulls all compositions to local files in a directory",
|
|
@@ -1542,13 +1680,19 @@ var CompositionPullModule = {
|
|
|
1542
1680
|
target,
|
|
1543
1681
|
mode,
|
|
1544
1682
|
whatIf,
|
|
1545
|
-
log: createSyncEngineConsoleLogger({ diffMode })
|
|
1683
|
+
log: createSyncEngineConsoleLogger({ diffMode }),
|
|
1684
|
+
onBeforeWriteObject: async (sourceObject) => {
|
|
1685
|
+
return extractAndDownloadUniformFilesForObject(sourceObject, {
|
|
1686
|
+
directory
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1546
1689
|
});
|
|
1547
1690
|
}
|
|
1548
1691
|
};
|
|
1549
1692
|
|
|
1550
1693
|
// src/commands/canvas/commands/composition/push.ts
|
|
1551
1694
|
import { UncachedCanvasClient as UncachedCanvasClient11 } from "@uniformdev/canvas";
|
|
1695
|
+
import { FileClient as FileClient2 } from "@uniformdev/files-sdk";
|
|
1552
1696
|
var CompositionPushModule = {
|
|
1553
1697
|
command: "push <directory>",
|
|
1554
1698
|
describe: "Pushes all compositions from files in a directory to Uniform Canvas",
|
|
@@ -1618,12 +1762,19 @@ var CompositionPushModule = {
|
|
|
1618
1762
|
});
|
|
1619
1763
|
}
|
|
1620
1764
|
const target = createComponentInstanceEngineDataSource({ client, state, onlyCompositions, onlyPatterns });
|
|
1765
|
+
const fileClient = new FileClient2({ apiKey, apiHost, fetch: fetch3, projectId });
|
|
1621
1766
|
await syncEngine({
|
|
1622
1767
|
source,
|
|
1623
1768
|
target,
|
|
1624
1769
|
mode,
|
|
1625
1770
|
whatIf,
|
|
1626
|
-
log: createSyncEngineConsoleLogger({ diffMode })
|
|
1771
|
+
log: createSyncEngineConsoleLogger({ diffMode }),
|
|
1772
|
+
onBeforeWriteObject: async (sourceObject) => {
|
|
1773
|
+
return extractAndUploadUniformFilesForObject(sourceObject, {
|
|
1774
|
+
directory,
|
|
1775
|
+
fileClient
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1627
1778
|
});
|
|
1628
1779
|
}
|
|
1629
1780
|
};
|
|
@@ -3791,8 +3942,10 @@ var package_default = {
|
|
|
3791
3942
|
format: 'prettier --write "src/**/*.{js,ts,tsx}"'
|
|
3792
3943
|
},
|
|
3793
3944
|
dependencies: {
|
|
3945
|
+
"@thi.ng/mime": "^2.2.23",
|
|
3794
3946
|
"@uniformdev/canvas": "workspace:*",
|
|
3795
3947
|
"@uniformdev/context": "workspace:*",
|
|
3948
|
+
"@uniformdev/files-sdk": "workspace:*",
|
|
3796
3949
|
"@uniformdev/project-map": "workspace:*",
|
|
3797
3950
|
"@uniformdev/redirect": "workspace:*",
|
|
3798
3951
|
colorette: "2.0.20",
|
|
@@ -3805,6 +3958,7 @@ var package_default = {
|
|
|
3805
3958
|
graphql: "16.7.1",
|
|
3806
3959
|
"graphql-request": "6.1.0",
|
|
3807
3960
|
"https-proxy-agent": "^7.0.0",
|
|
3961
|
+
"image-size": "^1.0.2",
|
|
3808
3962
|
inquirer: "9.2.9",
|
|
3809
3963
|
"isomorphic-git": "1.24.5",
|
|
3810
3964
|
"isomorphic-unfetch": "^3.1.0",
|
|
@@ -3813,6 +3967,7 @@ var package_default = {
|
|
|
3813
3967
|
"lodash.isequalwith": "^4.4.0",
|
|
3814
3968
|
open: "9.1.0",
|
|
3815
3969
|
ora: "6.3.1",
|
|
3970
|
+
"p-queue": "7.3.4",
|
|
3816
3971
|
"posthog-node": "3.1.1",
|
|
3817
3972
|
slugify: "1.6.6",
|
|
3818
3973
|
"update-check": "^1.5.4",
|
|
@@ -4150,7 +4305,7 @@ ${err.message}`);
|
|
|
4150
4305
|
// src/projects/cloneStarter.ts
|
|
4151
4306
|
import crypto2 from "crypto";
|
|
4152
4307
|
import fs3 from "fs";
|
|
4153
|
-
import
|
|
4308
|
+
import fsj2 from "fs-jetpack";
|
|
4154
4309
|
import * as git from "isomorphic-git";
|
|
4155
4310
|
import * as http from "isomorphic-git/http/node/index.js";
|
|
4156
4311
|
import os from "os";
|
|
@@ -4181,7 +4336,7 @@ async function cloneStarter({
|
|
|
4181
4336
|
throw new Error(`"${targetDir}" is not empty`);
|
|
4182
4337
|
}
|
|
4183
4338
|
const starterDir = path.join(cloneDir, ...pathSegments);
|
|
4184
|
-
|
|
4339
|
+
fsj2.copy(starterDir, targetDir, { overwrite: true });
|
|
4185
4340
|
if (dotEnvFile) {
|
|
4186
4341
|
fs3.writeFileSync(path.resolve(targetDir, ".env"), dotEnvFile, "utf-8");
|
|
4187
4342
|
}
|
|
@@ -6085,7 +6240,7 @@ async function checkForUpdateMiddleware() {
|
|
|
6085
6240
|
|
|
6086
6241
|
// src/middleware/checkLocalDepsVersionsMiddleware.ts
|
|
6087
6242
|
import { magenta, red as red6 } from "colorette";
|
|
6088
|
-
import { join as
|
|
6243
|
+
import { join as join3 } from "path";
|
|
6089
6244
|
|
|
6090
6245
|
// src/fs.ts
|
|
6091
6246
|
import { promises as fs5 } from "fs";
|
|
@@ -6124,7 +6279,7 @@ var checkLocalDepsVersions = async (args) => {
|
|
|
6124
6279
|
try {
|
|
6125
6280
|
let isOutside = false;
|
|
6126
6281
|
let warning = `${magenta("Warning:")} Installed Uniform packages should be the same version`;
|
|
6127
|
-
const localPackages = await tryReadJSON(
|
|
6282
|
+
const localPackages = await tryReadJSON(join3(process.cwd(), "package.json"));
|
|
6128
6283
|
if (!localPackages)
|
|
6129
6284
|
return;
|
|
6130
6285
|
let firstVersion;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/cli",
|
|
3
|
-
"version": "19.42.
|
|
3
|
+
"version": "19.42.1-alpha.6+8511a0877",
|
|
4
4
|
"description": "Uniform command line interface tool",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./cli.js",
|
|
@@ -16,10 +16,12 @@
|
|
|
16
16
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\""
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"@uniformdev/
|
|
21
|
-
"@uniformdev/
|
|
22
|
-
"@uniformdev/
|
|
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",
|
|
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
25
|
"colorette": "2.0.20",
|
|
24
26
|
"cosmiconfig": "8.2.0",
|
|
25
27
|
"cosmiconfig-typescript-loader": "5.0.0",
|
|
@@ -30,6 +32,7 @@
|
|
|
30
32
|
"graphql": "16.7.1",
|
|
31
33
|
"graphql-request": "6.1.0",
|
|
32
34
|
"https-proxy-agent": "^7.0.0",
|
|
35
|
+
"image-size": "^1.0.2",
|
|
33
36
|
"inquirer": "9.2.9",
|
|
34
37
|
"isomorphic-git": "1.24.5",
|
|
35
38
|
"isomorphic-unfetch": "^3.1.0",
|
|
@@ -38,6 +41,7 @@
|
|
|
38
41
|
"lodash.isequalwith": "^4.4.0",
|
|
39
42
|
"open": "9.1.0",
|
|
40
43
|
"ora": "6.3.1",
|
|
44
|
+
"p-queue": "7.3.4",
|
|
41
45
|
"posthog-node": "3.1.1",
|
|
42
46
|
"slugify": "1.6.6",
|
|
43
47
|
"update-check": "^1.5.4",
|
|
@@ -62,5 +66,5 @@
|
|
|
62
66
|
"publishConfig": {
|
|
63
67
|
"access": "public"
|
|
64
68
|
},
|
|
65
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "8511a0877200b169973a40ab7c7684e6744f3d2f"
|
|
66
70
|
}
|