-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathutils.ts
80 lines (70 loc) · 2.21 KB
/
utils.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
import { appVersion } from './constant'
import chalk from "chalk"
import figlet from "figlet"
import shelljs from "shelljs"
import osSys from 'os'
export function welcomeMessage() {
console.log(
chalk.white(
" " + figlet.textSync("sepack", {
font: "Colossal",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
})
)
)
console.log(
chalk.green(
" " + figlet.textSync("android", {
font: "Colossal",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: false,
})
)
)
console.log(chalk.green(" -------------------------------"))
console.log(
" " + chalk.green(appVersion) + " | " + "by github.com/" + chalk.redBright("utsmannn")
)
console.log(chalk.green(" -------------------------------"))
}
export function errorLine(error: string) {
console.log(chalk.red(`!! Error: ${error}`))
}
export function outLog(param: string, value: string) {
console.log(
chalk.blueBright(`> ${param}: `) + chalk.white(value)
)
}
export function folderNameOf(projectName: string): string {
return projectName.trim()
.split(" ")
.join("-")
.toLowerCase()
}
export function slash(path: string) {
const isExtendedLengthPath = /^\\\\\?\\/.test(path)
const hasNonAscii = /[^\u0000-\u0080]+/.test(path)
if (isExtendedLengthPath || hasNonAscii) {
return path;
}
return path.replace(/\\/g, '/')
}
export async function sdkPath(): Promise<string> {
return new Promise(resolve => {
shelljs.exec('whoami', { silent: true, async: true }, (code, stdout, stderr) => {
const user = stdout.split("\\").reverse()[0].trim()
const unixSdk = `/Users/${user}/Library/Android/sdk`
const winSdk = `C:/Users/${user}/AppData/Local/Android/Sdk`
if (osSys.type() == 'Windows_NT') {
resolve(slash(winSdk))
} else {
resolve(unixSdk)
}
})
})
}