tiendu 0.2.0 → 0.2.1
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/lib/dev.mjs +15 -4
- package/lib/preview.mjs +52 -13
- package/lib/pull.mjs +0 -4
- package/package.json +1 -1
package/lib/dev.mjs
CHANGED
|
@@ -4,7 +4,11 @@ import path from "node:path";
|
|
|
4
4
|
import * as p from "@clack/prompts";
|
|
5
5
|
import { zipSync } from "fflate";
|
|
6
6
|
import { loadConfigOrFail, writeConfig } from "./config.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
createPreview,
|
|
9
|
+
listPreviews,
|
|
10
|
+
resolveActivePreview,
|
|
11
|
+
} from "./preview.mjs";
|
|
8
12
|
import {
|
|
9
13
|
deletePreviewFile,
|
|
10
14
|
uploadPreviewFileMultipart,
|
|
@@ -102,15 +106,22 @@ export const dev = async () => {
|
|
|
102
106
|
process.exit(1);
|
|
103
107
|
}
|
|
104
108
|
|
|
105
|
-
const existing = listResult.data
|
|
109
|
+
const existing = resolveActivePreview(listResult.data, previewKey);
|
|
106
110
|
if (!existing) {
|
|
107
|
-
spinner.stop("
|
|
111
|
+
spinner.stop("Could not determine the active preview.", 1);
|
|
108
112
|
p.log.error(
|
|
109
|
-
|
|
113
|
+
listResult.data.length === 0
|
|
114
|
+
? "No previews found for this store. A new preview will be created if you clear the local config and run tiendu dev again."
|
|
115
|
+
: "Run tiendu preview list and then set or recreate the preview.",
|
|
110
116
|
);
|
|
111
117
|
process.exit(1);
|
|
112
118
|
}
|
|
113
119
|
|
|
120
|
+
previewKey = existing.previewKey;
|
|
121
|
+
if (config.previewKey !== previewKey) {
|
|
122
|
+
await writeConfig({ ...config, previewKey });
|
|
123
|
+
}
|
|
124
|
+
|
|
114
125
|
previewUrl = buildPreviewUrl(apiBaseUrl, existing.previewHostname);
|
|
115
126
|
spinner.stop(`Preview: ${previewUrl}`);
|
|
116
127
|
}
|
package/lib/preview.mjs
CHANGED
|
@@ -8,6 +8,25 @@ const buildPreviewUrl = (apiBaseUrl, previewHostname) => {
|
|
|
8
8
|
return `${base.protocol}//${previewHostname}${!hasExplicitPort && base.port ? `:${base.port}` : ""}/`;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @param {Array<any>} previews
|
|
13
|
+
* @param {string | undefined} previewKey
|
|
14
|
+
* @returns {any | null}
|
|
15
|
+
*/
|
|
16
|
+
export const resolveActivePreview = (previews, previewKey) => {
|
|
17
|
+
if (previewKey) {
|
|
18
|
+
return (
|
|
19
|
+
previews.find((preview) => preview.previewKey === previewKey) ?? null
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (previews.length === 1) {
|
|
24
|
+
return previews[0];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
|
|
11
30
|
/**
|
|
12
31
|
* @param {string} apiBaseUrl
|
|
13
32
|
* @param {string} apiKey
|
|
@@ -196,8 +215,11 @@ export const previewList = async () => {
|
|
|
196
215
|
`${result.data.length} preview${result.data.length === 1 ? "" : "s"}:`,
|
|
197
216
|
);
|
|
198
217
|
|
|
218
|
+
const activePreview = resolveActivePreview(result.data, config.previewKey);
|
|
219
|
+
|
|
199
220
|
for (const preview of result.data) {
|
|
200
|
-
const active =
|
|
221
|
+
const active =
|
|
222
|
+
activePreview?.previewKey === preview.previewKey ? " ← active" : "";
|
|
201
223
|
const url = buildPreviewUrl(config.apiBaseUrl, preview.previewHostname);
|
|
202
224
|
p.log.message(` ${preview.name} ${url}${active}`);
|
|
203
225
|
}
|
|
@@ -206,13 +228,31 @@ export const previewList = async () => {
|
|
|
206
228
|
export const previewDelete = async () => {
|
|
207
229
|
const { config, credentials } = await loadConfigOrFail();
|
|
208
230
|
|
|
209
|
-
|
|
210
|
-
|
|
231
|
+
const listResult = await listPreviews(
|
|
232
|
+
config.apiBaseUrl,
|
|
233
|
+
credentials.apiKey,
|
|
234
|
+
config.storeId,
|
|
235
|
+
);
|
|
236
|
+
if (!listResult.ok) {
|
|
237
|
+
p.log.error(listResult.error);
|
|
238
|
+
process.exit(1);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const activePreview = resolveActivePreview(
|
|
242
|
+
listResult.data,
|
|
243
|
+
config.previewKey,
|
|
244
|
+
);
|
|
245
|
+
if (!activePreview) {
|
|
246
|
+
p.log.error(
|
|
247
|
+
listResult.data.length === 0
|
|
248
|
+
? "No previews found for this store."
|
|
249
|
+
: "Could not determine the active preview. Run tiendu preview list first.",
|
|
250
|
+
);
|
|
211
251
|
process.exit(1);
|
|
212
252
|
}
|
|
213
253
|
|
|
214
254
|
const confirmed = await p.confirm({
|
|
215
|
-
message: `Delete preview ${
|
|
255
|
+
message: `Delete preview ${activePreview.previewKey}?`,
|
|
216
256
|
});
|
|
217
257
|
|
|
218
258
|
if (p.isCancel(confirmed) || !confirmed) {
|
|
@@ -227,7 +267,7 @@ export const previewDelete = async () => {
|
|
|
227
267
|
config.apiBaseUrl,
|
|
228
268
|
credentials.apiKey,
|
|
229
269
|
config.storeId,
|
|
230
|
-
|
|
270
|
+
activePreview.previewKey,
|
|
231
271
|
);
|
|
232
272
|
|
|
233
273
|
if (!result.ok) {
|
|
@@ -245,11 +285,6 @@ export const previewDelete = async () => {
|
|
|
245
285
|
export const previewOpen = async () => {
|
|
246
286
|
const { config, credentials } = await loadConfigOrFail();
|
|
247
287
|
|
|
248
|
-
if (!config.previewKey) {
|
|
249
|
-
p.log.error("No active preview. Create one with: tiendu preview create");
|
|
250
|
-
process.exit(1);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
288
|
const spinner = p.spinner();
|
|
254
289
|
spinner.start("Fetching preview URL...");
|
|
255
290
|
|
|
@@ -265,10 +300,14 @@ export const previewOpen = async () => {
|
|
|
265
300
|
process.exit(1);
|
|
266
301
|
}
|
|
267
302
|
|
|
268
|
-
const preview = result.data
|
|
303
|
+
const preview = resolveActivePreview(result.data, config.previewKey);
|
|
269
304
|
if (!preview) {
|
|
270
|
-
spinner.stop("
|
|
271
|
-
p.log.error(
|
|
305
|
+
spinner.stop("Could not determine the active preview.", 1);
|
|
306
|
+
p.log.error(
|
|
307
|
+
result.data.length === 0
|
|
308
|
+
? "No previews found for this store."
|
|
309
|
+
: "Run tiendu preview list and then set or recreate the preview.",
|
|
310
|
+
);
|
|
272
311
|
process.exit(1);
|
|
273
312
|
}
|
|
274
313
|
|
package/lib/pull.mjs
CHANGED