From 9c00f7ed9d748b370530782edaed829f051dc431 Mon Sep 17 00:00:00 2001 From: Alexander Marks Date: Wed, 29 Nov 2017 14:30:43 -0800 Subject: [PATCH] Asyncify gulpfile. --- gulpfile.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index ab7cac88b0..a849558a83 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -38,6 +38,10 @@ const {PolymerProject, HtmlSplitter} = require('polymer-build'); const {Transform} = require('stream'); +const {promisify} = require('util'); +const writeFile = promisify(fs.writeFile); +const readFile = promisify(fs.readFile); + class BackfillStream extends Transform { constructor(fileList) { super({objectMode: true}); @@ -260,21 +264,22 @@ gulp.task('lint', (done) => { runseq('lint-eslint', 'lint-closure', done); }); -gulp.task('generate-externs', ['clean'], () => { +gulp.task('generate-externs', ['clean'], async () => { let genClosure = require('@polymer/gen-closure-declarations').generateDeclarations; - return genClosure().then((declarations) => { - fs.writeFileSync('externs/closure-types.js', `${header}${declarations}`); - }); + const declarations = await genClosure(); + await writeFile('externs/closure-types.js', `${header}${declarations}`); }); -gulp.task('generate-typescript', () => { +gulp.task('generate-typescript', async () => { let genTs = require('@polymer/gen-typescript-declarations').generateDeclarations; - del.sync(['**/*.d.ts']); - return genTs('.', JSON.parse(fs.readFileSync('gen-tsd.json'))).then((files) => { - for (const [path, contents] of files) { - fs.writeFileSync(path, contents); - } - }); + await del(['**/*.d.ts']); + const config = JSON.parse(await readFile('gen-tsd.json')); + const files = await genTs('.', config); + const writes = []; + for (const [path, contents] of files) { + writes.push(writeFile(path, contents)); + } + await Promise.all(writes); }); gulp.task('update-version', () => {