Skip to content

Commit

Permalink
build(compiler): show gulp stdout while develop & fix tscpaths not wo…
Browse files Browse the repository at this point in the history
…rking @rex-zsd (#2013)
  • Loading branch information
rex-zsd authored and chenjiahan committed Sep 10, 2019
1 parent 0e8caf5 commit 9ee8d9a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 60 deletions.
126 changes: 67 additions & 59 deletions build/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,70 +18,78 @@ const libDir = path.resolve(__dirname, '../lib');
const esDir = path.resolve(__dirname, '../dist');
const exampleDir = path.resolve(__dirname, '../example/dist');

const compileLess = dist => () =>
gulp
.src(`${src}/**/*.less`)
.pipe(less())
.pipe(postcss())
.pipe(
insert.transform((contents, file) => {
if (!file.path.includes('packages' + path.sep + 'common')) {
contents = `@import '../common/index.wxss';${contents}`;
}
return contents;
})
)
.pipe(
rename(path => {
path.extname = '.wxss';
})
)
.pipe(gulp.dest(dist));
const lessCompiler = dist =>
function compileLess() {
return gulp
.src(`${src}/**/*.less`)
.pipe(less())
.pipe(postcss())
.pipe(
insert.transform((contents, file) => {
if (!file.path.includes('packages' + path.sep + 'common')) {
contents = `@import '../common/index.wxss';${contents}`;
}
return contents;
})
)
.pipe(rename({ extname: '.wxss' }))
.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 tsCompiler = (dist, config) =>
async function compileTs() {
await exec(`npx tsc -p ${config}`);
await exec(`npx tscpaths -p ${config} -s ../packages -o ${dist}`);
};

const copy = (dist, ext) => () =>
gulp.src(`${src}/**/*.${ext}`).pipe(gulp.dest(dist));
const copier = (dist, ext) =>
function copy() {
return gulp.src(`${src}/**/*.${ext}`).pipe(gulp.dest(dist));
};

const copyStatic = dist =>
gulp.parallel(copy(dist, 'wxml'), copy(dist, 'wxs'), copy(dist, 'json'));
const staticCopier = dist =>
gulp.parallel(
copier(dist, 'wxml'),
copier(dist, 'wxs'),
copier(dist, 'json')
);

const clean = path => () => exec(`npx rimraf ${path}`);
const cleaner = path =>
function clean() {
return exec(`npx rimraf ${path}`);
};

module.exports = {
buildEs: gulp.series(
clean(esDir),
gulp.parallel(
compileTs(esConfig, esDir),
compileLess(esDir),
copyStatic(esDir)
)
),
buildLib: gulp.series(
clean(libDir),
const tasks = [
['buildEs', esDir, esConfig],
['buildLib', libDir, libConfig]
].reduce((prev, [name, ...args]) => {
prev[name] = gulp.series(
cleaner(...args),
gulp.parallel(
compileTs(libConfig, libDir),
compileLess(libDir),
copyStatic(libDir)
)
),
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}/**/*.less`, compileLess(exampleDir));
gulp.watch(`${src}/**/*.wxml`, copy(exampleDir, 'wxml'));
gulp.watch(`${src}/**/*.wxs`, copy(exampleDir, 'wxs'));
gulp.watch(`${src}/**/*.json`, copy(exampleDir, 'json'));
}
tsCompiler(...args),
lessCompiler(...args),
staticCopier(...args)
)
);
return prev;
}, {});

tasks.buildExample = gulp.series(
cleaner(exampleDir),
gulp.parallel(
tsCompiler(exampleDir, exampleConfig),
lessCompiler(exampleDir),
staticCopier(exampleDir),
() =>
gulp.src(`${icons}/**/*`).pipe(gulp.dest(`${exampleDir}/@vant/icons`)),
() => {
gulp.watch(`${src}/**/*.ts`, tsCompiler(exampleDir, exampleConfig));
gulp.watch(`${src}/**/*.less`, lessCompiler(exampleDir));
gulp.watch(`${src}/**/*.wxml`, copier(exampleDir, 'wxml'));
gulp.watch(`${src}/**/*.wxs`, copier(exampleDir, 'wxs'));
gulp.watch(`${src}/**/*.json`, copier(exampleDir, 'json'));
}
)
};
);

module.exports = tasks;
4 changes: 3 additions & 1 deletion build/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ const gulpConfig = path.resolve(__dirname, './compiler.js');

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

0 comments on commit 9ee8d9a

Please sign in to comment.