chore: remove gulp-typescript (#4675)
parent
e48bc13c6a
commit
989d1d4202
|
@ -17,23 +17,22 @@ const chalk = require('chalk');
|
||||||
const getNpmArgs = require('./utils/get-npm-args');
|
const getNpmArgs = require('./utils/get-npm-args');
|
||||||
const getChangelog = require('./utils/getChangelog');
|
const getChangelog = require('./utils/getChangelog');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
// const watch = require('gulp-watch')
|
|
||||||
const ts = require('gulp-typescript');
|
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
|
const fg = require('fast-glob');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const rimraf = require('rimraf');
|
const rimraf = require('rimraf');
|
||||||
|
const { createCompilerHost, createProgram } = require('typescript');
|
||||||
const stripCode = require('gulp-strip-code');
|
const stripCode = require('gulp-strip-code');
|
||||||
const compareVersions = require('compare-versions');
|
const compareVersions = require('compare-versions');
|
||||||
const getTSCommonConfig = require('./getTSCommonConfig');
|
// const getTSCommonConfig = require('./getTSCommonConfig');
|
||||||
const replaceLib = require('./replaceLib');
|
const replaceLib = require('./replaceLib');
|
||||||
|
|
||||||
const packageJson = require(getProjectPath('package.json'));
|
const packageJson = require(getProjectPath('package.json'));
|
||||||
const tsDefaultReporter = ts.reporter.defaultReporter();
|
|
||||||
const cwd = process.cwd();
|
const cwd = process.cwd();
|
||||||
const libDir = getProjectPath('lib');
|
const libDir = getProjectPath('lib');
|
||||||
const esDir = getProjectPath('es');
|
const esDir = getProjectPath('es');
|
||||||
|
|
||||||
const tsConfig = getTSCommonConfig();
|
// const tsConfig = getTSCommonConfig();
|
||||||
|
|
||||||
function dist(done) {
|
function dist(done) {
|
||||||
rimraf.sync(path.join(cwd, 'dist'));
|
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) {
|
const createdFiles = {};
|
||||||
return stream
|
const host = createCompilerHost(options);
|
||||||
.pipe(ts(tsConfig))
|
host.writeFile = (fileName, contents) => {
|
||||||
.js.pipe(
|
createdFiles[path.isAbsolute(fileName) ? path.relative(cwd, fileName) : fileName] = contents;
|
||||||
through2.obj(function (file, encoding, next) {
|
};
|
||||||
// console.log(file.path, file.base);
|
|
||||||
file.path = file.path.replace(/\.[jt]sx$/, '.js');
|
const files = await fg(
|
||||||
this.push(file);
|
[
|
||||||
next();
|
'components/**/*.js',
|
||||||
}),
|
'components/**/*.jsx',
|
||||||
)
|
'components/**/*.tsx',
|
||||||
.pipe(gulp.dest(process.cwd()));
|
'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', () =>
|
gulp.task('tsc', () => compileTs());
|
||||||
compileTs(
|
|
||||||
gulp.src(tsFiles, {
|
|
||||||
base: cwd,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
function babelify(js, modules) {
|
function babelify(js, modules) {
|
||||||
const babelConfig = getBabelCommonConfig(modules);
|
const babelConfig = getBabelCommonConfig(modules);
|
||||||
|
@ -169,7 +190,7 @@ function compile(modules) {
|
||||||
const assets = gulp
|
const assets = gulp
|
||||||
.src(['components/**/*.@(png|svg)'])
|
.src(['components/**/*.@(png|svg)'])
|
||||||
.pipe(gulp.dest(modules === false ? esDir : libDir));
|
.pipe(gulp.dest(modules === false ? esDir : libDir));
|
||||||
let error = 0;
|
// let error = 0;
|
||||||
const source = [
|
const source = [
|
||||||
'components/**/*.js',
|
'components/**/*.js',
|
||||||
'components/**/*.jsx',
|
'components/**/*.jsx',
|
||||||
|
@ -179,27 +200,8 @@ function compile(modules) {
|
||||||
'!components/*/__tests__/*',
|
'!components/*/__tests__/*',
|
||||||
];
|
];
|
||||||
|
|
||||||
const tsResult = gulp.src(source).pipe(
|
const jsFilesStream = babelify(gulp.src(source), modules);
|
||||||
ts(tsConfig, {
|
return merge2([less, jsFilesStream, assets]);
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function tag() {
|
function tag() {
|
||||||
|
@ -329,11 +331,13 @@ function pub(done) {
|
||||||
gulp.task('compile-with-es', done => {
|
gulp.task('compile-with-es', done => {
|
||||||
console.log('[Parallel] Compile to es...');
|
console.log('[Parallel] Compile to es...');
|
||||||
compile(false).on('finish', done);
|
compile(false).on('finish', done);
|
||||||
|
compileTs(false, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('compile-with-lib', done => {
|
gulp.task('compile-with-lib', done => {
|
||||||
console.log('[Parallel] Compile to js...');
|
console.log('[Parallel] Compile to js...');
|
||||||
compile().on('finish', done);
|
compile().on('finish', done);
|
||||||
|
compileTs(true, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task(
|
gulp.task(
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
import Progress, { Line, Circle } from './src';
|
import Progress, { Line, Circle } from './src';
|
||||||
|
|
||||||
import type { ProgressProps } from './src';
|
import type { ProgressProps } from './src';
|
||||||
export { Line, Circle, ProgressProps };
|
export { Line, Circle };
|
||||||
|
|
||||||
|
export type { ProgressProps };
|
||||||
|
|
||||||
export default Progress;
|
export default Progress;
|
||||||
|
|
|
@ -2,7 +2,9 @@ import Line from './Line';
|
||||||
import Circle from './Circle';
|
import Circle from './Circle';
|
||||||
import type { ProgressProps } from './types';
|
import type { ProgressProps } from './types';
|
||||||
|
|
||||||
export { Line, Circle, ProgressProps };
|
export { Line, Circle };
|
||||||
|
|
||||||
|
export type { ProgressProps };
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Line,
|
Line,
|
||||||
|
|
|
@ -147,6 +147,7 @@
|
||||||
"eslint-plugin-no-explicit-type-exports": "^0.11.10",
|
"eslint-plugin-no-explicit-type-exports": "^0.11.10",
|
||||||
"eslint-plugin-prettier": "^3.1.0",
|
"eslint-plugin-prettier": "^3.1.0",
|
||||||
"eslint-plugin-vue": "^7.1.0",
|
"eslint-plugin-vue": "^7.1.0",
|
||||||
|
"fast-glob": "^3.2.7",
|
||||||
"fetch-jsonp": "^1.1.3",
|
"fetch-jsonp": "^1.1.3",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"glob": "^7.1.2",
|
"glob": "^7.1.2",
|
||||||
|
|
Loading…
Reference in New Issue