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