Skip to content

Commit

Permalink
perf: use js for CLI impl for now
Browse files Browse the repository at this point in the history
we can't use bun and it makes perf investigation harder
  • Loading branch information
pi0 committed Feb 21, 2024
1 parent ececa1d commit 8db3a91
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
4 changes: 1 addition & 3 deletions bin/cli.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/usr/bin/env node
import jiti from 'jiti'

jiti(import.meta.url, { esmResolve: true })('../layers/unjs/cli/main.ts')
import '../layers/unjs/cli/main.mjs'
18 changes: 9 additions & 9 deletions layers/core/cli/cli.ts → layers/core/cli/cli.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/usr/bin/env node
import { defineCommand, runMain } from 'citty'
import { setupDocs, type SetupDocsOptions } from './setup'
import { setupDocs } from './setup.mjs'
// import type { SetupDocsOptions } from './setup.mjs'

export interface DocsCLIOptions {
name?: string
description?: string
setup?: SetupDocsOptions
}
// export interface DocsCLIOptions {
// name?: string
// description?: string
// setup?: SetupDocsOptions
// }

export function createCLI(opts: DocsCLIOptions = {}) {
export function createCLI(opts) {
const sharedArgs = {
dir: {
type: 'positional',
description: 'Docs directory',
required: true,
default: '.',
},
} as const
}

const dev = defineCommand({
meta: {
Expand Down
24 changes: 12 additions & 12 deletions layers/core/cli/setup.ts → layers/core/cli/setup.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { fileURLToPath } from 'node:url'
import { resolve } from 'node:path'
import type { NuxtConfig } from 'nuxt/schema'
// import type { NuxtConfig } from 'nuxt/schema'
import { getColors } from 'theme-colors'
import { loadConfig } from 'c12'
import type { DocsConfig } from '../../../schema/config'
// import type { DocsConfig } from '../../../schema/config'

const appDir = fileURLToPath(new URL('../app', import.meta.url))
const pkgDir = fileURLToPath(new URL('../../..', import.meta.url))

export interface SetupDocsOptions {
defaults?: DocsConfig
dev?: boolean
extends?: string[]
}
// export interface SetupDocsOptions {
// defaults?: DocsConfig
// dev?: boolean
// extends?: string[]
// }

export async function setupDocs(docsDir: string, opts: SetupDocsOptions = {}) {
export async function setupDocs(docsDir, opts = {}) {
// Try to load docs config
const docsconfig = (await loadDocsConfig(docsDir, opts.defaults)) || ({} as DocsConfig)
const docsconfig = (await loadDocsConfig(docsDir, opts.defaults)) || ({})

// Normalize dir
docsconfig.dir = docsDir = resolve(docsconfig.dir || docsDir)
Expand All @@ -27,7 +27,7 @@ export async function setupDocs(docsDir: string, opts: SetupDocsOptions = {}) {
}

// Prepare loadNuxt overrides
const nuxtConfig: NuxtConfig = {
const nuxtConfig = {
rootDir: resolve(docsDir, '.docs'),
srcDir: resolve(docsDir, '.docs'),

Expand Down Expand Up @@ -85,8 +85,8 @@ export async function setupDocs(docsDir: string, opts: SetupDocsOptions = {}) {
}
}

async function loadDocsConfig(dir: string, defaults: DocsConfig = {}) {
const { config } = await loadConfig<DocsConfig>({
async function loadDocsConfig(dir, defaults = {}) {
const { config } = await loadConfig({
name: 'docs',
cwd: dir,
defaults: {
Expand Down
2 changes: 1 addition & 1 deletion layers/unjs/cli/main.ts → layers/unjs/cli/main.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileURLToPath } from 'node:url'
import { createCLI } from '../../core/cli/cli'
import { createCLI } from '../../core/cli/cli.mjs'

const appDir = fileURLToPath(new URL('../app', import.meta.url))

Expand Down

0 comments on commit 8db3a91

Please sign in to comment.