Skip to content

Commit ccee27d

Browse files
committed
chore: wip
1 parent 33fdd8a commit ccee27d

File tree

19 files changed

+54
-31
lines changed

19 files changed

+54
-31
lines changed

storage/framework/core/cli/dts.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,22 @@ export async function generate(entryPoints: string | string[], options?: DtsOpti
9494
emitDeclarationOnly: true,
9595
noEmit: false,
9696
outDir: options?.outdir ?? './dist',
97+
rootDir: p.resolve(cwd, root),
9798
}
9899

99100
console.log('Compiler Options:', JSON.stringify(compilerOptions, null, 2))
100101

101102
const host = ts.createCompilerHost(compilerOptions)
102103

103104
const program = ts.createProgram({
104-
rootNames: parsedCommandLine.fileNames,
105+
rootNames: parsedCommandLine.fileNames.filter((file) => file.startsWith(compilerOptions.rootDir ?? 'src')),
105106
options: compilerOptions,
106107
host,
107108
})
108109

109110
const emitResult = program.emit(undefined, (fileName, data) => {
110111
if (fileName.endsWith('.d.ts') || fileName.endsWith('.d.ts.map')) {
111-
const outputPath = p.join(compilerOptions.outDir!, p.relative(p.resolve(cwd, root), fileName))
112+
const outputPath = p.join(compilerOptions.outDir ?? './dist', p.relative(p.resolve(cwd, root), fileName))
112113
const dir = p.dirname(outputPath)
113114
if (!fs.existsSync(dir)) {
114115
fs.mkdirSync(dir, { recursive: true })

storage/framework/core/cli/src/actions/install.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { installPackage as installPkg } from '@antfu/install-pkg'
2-
import type { ExecaReturnValue } from 'execa'
32

43
interface InstallPackageOptions {
54
cwd?: string

storage/framework/core/cli/src/app.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
563563
}
564564

565565
const strip = (str: string) => str.replace(ansiRegex(), '')
566-
export const note = (message = '', title = '') => {
566+
export const note = (message = '', title = ''): void => {
567567
const lines = `\n${message}\n`.split('\n')
568568
const titleLen = strip(title).length
569569
const len =
@@ -584,19 +584,25 @@ export const note = (message = '', title = '') => {
584584
)
585585
}
586586

587-
export const cancel = (message = '') => {
587+
export const cancel = (message = ''): void => {
588588
process.stdout.write(`${color.gray(S_BAR_END)} ${color.red(message)}\n\n`)
589589
}
590590

591-
export const intro = (title = '') => {
591+
export const intro = (title = ''): void => {
592592
process.stdout.write(`${color.gray(S_BAR_START)} ${title}\n`)
593593
}
594594

595-
export const outro = (message = '') => {
595+
export const outro = (message = ''): void => {
596596
process.stdout.write(`${color.gray(S_BAR)}\n${color.gray(S_BAR_END)} ${message}\n\n`)
597597
}
598598

599-
export const spinner = () => {
599+
type Spinner = {
600+
start: (msg: string) => void
601+
stop: (msg: string, code: number) => void
602+
message: (msg: string) => void
603+
}
604+
605+
export const spinner = (): Spinner => {
600606
const frames = unicode ? ['◒', '◐', '◓', '◑'] : ['•', 'o', 'O', '0']
601607
const delay = unicode ? 80 : 120
602608

@@ -669,11 +675,13 @@ export const spinner = () => {
669675
_message = msg ?? _message
670676
}
671677

672-
return {
673-
start,
674-
stop,
675-
message,
678+
const spinner = {
679+
start: start,
680+
stop: stop,
681+
message: message,
676682
}
683+
684+
return spinner
677685
}
678686

679687
// Adapted from https://github.com/chalk/ansi-regex
@@ -761,13 +769,13 @@ export type Task = {
761769
/**
762770
* Define a group of tasks to be executed
763771
*/
764-
export const tasks = async (tasks: Task[]) => {
772+
export const tasks = async (tasks: Task[]): Promise<void> => {
765773
for (const task of tasks) {
766774
if (task.enabled === false) continue
767775

768776
const s = spinner()
769777
s.start(task.title)
770778
const result = await task.task(s.message)
771-
s.stop(result || task.title)
779+
s.stop(result || task.title, 0)
772780
}
773781
}

storage/framework/core/cli/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface CliOptions {
1414
// description: string
1515
}
1616

17-
export function cli(name?: string | CliOptions, options?: CliOptions) {
17+
export function cli(name?: string | CliOptions, options?: CliOptions): CAC {
1818
if (typeof name === 'object') {
1919
options = name
2020
name = options.name

storage/framework/core/cli/src/command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ export class Command {
3737
}
3838

3939
export const command = {
40-
run: async (command: string, options?: CliOptions) => {
40+
run: async (command: string, options?: CliOptions): Promise<void> => {
4141
return await runCommand(command, options)
4242
},
4343

44-
runSync: async (command: string, options?: CliOptions) => {
44+
runSync: async (command: string, options?: CliOptions): Promise<void> => {
4545
return await runCommand(command, options)
4646
},
4747
}

storage/framework/core/cli/src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function intro(command: string, options?: IntroOptions): Promise<nu
2727
/**
2828
* Prints the outro message.
2929
*/
30-
export function outro(text: string, options?: OutroOptions, error?: Error | string) {
30+
export function outro(text: string, options?: OutroOptions, error?: Error | string): Promise<number> {
3131
const opts = {
3232
type: 'success',
3333
useSeconds: true,

storage/framework/core/cli/src/parse.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import process from 'node:process'
2-
import { log } from '@stacksjs/logging'
32

43
interface ParsedArgv {
54
args: string[]
@@ -118,9 +117,9 @@ export function parseOptions(options?: CliOptions): CliOptions {
118117
(g) => (g[1] ? g[1].toUpperCase() : ''), // convert kebab-case to camelCase
119118
)
120119

121-
if (i + 1 < args.length && !args[i + 1].startsWith('--')) {
120+
if (i + 1 < args.length && !args?.[i + 1]?.startsWith('--')) {
122121
// if the next arg exists and is not an option
123-
if (args[i + 1] === 'true' || args[i + 1] === 'false') {
122+
if (args?.[i + 1] === 'true' || args?.[i + 1] === 'false') {
124123
// if the next arg is a boolean
125124
options[camelCaseKey] = args[i + 1] === 'true' // set the value to the boolean
126125
i++
@@ -147,8 +146,8 @@ export function parseOptions(options?: CliOptions): CliOptions {
147146
// }
148147
export function buddyOptions(options?: string[] | Record<string, any>): string {
149148
if (Array.isArray(options)) {
150-
options = Array.from(new Set(options))
151-
if (options[0] && !options[0].startsWith('-')) options.shift()
149+
options = Array.from(new Set(options)) as string[]
150+
if (Array.isArray(options) && options[0] && !options[0].startsWith('-')) options.shift()
152151
return options.join(' ')
153152
}
154153

storage/framework/core/cli/src/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export async function runCommandSync(command: string, options?: CliOptions): Pro
9090
* @param options The options to pass to the command.
9191
* @returns The result of the command.
9292
*/
93-
export async function runCommands(commands: string[], options?: CliOptions) {
93+
export async function runCommands(commands: string[], options?: CliOptions): Promise<Subprocess[]> {
9494
const results = []
9595

9696
for (const command of commands) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import ora from 'ora'
22

3-
export const spinner = ora
3+
export const spinner: typeof ora = ora

storage/framework/core/cli/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export {
6363
stripColors,
6464
} from 'kolorist'
6565

66-
export const quotes = collect([
66+
export const quotes: string[] = collect([
6767
// could be queried from any API or database
6868
'The best way to get started is to quit talking and begin doing.',
6969
'The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty.',

0 commit comments

Comments
 (0)