Skip to content

Commit

Permalink
fix(build): compatible to build on windows (element-plus#4747)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored Dec 10, 2021
1 parent fcd11d9 commit 5e76d0f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 26 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/preview-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ on: pull_request
jobs:
build:
name: Build
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false

env:
PULL_REQUEST_NUMBER: ${{ github.event.number }}

steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -39,6 +46,7 @@ jobs:

# share website dist
- name: Upload artifact
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v2
with:
name: docs
Expand All @@ -47,12 +55,12 @@ jobs:

# write pr.txt for share
- name: Save pr number
if: ${{ always() }}
if: matrix.os == 'ubuntu-latest'
run: echo ${PULL_REQUEST_NUMBER} > ./pr.txt

# share pr number
- name: Upload pr number
if: ${{ always() }}
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v2
with:
name: pr
Expand Down
39 changes: 28 additions & 11 deletions build/gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import path from 'path'
import { mkdir, copyFile } from 'fs/promises'
import { copy } from 'fs-extra'
import { series, parallel } from 'gulp'
import { run } from './utils/process'
import { withTaskName } from './utils/gulp'
import { buildOutput, epOutput, epPackage, projRoot } from './utils/paths'
import {
buildOutput,
epOutput,
epPackage,
epRoot,
projRoot,
} from './utils/paths'
import { buildConfig } from './build-info'
import type { TaskFunction } from 'gulp'
import type { Module } from './build-info'
Expand All @@ -12,34 +20,43 @@ const runTask = (name: string) =>

export const copyFiles = () => {
const copyTypings = async () => {
const src = path.resolve(projRoot, 'typings', 'global.d.ts')
await run(`cp ${src} ${epOutput}`)
await copyFile(
path.resolve(projRoot, 'typings/global.d.ts'),
path.resolve(epOutput, 'global.d.ts')
)
}

return Promise.all([
run(`cp ${epPackage} ${path.join(epOutput, 'package.json')}`),
run(`cp README.md ${epOutput}`),
copyFile(epPackage, path.join(epOutput, 'package.json')),
copyFile(
path.resolve(epRoot, 'README.md'),
path.resolve(epOutput, 'README.md')
),
copyTypings(),
])
}

export const copyTypesDefinitions: TaskFunction = (done) => {
const src = `${buildOutput}/types/`
const copy = (module: Module) =>
const src = path.resolve(buildOutput, 'types')
const copyTypes = (module: Module) =>
withTaskName(`copyTypes:${module}`, () =>
run(`rsync -a ${src} ${buildConfig[module].output.path}/`)
copy(src, buildConfig[module].output.path, { recursive: true })
)

return parallel(copy('esm'), copy('cjs'))(done)
return parallel(copyTypes('esm'), copyTypes('cjs'))(done)
}

export const copyFullStyle = async () => {
await run(`mkdir -p ${epOutput}/dist`)
await run(`cp ${epOutput}/theme-chalk/index.css ${epOutput}/dist/index.css`)
await mkdir(path.resolve(epOutput, 'dist'), { recursive: true })
await copyFile(
path.resolve(epOutput, 'theme-chalk/index.css'),
path.resolve(epOutput, 'dist/index.css')
)
}

export default series(
withTaskName('clean', () => run('pnpm run clean')),
withTaskName('createOutput', () => mkdir(epOutput, { recursive: true })),

parallel(
runTask('buildModules'),
Expand Down
9 changes: 2 additions & 7 deletions build/types-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Project } from 'ts-morph'
import glob from 'fast-glob'
import { bold } from 'chalk'

import { green, red, yellow } from './utils/log'
import { errorAndExit, green, yellow } from './utils/log'
import { buildOutput, epRoot, pkgRoot, projRoot } from './utils/paths'

import { excludeFiles, pathRewriter } from './utils/pkg'
Expand All @@ -20,16 +20,12 @@ const outDir = path.resolve(buildOutput, 'types')
export const generateTypesDefinitions = async () => {
const project = new Project({
compilerOptions: {
allowJs: true,
declaration: true,
emitDeclarationOnly: true,
noEmitOnError: false,
outDir,
baseUrl: projRoot,
paths: {
'@element-plus/*': ['packages/*'],
},
skipLibCheck: true,
},
tsConfigFilePath: TSCONFIG_PATH,
skipAddingFilesFromTsConfig: true,
Expand Down Expand Up @@ -103,8 +99,7 @@ export const generateTypesDefinitions = async () => {
const emitOutput = sourceFile.getEmitOutput()
const emitFiles = emitOutput.getOutputFiles()
if (emitFiles.length === 0) {
red(`Emit no file: ${bold(relativePath)}`)
return
errorAndExit(new Error(`Emit no file: ${bold(relativePath)}`))
}

const tasks = emitFiles.map(async (outputFile) => {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"gen": "bash ./scripts/gc.sh",
"gen:version": "sucrase-node scripts/gen-version.ts",
"update:version": "sucrase-node scripts/update-version.ts",
"clean": "pnpm run clean:lib && pnpm run clean -r --stream",
"clean:lib": "rimraf dist",
"clean": "pnpm run clean:dist && pnpm run clean -r --stream",
"clean:dist": "rimraf dist",
"build": "gulp --require sucrase/register/ts -f build/gulpfile.ts",
"build:theme": "pnpm run build -C packages/theme-chalk",
"format": "prettier --write .",
Expand Down Expand Up @@ -76,6 +76,7 @@
"@rollup/plugin-node-resolve": "13.0.6",
"@rollup/plugin-replace": "3.0.0",
"@sucrase/jest-plugin": "2.2.0",
"@types/fs-extra": "9.0.13",
"@types/gulp": "4.0.9",
"@types/jest": "27.0.2",
"@types/lodash": "4.14.178",
Expand All @@ -97,6 +98,7 @@
"eslint-plugin-vue": "8.2.0",
"expect-type": "0.13.0",
"fast-glob": "3.2.7",
"fs-extra": "10.0.0",
"gulp": "4.0.2",
"husky": "7.0.4",
"jest": "26.6.3",
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"compilerOptions": {
"allowJs": true,
"strict": true,
"module": "ES6",
"target": "ES6",
"target": "ES2018",
"noImplicitAny": false,
"declaration": true,
"moduleResolution": "Node",
Expand All @@ -12,8 +13,7 @@
"lib": ["ES2018", "DOM"],
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true
"resolveJsonModule": true
},
"include": ["packages"],
"exclude": ["node_modules", "**/__test?__", "**/dist"]
Expand Down

0 comments on commit 5e76d0f

Please sign in to comment.