From 0395a1931fc9fb3a233f39558ab6586e8e1d706d Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Thu, 17 Feb 2022 13:10:59 +0800 Subject: [PATCH 01/10] chore(website): upgrade Docusaurus, format files --- .prettierignore | 4 + website/docusaurus.config.js | 54 +- website/package.json | 6 +- website/scripts/build-readme.mjs | 93 +- website/sidebars.js | 102 +- website/src/pages/index.js | 40 +- website/yarn.lock | 8581 +++++++++++------------------- 7 files changed, 3426 insertions(+), 5454 deletions(-) diff --git a/.prettierignore b/.prettierignore index 492a816ce..b0d274e3c 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,6 +6,10 @@ !/scripts !/src !/tests +!/website +website/docs +website/readme-sources +website/static tests/main-realpath/symlink/tsconfig.json tests/throw error.ts tests/throw error react tsx.tsx diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 109116d2c..b27139a62 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -19,7 +19,7 @@ module.exports = { // //isCloseable: false, // Defaults to `true`. // }, colorMode: { - respectPrefersColorScheme: true + respectPrefersColorScheme: true, }, navbar: { title: 'ts-node', @@ -61,6 +61,20 @@ module.exports = { }, ], }, + metadata: [ + { + name: 'msapplication-TileColor', + content: '#2b5797', + }, + { + name: 'msapplication-config', + content: '/ts-node/img/favicon/browserconfig.xml', + }, + { + name: 'theme-color', + content: '#ffffff', + }, + ], // footer: { // style: 'dark', // links: [ @@ -124,9 +138,9 @@ module.exports = { { docs: { sidebarPath: require.resolve('./sidebars.js'), - editUrl: - 'https://github.com/TypeStrong/ts-node/edit/docs/website/', + editUrl: 'https://github.com/TypeStrong/ts-node/edit/docs/website/', }, + blog: false, // blog: { // showReadingTime: true, // // Please change this to your repo. @@ -139,4 +153,38 @@ module.exports = { }, ], ], + // Misleading API, probably will be refactored in Docusaurus, but this is + // simply a list of tags + stylesheets: [ + { + rel: 'apple-touch-icon', + sizes: '180x180', + href: '/ts-node/img/favicon/apple-touch-icon.png', + }, + { + rel: 'icon', + type: 'image/png', + sizes: '32x32', + href: '/ts-node/img/favicon/favicon-32x32.png', + }, + { + rel: 'icon', + type: 'image/png', + sizes: '16x16', + href: '/ts-node/img/favicon/favicon-16x16.png', + }, + { + rel: 'manifest', + href: '/ts-node/img/favicon/site.webmanifest', + }, + { + rel: 'mask-icon', + href: '/ts-node/img/favicon/safari-pinned-tab.svg', + color: '#5bbad5', + }, + { + rel: 'shortcut icon', + href: '/ts-node/img/favicon/favicon.ico', + }, + ], }; diff --git a/website/package.json b/website/package.json index 6c3851cd3..8da751413 100644 --- a/website/package.json +++ b/website/package.json @@ -13,9 +13,9 @@ "build-readme": "./scripts/build-readme.mjs" }, "dependencies": { - "@docusaurus/core": "2.0.0-alpha.75", - "@docusaurus/preset-classic": "2.0.0-alpha.75", - "@docusaurus/theme-search-algolia": "^2.0.0-alpha.75", + "@docusaurus/core": "2.0.0-beta.15", + "@docusaurus/preset-classic": "2.0.0-beta.15", + "@docusaurus/theme-search-algolia": "2.0.0-beta.15", "@mdx-js/react": "^1.6.21", "@types/js-yaml": "^4.0.0", "clsx": "^1.1.1", diff --git a/website/scripts/build-readme.mjs b/website/scripts/build-readme.mjs index b7cb22c48..0263c8f32 100755 --- a/website/scripts/build-readme.mjs +++ b/website/scripts/build-readme.mjs @@ -25,7 +25,7 @@ const readmePath = Path.resolve(__root, 'README.md'); const generateReadmeHeadersForCategories = { General: false, Advanced: true, - Recipes: true + Recipes: true, }; import sidebars from '../sidebars.js'; @@ -35,42 +35,50 @@ async function main() { await appendMarkdownFileToReadmeAst({ path: 'readme-sources/prefix.md', - headerLevel: 1 + headerLevel: 1, }); const sidebar = sidebars.primarySidebar; - for(const category of sidebar) { - const generateReadmeHeader = generateReadmeHeadersForCategories[category.label]; - if(generateReadmeHeader) { + for (const category of sidebar) { + const generateReadmeHeader = + generateReadmeHeadersForCategories[category.label]; + if (generateReadmeHeader) { readmeNodes.push(headerNode(1, category.label)); - } else if(generateReadmeHeader == null) { - throw new Error(`Update ${ import.meta.url } to include all sidebar categories`); + } else if (generateReadmeHeader == null) { + throw new Error( + `Update ${import.meta.url} to include all sidebar categories` + ); } - for(const page of category.items) { + for (const page of category.items) { await appendMarkdownFileToReadmeAst({ - path: `docs/${ page }.md`, - headerLevel: 1 + !!generateReadmeHeader + path: `docs/${page}.md`, + headerLevel: 1 + !!generateReadmeHeader, }); } } appendMarkdownFileToReadmeAst({ path: 'readme-sources/license.md', - headerLevel: 1 + headerLevel: 1, }); - async function appendMarkdownFileToReadmeAst({path, headerLevel}) { + async function appendMarkdownFileToReadmeAst({ path, headerLevel }) { const absPath = Path.resolve(__websiteRoot, path); - console.log(`Appending ${ path } at header level ${ headerLevel }`); + console.log(`Appending ${path} at header level ${headerLevel}`); const markdownSource = fs.readFileSync(absPath, 'utf8'); await remark() .use(remarkFrontmatter, ['yaml']) .use(parseFrontmatter) .use(remarkBehead, { after: '', depth: headerLevel - 1 }) .use(() => (ast) => { - const {frontmatter} = ast; - if(frontmatter && !frontmatter.omitHeaderOnMerge) { - readmeNodes.push(headerNode(headerLevel, frontmatter && frontmatter.title || Path.basename(absPath))); + const { frontmatter } = ast; + if (frontmatter && !frontmatter.omitHeaderOnMerge) { + readmeNodes.push( + headerNode( + headerLevel, + (frontmatter && frontmatter.title) || Path.basename(absPath) + ) + ); } readmeNodes.push(...ast.children); }) @@ -84,73 +92,78 @@ async function main() { .use(codeLanguageJsonToJsonc) .use(rewritePageLinksToAnchorLinks) .use(rewriteImgTargets) - .use(remarkToc, {tight: true}) - .process(vfile({ - path: readmePath, - contents: '' - })); + .use(remarkToc, { tight: true }) + .process( + vfile({ + path: readmePath, + contents: '', + }) + ); console.error(vfileReporter(renderedReadme)); - if(renderedReadme.messages.length) throw new Error('Aborting on diagnostics.'); + if (renderedReadme.messages.length) + throw new Error('Aborting on diagnostics.'); const lintResults = await remark() .use(remarkValidateLinks) .use(remarkRecommended) .process(renderedReadme); console.error(vfileReporter(lintResults)); - if(lintResults.messages.length) throw new Error('Aborting on diagnostics.'); + if (lintResults.messages.length) throw new Error('Aborting on diagnostics.'); fs.writeFileSync(readmePath, renderedReadme.contents); } function parseFrontmatter() { return (ast) => { - if(ast.children[0].type === 'yaml') { + if (ast.children[0].type === 'yaml') { ast.frontmatter = jsYaml.load(ast.children[0].value); ast.children.splice(0, 1); } - } + }; } function codeLanguageJsonToJsonc() { return (ast) => { - visit(ast, 'code', node => { - if(node.lang === 'json') node.lang = 'jsonc'; - }) - } + visit(ast, 'code', (node) => { + if (node.lang === 'json') node.lang = 'jsonc'; + }); + }; } function rewritePageLinksToAnchorLinks() { return (ast) => { - visit(ast, 'link', node => { - if(node.url?.match?.(/^https?\:\/\//)) return; + visit(ast, 'link', (node) => { + if (node.url?.match?.(/^https?\:\/\//)) return; // TODO take page title into account node.url = node.url.replace(/^[\.\/]*(?:([^#]+)|.*#(.*))$/, '#$1$2'); node.url = node.url.replace(/\.md$/, ''); }); - } + }; } function rewriteImgTargets() { return (ast) => { - visit(ast, 'image', node => { + visit(ast, 'image', (node) => { node.url = node.url.replace(/^\//, 'website/static/'); }); - } + }; } function headerNode(depth, value) { return { type: 'heading', depth, - children: [{ - type: 'text', - value, - children: [] - }] + children: [ + { + type: 'text', + value, + children: [], + }, + ], }; } try { await main(); -} catch(e) { +} catch (e) { console.error(e.message); process.exitCode = 1; } diff --git a/website/sidebars.js b/website/sidebars.js index 4f1d70e01..4e3dbd9f5 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -1,51 +1,55 @@ module.exports = { - primarySidebar: [{ - type: 'category', - label: 'General', - collapsed: false, - items: [ - 'overview', - 'installation', - 'usage', - 'configuration', - 'options', - 'imports', - 'troubleshooting', - 'performance', - ] - }, { - type: 'category', - label: 'Advanced', - collapsed: false, - items: [ - 'how-it-works', - 'paths', - 'types', - 'compilers', - 'transpilers', - 'module-type-overrides' - ], - }, { - type: 'category', - label: 'Recipes', - collapsed: false, - items: [ - 'recipes/watching-and-restarting', - 'recipes/ava', - 'recipes/gulp', - 'recipes/intellij', - 'recipes/mocha', - 'recipes/tape', - 'recipes/visual-studio-code', - 'recipes/other' - ] - }], - hiddenSidebar: [{ - type: 'category', - label: 'Hidden pages', - collapsed: false, - items: [ - 'options-table', - ] - }], + primarySidebar: [ + { + type: 'category', + label: 'General', + collapsed: false, + items: [ + 'overview', + 'installation', + 'usage', + 'configuration', + 'options', + 'imports', + 'troubleshooting', + 'performance', + ], + }, + { + type: 'category', + label: 'Advanced', + collapsed: false, + items: [ + 'how-it-works', + 'paths', + 'types', + 'compilers', + 'transpilers', + 'module-type-overrides', + ], + }, + { + type: 'category', + label: 'Recipes', + collapsed: false, + items: [ + 'recipes/watching-and-restarting', + 'recipes/ava', + 'recipes/gulp', + 'recipes/intellij', + 'recipes/mocha', + 'recipes/tape', + 'recipes/visual-studio-code', + 'recipes/other', + ], + }, + ], + hiddenSidebar: [ + { + type: 'category', + label: 'Hidden pages', + collapsed: false, + items: ['options-table'], + }, + ], }; diff --git a/website/src/pages/index.js b/website/src/pages/index.js index 9a50c6e39..dcb410ad0 100644 --- a/website/src/pages/index.js +++ b/website/src/pages/index.js @@ -2,12 +2,11 @@ import React from 'react'; import clsx from 'clsx'; import Layout from '@theme/Layout'; import Link from '@docusaurus/Link'; -import Head from '@docusaurus/Head'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import useBaseUrl from '@docusaurus/useBaseUrl'; import styles from './styles.module.css'; -function Feature({imageUrl, title, description}) { +function Feature({ imageUrl, title, description }) { const imgUrl = useBaseUrl(imageUrl); return (
@@ -22,38 +21,28 @@ function Feature({imageUrl, title, description}) { function Home() { const context = useDocusaurusContext(); - const {siteConfig = {}} = context; + const { siteConfig = {} } = context; return ( - - - - - - - - - - - - +

{siteConfig.title}

{siteConfig.tagline}

+ to={useBaseUrl('docs/')} + > Get Started