Skip to content

Commit

Permalink
chore: remove gulp-typescript (#4675)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amour1688 authored Sep 21, 2021
1 parent e48bc13 commit 989d1d4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 49 deletions.
98 changes: 51 additions & 47 deletions antd-tools/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@ const chalk = require('chalk');
const getNpmArgs = require('./utils/get-npm-args');
const getChangelog = require('./utils/getChangelog');
const path = require('path');
// const watch = require('gulp-watch')
const ts = require('gulp-typescript');
const gulp = require('gulp');
const fg = require('fast-glob');
const fs = require('fs');
const rimraf = require('rimraf');
const { createCompilerHost, createProgram } = require('typescript');
const stripCode = require('gulp-strip-code');
const compareVersions = require('compare-versions');
const getTSCommonConfig = require('./getTSCommonConfig');
// const getTSCommonConfig = require('./getTSCommonConfig');
const replaceLib = require('./replaceLib');

const packageJson = require(getProjectPath('package.json'));
const tsDefaultReporter = ts.reporter.defaultReporter();
const cwd = process.cwd();
const libDir = getProjectPath('lib');
const esDir = getProjectPath('es');

const tsConfig = getTSCommonConfig();
// const tsConfig = getTSCommonConfig();

function dist(done) {
rimraf.sync(path.join(cwd, 'dist'));
Expand Down Expand Up @@ -72,29 +71,51 @@ function dist(done) {
});
}

const tsFiles = ['**/*.ts', '**/*.tsx', '!node_modules/**/*.*', 'typings/**/*.d.ts'];
async function compileTs(modules = false, cb) {
const options = {
allowJs: true,
declaration: true,
emitDeclarationOnly: true,
};

function compileTs(stream) {
return stream
.pipe(ts(tsConfig))
.js.pipe(
through2.obj(function (file, encoding, next) {
// console.log(file.path, file.base);
file.path = file.path.replace(/\.[jt]sx$/, '.js');
this.push(file);
next();
}),
)
.pipe(gulp.dest(process.cwd()));
const createdFiles = {};
const host = createCompilerHost(options);
host.writeFile = (fileName, contents) => {
createdFiles[path.isAbsolute(fileName) ? path.relative(cwd, fileName) : fileName] = contents;
};

const files = await fg(
[
'components/**/*.js',
'components/**/*.jsx',
'components/**/*.tsx',
'components/**/*.ts',
'!components/*/__tests__/*',
'!components/*/style/*',
'!components/styles.ts',
],
{ cwd },
);

const program = createProgram(files, options, host);
program.emit();

Object.keys(createdFiles).forEach(fileName => {
const contents = createdFiles[fileName];
const filePath = path.join(
cwd,
fileName.replace(/^components/, modules === false ? 'es' : 'lib'),
);
const dir = path.dirname(filePath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
fs.writeFileSync(filePath, contents);
});
cb(0);
}

gulp.task('tsc', () =>
compileTs(
gulp.src(tsFiles, {
base: cwd,
}),
),
);
gulp.task('tsc', () => compileTs());

function babelify(js, modules) {
const babelConfig = getBabelCommonConfig(modules);
Expand Down Expand Up @@ -169,7 +190,7 @@ function compile(modules) {
const assets = gulp
.src(['components/**/*.@(png|svg)'])
.pipe(gulp.dest(modules === false ? esDir : libDir));
let error = 0;
// let error = 0;
const source = [
'components/**/*.js',
'components/**/*.jsx',
Expand All @@ -179,27 +200,8 @@ function compile(modules) {
'!components/*/__tests__/*',
];

const tsResult = gulp.src(source).pipe(
ts(tsConfig, {
error(e) {
tsDefaultReporter.error(e);
error = 1;
},
finish: tsDefaultReporter.finish,
}),
);

function check() {
if (error && !argv['ignore-error']) {
process.exit(1);
}
}

tsResult.on('finish', check);
tsResult.on('end', check);
const tsFilesStream = babelify(tsResult.js, modules);
const tsd = tsResult.dts.pipe(gulp.dest(modules === false ? esDir : libDir));
return merge2([less, tsFilesStream, tsd, assets]);
const jsFilesStream = babelify(gulp.src(source), modules);
return merge2([less, jsFilesStream, assets]);
}

function tag() {
Expand Down Expand Up @@ -329,11 +331,13 @@ function pub(done) {
gulp.task('compile-with-es', done => {
console.log('[Parallel] Compile to es...');
compile(false).on('finish', done);
compileTs(false, done);
});

gulp.task('compile-with-lib', done => {
console.log('[Parallel] Compile to js...');
compile().on('finish', done);
compileTs(true, done);
});

gulp.task(
Expand Down
4 changes: 3 additions & 1 deletion components/vc-progress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import Progress, { Line, Circle } from './src';

import type { ProgressProps } from './src';
export { Line, Circle, ProgressProps };
export { Line, Circle };

export type { ProgressProps };

export default Progress;
4 changes: 3 additions & 1 deletion components/vc-progress/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import Line from './Line';
import Circle from './Circle';
import type { ProgressProps } from './types';

export { Line, Circle, ProgressProps };
export { Line, Circle };

export type { ProgressProps };

export default {
Line,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"eslint-plugin-no-explicit-type-exports": "^0.11.10",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-vue": "^7.1.0",
"fast-glob": "^3.2.7",
"fetch-jsonp": "^1.1.3",
"fs-extra": "^10.0.0",
"glob": "^7.1.2",
Expand Down

0 comments on commit 989d1d4

Please sign in to comment.