@ikas/component-cli 1.4.0-beta.22 → 1.4.0-beta.23
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/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +12 -9
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +66 -118
- package/dist/commands/create.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -6
- package/dist/index.js.map +1 -1
- package/dist/utils/compile.d.ts.map +1 -1
- package/dist/utils/compile.js +17 -8
- package/dist/utils/compile.js.map +1 -1
- package/dist/utils/editor-action-client.d.ts +1 -1
- package/dist/utils/editor-action-client.d.ts.map +1 -1
- package/dist/utils/editor-action-client.js.map +1 -1
- package/dist/utils/websocket-server.d.ts +2 -2
- package/dist/utils/websocket-server.d.ts.map +1 -1
- package/dist/utils/websocket-server.js.map +1 -1
- package/package.json +1 -1
- package/dist/commands/list-page-sections.d.ts +0 -3
- package/dist/commands/list-page-sections.d.ts.map +0 -1
- package/dist/commands/list-page-sections.js +0 -25
- package/dist/commands/list-page-sections.js.map +0 -1
- package/dist/commands/proxy.d.ts +0 -39
- package/dist/commands/proxy.d.ts.map +0 -1
- package/dist/commands/proxy.js +0 -210
- package/dist/commands/proxy.js.map +0 -1
- package/dist/commands/update-section-prop.d.ts +0 -3
- package/dist/commands/update-section-prop.d.ts.map +0 -1
- package/dist/commands/update-section-prop.js +0 -59
- package/dist/commands/update-section-prop.js.map +0 -1
- package/dist/commands/upload-image.d.ts +0 -3
- package/dist/commands/upload-image.d.ts.map +0 -1
- package/dist/commands/upload-image.js +0 -79
- package/dist/commands/upload-image.js.map +0 -1
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { basename, extname } from "node:path";
|
|
4
|
-
import { printErrorAndExit, printResultAndExit, runEditorAction, } from "../utils/editor-action-client.js";
|
|
5
|
-
const MIME_BY_EXT = {
|
|
6
|
-
".png": "image/png",
|
|
7
|
-
".jpg": "image/jpeg",
|
|
8
|
-
".jpeg": "image/jpeg",
|
|
9
|
-
".webp": "image/webp",
|
|
10
|
-
".gif": "image/gif",
|
|
11
|
-
};
|
|
12
|
-
const VALID_IMAGE_TYPES = Object.values(MIME_BY_EXT);
|
|
13
|
-
const MAX_SIZE_BYTES = 10 * 1024 * 1024; // 10MB, mirrors the editor's IMAGE_UPLOAD_LIMIT_SIZE
|
|
14
|
-
async function loadImage(options) {
|
|
15
|
-
if (options.file && options.url) {
|
|
16
|
-
throw new Error("Provide only one of --file or --url, not both");
|
|
17
|
-
}
|
|
18
|
-
if (options.file) {
|
|
19
|
-
const buffer = await readFile(options.file);
|
|
20
|
-
const ext = extname(options.file).toLowerCase();
|
|
21
|
-
const mimeType = MIME_BY_EXT[ext];
|
|
22
|
-
if (!mimeType) {
|
|
23
|
-
throw new Error(`Unsupported image extension "${ext || "(none)"}". Supported: ${Object.keys(MIME_BY_EXT).join(", ")}`);
|
|
24
|
-
}
|
|
25
|
-
if (buffer.byteLength > MAX_SIZE_BYTES) {
|
|
26
|
-
throw new Error(`Image is ${(buffer.byteLength / 1024 / 1024).toFixed(1)}MB; the limit is 10MB`);
|
|
27
|
-
}
|
|
28
|
-
return { base64: buffer.toString("base64"), mimeType, fileName: basename(options.file) };
|
|
29
|
-
}
|
|
30
|
-
if (options.url) {
|
|
31
|
-
const res = await fetch(options.url);
|
|
32
|
-
if (!res.ok) {
|
|
33
|
-
throw new Error(`Failed to fetch image: ${res.status} ${res.statusText}`);
|
|
34
|
-
}
|
|
35
|
-
const mimeType = (res.headers.get("content-type") || "").split(";")[0].trim();
|
|
36
|
-
if (!VALID_IMAGE_TYPES.includes(mimeType)) {
|
|
37
|
-
throw new Error(`URL returned content-type "${mimeType || "(none)"}". Supported: ${VALID_IMAGE_TYPES.join(", ")}`);
|
|
38
|
-
}
|
|
39
|
-
const buffer = Buffer.from(await res.arrayBuffer());
|
|
40
|
-
if (buffer.byteLength > MAX_SIZE_BYTES) {
|
|
41
|
-
throw new Error(`Image is ${(buffer.byteLength / 1024 / 1024).toFixed(1)}MB; the limit is 10MB`);
|
|
42
|
-
}
|
|
43
|
-
const urlName = basename(new URL(options.url).pathname) || "image";
|
|
44
|
-
return { base64: buffer.toString("base64"), mimeType, fileName: urlName };
|
|
45
|
-
}
|
|
46
|
-
throw new Error("Provide --file <path> or --url <url>");
|
|
47
|
-
}
|
|
48
|
-
async function runUploadImage(options) {
|
|
49
|
-
const port = options.port ? parseInt(options.port, 10) : undefined;
|
|
50
|
-
try {
|
|
51
|
-
const { base64, mimeType, fileName } = await loadImage(options);
|
|
52
|
-
const result = await runEditorAction("upload-image", {
|
|
53
|
-
base64,
|
|
54
|
-
mimeType,
|
|
55
|
-
fileName,
|
|
56
|
-
...(options.alt ? { altText: options.alt } : {}),
|
|
57
|
-
isVideo: false,
|
|
58
|
-
},
|
|
59
|
-
// Uploads carry the full image payload and round-trip to the host, so give
|
|
60
|
-
// them a far more generous timeout than the default 10s.
|
|
61
|
-
{ ...(port ? { port } : {}), timeoutMs: 60_000 });
|
|
62
|
-
printResultAndExit(result);
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
printErrorAndExit(e);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export function createUploadImageCommand() {
|
|
69
|
-
const cmd = new Command("upload-image");
|
|
70
|
-
cmd
|
|
71
|
-
.description("Upload an image to the connected editor's project and return its image id. Supply the image with --file (local path) or --url. The returned id can be used as the `id` of an IMAGE prop value via `ikas-component update-section-prop`. Requires the editor to be embedded in the ikas admin panel (the host performs the actual upload).")
|
|
72
|
-
.option("--file <path>", "Local image file path (.png, .jpg, .jpeg, .webp, .gif)")
|
|
73
|
-
.option("--url <url>", "Image URL to fetch and upload")
|
|
74
|
-
.option("--alt <text>", "Alt text for the image")
|
|
75
|
-
.option("--port <port>", "Dev server WebSocket port", "5201")
|
|
76
|
-
.action(runUploadImage);
|
|
77
|
-
return cmd;
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=upload-image.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upload-image.js","sourceRoot":"","sources":["../../src/commands/upload-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAS1C,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;CACpB,CAAC;AAEF,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACrD,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,qDAAqD;AAE9F,KAAK,UAAU,SAAS,CACtB,OAA2B;IAE3B,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAChD,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MA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