Skip to content

Commit

Permalink
fix: fix fig dir check
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Jun 5, 2024
1 parent c4ac029 commit 268b70d
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/commands/cli/fig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { clText, clUtil } from "@commercelayer/cli-core"
import { clColor, clText, clUtil } from "@commercelayer/cli-core"
import { Command, Flags, ux as cliux } from "@oclif/core"
import { writeFileSync } from "node:fs"
import { writeFileSync, existsSync } from "node:fs"
import { join } from "node:path"
import { format } from 'prettier'
import { homedir } from 'node:os'


const FIG_SPECS_DIR = '/Users/pierlu/Documents/GitHub/fig-autocomplete/src'
const FIG_SPECS_DIR = `${homedir()}/Documents/GitHub/fig-autocomplete/src`
const SPEC_NAME = 'commercelayer'

const processedCommands: string[] = []
Expand Down Expand Up @@ -74,8 +75,16 @@ function getFigOptions(options: Command.Flag.Cached[]): Fig.Option[] {



function description(desc?: string): string | undefined {
function description(desc?: string | string[]): string | undefined {

if (!desc) return desc
let d = desc

if (Array.isArray(d)) {
if (d.length > 0) d = d[0]
else d = ''
}

if (d) {
if (d.length > 80) {
d = d.substring(0, d.indexOf('.')+1)
Expand All @@ -86,7 +95,9 @@ function description(desc?: string): string | undefined {
if (d.endsWith('.')) d = d.substring(0, d.length - 1)
d = d.trim()
}

return d

}


Expand Down Expand Up @@ -234,7 +245,8 @@ export default class CliFig extends Command {
install: Flags.boolean({
char: 'i',
description: 'copy into Fig specs directory',
exclusive: ['dir']
exclusive: ['dir'],
hidden: true
}),
blind: Flags.boolean({
char: 'b',
Expand Down Expand Up @@ -267,6 +279,8 @@ export default class CliFig extends Command {
if (flags.dir) fileDir = clUtil.specialFolder(flags.dir)
else if (flags.install) fileDir = FIG_SPECS_DIR

if (!existsSync(fileDir)) this.error(`Folder does not exists: ${clColor.msg.error(fileDir)}`)

const filePath = join(fileDir, fileName)
cliux.action.start(`Generating spec file ${filePath}`)
writeFileSync(filePath, template, { encoding: 'utf8', flag: 'w' })
Expand Down

0 comments on commit 268b70d

Please sign in to comment.