From 6710eb0bd22254ecee0858e92ca00b8e8437b6a7 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Fri, 4 May 2018 00:46:48 +0200 Subject: [PATCH] feat: add copying Flow files In order to make the Flow types usable for the tooling, the flow files need to reside in the `lib` directory. The files are now copied when calling `aegir build`. Watching files is also supported. --- src/build/lib.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/build/lib.js b/src/build/lib.js index 9ebd4d1dc..b71ad169c 100644 --- a/src/build/lib.js +++ b/src/build/lib.js @@ -36,7 +36,7 @@ const babelConfig = { * * @returns {Promise} */ -const transform = (filename) => { +const babel = (filename) => { const src = path.join('src', filename) const dest = path.join('lib', filename) @@ -56,7 +56,21 @@ const transform = (filename) => { }) } -const babel = (ctx) => { +/** + * Copies a file from `src` to `lib` with flow extension + * + * @param {string} filename The filename relative to the `src` directory + * + * @returns {Promise} + */ +const flowCopy = (filename) => { + const src = path.join('src', filename) + const dest = path.join('lib', filename + '.flow') + + return fs.copy(src, dest) +} + +const transform = (ctx) => { const srcDir = path.join(utils.getBasePath(), 'src') return new Promise((resolve, reject) => { @@ -74,8 +88,9 @@ const babel = (ctx) => { ;['add', 'change'].forEach((type) => { watcher.on(type, (filename) => { const relative = path.relative(srcDir, filename) - console.log('Transpile file: ' + relative) - transform(relative) + console.log('Transform file: ' + relative) + babel(relative) + flowCopy(relative) }) }) @@ -91,4 +106,4 @@ const babel = (ctx) => { }) } -module.exports = babel +module.exports = transform