2022-04-02 00:45:20 +08:00
|
|
|
import fs from 'fs'
|
2022-04-08 14:02:50 +08:00
|
|
|
import path from 'path'
|
2022-04-02 00:45:20 +08:00
|
|
|
|
|
|
|
export const createDirIfNotExist = (dir: string) => {
|
|
|
|
if (!fs.existsSync(dir)) {
|
|
|
|
fs.mkdirSync(dir, { recursive: true })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const createFileIfNotExist = (file: string) => {
|
2022-04-08 14:02:50 +08:00
|
|
|
createDirIfNotExist(path.dirname(file))
|
2022-04-02 00:45:20 +08:00
|
|
|
if (!fs.existsSync(file)) {
|
|
|
|
fs.writeFileSync(file, '')
|
|
|
|
}
|
|
|
|
}
|
2022-05-13 01:47:55 +08:00
|
|
|
|
|
|
|
export const isDev = process.env.NODE_ENV === 'development'
|
|
|
|
export const isProd = process.env.NODE_ENV === 'production'
|
|
|
|
export const isWindows = process.platform === 'win32'
|
|
|
|
export const isMac = process.platform === 'darwin'
|
|
|
|
export const isLinux = process.platform === 'linux'
|
|
|
|
export const dirname = isDev ? process.cwd() : __dirname
|