chore: remove gulp-typescript (#4675)

v2.3
Amour1688 2021-09-21 10:32:17 +08:00 committed by GitHub
parent e48bc13c6a
commit 989d1d4202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 49 deletions

View File

@ -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'));
@ -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);
@ -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',
@ -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() {
@ -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(

View File

@ -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;

View File

@ -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,

View File

@ -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",