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