diff --git a/package.json b/package.json index 17354e2b24..4f64bbf7d0 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "workspaces": [ "packages/*", "website", - "website-1.x" + "website-1.x", + "packages/docusaurus/templates/*" ], "scripts": { "start": "yarn tsc && yarn start:v2", diff --git a/packages/docusaurus/src/commands/init.ts b/packages/docusaurus/src/commands/init.ts index f8740f0d90..f06a3ef1da 100644 --- a/packages/docusaurus/src/commands/init.ts +++ b/packages/docusaurus/src/commands/init.ts @@ -13,7 +13,7 @@ import path from 'path'; import _ from 'lodash'; import {execSync} from 'child_process'; -function hasYarn() { +function hasYarn(): Boolean { try { execSync('yarnpkg --version', {stdio: 'ignore'}); return true; @@ -22,11 +22,11 @@ function hasYarn() { } } -function isValidGitRepoUrl(gitRepoUrl) { +function isValidGitRepoUrl(gitRepoUrl): Boolean { return gitRepoUrl.startsWith('https://') || gitRepoUrl.startsWith('git@'); } -async function updatePkg(pkgPath, obj) { +async function updatePkg(pkgPath: string, obj): Promise { const content = await fs.readFile(pkgPath, 'utf-8'); const pkg = JSON.parse(content); const newPkg = Object.assign(pkg, obj); @@ -87,7 +87,7 @@ export async function init( const {gitRepoUrl} = await inquirer.prompt({ type: 'input', name: 'gitRepoUrl', - validate: url => { + validate: (url?: string) => { if (url && isValidGitRepoUrl(url)) { return true; } diff --git a/packages/docusaurus/src/server/routes.ts b/packages/docusaurus/src/server/routes.ts index 19ae8daa19..3a22622508 100644 --- a/packages/docusaurus/src/server/routes.ts +++ b/packages/docusaurus/src/server/routes.ts @@ -78,7 +78,7 @@ export async function loadRoutes(pluginsRouteConfigs: RouteConfig[]) { } function genRouteChunkNames( - value: RouteModule | Module | null | undefined, + value: RouteModule | RouteModule[] | Module | null | undefined, prefix?: string, name?: string, ) { diff --git a/packages/docusaurus/templates/README.MD b/packages/docusaurus/templates/README.MD new file mode 100644 index 0000000000..994ca5fd20 --- /dev/null +++ b/packages/docusaurus/templates/README.MD @@ -0,0 +1,8 @@ +# Templates + +Official templates provided by Docusaurus. They are designed to be selected when using the `docusaurus init` CLI command. + +## Guide to Test Templates for Developer + +1. `yarn install` in the root of the repo (one level above this directory). +1. Go to any template's directory, example: `cd classic && yarn start`. diff --git a/packages/docusaurus/templates/classic/package.json b/packages/docusaurus/templates/classic/package.json index b91cd200da..c155fed15b 100644 --- a/packages/docusaurus/templates/classic/package.json +++ b/packages/docusaurus/templates/classic/package.json @@ -1,4 +1,6 @@ { + "name": "docusaurus-2-classic-template", + "version": "2.0.0-alpha.16", "private": true, "scripts": { "docusaurus": "docusaurus",