Skip to content

Commit

Permalink
build(tokens): fix token build script (element-plus#3703)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored Sep 28, 2021
1 parent 4a4f049 commit 0cb8250
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 64 deletions.
87 changes: 38 additions & 49 deletions packages/tokens/gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,46 @@
import path from 'path'
import gulp from 'gulp'
import { src, dest, parallel, series } from 'gulp'
import ts from 'gulp-typescript'
import { buildOutput } from '../../build/utils/paths'
import { epOutput, projRoot } from '../../build/utils/paths'
import rewriter from '../../build/gulp-rewriter'

export const esm = './es'
export const cjs = './lib'
const tsProject = ts.createProject('tsconfig.json')

const inputs = [
'./*.ts',
'!./node_modules',
'!./gulpfile.ts',
'!./__tests__/*.ts',
]

function compileEsm() {
return gulp
.src(inputs)
.pipe(tsProject())
.pipe(rewriter('..'))
.pipe(gulp.dest(esm))
import { buildConfig } from '../../build/info'
import { withTaskName } from '../../build/utils/gulp'

import type { Module } from '../../build/info'

export const buildTokens = (module: Module) => {
const tsConfig = path.resolve(projRoot, 'tsconfig.json')
const inputs = [
'./*.ts',
'!./node_modules',
'!./gulpfile.ts',
'!./__tests__/*.ts',
path.resolve(projRoot, 'typings', 'vue-shim.d.ts'),
]
const config = buildConfig[module]
return withTaskName(`buildTokens:${module}`, () =>
src(inputs)
.pipe(
ts.createProject(tsConfig, {
module: config.module,
strict: false,
})()
)
.pipe(rewriter('..'))
.pipe(dest(path.resolve(__dirname, config.output.name)))
)
}

function compileCjs() {
return gulp
.src(inputs)
.pipe(
ts.createProject('tsconfig.json', {
module: 'commonjs',
})()
const copyTokens = (module: Module) => {
const config = buildConfig[module]
return withTaskName(`copyTokens:${module}`, () => {
return src(`${path.resolve(__dirname, config.output.name)}/**`).pipe(
dest(path.resolve(epOutput, config.output.name, 'tokens'))
)
.pipe(rewriter('..'))
.pipe(gulp.dest(cjs))
})
}

const distBundle = path.resolve(buildOutput, './element-plus')

/**
* copy from packages/hooks/lib to dist/hooks
*/
function copyEsm() {
return gulp
.src(`${esm}/**`)
.pipe(gulp.dest(path.resolve(distBundle, './es/tokens')))
}

function copyCjs() {
return gulp
.src(`${cjs}/**`)
.pipe(gulp.dest(path.resolve(distBundle, './lib/tokens')))
}

export const build = gulp.series(compileEsm, compileCjs, copyEsm, copyCjs)

export default build
export default parallel(
series(buildTokens('cjs'), copyTokens('cjs')),
series(buildTokens('esm'), copyTokens('esm'))
)
2 changes: 1 addition & 1 deletion packages/tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"scripts": {
"clean": "rimraf lib",
"build": "gulp build"
"build": "gulp"
},
"main": "index.ts",
"module": "index.ts",
Expand Down
11 changes: 0 additions & 11 deletions packages/tokens/tsconfig.json

This file was deleted.

3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"strict": true
"strict": true,
"skipLibCheck": true
},
"exclude": [
"node_modules",
Expand Down
4 changes: 2 additions & 2 deletions typings/vue-shim.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
declare module '*.vue' {
import { DefineComponent } from 'vue'
import type { DefineComponent } from 'vue'
// eslint-disable-next-line @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any>
export default component
}

0 comments on commit 0cb8250

Please sign in to comment.