-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: vitepress init command (#2020)
close #1252
- Loading branch information
Showing
22 changed files
with
786 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
.vscode | ||
dist | ||
cache | ||
temp | ||
examples-temp | ||
node_modules | ||
pnpm-global | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
dist | ||
pnpm-lock.yaml | ||
cache | ||
template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { chromium, type Browser, type Page } from 'playwright-chromium' | ||
import { fileURLToPath } from 'url' | ||
import path from 'path' | ||
import fs from 'fs-extra' | ||
import { | ||
scaffold, | ||
build, | ||
createServer, | ||
serve, | ||
ScaffoldThemeType, | ||
type ScaffoldOptions | ||
} from 'vitepress' | ||
import type { ViteDevServer } from 'vite' | ||
import type { Server } from 'net' | ||
import getPort from 'get-port' | ||
|
||
let browser: Browser | ||
let page: Page | ||
|
||
beforeAll(async () => { | ||
browser = await chromium.connect(process.env['WS_ENDPOINT']!) | ||
page = await browser.newPage() | ||
}) | ||
|
||
afterAll(async () => { | ||
await page.close() | ||
await browser.close() | ||
}) | ||
|
||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'temp') | ||
|
||
async function testVariation(options: ScaffoldOptions) { | ||
fs.removeSync(root) | ||
scaffold({ | ||
...options, | ||
root | ||
}) | ||
|
||
let server: ViteDevServer | Server | ||
const port = await getPort() | ||
|
||
async function goto(path: string) { | ||
await page.goto(`http://localhost:${port}${path}`) | ||
await page.waitForSelector('#app div') | ||
} | ||
|
||
if (process.env['VITE_TEST_BUILD']) { | ||
await build(root) | ||
server = (await serve({ root, port })).server | ||
} else { | ||
server = await createServer(root, { port }) | ||
await server!.listen() | ||
} | ||
|
||
try { | ||
await goto('/') | ||
expect(await page.textContent('h1')).toMatch('My Awesome Project') | ||
|
||
await page.click('a[href="/markdown-examples.html"]') | ||
await page.waitForSelector('pre code') | ||
expect(await page.textContent('h1')).toMatch('Markdown Extension Examples') | ||
|
||
await goto('/') | ||
expect(await page.textContent('h1')).toMatch('My Awesome Project') | ||
|
||
await page.click('a[href="/api-examples.html"]') | ||
await page.waitForSelector('pre code') | ||
expect(await page.textContent('h1')).toMatch('Runtime API Examples') | ||
} finally { | ||
fs.removeSync(root) | ||
if ('ws' in server) { | ||
await server.close() | ||
} else { | ||
await new Promise<void>((resolve, reject) => { | ||
server.close((error) => (error ? reject(error) : resolve())) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
const themes = [ | ||
ScaffoldThemeType.Default, | ||
ScaffoldThemeType.DefaultCustom, | ||
ScaffoldThemeType.Custom | ||
] | ||
const usingTs = [false, true] | ||
|
||
for (const theme of themes) { | ||
for (const useTs of usingTs) { | ||
test(`${theme}${useTs ? ` + TypeScript` : ``}`, () => | ||
testVariation({ | ||
root: '.', | ||
theme, | ||
useTs, | ||
injectNpmScripts: false | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"private": true, | ||
"type": "module", | ||
"devDependencies": { | ||
"vitepress": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { dirname, resolve } from 'path' | ||
import { fileURLToPath } from 'url' | ||
import { defineConfig } from 'vitest/config' | ||
|
||
const dir = dirname(fileURLToPath(import.meta.url)) | ||
|
||
const timeout = 60_000 | ||
|
||
export default defineConfig({ | ||
resolve: { | ||
alias: { | ||
node: resolve(dir, '../../src/node') | ||
} | ||
}, | ||
test: { | ||
watchExclude: ['**/node_modules/**', '**/temp/**'], | ||
globalSetup: ['__tests__/init/vitestGlobalSetup.ts'], | ||
testTimeout: timeout, | ||
hookTimeout: timeout, | ||
teardownTimeout: timeout, | ||
globals: true | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { chromium, type BrowserServer } from 'playwright-chromium' | ||
|
||
let browserServer: BrowserServer | ||
|
||
export async function setup() { | ||
browserServer = await chromium.launchServer({ | ||
headless: !process.env.DEBUG, | ||
args: process.env.CI | ||
? ['--no-sandbox', '--disable-setuid-sandbox'] | ||
: undefined | ||
}) | ||
process.env['WS_ENDPOINT'] = browserServer.wsEndpoint() | ||
} | ||
|
||
export async function teardown() { | ||
await browserServer.close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.