element-plus/build/utils.ts
三咲智子 0636e1e240
style: add import and stricter lint (#3440)
* style: add import lint

* chore: apply eslint rules

* chore: add stricter lint

* chore: lint all files

* auto fix

* manually fix

* restore build-indices.ts
2021-09-17 15:27:31 +08:00

50 lines
1.2 KiB
TypeScript

import path from 'path'
import os from 'os'
import { getPackagesSync } from '@lerna/project'
import chalk from 'chalk'
import { compRoot } from './paths'
export const getDeps = (pkgPath: string): string[] => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkgJson = require(pkgPath)
const { dependencies } = pkgJson
return Object.keys(dependencies)
}
export const getCpuCount = () => os.cpus().length
export const getPkgs = (): { name: string }[] => getPackagesSync()
export const getExternals = (options: { full: boolean }) => (id: string) => {
const packages: string[] = ['vue']
if (!options.full) {
const compPkg = path.resolve(compRoot, './package.json')
const monoPackages = getPkgs().map((pkg) => pkg.name)
const depPackages = getDeps(compPkg)
packages.push('@vue', ...monoPackages, ...depPackages)
}
return [...new Set(packages)].some(
(pkg) => id === pkg || id.startsWith(`${pkg}/`)
)
}
export function yellow(str: string) {
console.log(chalk.cyan(str))
}
export function green(str: string) {
console.log(chalk.green(str))
}
export function red(str: string) {
console.error(chalk.red(str))
}
export function errorAndExit(e: Error) {
red(e.message)
process.exit(1)
}