build(compiler): show gulp stdout while develop & fix tscpaths not working @rex-zsd (#2013)

This commit is contained in:
rex 2019-09-10 17:06:27 +08:00 committed by 陈嘉涵
parent 0e8caf56c4
commit 9ee8d9a895
2 changed files with 70 additions and 60 deletions

View File

@ -18,8 +18,9 @@ const libDir = path.resolve(__dirname, '../lib');
const esDir = path.resolve(__dirname, '../dist'); const esDir = path.resolve(__dirname, '../dist');
const exampleDir = path.resolve(__dirname, '../example/dist'); const exampleDir = path.resolve(__dirname, '../example/dist');
const compileLess = dist => () => const lessCompiler = dist =>
gulp function compileLess() {
return gulp
.src(`${src}/**/*.less`) .src(`${src}/**/*.less`)
.pipe(less()) .pipe(less())
.pipe(postcss()) .pipe(postcss())
@ -31,57 +32,64 @@ const compileLess = dist => () =>
return contents; return contents;
}) })
) )
.pipe( .pipe(rename({ extname: '.wxss' }))
rename(path => {
path.extname = '.wxss';
})
)
.pipe(gulp.dest(dist)); .pipe(gulp.dest(dist));
const compileTs = (config, dest) => async () => {
await exec(`npx tsc -p ${config}`);
await exec(`npx tscpaths -p ${config} -s ../packages -o ../${dest}`);
}; };
const copy = (dist, ext) => () => const tsCompiler = (dist, config) =>
gulp.src(`${src}/**/*.${ext}`).pipe(gulp.dest(dist)); async function compileTs() {
await exec(`npx tsc -p ${config}`);
await exec(`npx tscpaths -p ${config} -s ../packages -o ${dist}`);
};
const copyStatic = dist => const copier = (dist, ext) =>
gulp.parallel(copy(dist, 'wxml'), copy(dist, 'wxs'), copy(dist, 'json')); function copy() {
return gulp.src(`${src}/**/*.${ext}`).pipe(gulp.dest(dist));
};
const clean = path => () => exec(`npx rimraf ${path}`); const staticCopier = dist =>
module.exports = {
buildEs: gulp.series(
clean(esDir),
gulp.parallel( gulp.parallel(
compileTs(esConfig, esDir), copier(dist, 'wxml'),
compileLess(esDir), copier(dist, 'wxs'),
copyStatic(esDir) copier(dist, 'json')
);
const cleaner = path =>
function clean() {
return exec(`npx rimraf ${path}`);
};
const tasks = [
['buildEs', esDir, esConfig],
['buildLib', libDir, libConfig]
].reduce((prev, [name, ...args]) => {
prev[name] = gulp.series(
cleaner(...args),
gulp.parallel(
tsCompiler(...args),
lessCompiler(...args),
staticCopier(...args)
) )
), );
buildLib: gulp.series( return prev;
clean(libDir), }, {});
tasks.buildExample = gulp.series(
cleaner(exampleDir),
gulp.parallel( gulp.parallel(
compileTs(libConfig, libDir), tsCompiler(exampleDir, exampleConfig),
compileLess(libDir), lessCompiler(exampleDir),
copyStatic(libDir) staticCopier(exampleDir),
) () =>
), gulp.src(`${icons}/**/*`).pipe(gulp.dest(`${exampleDir}/@vant/icons`)),
buildExample: gulp.series(
clean(exampleDir),
gulp.parallel(
compileTs(exampleConfig, exampleDir),
compileLess(exampleDir),
copyStatic(exampleDir),
() => gulp.src(`${icons}/**/*`).pipe(gulp.dest(`${exampleDir}/@vant/icons`)),
() => { () => {
gulp.watch(`${src}/**/*.ts`, compileTs(exampleConfig, exampleDir)); gulp.watch(`${src}/**/*.ts`, tsCompiler(exampleDir, exampleConfig));
gulp.watch(`${src}/**/*.less`, compileLess(exampleDir)); gulp.watch(`${src}/**/*.less`, lessCompiler(exampleDir));
gulp.watch(`${src}/**/*.wxml`, copy(exampleDir, 'wxml')); gulp.watch(`${src}/**/*.wxml`, copier(exampleDir, 'wxml'));
gulp.watch(`${src}/**/*.wxs`, copy(exampleDir, 'wxs')); gulp.watch(`${src}/**/*.wxs`, copier(exampleDir, 'wxs'));
gulp.watch(`${src}/**/*.json`, copy(exampleDir, 'json')); gulp.watch(`${src}/**/*.json`, copier(exampleDir, 'json'));
} }
) )
) );
};
module.exports = tasks;

View File

@ -7,4 +7,6 @@ const gulpConfig = path.resolve(__dirname, './compiler.js');
serve({}, { config }); serve({}, { config });
exec(`npx gulp -f ${gulpConfig} buildExample`); const p = exec(`npx gulp -f ${gulpConfig} buildExample --color`);
p.stdout.on('data', stdout => console.info(stdout));
p.stderr.on('data', stderr => console.info(stderr));