create-contentisland 0.2.0 → 0.3.0
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.js +337 -306
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { cac as
|
|
2
|
-
import
|
|
1
|
+
import { cac as de } from "cac";
|
|
2
|
+
import f from "prompts";
|
|
3
3
|
import l from "node:fs/promises";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { existsSync as
|
|
7
|
-
import { createClient as
|
|
8
|
-
const
|
|
4
|
+
import r from "node:path";
|
|
5
|
+
import Z from "node:child_process";
|
|
6
|
+
import { existsSync as E } from "node:fs";
|
|
7
|
+
import { createClient as ue } from "@content-island/api-client";
|
|
8
|
+
const F = ".content-island", X = "config.json", B = ".gitignore", $ = ".env", G = {
|
|
9
9
|
aa: "Afaraf",
|
|
10
10
|
ab: "Аҧсуа",
|
|
11
11
|
ae: "Avesta",
|
|
@@ -198,17 +198,17 @@ const P = ".content-island", U = "config.json", O = ".gitignore", A = ".env", M
|
|
|
198
198
|
bold: "\x1B[1m",
|
|
199
199
|
cyan: "\x1B[36m",
|
|
200
200
|
magenta: "\x1B[35m"
|
|
201
|
-
},
|
|
201
|
+
}, v = (e) => {
|
|
202
202
|
let t = "";
|
|
203
203
|
return e?.bold && (t += p.bold), t;
|
|
204
204
|
}, g = {
|
|
205
|
-
green: (e, t) => `${p.green}${
|
|
206
|
-
red: (e, t) => `${p.red}${
|
|
207
|
-
yellow: (e, t) => `${p.yellow}${
|
|
205
|
+
green: (e, t) => `${p.green}${v(t)}${e}${p.reset}`,
|
|
206
|
+
red: (e, t) => `${p.red}${v(t)}${e}${p.reset}`,
|
|
207
|
+
yellow: (e, t) => `${p.yellow}${v(t)}${e}${p.reset}`,
|
|
208
208
|
bold: (e) => `${p.bold}${e}${p.reset}`,
|
|
209
|
-
cyan: (e, t) => `${p.cyan}${
|
|
210
|
-
magenta: (e, t) => `${p.magenta}${
|
|
211
|
-
},
|
|
209
|
+
cyan: (e, t) => `${p.cyan}${v(t)}${e}${p.reset}`,
|
|
210
|
+
magenta: (e, t) => `${p.magenta}${v(t)}${e}${p.reset}`
|
|
211
|
+
}, n = {
|
|
212
212
|
info: (e) => console.log(g.cyan("ℹ️ " + e)),
|
|
213
213
|
success: (e) => console.log(g.green("✅ " + e)),
|
|
214
214
|
warning: (e) => console.log(g.yellow("⚠️ " + e)),
|
|
@@ -233,222 +233,252 @@ const P = ".content-island", U = "config.json", O = ".gitignore", A = ".env", M
|
|
|
233
233
|
updating: (e) => console.log(g.green("🔄 " + e)),
|
|
234
234
|
run: (e) => console.log(g.green("🚀 " + e)),
|
|
235
235
|
command: (e) => console.log(" " + g.magenta(e, { bold: !0 }))
|
|
236
|
-
}, x = () =>
|
|
237
|
-
const e = process.cwd(), t =
|
|
236
|
+
}, x = () => r.join(process.cwd(), F), pe = async () => {
|
|
237
|
+
const e = process.cwd(), t = r.join(e, B), a = `${F}/`;
|
|
238
238
|
let o = "";
|
|
239
|
-
|
|
239
|
+
E(t) && (o = await l.readFile(t, "utf-8"), o.includes(a)) || (o = o + `${o.endsWith(`
|
|
240
240
|
`) ? "" : `
|
|
241
|
-
`}${
|
|
242
|
-
`, await l.writeFile(t, o, "utf-8"),
|
|
243
|
-
},
|
|
241
|
+
`}${a}
|
|
242
|
+
`, await l.writeFile(t, o, "utf-8"), n.saved(`Added ${a} to ${B}`));
|
|
243
|
+
}, me = async () => {
|
|
244
244
|
const e = x();
|
|
245
245
|
try {
|
|
246
|
-
|
|
246
|
+
E(e) || (await l.mkdir(e, { recursive: !0 }), n.created(`Created: ${F}/`)), await pe();
|
|
247
247
|
} catch (t) {
|
|
248
|
-
|
|
248
|
+
n.error(`Failed to create config directory: ${t.message}`);
|
|
249
249
|
}
|
|
250
|
-
},
|
|
251
|
-
const e = await
|
|
252
|
-
if (!
|
|
250
|
+
}, Q = async () => r.join(x(), X), L = async () => {
|
|
251
|
+
const e = await Q();
|
|
252
|
+
if (!E(e))
|
|
253
253
|
return null;
|
|
254
254
|
try {
|
|
255
255
|
const t = await l.readFile(e, "utf-8");
|
|
256
256
|
return JSON.parse(t);
|
|
257
257
|
} catch (t) {
|
|
258
|
-
return
|
|
258
|
+
return n.warning(`Could not parse ${X}: ${t.message}`), null;
|
|
259
259
|
}
|
|
260
|
-
},
|
|
260
|
+
}, b = async (e) => {
|
|
261
261
|
let t = {
|
|
262
262
|
...e
|
|
263
263
|
};
|
|
264
|
-
await
|
|
265
|
-
const
|
|
266
|
-
if (
|
|
267
|
-
const o = await
|
|
264
|
+
await me();
|
|
265
|
+
const a = await Q();
|
|
266
|
+
if (E(a)) {
|
|
267
|
+
const o = await L();
|
|
268
268
|
o && (t = { ...o, ...e });
|
|
269
269
|
}
|
|
270
270
|
try {
|
|
271
271
|
const o = JSON.stringify(t, null, 2);
|
|
272
|
-
await l.writeFile(
|
|
272
|
+
await l.writeFile(a, o, "utf-8"), n.saved(`Saved configuration to ${a}`);
|
|
273
273
|
} catch (o) {
|
|
274
|
-
|
|
274
|
+
n.error(`Failed to save configuration: ${o.message}`);
|
|
275
275
|
}
|
|
276
|
-
},
|
|
277
|
-
let s = 0, i = t,
|
|
278
|
-
const S = ['"', "'", "`"].includes(
|
|
279
|
-
for (let
|
|
280
|
-
const d = e[
|
|
276
|
+
}, fe = (e, t, a, o) => {
|
|
277
|
+
let s = 0, i = t, c = !1, m = "", u = !1;
|
|
278
|
+
const S = ['"', "'", "`"].includes(a);
|
|
279
|
+
for (let w = t; w < e.length; w++) {
|
|
280
|
+
const d = e[w];
|
|
281
281
|
if (u) {
|
|
282
282
|
u = !1;
|
|
283
283
|
continue;
|
|
284
284
|
}
|
|
285
|
-
if (d === "\\" &&
|
|
285
|
+
if (d === "\\" && c) {
|
|
286
286
|
u = !0;
|
|
287
287
|
continue;
|
|
288
288
|
}
|
|
289
289
|
if (S) {
|
|
290
|
-
if (d ===
|
|
290
|
+
if (d === a && !c) {
|
|
291
291
|
if (s++, s === 1)
|
|
292
292
|
continue;
|
|
293
293
|
if (s === 2) {
|
|
294
|
-
i =
|
|
294
|
+
i = w + 1;
|
|
295
295
|
break;
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
} else if (!
|
|
299
|
-
|
|
300
|
-
else if (
|
|
301
|
-
|
|
302
|
-
else if (!
|
|
303
|
-
if (d ===
|
|
298
|
+
} else if (!c && (d === '"' || d === "'" || d === "`"))
|
|
299
|
+
c = !0, m = d;
|
|
300
|
+
else if (c && d === m)
|
|
301
|
+
c = !1;
|
|
302
|
+
else if (!c) {
|
|
303
|
+
if (d === a)
|
|
304
304
|
s++;
|
|
305
305
|
else if (d === o && (s--, s === 0)) {
|
|
306
|
-
i =
|
|
306
|
+
i = w + 1;
|
|
307
307
|
break;
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
return i;
|
|
312
|
-
},
|
|
313
|
-
const { filePath: t, property:
|
|
314
|
-
let
|
|
315
|
-
o === "[" && (
|
|
316
|
-
const m = new RegExp(`${
|
|
312
|
+
}, j = async (e) => {
|
|
313
|
+
const { filePath: t, property: a, startSymbol: o, endSymbol: s } = e, i = await l.readFile(t, "utf-8");
|
|
314
|
+
let c = o;
|
|
315
|
+
o === "[" && (c = "\\["), o === "{" && (c = "\\{"), o === "(" && (c = "\\(");
|
|
316
|
+
const m = new RegExp(`${a}\\s*:\\s*(${c})`), u = i.match(m);
|
|
317
317
|
if (!u)
|
|
318
318
|
return null;
|
|
319
|
-
const S = i.indexOf(u[0]) + u[0].length - 1,
|
|
320
|
-
return i.substring(S,
|
|
321
|
-
},
|
|
319
|
+
const S = i.indexOf(u[0]) + u[0].length - 1, w = fe(i, S, o, s);
|
|
320
|
+
return i.substring(S, w);
|
|
321
|
+
}, we = (e) => JSON.parse(
|
|
322
322
|
e.replace(/'/g, '"').replace(/(\w+):/g, '"$1":').replace(/,\s*}/g, "}").replace(/,\s*]/g, "]")
|
|
323
|
-
),
|
|
324
|
-
let s = await
|
|
325
|
-
if (s || (s = await
|
|
323
|
+
), ee = (e) => e.replace(/"/g, "'").replace(/'(\w+)':/g, "$1:"), he = async (e, t, a, o) => {
|
|
324
|
+
let s = await j(a);
|
|
325
|
+
if (s || (s = await j(o)), !s)
|
|
326
326
|
throw new Error(
|
|
327
|
-
`Could not find property '${
|
|
327
|
+
`Could not find property '${a.property}' or fallback property '${o.property}' in file ${a.filePath}`
|
|
328
328
|
);
|
|
329
|
-
const i =
|
|
330
|
-
return (await l.readFile(
|
|
329
|
+
const i = ee(JSON.stringify(t, null, 2));
|
|
330
|
+
return (await l.readFile(a.filePath, "utf-8")).replace(s, (m) => `${m},
|
|
331
331
|
${e}: ${i}`);
|
|
332
|
-
},
|
|
333
|
-
const
|
|
332
|
+
}, ye = ".git", N = (e, t) => {
|
|
333
|
+
const a = Z.spawn("git", ["clone", "--depth=1", e, t], { stdio: "inherit" });
|
|
334
334
|
return new Promise((o, s) => {
|
|
335
|
-
|
|
336
|
-
l.rm(
|
|
335
|
+
a.on("close", (i) => {
|
|
336
|
+
l.rm(r.join(t, ye), { recursive: !0, force: !0 }).finally(() => {
|
|
337
337
|
i === 0 ? o() : s(new Error("Failed to clone repository. Please make sure the target folder is empty and try again."));
|
|
338
338
|
});
|
|
339
339
|
});
|
|
340
340
|
});
|
|
341
|
-
},
|
|
342
|
-
const t =
|
|
341
|
+
}, _ = (e) => {
|
|
342
|
+
const t = Z.spawn("npm install", {
|
|
343
343
|
cwd: e,
|
|
344
344
|
stdio: "inherit",
|
|
345
345
|
shell: !0
|
|
346
346
|
});
|
|
347
|
-
return new Promise((
|
|
347
|
+
return new Promise((a, o) => {
|
|
348
348
|
t.on("error", (s) => {
|
|
349
|
-
|
|
349
|
+
n.error(`Failed to install dependencies: ${s.message}`), n.error("Please try running 'npm install' manually."), o(s);
|
|
350
350
|
}), t.on("close", (s) => {
|
|
351
|
-
s === 0 ||
|
|
351
|
+
s === 0 || n.error("Failed to install dependencies. Please try running 'npm install' manually."), a();
|
|
352
352
|
});
|
|
353
353
|
});
|
|
354
|
-
},
|
|
355
|
-
const t =
|
|
354
|
+
}, O = async (e) => {
|
|
355
|
+
const t = r.join(e, "package.json"), a = await l.readFile(t, "utf-8"), o = JSON.parse(a);
|
|
356
356
|
if (o.scripts) {
|
|
357
357
|
const { predev: s, ...i } = o.scripts;
|
|
358
358
|
o.scripts = i;
|
|
359
359
|
}
|
|
360
360
|
await l.writeFile(t, JSON.stringify(o, null, 2), "utf-8");
|
|
361
|
-
},
|
|
362
|
-
const
|
|
363
|
-
await l.writeFile(o,
|
|
364
|
-
},
|
|
365
|
-
let
|
|
366
|
-
const
|
|
361
|
+
}, D = async (e, t) => {
|
|
362
|
+
const a = 'CONTENT_ISLAND_ACCESS_TOKEN=YOUR_TOKEN_HERE # You can find the access token in your project’s "General tab" (https://docs.contentisland.net/ui/project/general/)', o = r.join(e, t);
|
|
363
|
+
await l.writeFile(o, a, "utf-8");
|
|
364
|
+
}, ke = "https://github.com/content-island/template-new-bussines-landing-one-page.git", Ee = "create-dev-env.js", J = ".env-sample";
|
|
365
|
+
let h = process.cwd();
|
|
366
|
+
const Se = () => ({
|
|
367
|
+
id: "business-landing",
|
|
368
|
+
hasToSaveConfig: !1,
|
|
369
|
+
getEnvFilePath: () => r.join(h, $),
|
|
370
|
+
onInit: async () => {
|
|
371
|
+
const { projectPath: e } = await f({
|
|
372
|
+
type: "text",
|
|
373
|
+
name: "projectPath",
|
|
374
|
+
message: "Where should we create your new business landing project?",
|
|
375
|
+
initial: "./"
|
|
376
|
+
});
|
|
377
|
+
e && (h = r.join(process.cwd(), e), n.loading("Cloning Business Landing template repository..."), await N(ke, h), n.success("Business Landing template repository cloned."));
|
|
378
|
+
const { installDeps: t } = await f({
|
|
379
|
+
type: "confirm",
|
|
380
|
+
name: "installDeps",
|
|
381
|
+
message: "Do you want to install the dependencies now?",
|
|
382
|
+
initial: !0
|
|
383
|
+
});
|
|
384
|
+
t && (n.loading("Installing dependencies..."), await _(h), n.success("Dependencies installed."));
|
|
385
|
+
},
|
|
386
|
+
syncProject: async () => {
|
|
387
|
+
n.info("Syncing Business Landing project..."), await l.unlink(r.join(h, Ee)), await l.unlink(r.join(h, J)), await D(h, J), await O(h), n.success("Business Landing project synchronized.");
|
|
388
|
+
},
|
|
389
|
+
onFinish: async () => {
|
|
390
|
+
n.run("Now you can start your project by running:"), n.newLine();
|
|
391
|
+
const e = r.relative(process.cwd(), h);
|
|
392
|
+
e && n.command(`cd ${e}`), n.command("npm run dev"), n.newLine();
|
|
393
|
+
}
|
|
394
|
+
}), Ce = "https://github.com/content-island/template-minimal-astro.git", ve = "create-dev-env.js", K = ".env-sample";
|
|
395
|
+
let y = process.cwd();
|
|
396
|
+
const be = () => ({
|
|
367
397
|
id: "minimal-astro",
|
|
368
398
|
hasToSaveConfig: !1,
|
|
369
|
-
getEnvFilePath: () =>
|
|
399
|
+
getEnvFilePath: () => r.join(y, $),
|
|
370
400
|
onInit: async () => {
|
|
371
|
-
const { projectPath: e } = await
|
|
401
|
+
const { projectPath: e } = await f({
|
|
372
402
|
type: "text",
|
|
373
403
|
name: "projectPath",
|
|
374
|
-
message: "Where should we create your new minimal astro
|
|
404
|
+
message: "Where should we create your new minimal astro project?",
|
|
375
405
|
initial: "./"
|
|
376
406
|
});
|
|
377
|
-
e && (
|
|
378
|
-
const { installDeps: t } = await
|
|
407
|
+
e && (y = r.join(process.cwd(), e), n.loading("Cloning Minimal Astro template repository..."), await N(Ce, y), n.success("Minimal Astro template repository cloned."));
|
|
408
|
+
const { installDeps: t } = await f({
|
|
379
409
|
type: "confirm",
|
|
380
410
|
name: "installDeps",
|
|
381
411
|
message: "Do you want to install the dependencies now?",
|
|
382
412
|
initial: !0
|
|
383
413
|
});
|
|
384
|
-
t && (
|
|
414
|
+
t && (n.loading("Installing dependencies..."), await _(y), n.success("Dependencies installed."));
|
|
385
415
|
},
|
|
386
416
|
syncProject: async () => {
|
|
387
|
-
|
|
417
|
+
n.info("Syncing Minimal Astro project..."), await l.unlink(r.join(y, ve)), await l.unlink(r.join(y, K)), await D(y, K), await O(y), n.success("Minimal Astro project synchronized.");
|
|
388
418
|
},
|
|
389
419
|
onFinish: async () => {
|
|
390
|
-
|
|
391
|
-
const e =
|
|
392
|
-
e &&
|
|
420
|
+
n.run("Now you can start your project by running:"), n.newLine();
|
|
421
|
+
const e = r.relative(process.cwd(), y);
|
|
422
|
+
e && n.command(`cd ${e}`), n.command("npm run dev"), n.newLine();
|
|
393
423
|
}
|
|
394
|
-
}),
|
|
395
|
-
let
|
|
396
|
-
const
|
|
424
|
+
}), Te = "https://github.com/content-island/template-personal-static-site.git", Ie = "create-dev-env.js", V = ".env-sample";
|
|
425
|
+
let k = process.cwd();
|
|
426
|
+
const je = () => ({
|
|
397
427
|
id: "personal-static-site",
|
|
398
428
|
hasToSaveConfig: !1,
|
|
399
|
-
getEnvFilePath: () =>
|
|
429
|
+
getEnvFilePath: () => r.join(k, $),
|
|
400
430
|
onInit: async () => {
|
|
401
|
-
const { projectPath: e } = await
|
|
431
|
+
const { projectPath: e } = await f({
|
|
402
432
|
type: "text",
|
|
403
433
|
name: "projectPath",
|
|
404
434
|
message: "Where should we create your new personal static site project?",
|
|
405
435
|
initial: "./"
|
|
406
436
|
});
|
|
407
|
-
e && (
|
|
408
|
-
const { installDeps: t } = await
|
|
437
|
+
e && (k = r.join(process.cwd(), e), n.loading("Cloning Personal Static Site template repository..."), await N(Te, k), n.success("Personal Static Site template repository cloned."));
|
|
438
|
+
const { installDeps: t } = await f({
|
|
409
439
|
type: "confirm",
|
|
410
440
|
name: "installDeps",
|
|
411
441
|
message: "Do you want to install the dependencies now?",
|
|
412
442
|
initial: !0
|
|
413
443
|
});
|
|
414
|
-
t && (
|
|
444
|
+
t && (n.loading("Installing dependencies..."), await _(k), n.success("Dependencies installed."));
|
|
415
445
|
},
|
|
416
446
|
syncProject: async () => {
|
|
417
|
-
|
|
447
|
+
n.info("Syncing Personal Static Site project..."), await l.unlink(r.join(k, Ie)), await l.unlink(r.join(k, V)), await D(k, V), await O(k), n.success("Personal Static Site project synchronized.");
|
|
418
448
|
},
|
|
419
449
|
onFinish: async () => {
|
|
420
|
-
|
|
421
|
-
const e =
|
|
422
|
-
e &&
|
|
450
|
+
n.run("Now you can start your project by running:"), n.newLine();
|
|
451
|
+
const e = r.relative(process.cwd(), k);
|
|
452
|
+
e && n.command(`cd ${e}`), n.command("npm run dev"), n.newLine();
|
|
423
453
|
}
|
|
424
|
-
}),
|
|
454
|
+
}), P = (e, t) => Array.isArray(e) ? e.map(t) : [], $e = (e, t) => ({
|
|
425
455
|
id: e.id,
|
|
426
456
|
language: e.language,
|
|
427
457
|
name: e.name,
|
|
428
458
|
label: e.label,
|
|
429
|
-
pages:
|
|
430
|
-
}),
|
|
459
|
+
pages: P(e.pages, (a) => t.find((o) => o.id === a))
|
|
460
|
+
}), Pe = (e, t) => ({
|
|
431
461
|
id: e.id,
|
|
432
462
|
language: e.language,
|
|
433
463
|
index: e.index,
|
|
434
|
-
folders:
|
|
464
|
+
folders: P(e.folders, (a) => $e(a, t))
|
|
435
465
|
});
|
|
436
|
-
let
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
},
|
|
440
|
-
if (!
|
|
466
|
+
let A = null;
|
|
467
|
+
const Ae = (e) => {
|
|
468
|
+
A = ue({ accessToken: e });
|
|
469
|
+
}, M = () => {
|
|
470
|
+
if (!A)
|
|
441
471
|
throw new Error("API client not initialized. Call initializeClient first.");
|
|
442
|
-
return
|
|
443
|
-
},
|
|
444
|
-
const t =
|
|
472
|
+
return A;
|
|
473
|
+
}, Fe = async () => await M().getProject(), U = async (e) => {
|
|
474
|
+
const t = M(), a = await t.getContent({
|
|
445
475
|
contentType: "Root",
|
|
446
476
|
includeRelatedContent: !0,
|
|
447
477
|
language: e
|
|
448
478
|
});
|
|
449
|
-
if (!
|
|
479
|
+
if (!a)
|
|
450
480
|
throw new Error(`Root content not found for language: ${e}`);
|
|
451
|
-
const o =
|
|
481
|
+
const o = a.folders?.flatMap((i) => i.pages) || [], s = await t.getContentList({
|
|
452
482
|
contentType: "Page",
|
|
453
483
|
id: {
|
|
454
484
|
in: o
|
|
@@ -457,71 +487,71 @@ const Ie = (e) => {
|
|
|
457
487
|
});
|
|
458
488
|
if (!s)
|
|
459
489
|
throw new Error(`Pages not found for IDs: ${o.join(", ")}`);
|
|
460
|
-
return
|
|
461
|
-
},
|
|
490
|
+
return Pe(a, s);
|
|
491
|
+
}, xe = async () => {
|
|
462
492
|
try {
|
|
463
|
-
return await
|
|
493
|
+
return await M().getContent({
|
|
464
494
|
contentType: "Meta"
|
|
465
495
|
});
|
|
466
496
|
} catch (e) {
|
|
467
|
-
e.message.includes("401") ?
|
|
497
|
+
e.message.includes("401") ? n.error(
|
|
468
498
|
"The Content Island API token is missing or malformed. Verify that you've copied the complete token and that you have sufficient permissions."
|
|
469
|
-
) :
|
|
499
|
+
) : n.error("The requested template is not of type StarLight, so the meta field could not be found."), process.exit(1);
|
|
470
500
|
}
|
|
471
|
-
},
|
|
472
|
-
const e = [], t =
|
|
473
|
-
|
|
474
|
-
const
|
|
475
|
-
return
|
|
501
|
+
}, te = "astro.config.mjs", R = () => r.join(process.cwd(), "src", "content", "docs"), z = () => r.join(process.cwd(), te), Le = () => {
|
|
502
|
+
const e = [], t = z();
|
|
503
|
+
E(t) || e.push(te);
|
|
504
|
+
const a = R();
|
|
505
|
+
return E(a) || e.push("src/content/docs directory"), {
|
|
476
506
|
valid: e.length === 0,
|
|
477
507
|
missingItems: e
|
|
478
508
|
};
|
|
479
|
-
},
|
|
480
|
-
const e =
|
|
481
|
-
if (!
|
|
482
|
-
|
|
509
|
+
}, Ne = async () => {
|
|
510
|
+
const e = R();
|
|
511
|
+
if (!E(e)) {
|
|
512
|
+
n.info("Content docs directory not found, creating it..."), await l.mkdir(e, { recursive: !0 });
|
|
483
513
|
return;
|
|
484
514
|
}
|
|
485
515
|
const t = await l.readdir(e);
|
|
486
|
-
for (const
|
|
487
|
-
const o =
|
|
516
|
+
for (const a of t) {
|
|
517
|
+
const o = r.join(e, a);
|
|
488
518
|
await l.rm(o, { recursive: !0, force: !0 });
|
|
489
519
|
}
|
|
490
520
|
}, C = {
|
|
491
521
|
sidebar: { start: "[", end: "]" },
|
|
492
522
|
locales: { start: "{", end: "}" },
|
|
493
523
|
title: { start: "'", end: "'" }
|
|
494
|
-
},
|
|
495
|
-
const
|
|
524
|
+
}, ne = (e, t) => {
|
|
525
|
+
const a = [], o = [];
|
|
496
526
|
for (const s of t) {
|
|
497
|
-
const i = e.findIndex((
|
|
527
|
+
const i = e.findIndex((c) => c.label === s.label);
|
|
498
528
|
if (i >= 0) {
|
|
499
|
-
const
|
|
500
|
-
|
|
529
|
+
const c = s.items && e[i].items ? ne(e[i].items || [], s.items) : s.items;
|
|
530
|
+
a[i] = {
|
|
501
531
|
...e[i],
|
|
502
532
|
...s,
|
|
503
|
-
items:
|
|
533
|
+
items: c
|
|
504
534
|
};
|
|
505
535
|
} else
|
|
506
536
|
o.push(s);
|
|
507
537
|
}
|
|
508
|
-
return
|
|
509
|
-
const
|
|
510
|
-
return
|
|
538
|
+
return a.push(...o), a.sort((s, i) => {
|
|
539
|
+
const c = t.findIndex((u) => u.label === s.label), m = t.findIndex((u) => u.label === i.label);
|
|
540
|
+
return c - m;
|
|
511
541
|
});
|
|
512
|
-
},
|
|
513
|
-
const
|
|
514
|
-
root: { lang: e, label:
|
|
542
|
+
}, _e = (e, t) => {
|
|
543
|
+
const a = {
|
|
544
|
+
root: { lang: e, label: G[e] }
|
|
515
545
|
};
|
|
516
546
|
return Array.isArray(t) ? t.reduce(
|
|
517
547
|
(o, s) => ({
|
|
518
548
|
...o,
|
|
519
|
-
[s]: { lang: s, label:
|
|
549
|
+
[s]: { lang: s, label: G[s] }
|
|
520
550
|
}),
|
|
521
|
-
|
|
522
|
-
) :
|
|
523
|
-
},
|
|
524
|
-
const o =
|
|
551
|
+
a
|
|
552
|
+
) : a;
|
|
553
|
+
}, Y = async (e, t, a) => {
|
|
554
|
+
const o = z(), s = await j({
|
|
525
555
|
filePath: o,
|
|
526
556
|
property: t,
|
|
527
557
|
startSymbol: C[t]?.start,
|
|
@@ -529,17 +559,17 @@ const Ie = (e) => {
|
|
|
529
559
|
});
|
|
530
560
|
let i;
|
|
531
561
|
if (s) {
|
|
532
|
-
const
|
|
533
|
-
i = (await l.readFile(o, "utf-8")).replace(s,
|
|
562
|
+
const c = ee(JSON.stringify(e, null, 2));
|
|
563
|
+
i = (await l.readFile(o, "utf-8")).replace(s, c);
|
|
534
564
|
} else
|
|
535
|
-
i = await
|
|
565
|
+
i = await he(
|
|
536
566
|
t,
|
|
537
567
|
e,
|
|
538
568
|
{
|
|
539
569
|
filePath: o,
|
|
540
|
-
property:
|
|
541
|
-
startSymbol: C[
|
|
542
|
-
endSymbol: C[
|
|
570
|
+
property: a,
|
|
571
|
+
startSymbol: C[a]?.start,
|
|
572
|
+
endSymbol: C[a]?.end
|
|
543
573
|
},
|
|
544
574
|
{
|
|
545
575
|
filePath: o,
|
|
@@ -549,69 +579,69 @@ const Ie = (e) => {
|
|
|
549
579
|
}
|
|
550
580
|
);
|
|
551
581
|
await l.writeFile(o, i, "utf-8");
|
|
552
|
-
},
|
|
582
|
+
}, Oe = async (e, t, a) => {
|
|
553
583
|
try {
|
|
554
|
-
let o = await
|
|
555
|
-
filePath:
|
|
584
|
+
let o = await j({
|
|
585
|
+
filePath: z(),
|
|
556
586
|
property: "sidebar",
|
|
557
587
|
startSymbol: C.sidebar.start,
|
|
558
588
|
endSymbol: C.sidebar.end
|
|
559
589
|
}), s = [];
|
|
560
590
|
try {
|
|
561
|
-
s = o ?
|
|
591
|
+
s = o ? we(o) : null;
|
|
562
592
|
} catch {
|
|
563
|
-
|
|
593
|
+
n.warning("Could not parse existing sidebar in astro.config.mjs. A new sidebar will be created."), s = [];
|
|
564
594
|
}
|
|
565
|
-
s || (
|
|
566
|
-
const i =
|
|
567
|
-
await
|
|
568
|
-
const
|
|
569
|
-
await
|
|
595
|
+
s || (n.warning("No existing sidebar found in astro.config.mjs. A new sidebar will be created."), s = []);
|
|
596
|
+
const i = ne(s, e);
|
|
597
|
+
await Y(i, "sidebar", "locales");
|
|
598
|
+
const c = _e(t, a);
|
|
599
|
+
await Y(c, "locales", "sidebar");
|
|
570
600
|
} catch (o) {
|
|
571
|
-
|
|
601
|
+
n.error(`Error reading astro.config.mjs: ${o.message}`), process.exit(1);
|
|
572
602
|
}
|
|
573
|
-
},
|
|
574
|
-
function
|
|
575
|
-
if (
|
|
603
|
+
}, De = (e) => /^---\s*\n([\s\S]*?)\n---\s*\n/.test(e), Me = (e) => r.parse(e).name.replace(/[-_]/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").split(" ").filter((o) => o.length > 0).map((o) => o.charAt(0).toUpperCase() + o.slice(1).toLowerCase()).join(" ");
|
|
604
|
+
function Re(e, t, a) {
|
|
605
|
+
if (De(e))
|
|
576
606
|
return e;
|
|
577
|
-
const o =
|
|
607
|
+
const o = Me(t), s = `---
|
|
578
608
|
title: "${o}"
|
|
579
609
|
---
|
|
580
610
|
|
|
581
611
|
`;
|
|
582
|
-
return
|
|
612
|
+
return n.warning(`Missing frontmatter in ${a}`), n.info(`Added default title: "${o}"`), n.warning("Please update the content in Content Island 🏝️ to include proper frontmatter"), n.newLine(), s + e;
|
|
583
613
|
}
|
|
584
614
|
const I = async (e, t) => {
|
|
585
|
-
const
|
|
586
|
-
|
|
587
|
-
},
|
|
615
|
+
const a = R(), o = r.join(a, e), s = Re(t, e, r.relative(process.cwd(), o)), i = r.dirname(o);
|
|
616
|
+
E(i) || await l.mkdir(i, { recursive: !0 }), await l.writeFile(o, s, "utf-8");
|
|
617
|
+
}, ze = async (e, t) => {
|
|
588
618
|
try {
|
|
589
619
|
await I(e.index.filename, e.index.content);
|
|
590
|
-
for (const
|
|
591
|
-
for (const o of
|
|
592
|
-
await I(
|
|
593
|
-
for (const
|
|
594
|
-
await I(
|
|
595
|
-
for (const o of
|
|
620
|
+
for (const a of e.folders)
|
|
621
|
+
for (const o of a.pages)
|
|
622
|
+
await I(r.join(a.name, o.filename), o.content);
|
|
623
|
+
for (const a of t) {
|
|
624
|
+
await I(r.join(a.language, a.index.filename), a.index.content);
|
|
625
|
+
for (const o of a.folders)
|
|
596
626
|
for (const s of o.pages)
|
|
597
|
-
await I(
|
|
627
|
+
await I(r.join(a.language, o.name, s.filename), s.content);
|
|
598
628
|
}
|
|
599
|
-
} catch (
|
|
600
|
-
|
|
629
|
+
} catch (a) {
|
|
630
|
+
n.error(`Error updating docs content: ${a.message}`), process.exit(1);
|
|
601
631
|
}
|
|
602
|
-
},
|
|
632
|
+
}, Be = async (e, t) => {
|
|
603
633
|
if (e.length === 1) {
|
|
604
634
|
const s = e[0];
|
|
605
|
-
return
|
|
635
|
+
return n.success(`Single language found: ${s}. Continuing...`), await b({ languageCode: s }), s;
|
|
606
636
|
}
|
|
607
|
-
const
|
|
608
|
-
if (
|
|
609
|
-
if (e.includes(
|
|
610
|
-
return
|
|
611
|
-
|
|
637
|
+
const a = (await L())?.languageCode;
|
|
638
|
+
if (a && !t) {
|
|
639
|
+
if (e.includes(a))
|
|
640
|
+
return n.info(`Using saved default language: ${a}`), a;
|
|
641
|
+
n.warning(`Saved language '${a}' not found in project languages`), n.step("Will ask for new default language and save it");
|
|
612
642
|
}
|
|
613
|
-
|
|
614
|
-
const o = await
|
|
643
|
+
n.step("Multiple languages found. Please select the default language:");
|
|
644
|
+
const o = await f({
|
|
615
645
|
type: "select",
|
|
616
646
|
name: "language",
|
|
617
647
|
message: "Select the default language:",
|
|
@@ -621,9 +651,9 @@ const I = async (e, t) => {
|
|
|
621
651
|
})),
|
|
622
652
|
initial: 0
|
|
623
653
|
});
|
|
624
|
-
return o.language || (
|
|
625
|
-
},
|
|
626
|
-
|
|
654
|
+
return o.language || (n.error("Language selection is required to continue."), process.exit(1)), a !== o.language && (await b({ languageCode: o.language }), n.config(`Saving default language '${o.language}' to config`)), o.language;
|
|
655
|
+
}, Ge = () => {
|
|
656
|
+
n.detected(`
|
|
627
657
|
⭐ ✨ STARLIGHT PROJECT DETECTED ✨ ⭐
|
|
628
658
|
|
|
629
659
|
⭐ ✨ ⭐ ✨
|
|
@@ -633,197 +663,198 @@ const I = async (e, t) => {
|
|
|
633
663
|
⭐ ✨ ⭐ ✨ ⭐
|
|
634
664
|
✨ ⭐ ✨ ⭐ ✨
|
|
635
665
|
⭐ ✨ ⭐ ✨
|
|
636
|
-
`),
|
|
637
|
-
},
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}),
|
|
641
|
-
},
|
|
666
|
+
`), n.success("All good! Starlight ⭐ project detected successfully."), n.loading("Launching process..."), n.newLine();
|
|
667
|
+
}, Je = (e) => {
|
|
668
|
+
n.newLine(), n.error("Starlight ⭐ project not found!"), n.newLine(), n.error("Missing required items:"), e.forEach((t) => {
|
|
669
|
+
n.error(` • ${t}`);
|
|
670
|
+
}), n.newLine(), n.error("Please make sure you are in the root directory of a Starlight ⭐ project."), n.warning("A Starlight ⭐ project should have:"), n.warning(" • astro.config.mjs file"), n.warning(" • src/content/docs directory"), n.newLine();
|
|
671
|
+
}, ae = (e) => {
|
|
642
672
|
const t = e.reduce(
|
|
643
|
-
(
|
|
673
|
+
(a, o) => ({ ...a, ...o }),
|
|
644
674
|
{}
|
|
645
675
|
);
|
|
646
676
|
return Object.keys(t).length > 0 ? t : void 0;
|
|
647
|
-
},
|
|
648
|
-
const
|
|
649
|
-
return
|
|
650
|
-
},
|
|
677
|
+
}, oe = (e) => e.filename.replace(/\.(mdx?|md)$/, ""), q = (e) => e.label ? e.label.trim() : oe(e), Ke = (e, t) => {
|
|
678
|
+
const a = oe(e), o = t.trim().toLowerCase();
|
|
679
|
+
return a.toLocaleLowerCase() === "index" ? o : `${o}/${a}`;
|
|
680
|
+
}, Ve = (e, t, a) => {
|
|
651
681
|
e.filename.replace(/\.(mdx?|md)$/, "");
|
|
652
|
-
const o =
|
|
682
|
+
const o = a.filter((s) => s.id === e.id).map((s) => ({ [s.language]: q(s) }));
|
|
653
683
|
return {
|
|
654
|
-
label:
|
|
655
|
-
slug:
|
|
656
|
-
translations:
|
|
684
|
+
label: q(e),
|
|
685
|
+
slug: Ke(e, t),
|
|
686
|
+
translations: ae(o)
|
|
657
687
|
};
|
|
658
|
-
},
|
|
659
|
-
const
|
|
688
|
+
}, W = (e) => e.label ? e.label.trim() : e.name, Ue = (e, t) => {
|
|
689
|
+
const a = t.flatMap((i) => i.folders ?? []).filter((i) => i.id === e.id), o = a.flatMap((i) => i.pages ?? []).filter((i) => e.pages.some((c) => c.id === i.id)), s = a.map((i) => ({ [i.language]: W(i) }));
|
|
660
690
|
return {
|
|
661
|
-
label:
|
|
662
|
-
translations:
|
|
663
|
-
items:
|
|
691
|
+
label: W(e),
|
|
692
|
+
translations: ae(s),
|
|
693
|
+
items: P(e.pages, (i) => Ve(i, e.name, o))
|
|
664
694
|
};
|
|
665
|
-
},
|
|
695
|
+
}, Ye = (e, t) => P(e.folders, (a) => Ue(a, t)), qe = () => ({
|
|
666
696
|
id: "starlight",
|
|
667
697
|
hasToSaveConfig: !0,
|
|
668
|
-
getEnvFilePath: () =>
|
|
698
|
+
getEnvFilePath: () => r.join(x(), $),
|
|
669
699
|
onInit: async (e) => {
|
|
670
|
-
|
|
671
|
-
const { valid: t, missingItems:
|
|
672
|
-
if (t || (
|
|
673
|
-
const o =
|
|
674
|
-
i.scripts = { ...
|
|
700
|
+
n.step("Checking for Starlight ⭐ project...");
|
|
701
|
+
const { valid: t, missingItems: a } = Le();
|
|
702
|
+
if (t || (Je(a), process.exit(1)), Ge(), e.command === "init") {
|
|
703
|
+
const o = r.join(process.cwd(), "package.json"), s = await l.readFile(o, "utf-8"), i = JSON.parse(s), c = i.scripts || {};
|
|
704
|
+
i.scripts = { ...c, "content-update": "npm create contentisland@latest update" }, await l.writeFile(o, JSON.stringify(i, null, 2), "utf-8");
|
|
675
705
|
}
|
|
676
706
|
},
|
|
677
707
|
syncProject: async (e) => {
|
|
678
|
-
const { accessToken: t, askIfMultipleLanguages:
|
|
679
|
-
|
|
680
|
-
const o = await
|
|
681
|
-
|
|
708
|
+
const { accessToken: t, askIfMultipleLanguages: a } = e;
|
|
709
|
+
n.connecting("Initializing Content Island 🏝️ client..."), Ae(t);
|
|
710
|
+
const o = await xe();
|
|
711
|
+
n.success(`Connected to project using template: ${o.template} (version: ${o.version})`), o.template !== "starlight" && (n.warning(
|
|
682
712
|
"The project you are trying to sync is not using the Starlight ⭐ template. Please make sure you are using the correct template."
|
|
683
|
-
), process.exit(1)), await
|
|
713
|
+
), process.exit(1)), await b({
|
|
684
714
|
version: o.version
|
|
685
|
-
}),
|
|
686
|
-
const s = await
|
|
687
|
-
|
|
715
|
+
}), n.fetching("Fetching project information from Content Island 🏝️ ...");
|
|
716
|
+
const s = await Fe();
|
|
717
|
+
n.success(`Project fetched: ${s.name}`);
|
|
688
718
|
const i = s.languages.map((d) => d);
|
|
689
|
-
|
|
690
|
-
const
|
|
691
|
-
|
|
692
|
-
const m = i.filter((d) => d !==
|
|
719
|
+
n.info(`Languages found (${i.length}): ${i.join(", ")}`);
|
|
720
|
+
const c = await Be(i, a);
|
|
721
|
+
n.language(c);
|
|
722
|
+
const m = i.filter((d) => d !== c), u = await U(c);
|
|
693
723
|
let S = [];
|
|
694
724
|
for (const d of m) {
|
|
695
|
-
const
|
|
696
|
-
S.push(
|
|
725
|
+
const ge = await U(d);
|
|
726
|
+
S.push(ge);
|
|
697
727
|
}
|
|
698
|
-
|
|
699
|
-
const
|
|
700
|
-
await
|
|
728
|
+
n.clearing("Clearing existing docs content..."), await Ne(), n.docs("Existing docs content cleared"), n.updating("Updating docs content with fetched data..."), await ze(u, S), n.docs("Docs content updated"), n.config("Generating sidebar configuration...");
|
|
729
|
+
const w = Ye(u, S);
|
|
730
|
+
await Oe(w, c, m), n.config("Sidebar configuration updated in astro.config.mjs");
|
|
701
731
|
},
|
|
702
732
|
onFinish: async () => {
|
|
703
|
-
|
|
733
|
+
n.run("Now you can start your project by running:"), n.newLine(), n.command("npm run dev"), n.newLine();
|
|
704
734
|
}
|
|
705
|
-
}),
|
|
706
|
-
starlight:
|
|
707
|
-
"personal-static-site":
|
|
708
|
-
"minimal-astro":
|
|
709
|
-
|
|
710
|
-
|
|
735
|
+
}), se = {
|
|
736
|
+
starlight: qe,
|
|
737
|
+
"personal-static-site": je,
|
|
738
|
+
"minimal-astro": be,
|
|
739
|
+
"business-landing": Se
|
|
740
|
+
}, We = (e) => {
|
|
741
|
+
const t = se[e];
|
|
711
742
|
if (!t)
|
|
712
743
|
throw new Error(`Template "${e}" not found`);
|
|
713
744
|
return t();
|
|
714
|
-
},
|
|
715
|
-
let
|
|
716
|
-
return
|
|
745
|
+
}, He = () => Object.keys(se), Ze = async (e, t) => {
|
|
746
|
+
let a;
|
|
747
|
+
return a || (a = (await L())?.templateID), a && t && (n.info(`Existing template found: ${a}`), (await f({
|
|
717
748
|
type: "confirm",
|
|
718
749
|
name: "useExisting",
|
|
719
|
-
message: `An existing template (${
|
|
750
|
+
message: `An existing template (${a}) was found. Do you want to use it?`,
|
|
720
751
|
initial: !0
|
|
721
|
-
}))?.useExisting ?
|
|
752
|
+
}))?.useExisting ? n.success(`Using existing template: ${a}`) : (a = null, n.step("Selecting new template..."))), a || (n.step("Please select a template:"), a = (await f({
|
|
722
753
|
type: "select",
|
|
723
754
|
name: "templateID",
|
|
724
755
|
message: "Select a template:",
|
|
725
756
|
choices: e.map((s) => ({ title: s, value: s }))
|
|
726
|
-
}))?.templateID),
|
|
727
|
-
},
|
|
757
|
+
}))?.templateID), a || (n.error("Template is required to continue"), process.exit(1)), a;
|
|
758
|
+
}, ie = async (e) => {
|
|
728
759
|
try {
|
|
729
|
-
const { selectedTemplateId: t, askIfExists:
|
|
760
|
+
const { selectedTemplateId: t, askIfExists: a } = e, o = He();
|
|
730
761
|
let s = o.find((i) => i === t);
|
|
731
|
-
return s || (s = await
|
|
762
|
+
return s || (s = await Ze(o, a)), n.detected(`Template selected: ${s}`), We(s);
|
|
732
763
|
} catch (t) {
|
|
733
|
-
|
|
764
|
+
n.error(`Error configuring template: ${t.message}`), process.exit(1);
|
|
734
765
|
}
|
|
735
|
-
},
|
|
736
|
-
if (!
|
|
766
|
+
}, re = "CONTENT_ISLAND_ACCESS_TOKEN", Xe = async (e) => {
|
|
767
|
+
if (!E(e))
|
|
737
768
|
return null;
|
|
738
769
|
try {
|
|
739
|
-
const
|
|
740
|
-
return
|
|
770
|
+
const a = (await l.readFile(e, "utf-8")).match(new RegExp(`${re}=(.+)`));
|
|
771
|
+
return a ? a[1].trim() : null;
|
|
741
772
|
} catch {
|
|
742
773
|
return null;
|
|
743
774
|
}
|
|
744
|
-
},
|
|
775
|
+
}, ce = async (e, t) => {
|
|
745
776
|
try {
|
|
746
|
-
const
|
|
747
|
-
`, o =
|
|
748
|
-
await l.mkdir(o, { recursive: !0 }), await l.writeFile(t,
|
|
749
|
-
} catch (
|
|
750
|
-
|
|
777
|
+
const a = `${re}=${e}
|
|
778
|
+
`, o = r.dirname(t);
|
|
779
|
+
await l.mkdir(o, { recursive: !0 }), await l.writeFile(t, a, "utf-8"), n.token(`Access token saved to ${t}`);
|
|
780
|
+
} catch (a) {
|
|
781
|
+
n.error(`Failed to save the access token: ${a.message}`);
|
|
751
782
|
}
|
|
752
|
-
},
|
|
753
|
-
e || (
|
|
754
|
-
},
|
|
755
|
-
let
|
|
756
|
-
if (
|
|
783
|
+
}, H = (e) => {
|
|
784
|
+
e || (n.error("Token is required to continue"), process.exit(1));
|
|
785
|
+
}, Qe = async (e, t) => {
|
|
786
|
+
let a = e ? await Xe(e) : null;
|
|
787
|
+
if (a && t && (n.info("Found existing Content Island 🏝️ token"), (await f({
|
|
757
788
|
type: "confirm",
|
|
758
789
|
name: "useExisting",
|
|
759
790
|
message: "An existing token was found. Do you want to use it?",
|
|
760
791
|
initial: !0
|
|
761
|
-
}))?.useExisting || (
|
|
762
|
-
|
|
792
|
+
}))?.useExisting || (a = null)), a)
|
|
793
|
+
n.success("Using existing Content Island 🏝️ token");
|
|
763
794
|
else {
|
|
764
|
-
t ||
|
|
765
|
-
const o = await
|
|
795
|
+
t || n.warning("No existing token found");
|
|
796
|
+
const o = await f({
|
|
766
797
|
type: "password",
|
|
767
798
|
name: "token",
|
|
768
799
|
message: "Enter your Content Island 🏝️ API token:",
|
|
769
800
|
validate: (s) => s.length > 0 ? !0 : "Token is required"
|
|
770
801
|
});
|
|
771
|
-
|
|
802
|
+
H(o?.token), a = o?.token, e && await ce(a, e);
|
|
772
803
|
}
|
|
773
|
-
return
|
|
774
|
-
},
|
|
775
|
-
const { accessToken: t, envFilePath:
|
|
804
|
+
return H(a), a;
|
|
805
|
+
}, le = async (e) => {
|
|
806
|
+
const { accessToken: t, envFilePath: a, askIfExists: o } = e;
|
|
776
807
|
let s = t;
|
|
777
|
-
return s ? (
|
|
778
|
-
},
|
|
808
|
+
return s ? (n.success("Using provided Content Island 🏝️ token"), await ce(s, a)) : s = await Qe(a, o), s;
|
|
809
|
+
}, et = async (e) => {
|
|
779
810
|
try {
|
|
780
|
-
|
|
781
|
-
const t = await
|
|
811
|
+
n.title("Content Island Integration"), n.step("Configuring template...");
|
|
812
|
+
const t = await ie({
|
|
782
813
|
selectedTemplateId: e.template,
|
|
783
814
|
askIfExists: !0
|
|
784
815
|
});
|
|
785
|
-
t.onInit && (
|
|
816
|
+
t.onInit && (n.step("Running template initialization..."), await t.onInit({
|
|
786
817
|
command: "init"
|
|
787
|
-
})), t.hasToSaveConfig && (
|
|
788
|
-
const
|
|
818
|
+
})), t.hasToSaveConfig && (n.step("Saving configuration..."), await b({ templateID: t.id }), n.config("Template configuration saved")), n.step("Configuring access token...");
|
|
819
|
+
const a = t.getEnvFilePath ? t.getEnvFilePath() : null, o = await le({
|
|
789
820
|
accessToken: e.token,
|
|
790
|
-
envFilePath:
|
|
821
|
+
envFilePath: a,
|
|
791
822
|
askIfExists: !0
|
|
792
823
|
});
|
|
793
|
-
|
|
824
|
+
n.token("Access token configured successfully"), n.step("Synchronizing project..."), await t.syncProject({ accessToken: o, askIfMultipleLanguages: !0 }), n.newLine(), n.complete("Content Island 🏝️ integration completed successfully!"), n.newLine(), t.onFinish && await t.onFinish();
|
|
794
825
|
} catch (t) {
|
|
795
|
-
|
|
826
|
+
n.newLine(), n.error("Error during Content Island integration:"), n.error(t instanceof Error ? t.message : String(t)), process.exit(1);
|
|
796
827
|
}
|
|
797
|
-
},
|
|
828
|
+
}, tt = async () => {
|
|
798
829
|
try {
|
|
799
|
-
|
|
800
|
-
const e = await
|
|
801
|
-
e.onInit && (
|
|
830
|
+
n.title("Content Island Integration"), n.step("Configuring template...");
|
|
831
|
+
const e = await ie({ askIfExists: !1 });
|
|
832
|
+
e.onInit && (n.step("Running template initialization..."), await e.onInit({
|
|
802
833
|
command: "update"
|
|
803
|
-
})), e.hasToSaveConfig && (
|
|
804
|
-
const t = e.getEnvFilePath ? e.getEnvFilePath() : null,
|
|
834
|
+
})), e.hasToSaveConfig && (n.step("Saving configuration..."), await b({ templateID: e.id }), n.config("Template configuration saved")), n.step("Configuring access token...");
|
|
835
|
+
const t = e.getEnvFilePath ? e.getEnvFilePath() : null, a = await le({
|
|
805
836
|
envFilePath: t,
|
|
806
837
|
askIfExists: !1
|
|
807
838
|
});
|
|
808
|
-
|
|
839
|
+
n.token("Access token configured successfully"), n.step("Synchronizing project..."), await e.syncProject({ accessToken: a, askIfMultipleLanguages: !1 }), n.newLine(), n.complete("Content Island 🏝️ integration completed successfully!"), n.newLine(), e.onFinish && await e.onFinish();
|
|
809
840
|
} catch (e) {
|
|
810
|
-
|
|
841
|
+
n.newLine(), n.error("Error during Content Island integration:"), n.error(e instanceof Error ? e.message : String(e)), process.exit(1);
|
|
811
842
|
}
|
|
812
|
-
},
|
|
813
|
-
version:
|
|
814
|
-
},
|
|
815
|
-
|
|
843
|
+
}, nt = "0.3.0", at = {
|
|
844
|
+
version: nt
|
|
845
|
+
}, T = de("create-contentisland");
|
|
846
|
+
T.command("", "Initialize and validate a project").example("npm create contentisland").example("npm create contentisland --token <token>").example("npm create contentisland --token <token> --template starlight").option(
|
|
816
847
|
"--token <token>",
|
|
817
848
|
"Your Content Island token (you can also set the CONTENT_ISLAND_ACCESS_TOKEN environment variable)",
|
|
818
849
|
{
|
|
819
850
|
default: process.env.CONTENT_ISLAND_ACCESS_TOKEN || void 0
|
|
820
851
|
}
|
|
821
852
|
).option("--template <template>", "The template to use: starlight.").action(async (e) => {
|
|
822
|
-
await
|
|
853
|
+
await et(e);
|
|
823
854
|
});
|
|
824
|
-
|
|
825
|
-
await
|
|
855
|
+
T.command("update", "Update content from Content Island 🏝️ (preserves existing token)").example("npm create contentisland update").action(async () => {
|
|
856
|
+
await tt();
|
|
826
857
|
});
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
858
|
+
T.help();
|
|
859
|
+
T.version(at.version);
|
|
860
|
+
T.parse();
|