@lukoweb/apitogo 0.1.82 → 0.1.83
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/cli/cli.js +52 -41
- package/package.json +1 -1
package/dist/cli/cli.js
CHANGED
|
@@ -5633,7 +5633,7 @@ import {
|
|
|
5633
5633
|
// package.json
|
|
5634
5634
|
var package_default = {
|
|
5635
5635
|
name: "@lukoweb/apitogo",
|
|
5636
|
-
version: "0.1.
|
|
5636
|
+
version: "0.1.83",
|
|
5637
5637
|
type: "module",
|
|
5638
5638
|
sideEffects: [
|
|
5639
5639
|
"**/*.css",
|
|
@@ -10937,6 +10937,17 @@ export default buildApitogoConfig({
|
|
|
10937
10937
|
function isThinConfigWrapper(source) {
|
|
10938
10938
|
return /export\s+default\s+buildApitogoConfig\s*\(/.test(source);
|
|
10939
10939
|
}
|
|
10940
|
+
function isManagedConfigWrapper(source) {
|
|
10941
|
+
if (isThinConfigWrapper(source)) {
|
|
10942
|
+
return true;
|
|
10943
|
+
}
|
|
10944
|
+
return /from\s+["']\.\/apitogo\.config\.json["']/.test(source) && /buildApitogoConfig\s*\(/.test(source) && /type:\s*["']custom-page["']/.test(source);
|
|
10945
|
+
}
|
|
10946
|
+
function labelFromRoutePath(routePath) {
|
|
10947
|
+
const slug = routePath.replace(/^\/+/, "");
|
|
10948
|
+
const leaf = slug.split("/").filter(Boolean).pop() ?? slug;
|
|
10949
|
+
return titleFromDirectoryName(leaf);
|
|
10950
|
+
}
|
|
10940
10951
|
function buildThinWrapperWithCustomPages(tsxRoutePaths) {
|
|
10941
10952
|
if (tsxRoutePaths.length === 0) {
|
|
10942
10953
|
return THIN_WRAPPER_SOURCE;
|
|
@@ -10949,9 +10960,11 @@ function buildThinWrapperWithCustomPages(tsxRoutePaths) {
|
|
|
10949
10960
|
const customPages = tsxRoutePaths.map((routePath) => {
|
|
10950
10961
|
const slug = routePath.replace(/^\//, "");
|
|
10951
10962
|
const name = pageComponentName(slug);
|
|
10963
|
+
const label = labelFromRoutePath(routePath);
|
|
10952
10964
|
return ` {
|
|
10953
10965
|
type: "custom-page",
|
|
10954
10966
|
path: ${JSON.stringify(routePath)},
|
|
10967
|
+
label: ${JSON.stringify(label)},
|
|
10955
10968
|
element: <${name} />,
|
|
10956
10969
|
},`;
|
|
10957
10970
|
}).join("\n");
|
|
@@ -10973,13 +10986,17 @@ export default {
|
|
|
10973
10986
|
label: ${JSON.stringify(DOCUMENTATION_NAV_LABEL)},
|
|
10974
10987
|
items: [
|
|
10975
10988
|
${customPages}
|
|
10976
|
-
...(((config.navigation ?? []).find(
|
|
10989
|
+
...((((config.navigation ?? []).find(
|
|
10977
10990
|
(item) =>
|
|
10978
10991
|
typeof item === "object" &&
|
|
10979
10992
|
item !== null &&
|
|
10980
10993
|
"label" in item &&
|
|
10981
10994
|
item.label === ${JSON.stringify(DOCUMENTATION_NAV_LABEL)},
|
|
10982
|
-
) as { items?: unknown[] } | undefined)?.items ?? [])
|
|
10995
|
+
) as { items?: unknown[] } | undefined)?.items ?? []).filter(
|
|
10996
|
+
(item) =>
|
|
10997
|
+
typeof item !== "string" ||
|
|
10998
|
+
!${JSON.stringify(tsxRoutePaths)}.includes(item),
|
|
10999
|
+
)),
|
|
10983
11000
|
],
|
|
10984
11001
|
},
|
|
10985
11002
|
...(config.navigation ?? []).filter(
|
|
@@ -11519,7 +11536,8 @@ async function persistConfig(config2, ctx) {
|
|
|
11519
11536
|
(file) => toRoutePath(file, ctx.pagesDir)
|
|
11520
11537
|
);
|
|
11521
11538
|
const tsxRoutes = tsxFiles.map((file) => toRoutePath(file, ctx.pagesDir));
|
|
11522
|
-
|
|
11539
|
+
const docRoutes = [.../* @__PURE__ */ new Set([...markdownRoutes, ...tsxRoutes])];
|
|
11540
|
+
if (docRoutes.length === 0) {
|
|
11523
11541
|
printDiagnosticsToConsole(
|
|
11524
11542
|
`No docs pages under '${ctx.pagesDir}/' \u2014 skipping documentation nav scan.`
|
|
11525
11543
|
);
|
|
@@ -11528,7 +11546,7 @@ async function persistConfig(config2, ctx) {
|
|
|
11528
11546
|
...config2,
|
|
11529
11547
|
navigation: mergeDocumentationNavigation(
|
|
11530
11548
|
config2.navigation,
|
|
11531
|
-
|
|
11549
|
+
docRoutes,
|
|
11532
11550
|
{ force: ctx.force }
|
|
11533
11551
|
)
|
|
11534
11552
|
};
|
|
@@ -11537,7 +11555,7 @@ async function persistConfig(config2, ctx) {
|
|
|
11537
11555
|
const tsxPath = path36.join(ctx.dir, "apitogo.config.tsx");
|
|
11538
11556
|
if (await fileExists3(tsxPath) && tsxRoutes.length > 0) {
|
|
11539
11557
|
const tsxSource = await readFile5(tsxPath, "utf8");
|
|
11540
|
-
if (
|
|
11558
|
+
if (isManagedConfigWrapper(tsxSource)) {
|
|
11541
11559
|
await writeFile7(
|
|
11542
11560
|
tsxPath,
|
|
11543
11561
|
buildThinWrapperWithCustomPages(tsxRoutes),
|
|
@@ -11636,50 +11654,17 @@ async function makeConfig(argv) {
|
|
|
11636
11654
|
interactiveHasPaidPlans = prompted.hasPaidPlans;
|
|
11637
11655
|
} else {
|
|
11638
11656
|
config2 = applyConfigPatches(config2, flagPatches);
|
|
11639
|
-
const pageFiles = await glob5(`${pagesDir}/**/*.{md,mdx,tsx,jsx}`, {
|
|
11640
|
-
cwd: dir,
|
|
11641
|
-
ignore: ["**/node_modules/**", "**/.git/**", "**/dist/**"],
|
|
11642
|
-
posix: true
|
|
11643
|
-
});
|
|
11644
|
-
const markdownFiles = pageFiles.filter((file) => /\.mdx?$/i.test(file));
|
|
11645
|
-
const tsxFiles = pageFiles.filter((file) => /\.(tsx|jsx)$/i.test(file));
|
|
11646
|
-
const markdownRoutes = markdownFiles.map(
|
|
11647
|
-
(file) => toRoutePath(file, pagesDir)
|
|
11648
|
-
);
|
|
11649
|
-
const tsxRoutes = tsxFiles.map((file) => toRoutePath(file, pagesDir));
|
|
11650
|
-
if (markdownRoutes.length === 0 && tsxRoutes.length === 0) {
|
|
11651
|
-
printDiagnosticsToConsole(
|
|
11652
|
-
`No docs pages under '${pagesDir}/' \u2014 skipping documentation nav scan.`
|
|
11653
|
-
);
|
|
11654
|
-
}
|
|
11655
|
-
config2.navigation = mergeDocumentationNavigation(
|
|
11656
|
-
config2.navigation,
|
|
11657
|
-
markdownRoutes,
|
|
11658
|
-
{ force: argv.force === true }
|
|
11659
|
-
);
|
|
11660
11657
|
if (discoveredOpenApi) {
|
|
11661
11658
|
config2 = applyOpenApiToJsonConfig(
|
|
11662
11659
|
config2,
|
|
11663
11660
|
openapiInputForConfig(discoveredOpenApi)
|
|
11664
11661
|
);
|
|
11665
11662
|
}
|
|
11666
|
-
await
|
|
11667
|
-
`, "utf8");
|
|
11668
|
-
const tsxPath = path36.join(dir, "apitogo.config.tsx");
|
|
11669
|
-
if (await fileExists3(tsxPath) && tsxRoutes.length > 0) {
|
|
11670
|
-
const tsxSource = await readFile5(tsxPath, "utf8");
|
|
11671
|
-
if (isThinConfigWrapper(tsxSource)) {
|
|
11672
|
-
await writeFile7(
|
|
11673
|
-
tsxPath,
|
|
11674
|
-
buildThinWrapperWithCustomPages(tsxRoutes),
|
|
11675
|
-
"utf8"
|
|
11676
|
-
);
|
|
11677
|
-
}
|
|
11678
|
-
}
|
|
11663
|
+
config2 = await persistConfig(config2, persistCtx);
|
|
11679
11664
|
}
|
|
11680
11665
|
const action = createdJson ? "Initialized" : "Updated";
|
|
11681
11666
|
printResultToConsole(
|
|
11682
|
-
`${action} ${APITOGO_JSON_FILENAME}
|
|
11667
|
+
`${action} ${APITOGO_JSON_FILENAME}.`
|
|
11683
11668
|
);
|
|
11684
11669
|
if (createdPackageJson) {
|
|
11685
11670
|
printDiagnosticsToConsole(
|
|
@@ -12163,10 +12148,36 @@ var dev_default = {
|
|
|
12163
12148
|
};
|
|
12164
12149
|
|
|
12165
12150
|
// src/cli/init/handler.ts
|
|
12151
|
+
import { mkdir as mkdir8, readdir, stat as stat4 } from "node:fs/promises";
|
|
12166
12152
|
import path40 from "node:path";
|
|
12153
|
+
var IGNORED_TARGET_ENTRIES = /* @__PURE__ */ new Set([".DS_Store", "Thumbs.db"]);
|
|
12154
|
+
async function ensureEmptyTargetDir(dir) {
|
|
12155
|
+
try {
|
|
12156
|
+
const existing = await stat4(dir);
|
|
12157
|
+
if (!existing.isDirectory()) {
|
|
12158
|
+
throw new Error(`${dir} exists and is not a directory.`);
|
|
12159
|
+
}
|
|
12160
|
+
} catch (err) {
|
|
12161
|
+
const code = err.code;
|
|
12162
|
+
if (code !== "ENOENT") {
|
|
12163
|
+
throw err;
|
|
12164
|
+
}
|
|
12165
|
+
await mkdir8(dir, { recursive: true });
|
|
12166
|
+
return;
|
|
12167
|
+
}
|
|
12168
|
+
const entries = (await readdir(dir)).filter(
|
|
12169
|
+
(name) => !IGNORED_TARGET_ENTRIES.has(name)
|
|
12170
|
+
);
|
|
12171
|
+
if (entries.length > 0) {
|
|
12172
|
+
throw new Error(
|
|
12173
|
+
`Directory '${dir}' is not empty. Choose a new directory or remove existing files.`
|
|
12174
|
+
);
|
|
12175
|
+
}
|
|
12176
|
+
}
|
|
12167
12177
|
async function init2(argv) {
|
|
12168
12178
|
const dir = path40.resolve(process.cwd(), argv.dir ?? ".");
|
|
12169
12179
|
try {
|
|
12180
|
+
await ensureEmptyTargetDir(dir);
|
|
12170
12181
|
const createdPackageJson = await ensurePackageJson(dir);
|
|
12171
12182
|
const createdTsconfig = await ensureTsconfigJson(dir);
|
|
12172
12183
|
await ensurePortalStubFiles(dir);
|