@plasmicapp/cli 0.1.237 → 0.1.239
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.
|
@@ -13,7 +13,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.fixComponentImagesReferences = exports.fixComponentCssReferences = exports.syncProjectImageAssets = void 0;
|
|
16
|
+
const cli_progress_1 = __importDefault(require("cli-progress"));
|
|
16
17
|
const lodash_1 = __importDefault(require("lodash"));
|
|
18
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
17
19
|
const upath_1 = __importDefault(require("upath"));
|
|
18
20
|
const deps_1 = require("../deps");
|
|
19
21
|
const config_utils_1 = require("../utils/config-utils");
|
|
@@ -28,6 +30,7 @@ function syncProjectImageAssets(context, projectId, branchName, version, imageBu
|
|
|
28
30
|
const imageFileLocks = lodash_1.default.keyBy(projectLock.fileLocks.filter((fileLock) => fileLock.type === "image"), (fl) => fl.assetId);
|
|
29
31
|
const id2ImageChecksum = new Map(checksums.imageChecksums);
|
|
30
32
|
const deletedImages = lodash_1.default.filter(knownImageConfigs, (i) => !imageBundleIds[i.id] && !id2ImageChecksum.has(i.id));
|
|
33
|
+
yield ensureImageAssetContents(imageBundles);
|
|
31
34
|
for (const bundle of imageBundles) {
|
|
32
35
|
if (context.cliArgs.quiet !== true) {
|
|
33
36
|
deps_1.logger.info(`Syncing image: ${bundle.name}@${version}\t['${project.projectName}' ${project.projectId}/${bundle.id} ${project.version}]`);
|
|
@@ -87,6 +90,37 @@ function syncProjectImageAssets(context, projectId, branchName, version, imageBu
|
|
|
87
90
|
});
|
|
88
91
|
}
|
|
89
92
|
exports.syncProjectImageAssets = syncProjectImageAssets;
|
|
93
|
+
function ensureImageAssetContents(bundles) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
// The server may send images as a url instead of a base64 blob. In that
|
|
96
|
+
// case, we fetch the images here in the cli, instead of on the server.
|
|
97
|
+
// If you have a lot of images, this moves the expensive / long fetch
|
|
98
|
+
// from the codegen server to the cli
|
|
99
|
+
const needsFetching = bundles.filter((b) => b.blob.startsWith("https://site-assets.plasmic.app/"));
|
|
100
|
+
if (needsFetching.length === 0) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const bar = new cli_progress_1.default.SingleBar({
|
|
104
|
+
format: `Downloading images [{bar}] | {value}/{total}`,
|
|
105
|
+
});
|
|
106
|
+
bar.start(needsFetching.length, 0);
|
|
107
|
+
yield Promise.all(needsFetching.map((bundle) => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
try {
|
|
109
|
+
const res = yield node_fetch_1.default(bundle.blob);
|
|
110
|
+
if (res.status !== 200) {
|
|
111
|
+
throw new Error(`Fetching ${bundle.blob} failed with status ${res.status}`);
|
|
112
|
+
}
|
|
113
|
+
const arrayBuffer = yield res.arrayBuffer();
|
|
114
|
+
bundle.blob = Buffer.from(arrayBuffer).toString("base64");
|
|
115
|
+
bar.increment();
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
deps_1.logger.error(`Failed to fetch image ${bundle.fileName}: ${err}`);
|
|
119
|
+
}
|
|
120
|
+
})));
|
|
121
|
+
bar.stop();
|
|
122
|
+
});
|
|
123
|
+
}
|
|
90
124
|
function getImagePublicUrl(context, asset) {
|
|
91
125
|
return (lang_utils_1.ensure(context.config.images.publicUrlPrefix) +
|
|
92
126
|
(lang_utils_1.ensure(context.config.images.publicUrlPrefix).endsWith("/") ? "" : "/") +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.239",
|
|
4
4
|
"description": "plasmic cli for syncing local code with Plasmic designs",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12"
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@babel/preset-typescript": "^7.12.1",
|
|
23
|
-
"@plasmicapp/react-web": "0.2.
|
|
23
|
+
"@plasmicapp/react-web": "0.2.180",
|
|
24
|
+
"@types/cli-progress": "^3.11.0",
|
|
24
25
|
"@types/findup-sync": "^2.0.2",
|
|
25
26
|
"@types/glob": "^7.1.3",
|
|
26
27
|
"@types/inquirer": "^6.5.0",
|
|
@@ -54,6 +55,7 @@
|
|
|
54
55
|
"@sentry/node": "^5.19.2",
|
|
55
56
|
"axios": "^0.21.1",
|
|
56
57
|
"chalk": "^4.1.0",
|
|
58
|
+
"cli-progress": "^3.12.0",
|
|
57
59
|
"fast-glob": "^3.2.4",
|
|
58
60
|
"findup-sync": "^4.0.0",
|
|
59
61
|
"fs": "^0.0.1-security",
|
|
@@ -77,5 +79,5 @@
|
|
|
77
79
|
"wrap-ansi": "^7.0.0",
|
|
78
80
|
"yargs": "^15.4.1"
|
|
79
81
|
},
|
|
80
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "c1f2560551d97e2e4b2c52669a262532795f54b2"
|
|
81
83
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import cliProgress from "cli-progress";
|
|
1
2
|
import L from "lodash";
|
|
3
|
+
import fetch from "node-fetch";
|
|
2
4
|
import path from "upath";
|
|
3
5
|
import { ChecksumBundle, ImageBundle } from "../api";
|
|
4
6
|
import { logger } from "../deps";
|
|
@@ -43,6 +45,8 @@ export async function syncProjectImageAssets(
|
|
|
43
45
|
(i) => !imageBundleIds[i.id] && !id2ImageChecksum.has(i.id)
|
|
44
46
|
);
|
|
45
47
|
|
|
48
|
+
await ensureImageAssetContents(imageBundles);
|
|
49
|
+
|
|
46
50
|
for (const bundle of imageBundles) {
|
|
47
51
|
if (context.cliArgs.quiet !== true) {
|
|
48
52
|
logger.info(
|
|
@@ -125,6 +129,43 @@ export async function syncProjectImageAssets(
|
|
|
125
129
|
);
|
|
126
130
|
}
|
|
127
131
|
|
|
132
|
+
async function ensureImageAssetContents(bundles: ImageBundle[]) {
|
|
133
|
+
// The server may send images as a url instead of a base64 blob. In that
|
|
134
|
+
// case, we fetch the images here in the cli, instead of on the server.
|
|
135
|
+
// If you have a lot of images, this moves the expensive / long fetch
|
|
136
|
+
// from the codegen server to the cli
|
|
137
|
+
const needsFetching = bundles.filter((b) =>
|
|
138
|
+
b.blob.startsWith("https://site-assets.plasmic.app/")
|
|
139
|
+
);
|
|
140
|
+
if (needsFetching.length === 0) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const bar = new cliProgress.SingleBar({
|
|
145
|
+
format: `Downloading images [{bar}] | {value}/{total}`,
|
|
146
|
+
});
|
|
147
|
+
bar.start(needsFetching.length, 0);
|
|
148
|
+
|
|
149
|
+
await Promise.all(
|
|
150
|
+
needsFetching.map(async (bundle) => {
|
|
151
|
+
try {
|
|
152
|
+
const res = await fetch(bundle.blob);
|
|
153
|
+
if (res.status !== 200) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
`Fetching ${bundle.blob} failed with status ${res.status}`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
const arrayBuffer = await res.arrayBuffer();
|
|
159
|
+
bundle.blob = Buffer.from(arrayBuffer).toString("base64");
|
|
160
|
+
bar.increment();
|
|
161
|
+
} catch (err) {
|
|
162
|
+
logger.error(`Failed to fetch image ${bundle.fileName}: ${err}`);
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
bar.stop();
|
|
167
|
+
}
|
|
168
|
+
|
|
128
169
|
function getImagePublicUrl(context: PlasmicContext, asset: ImageConfig) {
|
|
129
170
|
return (
|
|
130
171
|
ensure(context.config.images.publicUrlPrefix) +
|