Skip to content

Commit

Permalink
feat: add copying Flow files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vmx committed May 3, 2018
1 parent d590f4f commit 6710eb0
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/build/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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) => {
Expand All @@ -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)
})
})

Expand All @@ -91,4 +106,4 @@ const babel = (ctx) => {
})
}

module.exports = babel
module.exports = transform

0 comments on commit 6710eb0

Please sign in to comment.