nowebcli 0.2.6 → 0.2.7
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/package.json +1 -1
- package/scripts/noweb.mjs +10 -4
package/package.json
CHANGED
package/scripts/noweb.mjs
CHANGED
|
@@ -103,6 +103,7 @@ async function buildTemplate(directory, slugOverride, assetBase = "/assets") {
|
|
|
103
103
|
const metadata = JSON.parse(metadataSource);
|
|
104
104
|
const currentSlug = requireSlug(slugOverride || metadata?.slug);
|
|
105
105
|
if (!metadata || !types.has(metadata.type)) throw new Error(`${currentSlug}: template.json needs a type (${[...types].join(", ")}).`);
|
|
106
|
+
if (metadata.id != null && (!Number.isInteger(metadata.id) || metadata.id < 1)) throw new Error(`${currentSlug}: template.json has an invalid id.`);
|
|
106
107
|
|
|
107
108
|
const [{ compileTemplateAssets }, { validateTemplateCode }, { validateTemplateCustomizations }] = await Promise.all([
|
|
108
109
|
load("templates/templateCompiler.ts"),
|
|
@@ -167,6 +168,7 @@ async function upload() {
|
|
|
167
168
|
const form = new FormData();
|
|
168
169
|
form.set("slug", template.slug);
|
|
169
170
|
form.set("type", template.type);
|
|
171
|
+
if (template.id) form.set("id", String(template.id));
|
|
170
172
|
form.set("source", template.source);
|
|
171
173
|
form.set("customizations", JSON.stringify(template.customizations));
|
|
172
174
|
form.set("assetPaths", JSON.stringify(template.assetFiles.map((file) => file.path)));
|
|
@@ -180,13 +182,15 @@ async function upload() {
|
|
|
180
182
|
});
|
|
181
183
|
const result = await response.json().catch(() => ({}));
|
|
182
184
|
if (!response.ok) throw new Error(result.error || `Upload failed (${response.status}).`);
|
|
185
|
+
if (!Number.isInteger(result.id) || result.id < 1) throw new Error("Upload returned an invalid template ID.");
|
|
186
|
+
await writeFile(join(root, "template.json"), `${JSON.stringify({ id: result.id, slug: template.slug, type: template.type }, null, 2)}\n`);
|
|
183
187
|
console.log(`Published ${template.slug}: ${new URL(result.url, apiBase)}`);
|
|
184
188
|
}
|
|
185
189
|
|
|
186
190
|
async function deleteTemplate(value) {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
191
|
+
const metadata = value ? null : JSON.parse(await readFile(join(root, "template.json"), "utf8"));
|
|
192
|
+
const selectedSlug = requireSlug(value || metadata?.slug);
|
|
193
|
+
const selectedId = Number.isInteger(metadata?.id) && metadata.id > 0 ? metadata.id : null;
|
|
190
194
|
|
|
191
195
|
if (!cliArgs.includes("--yes")) {
|
|
192
196
|
if (!process.stdin.isTTY) throw new Error("Pass --yes to confirm deletion.");
|
|
@@ -197,7 +201,8 @@ async function deleteTemplate(value) {
|
|
|
197
201
|
}
|
|
198
202
|
|
|
199
203
|
const credentials = await requireCredentials();
|
|
200
|
-
const
|
|
204
|
+
const selector = selectedId ? `id=${selectedId}` : `slug=${encodeURIComponent(selectedSlug)}`;
|
|
205
|
+
const response = await fetch(`${apiBase}/api/templates/download?${selector}`, {
|
|
201
206
|
method: "DELETE",
|
|
202
207
|
headers: { Authorization: `Bearer ${credentials.token}` },
|
|
203
208
|
});
|
|
@@ -245,6 +250,7 @@ async function downloadTemplate(value) {
|
|
|
245
250
|
const template = result.template;
|
|
246
251
|
if (
|
|
247
252
|
!template || typeof template.metadata?.slug !== "string" ||
|
|
253
|
+
!Number.isInteger(template.metadata?.id) || template.metadata.id < 1 ||
|
|
248
254
|
!types.has(template.metadata?.type) || typeof template.source !== "string" ||
|
|
249
255
|
!Array.isArray(template.customizations) || !Array.isArray(template.assets) || template.assets.length > 200
|
|
250
256
|
) throw new Error("The server returned an invalid template.");
|