Skip to content

Commit

Permalink
build: ensure Vite build effective
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Oct 31, 2023
1 parent c5fa815 commit d0c919d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 282 deletions.
2 changes: 1 addition & 1 deletion scripts/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { format } from 'prettier'
import { ESLint } from 'eslint'
import { logger } from '@vexip-ui/scripts'
import { runParallel, toCapitalCase } from '@vexip-ui/utils'
import { components as allComponents, componentsDir, prettierConfig, rootDir } from './utils'
import { components as allComponents, componentsDir, prettierConfig, rootDir } from './constant'

async function main() {
const plugins = ['confirm', 'contextmenu', 'loading', 'message', 'notice', 'toast']
Expand Down
42 changes: 42 additions & 0 deletions scripts/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { resolve } from 'node:path'
import { existsSync, readdirSync, statSync } from 'node:fs'
import { fileURLToPath } from 'node:url'

import type { Config } from 'prettier'

export const rootDir = resolve(fileURLToPath(import.meta.url), '../..')

export const prettierConfig: Config = {
printWidth: 100,
arrowParens: 'avoid',
bracketSpacing: true,
endOfLine: 'lf',
bracketSameLine: false,
quoteProps: 'as-needed',
semi: false,
singleQuote: true,
tabWidth: 2,
trailingComma: 'none',
useTabs: false,
vueIndentScriptAndStyle: false,
overrides: [
{
files: '*.md',
options: {
embeddedLanguageFormatting: 'off'
}
}
]
}

export const componentsDir = resolve(rootDir, 'components')

export const components = readdirSync(componentsDir).filter(f => {
const path = resolve(componentsDir, f)

if (!statSync(path).isDirectory()) {
return false
}

return existsSync(`${path}/index.ts`)
})
2 changes: 1 addition & 1 deletion scripts/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import minimist from 'minimist'
import prompts from 'prompts'
import { logger } from '@vexip-ui/scripts'
import { toCamelCase, toCapitalCase, toKebabCase } from '@vexip-ui/utils'
import { components as allComponents, prettierConfig, rootDir } from './utils'
import { components as allComponents, prettierConfig, rootDir } from './constant'
import pkg from '../package.json'

const args = minimist(process.argv.slice(2))
Expand Down
2 changes: 1 addition & 1 deletion scripts/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { format } from 'prettier'
import { ESLint } from 'eslint'
import { logger } from '@vexip-ui/scripts'
import { runParallel, toCamelCase, toCapitalCase } from '@vexip-ui/utils'
import { components, componentsDir, prettierConfig } from './utils'
import { components, componentsDir, prettierConfig } from './constant'

async function main() {
const ignores = ['config-provider', 'typography']
Expand Down
3 changes: 2 additions & 1 deletion scripts/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { resolve } from 'node:path'

import minimist from 'minimist'
import { logger, publish } from '@vexip-ui/scripts'
import { getPackageName, rootDir } from './utils'
import { rootDir } from './constant'
import { getPackageName } from './utils'

const args = minimist<{
d?: boolean,
Expand Down
3 changes: 2 additions & 1 deletion scripts/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { existsSync, readdirSync, statSync, writeFileSync } from 'node:fs'
import minimist from 'minimist'
import { format } from 'prettier'
import { logger, queryIdlePort, run } from '@vexip-ui/scripts'
import { prettierConfig, rootDir, specifyComponent } from './utils'
import { prettierConfig, rootDir } from './constant'
import { specifyComponent } from './utils'

const args = minimist<{
s?: boolean,
Expand Down
275 changes: 1 addition & 274 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,173 +1,15 @@
import { resolve } from 'node:path'
import {
existsSync,
// lstatSync,
// readFileSync,
readdirSync,
// rmdirSync,
statSync
// unlinkSync
} from 'node:fs'
import { fileURLToPath } from 'node:url'
// import { createServer } from 'node:net'

// import { execa } from 'execa'
// import { bgCyan, bgGreen, bgRed, bgYellow, cyan, green, lightBlue, red, yellow } from 'kolorist'
import prompts from 'prompts'
import { fuzzyMatch, getPkgInfo, logger, specifyFromList } from '@vexip-ui/scripts'
import { components, rootDir } from './constant'

// import type { Options } from 'execa'
import type { ParsedArgs } from 'minimist'
import type { Config } from 'prettier'

export const rootDir = resolve(fileURLToPath(import.meta.url), '../..')

export const prettierConfig: Config = {
printWidth: 100,
arrowParens: 'avoid',
bracketSpacing: true,
endOfLine: 'lf',
bracketSameLine: false,
quoteProps: 'as-needed',
semi: false,
singleQuote: true,
tabWidth: 2,
trailingComma: 'none',
useTabs: false,
vueIndentScriptAndStyle: false,
overrides: [
{
files: '*.md',
options: {
embeddedLanguageFormatting: 'off'
}
}
]
}

// type LogFn = () => void

// export const logger = {
// ln: () => console.log(),
// withStartLn: (log: LogFn) => {
// logger.ln()
// log()
// },
// withEndLn: (log: LogFn) => {
// log()
// logger.ln()
// },
// withBothLn: (log: LogFn) => {
// logger.ln()
// log()
// logger.ln()
// },
// warning: (msg: string) => {
// console.warn(`${bgYellow(' WARNING ')} ${yellow(msg)}`)
// },
// info: (msg: string) => {
// console.log(`${bgCyan(' INFO ')} ${cyan(msg)}`)
// },
// success: (msg: string) => {
// console.log(`${bgGreen(' SUCCESS ')} ${green(msg)}`)
// },
// error: (msg: string) => {
// console.error(`${bgRed(' ERROR ')} ${red(msg)}`)
// },
// warningText: (msg: string) => {
// console.warn(`${yellow(msg)}`)
// },
// infoText: (msg: string) => {
// console.log(`${cyan(msg)}`)
// },
// successText: (msg: string) => {
// console.log(`${green(msg)}`)
// },
// errorText: (msg: string) => {
// console.error(`${red(msg)}`)
// }
// }

export function bin(name: string) {
return resolve(rootDir, 'node_modules/.bin/' + name)
}

// export async function run(bin: string, args: string[], opts: Options = {}) {
// return execa(bin, args, { stdio: 'inherit', ...opts })
// }

// export async function dryRun(bin: string, args: string[], opts: Options = {}) {
// console.log(lightBlue(`[dryrun] ${bin} ${args.join(' ')}`), opts)
// }

// function allCapital(value: string) {
// const matched = value.match(/[A-Z]+/)

// return matched && matched[0] === value
// }

// // 短横线命名
// export function toKebabCase(value: string) {
// if (allCapital(value)) {
// return value.toLocaleLowerCase()
// }

// return (
// value.charAt(0).toLowerCase() +
// value
// .slice(1)
// .replace(/([A-Z])/g, '-$1')
// .toLowerCase()
// )
// }

// 全大写命名
// export function toCapitalCase(value: string) {
// return (
// value.charAt(0).toUpperCase() +
// value.slice(1).replace(/-([a-z])/g, (_, char) => (char ? char.toUpperCase() : ''))
// )
// }

// // 驼峰命名
// export function toCamelCase(value: string) {
// const capitalName = toCapitalCase(value)

// if (allCapital(capitalName)) {
// return capitalName.toLocaleLowerCase()
// }

// return capitalName.charAt(0).toLowerCase() + capitalName.slice(1)
// }

export const componentsDir = resolve(rootDir, 'components')

export const components = readdirSync(componentsDir).filter(f => {
const path = resolve(componentsDir, f)

if (!statSync(path).isDirectory()) {
return false
}

return existsSync(`${path}/index.ts`)
})

// export function fuzzyMatch(partials: string[], total: string[], includeAll = false) {
// const matched: string[] = []

// partials.forEach(partial => {
// for (const target of total) {
// if (target.match(partial)) {
// matched.push(target)

// if (!includeAll) break
// }
// }
// })

// return matched
// }

export function fuzzyMatchComponent(
partialComponents: string[],
includeAll = false,
Expand All @@ -193,84 +35,8 @@ export async function specifyComponent(
message: 'Select a component:',
errorMessage: 'Component must be specified.'
})
// const matchedComponents = args._.length ? fuzzyMatchComponent(args._, true, allComponents) : ['']

// let component: string

// if (matchedComponents.length > 1 || !matchedComponents[0]) {
// component = (
// await prompts({
// type: 'autocomplete',
// name: 'component',
// message: 'Select a component:',
// choices: (matchedComponents.length > 1 ? matchedComponents : allComponents).map(name => ({
// title: name,
// value: name
// })),
// onState(this: any) {
// this.fallback = { title: this.input, value: this.input }
// if (this.suggestions.length === 0) {
// this.value = this.fallback.value
// }
// }
// })
// ).component
// } else {
// component = matchedComponents[0] || ''
// }

// if (!component && required) {
// logger.withStartLn(() => logger.error('Component must be specified.'))
// process.exit(1)
// }

// return component
}

// export async function runParallel<T>(
// maxConcurrency: number,
// source: T[],
// iteratorFn: (item: T, source: T[]) => Promise<any>
// ) {
// const ret: Array<Promise<any>> = []
// const executing: Array<Promise<any>> = []

// for (const item of source) {
// const p = Promise.resolve().then(() => iteratorFn(item, source))

// ret.push(p)

// if (maxConcurrency <= source.length) {
// const e: Promise<any> = p.then(() => executing.splice(executing.indexOf(e), 1))

// executing.push(e)

// if (executing.length >= maxConcurrency) {
// await Promise.race(executing)
// }
// }
// }

// return Promise.all(ret)
// }

// export function emptyDir(dir: string) {
// if (!existsSync(dir)) {
// return
// }

// for (const file of readdirSync(dir)) {
// const abs = resolve(dir, file)

// if (lstatSync(abs).isDirectory()) {
// emptyDir(abs)
// rmdirSync(abs)
// } else {
// unlinkSync(abs)
// }
// }
// }

const packages = [
'vexip-ui',
'common/bem-helper',
Expand Down Expand Up @@ -320,15 +86,6 @@ export async function getPackageInfo(inputPkg: string) {

const info = getPkgInfo(pkgDir, true)

// const pkgPath = resolve(pkgDir, 'package.json')

// if (!existsSync(pkgPath)) {
// throw new Error(`Release package ${pkgName} not found`)
// }

// const rawPkg = readFileSync(pkgPath, 'utf-8')
// const pkg = JSON.parse(rawPkg)

if (info.pkg.private) {
throw new Error(`Release package ${pkgName} is private`)
}
Expand All @@ -340,33 +97,3 @@ export async function getPackageInfo(inputPkg: string) {
currentVersion: info.pkg.version || '0.0.0'
}
}

// export function queryIdlePort(startPort: number, host = 'localhost', maxTry = 20) {
// const server = createServer()

// return new Promise<number>((resolve, reject) => {
// const close = () => {
// server.off('error', onError)
// server.close()
// }

// const onError = (error: Error & { code?: string }) => {
// if (error.code === 'EADDRINUSE') {
// if (maxTry-- <= 0) {
// close()
// }

// server.listen(++startPort, host)
// } else {
// close()
// reject(error)
// }
// }

// server.on('error', onError)
// server.listen(startPort, host, () => {
// close()
// resolve(startPort)
// })
// })
// }
Loading

0 comments on commit d0c919d

Please sign in to comment.