From 7ac759f4c793ea65a8f87973b5348ef3b01e5ce1 Mon Sep 17 00:00:00 2001 From: vagusX Date: Thu, 23 Jul 2020 15:11:07 +0800 Subject: [PATCH] fix: missing ensure-dir --- scripts/generate.js | 46 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/scripts/generate.js b/scripts/generate.js index f90c5fb..d6ec7ed 100644 --- a/scripts/generate.js +++ b/scripts/generate.js @@ -153,26 +153,32 @@ class Extension { } async function generate() { - await fse.emptyDir(targetDir) - - // copy `loader.js` - await fse.copyFile( - path.resolve(__dirname, './loaders/loader.js'), - path.resolve(targetDir, './loader.js') - ) - - // copy `loader-es.js` - await fse.copyFile( - path.resolve(__dirname, './loaders/loader-es.js'), - path.resolve(targetEsDir, './loader.js') - ) - - const extensionNames = await promisify(fs.readdir)(extensionsDir) - for (const extName of extensionNames) { - // read extension package.json - const extPath = path.resolve(extensionsDir, extName) - const extension = new Extension(extPath) - await extension.run() + try { + for (const dir of [targetDir, targetEsDir]) { + await fse.emptyDir(dir) + } + // copy `loader.js` + await fse.copyFile( + path.resolve(__dirname, './loaders/loader.js'), + path.resolve(targetDir, './loader.js') + ) + + // copy `loader-es.js` + await fse.copyFile( + path.resolve(__dirname, './loaders/loader-es.js'), + path.resolve(targetEsDir, './loader.js') + ) + + const extensionNames = await promisify(fs.readdir)(extensionsDir) + for (const extName of extensionNames) { + // read extension package.json + const extPath = path.resolve(extensionsDir, extName) + const extension = new Extension(extPath) + await extension.run() + } + } catch (err) { + console.log(err) + process.exit(128) } }