forked from InhiblabCore/vue-hooks-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilts.ts
93 lines (85 loc) · 2.18 KB
/
utilts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { existsSync, readdirSync, statSync } from 'fs-extra'
import { resolve } from 'node:path'
import { bgYellow, bgCyan, bgGreen, bgRed, yellow, cyan, green, red } from 'kolorist'
import { Config } from 'prettier'
import { execa } from 'execa'
import type { Options } from 'execa'
export const prettierConfig: Config = {
printWidth: 100,
arrowParens: 'avoid',
bracketSpacing: true,
endOfLine: 'lf',
bracketSameLine: false,
quoteProps: 'as-needed',
semi: false,
singleQuote: true,
tabWidth: 2,
trailingComma: 'none',
useTabs: false,
vueIndentScriptAndStyle: false,
overrides: [
{
files: '*.md',
options: {
embeddedLanguageFormatting: 'off',
},
},
],
}
export const rootDir = resolve(__dirname, '..')
export const hooksRootDir = resolve(rootDir, 'packages/hooks')
export const hooksDir = resolve(hooksRootDir, 'src')
export const hooks = readdirSync(hooksDir).filter(f => {
const path = resolve(hooksDir, f)
if (!statSync(path).isDirectory()) {
return false
}
return existsSync(`${path}/index.ts`)
})
type LogFn = () => void
export const logger = {
ln: () => console.log(),
withStartLn: (log: LogFn) => {
logger.ln()
log()
},
withEndLn: (log: LogFn) => {
log()
logger.ln()
},
withBothLn: (log: LogFn) => {
logger.ln()
log()
logger.ln()
},
warning: (msg: string) => {
console.warn(`${bgYellow(' WARNING ')} ${yellow(msg)}`)
},
info: (msg: string) => {
console.log(`${bgCyan(' INFO ')} ${cyan(msg)}`)
},
success: (msg: string) => {
console.log(`${bgGreen(' SUCCESS ')} ${green(msg)}`)
},
error: (msg: string) => {
console.error(`${bgRed(' ERROR ')} ${red(msg)}`)
},
warningText: (msg: string) => {
console.warn(`${yellow(msg)}`)
},
infoText: (msg: string) => {
console.log(`${cyan(msg)}`)
},
successText: (msg: string) => {
console.log(`${green(msg)}`)
},
errorText: (msg: string) => {
console.error(`${red(msg)}`)
},
}
export function bin(name: string) {
return resolve(rootDir, 'node_modules/.bin/' + name)
}
export async function run(bin: string, args: string[], opts: Options = {}) {
return execa(bin, args, { stdio: 'inherit', ...opts })
}