Skip to content

Commit

Permalink
chore: lint and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoepics committed Oct 8, 2024
1 parent 7d6ed72 commit 0bb1c8b
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 159 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vitepress-carbon",
"version": "1.3.3",
"name": "vitepress-carbon-monorepo",
"version": "1.3.4",
"description": "Carbon embraces GitHub's monochromatic ethos, offering a theme for VitePress documentation that is sleek, modern, and effortlessly stylish.",
"keywords": [
"vue",
Expand Down
39 changes: 0 additions & 39 deletions packages/cli/CHANGELOG.md

This file was deleted.

18 changes: 10 additions & 8 deletions packages/cli/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ export default defineBuildConfig({
hooks: {
'rollup:options'(_, options) {
const plugins = (options.plugins ||= []) as InputPluginOption[]
plugins.push(purgePolyfills.rollup({
logLevel: 'verbose',
}))
},
plugins.push(
purgePolyfills.rollup({
logLevel: 'verbose'
})
)
}
},
rollup: {
inlineDependencies: true,
resolve: {
exportConditions: ['production', 'node'] as any,
},
exportConditions: ['production', 'node'] as any
}
},
entries: ['src/index'],
externals: [
Expand All @@ -27,6 +29,6 @@ export default defineBuildConfig({
'node:child_process',
'node:process',
'node:path',
'node:os',
],
'node:os'
]
})
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vpcar",
"version": "0.0.1",
"version": "1.0.0",
"description": "VitePress Carbon CLI",
"repository": {
"type": "git",
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/commands/_shared.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export const sharedArgs = {
cwd: {
type: 'string',
description: 'Current working directory',
description: 'Current working directory'
},
logLevel: {
type: 'string',
description: 'Log level',
},
description: 'Log level'
}
} as const

export const legacyRootDirArgs = {
rootDir: {
type: 'positional',
description: 'Root Directory',
required: false,
},
required: false
}
} as const
2 changes: 1 addition & 1 deletion packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import type { CommandDef } from 'citty'
const _rDefault = (r: any) => (r.default || r) as Promise<CommandDef>

export const commands = {
'init': () => import('./init').then(_rDefault),
init: () => import('./init').then(_rDefault)
} as const
81 changes: 52 additions & 29 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import { promises as fsp } from 'node:fs'
import { dependabotTemplate, githubPagesTemplate } from '../utils/templates'
import { Hyperlink } from '../utils/console'

