Skip to content

Commit

Permalink
chore(vitepress): edit vitepress cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemeras246 committed Dec 17, 2024
1 parent 0d9332c commit 4d863ed
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 60 deletions.
22 changes: 13 additions & 9 deletions packages/vitepress/src/node/cli/command/init.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Parser, nunjucks, type ParserOptions } from '@ephemeras/parser'
import { Parser, nunjucks } from '@ephemeras/parser'
import { resolve } from 'node:path'
import ora from 'ora'
import { fileURLToPath } from 'node:url'
import { INIT_PROMPTS } from '../prompts'
import { answerPrompts, setNpmScript, runCmd } from '../utils'
import { answerPrompts, setPkg, runCmd, getRepoInfo } from '../utils'
import TEXT from '../locales/text'

export type InitData = {
title: string
slogan: string
repo: string
user: string
}
export async function init(data: InitData) {
const parser = new Parser({
Expand All @@ -25,24 +26,27 @@ export async function init(data: InitData) {

export default async function () {
console.log(TEXT.TITLE_INPUT_INFORMATION)
const { title, slogan, repo } = await answerPrompts(INIT_PROMPTS)
const answers: any = await answerPrompts(INIT_PROMPTS)

const { repo, user } = getRepoInfo(answers.repo) || 'ephemeras'

console.log()
console.log(TEXT.TITLE_CREATE_DOCUMENTS)

const { dest } = await init({
title,
slogan,
repo
...answers,
repo,
user
})

console.log(dest.map(i => `📃 create ${i}`).join('\n'))

console.log()
console.log(TEXT.TITLE_INSTALL_DEPENDENCIES)
await setNpmScript('dev', 'vitepress dev --port 28802')
await setNpmScript('build', 'vitepress build')
await setNpmScript('preview', 'vitepress preview')
await setPkg('scripts.dev', 'vitepress dev --port 28802')
await setPkg('scripts.build', 'vitepress build')
await setPkg('scripts.preview', 'vitepress preview')
await setPkg('type', 'module')

const spinner = ora('start install dependencies').start()
await runCmd('pnpm', [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const TITLE = 'Ephemeras'
export const DESCRIPTION = 'Make development easier and more efficient'
export const TITLE = '{{ title }}'
export const DESCRIPTION = '{{ slogan }}'

export const GITHUB_URL = 'https://github.com/Kythuen/ephemeras'
export const OG_URL = 'https://kythuen.github.io/ephemeras'
export const GITHUB_URL = 'https://github.com/{{ user }}/{{ repo }}'
export const OG_URL = 'https://{{ user | lower }}.github.io/{{ repo }}'
export const OG_IMAGE = `${OG_URL}/logo.png`
12 changes: 7 additions & 5 deletions packages/vitepress/src/node/cli/files/.vitepress/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { NAV, SIDEBAR } from './routes/en'

export default defineConfig({
lang: 'en',
base: '/ephemeras/',
base: '/{{ repo }}/',
srcDir: 'src',
title: 'Ephemeras',
description: 'Make development easier and more efficient',
title: '{{ title }}',
description: '{{ slogan }}',
cleanUrls: true,
head: [['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }]],
head: [
['link', { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }]
],
themeConfig: {
search: {
provider: 'local'
Expand All @@ -22,7 +24,7 @@ export default defineConfig({
description: DESCRIPTION,
head: [['meta', { name: 'og:description', content: DESCRIPTION }]],
themeConfig: {
logo: '/logo.png',
logo: '/logo.svg',
siteTitle: '',
nav: NAV,
socialLinks: [{ icon: 'github', link: GITHUB_URL }],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,11 @@
import type { DefaultTheme } from 'vitepress'

const SidebarGuides: DefaultTheme.NavItemWithLink[] = [
{ text: 'Getting Started', link: '/guide' },
{ text: 'Overview', link: '/guide/overview' },
{ text: 'Colors', link: '/guide/colors' }
]

const SidebarPackages: DefaultTheme.NavItemWithLink[] = [
{ text: 'Linter', link: '/linter/' },
{ text: 'Compiler', link: '/compiler/' },
{ text: 'File', link: '/file/' },
{ text: 'File System', link: '/fs/' },
{ text: 'Profile', link: '/profile/' },
{ text: 'Utils', link: '/utils/' }
]

const SidebarFS = [
{ text: 'Getting Started', link: '/fs/guide' },
{ text: 'Functions', link: '/fs/functions' }
]

const SidebarTP = [
{ text: 'Getting Started', link: '/parser/guide' },
{ text: 'Plugins', link: '/parser/plugins' },
{ text: 'Types', link: '/parser/types' }
{ text: 'Getting Started', link: '/guide' }
]

export const SIDEBAR: Record<string, DefaultTheme.SidebarItem[]> = {
'/guide': [{ text: 'Packages', items: SidebarGuides }],
'/packages/': [{ text: 'Packages', items: SidebarPackages }],
'/fs/': [
{ text: 'Guides', items: SidebarFS },
{ text: 'Packages', items: SidebarPackages }
],
'/parser/': [
{ text: 'Guides', items: SidebarTP },
{ text: 'Packages', items: SidebarPackages }
]
'/guide': [{ text: 'Guide', items: SidebarGuides }]
}

export const NAV = [
{ text: 'Guide', link: '/guide' },
{ text: 'Packages', link: '/packages' }
]
export const NAV = [{ text: 'Guide', link: '/guide' }]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
5 changes: 2 additions & 3 deletions packages/vitepress/src/node/cli/locales/text.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import gradient from 'gradient-string'
import { retro, vice } from 'gradient-string'
import picocolors from 'picocolors'
import { $t } from '.'

const { reset, bold, underline, cyan } = picocolors
const { retro, vice } = gradient
const { bold } = picocolors

export default {
TIP_WELCOME: bold(retro($t('TIP.WELCOME'))),
Expand Down
24 changes: 22 additions & 2 deletions packages/vitepress/src/node/cli/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,29 @@ export function answerPrompts(questions: PromptObject[]) {
}

const asyncExecFile = promisify(execFile)
export async function setNpmScript(name: string, script: string) {
return asyncExecFile('npm', ['pkg', 'set', `scripts.${name}=${script}`])
export async function setPkg(field: string, script: string) {
return asyncExecFile('npm', ['pkg', 'set', `${field}=${script}`])
}
export async function runCmd(cmd: string, args: string[]) {
return asyncExecFile(cmd, args)
}

export function getRepoInfo(url: string) {
const trimmedUrl = url.replace(/\/+$/, '')

const gitMatch = trimmedUrl.match(
/(?:https?:\/\/|git@)([^/:]+)[:/](.*?)(?:\.git)?$/i
)

if (gitMatch && gitMatch[2]) {
const parts = gitMatch[2].split('/')
if (parts.length >= 2) {
return {
user: parts[0],
repo: parts.slice(1).join('/')
}
}
}

return { user: '', repo: '' }
}

0 comments on commit 4d863ed

Please sign in to comment.