utils.ts 1.0 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import path from 'path'
fxy060608's avatar
fxy060608 已提交
2
import { BuildOptions } from 'vite'
fxy060608's avatar
fxy060608 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import { CliOptions } from '.'

export const PLATFORMS = [
  'app',
  'h5',
  'mp-alipay',
  'mp-baidu',
  'mp-qq',
  'mp-toutiao',
  'mp-weixin',
  'quickapp-webview-huawei',
  'quickapp-webview-union',
]

export function initEnv(options: CliOptions) {
fxy060608's avatar
fxy060608 已提交
18 19
  process.env.UNI_CLI_CONTEXT = process.cwd() // TODO HBuilderX

fxy060608's avatar
fxy060608 已提交
20
  process.env.VITE_ROOT_DIR = process.env.UNI_INPUT_DIR || process.cwd()
fxy060608's avatar
fxy060608 已提交
21

fxy060608's avatar
fxy060608 已提交
22 23 24
  process.env.UNI_INPUT_DIR =
    process.env.UNI_INPUT_DIR || path.resolve(process.cwd(), 'src')

fxy060608's avatar
fxy060608 已提交
25 26 27 28 29
  process.env.UNI_OUTPUT_DIR =
    (options as BuildOptions).outDir ||
    process.env.UNI_OUTPUT_DIR ||
    path.resolve(process.cwd(), 'dist')

fxy060608's avatar
fxy060608 已提交
30 31
  process.env.UNI_PLATFORM = options.platform as UniApp.PLATFORM
}
fxy060608's avatar
fxy060608 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

export function cleanOptions(options: CliOptions) {
  const ret = { ...options }
  delete ret['--']

  delete ret.platform
  delete ret.p
  delete ret.ssr

  delete ret.debug
  delete ret.d
  delete ret.filter
  delete ret.f
  delete ret.logLevel
  delete ret.l
  delete ret.clearScreen
  return ret
}