-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.ts
More file actions
33 lines (28 loc) · 926 Bytes
/
Copy pathadd.ts
File metadata and controls
33 lines (28 loc) · 926 Bytes
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
import {Args, Command} from '@oclif/core'
import {copyFileSync, existsSync, mkdirSync} from 'node:fs'
import {basename, join} from 'node:path'
export default class Add extends Command {
static args = {
path: Args.string({
description: '脚本文件路径',
required: true,
}),
}
static description = '添加脚本到用户配置目录'
static examples = [
'<%= config.bin %> <%= command.id %> ./script.ps1',
]
async run(): Promise<void> {
const {args} = await this.parse(Add)
const scriptPath = args.path
const scriptsDir = join(this.config.configDir, 'scripts')
if (!existsSync(scriptsDir)) {
mkdirSync(scriptsDir, {recursive: true})
}
const fileName = basename(scriptPath)
const destPath = join(scriptsDir, fileName)
copyFileSync(scriptPath, destPath)
this.log(`脚本已添加: ${fileName}`)
this.log(`保存位置: ${destPath}`)
}
}