const DEFAULT_REGISTRY
= 'https://raw.githubusercontent.com/brenoepics/vitepress-carbon/main/packages/templates/'
const repoLink = Hyperlink('VitePress Carbon', 'https://github.com/brenoepics/vitepress-carbon')
const DEFAULT_REGISTRY =
'https://raw.githubusercontent.com/brenoepics/vitepress-carbon/main/packages/templates/'
const repoLink = Hyperlink(
'VitePress Carbon',
'https://github.com/brenoepics/vitepress-carbon'
)
export default defineCommand({
meta: {
name: 'init',
Expand Down Expand Up @@ -70,10 +73,10 @@ export default defineCommand({
const cwd = resolve(ctx.args.cwd || '.')

type SelectOption = {
label: string;
value: string;
hint?: string;
};
label: string
value: string
hint?: string
}
// Get template name
const templateOptions: SelectOption[] = [
{
Expand All @@ -84,13 +87,17 @@ export default defineCommand({
{
label: 'JavaScript',
value: 'javascript'
}]
const templateName = ctx.args.language && templateOptions.some((value) => value.value === ctx.args.language)
? templateOptions.find((value) => value.value === ctx.args.language)!.value
: (await consola.prompt('Which template would you like to use?', {
type: 'select',
options: templateOptions
})) as unknown as string
}
]
const templateName =
ctx.args.language &&
templateOptions.some((value) => value.value === ctx.args.language)
? templateOptions.find((value) => value.value === ctx.args.language)!
.value
: ((await consola.prompt('Which template would you like to use?', {
type: 'select',
options: templateOptions
})) as unknown as string)

// Download template
let template: DownloadTemplateResult
Expand Down Expand Up @@ -125,31 +132,47 @@ export default defineCommand({
)
? packageManagerArg
: await consola.prompt('Which package manager would you like to use?', {
type: 'select',
options: packageManagerOptions
})
type: 'select',
options: packageManagerOptions
})

const ghActionsOptions = ['dependabot', 'github-pages', 'none']
const selectedGHActions = ctx.args.addGHActions
? ctx.args.addGHActions.split(',')
: await consola.prompt('Which GitHub Actions workflows would you like to add?', {
type: 'multiselect',
options: ghActionsOptions,
required: false
})
: await consola.prompt(
'Which GitHub Actions workflows would you like to add?',
{
type: 'multiselect',
options: ghActionsOptions,
required: false
}
)

if (!selectedGHActions.includes('none') && selectedGHActions.includes('dependabot')) {
if (
!selectedGHActions.includes('none') &&
selectedGHActions.includes('dependabot')
) {
consola.info('Adding Dependabot configuration...')
const dependabotConfig = stringify(dependabotTemplate)
const dependabotPath = join(template.dir, '.github', 'dependabot.yml')
await fsp.mkdir(dirname(dependabotPath), { recursive: true })
await fsp.writeFile(dependabotPath, dependabotConfig, 'utf8')
}

if (!selectedGHActions.includes('none') && selectedGHActions.includes('github-pages')) {
if (
!selectedGHActions.includes('none') &&
selectedGHActions.includes('github-pages')
) {
consola.info('Adding GitHub Pages workflow...')
const githubPagesConfig = stringify(githubPagesTemplate(selectedPackageManager))
const githubPagesPath = join(template.dir, '.github', 'workflows', 'deploy-pages.yml')
const githubPagesConfig = stringify(
githubPagesTemplate(selectedPackageManager)
)
const githubPagesPath = join(
template.dir,
'.github',
'workflows',
'deploy-pages.yml'
)
await fsp.mkdir(dirname(githubPagesPath), { recursive: true })
await fsp.writeFile(githubPagesPath, githubPagesConfig, 'utf8')
}
Expand Down Expand Up @@ -201,9 +224,9 @@ export default defineCommand({
)
const relativeTemplateDir = relative(process.cwd(), template.dir) || '.'
const nextSteps = [
!ctx.args.shell
&& relativeTemplateDir.length > 1
&& `\`cd ${relativeTemplateDir}\``,
!ctx.args.shell &&
relativeTemplateDir.length > 1 &&
`\`cd ${relativeTemplateDir}\``,
`Start development server with \`${selectedPackageManager} run docs:dev\``
].filter(Boolean)

Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export const main = defineCommand({
backgroundTasks = Promise.all([
checkEngines()
// checkForUpdates(),
]).catch(err => console.error(err))

]).catch((err) => console.error(err))

// Avoid background check to fix prompt issues
if (command === 'init') {
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ globalThis.__vp_cli__ = globalThis.__vp_cli__ || {
import.meta.url.endsWith('.ts')
? '../bin/vpcar.mjs'
: '../../bin/vpcar.mjs',
import.meta.url,
),
),
import.meta.url
)
)
}

export const runMain = () => _runMain(main)

export async function runCommand(
name: string,
argv: string[] = process.argv.slice(2),
data: { overrides?: Record<string, any> } = {},
data: { overrides?: Record<string, any> } = {}
) {
argv.push('--no-clear') // Dev

Expand All @@ -33,7 +33,7 @@ export async function runCommand(
return await _runCommand(await commands[name as keyof typeof commands](), {
rawArgs: argv,
data: {
overrides: data.overrides || {},
},
overrides: data.overrides || {}
}
})
}
4 changes: 2 additions & 2 deletions packages/cli/src/utils/console.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function Hyperlink(text: string, url: string): string {
return `\u001b]8;;${url}\u0007${text}\u001b]8;;\u0007`;
return `\u001b]8;;${url}\u0007${text}\u001b]8;;\u0007`
}

export function Bold(text: string): string {
return `\u001b[1m${text}\u001b[22m`;
return `\u001b[1m${text}\u001b[22m`
}
6 changes: 3 additions & 3 deletions packages/cli/src/utils/engines.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export async function checkEngines() {
const satisfies = await import('semver/functions/satisfies.js').then(
r =>
r.default || (r as any as typeof import('semver/functions/satisfies.js')),
(r) =>
r.default || (r as any as typeof import('semver/functions/satisfies.js'))
) // npm/node-semver#381
const currentNode = process.versions.node
const nodeRange = '>= 18.0.0'

if (!satisfies(currentNode, nodeRange)) {
console.warn(
`Current version of Node.js (\`${currentNode}\`) is unsupported and might cause issues.\n Please upgrade to a compatible version \`${nodeRange}\`.`,
`Current version of Node.js (\`${currentNode}\`) is unsupported and might cause issues.\n Please upgrade to a compatible version \`${nodeRange}\`.`
)
}
}
5 changes: 2 additions & 3 deletions packages/cli/src/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ export async function exists(path: string) {
try {
await fsp.access(path)
return true
}
catch {
} catch {
return false
}
}

export function findup<T>(
rootDir: string,
fn: (dir: string) => T | undefined,
fn: (dir: string) => T | undefined
): T | null {
let dir = rootDir
while (dir !== dirname(dir)) {
Expand Down
Loading

0 comments on commit 0bb1c8b

Please sign in to comment.