mirror of
https://github.com/tauri-apps/typedocusaurus.git
synced 2026-02-04 02:31:22 +01:00
feat: Now generating a JSON file instead of writing to sidebars.json
This commit is contained in:
1067
dist/index.js
vendored
1067
dist/index.js
vendored
File diff suppressed because one or more lines are too long
10
package.json
10
package.json
@@ -5,16 +5,16 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"run-source": "node index.js",
|
||||
"pkg": "ncc build src/index.ts -o dist -m"
|
||||
"pkg": "ncc build src/index.ts -o dist"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.14.35",
|
||||
"@zeit/ncc": "^0.27.0",
|
||||
"@vercel/ncc": "^0.28.5",
|
||||
"override-require": "^1.1.1",
|
||||
"typescript": "^4.2.3",
|
||||
"tslib": "^2.1.0"
|
||||
"tslib": "^2.1.0",
|
||||
"typescript": "^4.2.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
src/index.ts
12
src/index.ts
@@ -1,13 +1,15 @@
|
||||
// const core = require("@actions/core");
|
||||
let core = require("@actions/core");
|
||||
const { rmdir } = require("fs").promises;
|
||||
|
||||
const path = require("path");
|
||||
|
||||
const overrideRequire = require("override-require");
|
||||
const core = {
|
||||
getInput: (variable) => process.env[variable],
|
||||
setFailed: (message) => console.log(message)
|
||||
};
|
||||
if (process.env.DEV) {
|
||||
core = {
|
||||
getInput: (variable) => process.env[variable],
|
||||
setFailed: (message) => console.log(message)
|
||||
};
|
||||
}
|
||||
(async () => {
|
||||
try {
|
||||
// Where your docs live, should be the folder containing the crates docs
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import { ProjectReflection, UrlMapping } from 'typedoc';
|
||||
// @ts-ignore
|
||||
import { RendererEvent } from 'typedoc/dist/lib/output/events';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
export async function render(
|
||||
project: ProjectReflection,
|
||||
@@ -26,11 +25,11 @@ export async function render(
|
||||
if (!output.isDefaultPrevented) {
|
||||
output.urls?.forEach((mapping: UrlMapping, i) => {
|
||||
this.renderDocument(output.createPageEvent(mapping));
|
||||
ts.sys.write(
|
||||
console.log(
|
||||
`\rGenerated ${i + 1} of ${output.urls?.length} TypeDoc docs`,
|
||||
);
|
||||
});
|
||||
ts.sys.write(`\n`);
|
||||
console.log(`\n`);
|
||||
this.trigger(RendererEvent.END, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { RendererComponent } from 'typedoc/dist/lib/output/components';
|
||||
import { RendererEvent } from 'typedoc/dist/lib/output/events';
|
||||
|
||||
import { SidebarItem, SidebarOptions } from './types';
|
||||
import { readFile, writeFile } from 'fs/promises';
|
||||
import { writeFile } from 'fs/promises';
|
||||
|
||||
@Component({ name: 'sidebar' })
|
||||
export class SidebarComponent extends RendererComponent {
|
||||
@@ -73,14 +73,8 @@ export class SidebarComponent extends RendererComponent {
|
||||
: [];
|
||||
|
||||
const sidebarPath = this.sidebar.sidebarPath;
|
||||
|
||||
const sidebarContent = JSON.parse(await readFile(sidebarPath!, "utf-8"));
|
||||
const index = sidebarContent.docs[3].items
|
||||
.map((row, index) => (row.label && row.label === "JavaScript" ? index : 0))
|
||||
.reduce((accumulator, value) => accumulator + value);
|
||||
sidebarContent.docs[3].items[index].items = sidebarItems; // Specify where to put the items
|
||||
|
||||
writeFile(sidebarPath, JSON.stringify(sidebarContent, null, 2));
|
||||
writeFile(sidebarPath, JSON.stringify(sidebarItems, null, 2));
|
||||
// @ts-ignore
|
||||
this.application.logger.success(
|
||||
`TypeDoc sidebar written to ${sidebarPath}`,
|
||||
@@ -92,9 +86,9 @@ export class SidebarComponent extends RendererComponent {
|
||||
*/
|
||||
getSidebarCategory(title: string, items: SidebarItem[]) {
|
||||
return {
|
||||
items,
|
||||
type: 'category',
|
||||
label: title,
|
||||
items,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.35.tgz#42c953a4e2b18ab931f72477e7012172f4ffa313"
|
||||
integrity sha512-Lt+wj8NVPx0zUmUwumiVXapmaLUcAk3yPuHCFVXras9k5VT9TdhJqKqGVUQCD60OTMCl0qxJ57OiTL0Mic3Iag==
|
||||
|
||||
"@zeit/ncc@^0.27.0":
|
||||
version "0.22.3"
|
||||
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.22.3.tgz#fca6b86b4454ce7a7e1e7e755165ec06457f16cd"
|
||||
integrity sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ==
|
||||
"@vercel/ncc@^0.28.5":
|
||||
version "0.28.5"
|
||||
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.28.5.tgz#6d735379f81b70b708a9c3d2196507b2a841824f"
|
||||
integrity sha512-ZSwD4EDCon2EsnPZ2/Qcigx4N2DiuBLV/rDnF04giEPFuDeBeUDdnSTyYYfX8KNic/prrJuS1vUEmAOHmj+fRg==
|
||||
|
||||
override-require@^1.1.1:
|
||||
version "1.1.1"
|
||||
|
||||
Reference in New Issue
Block a user