From 8dddbab3446c12242fd9995a311d0dcede75f2ca Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 16 Aug 2016 11:00:00 +0200 Subject: [PATCH] Recreate symlinks when calling `copySync` --- script/lib/copy-sync.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/script/lib/copy-sync.js b/script/lib/copy-sync.js index c86555343..717d115ec 100644 --- a/script/lib/copy-sync.js +++ b/script/lib/copy-sync.js @@ -5,26 +5,26 @@ const path = require('path') module.exports = copySync -function copySync(src, dest, options) { - if (fs.existsSync(src)) { - options = options || {} - options.filter = options.filter || () => true - - const destFolder = path.dirname(dest) - const stat = fs.statSync(src) - - if (options.filter(src)) { - if (stat.isFile()) { - if (!fs.existsSync(destFolder)) fs.mkdirsSync(destFolder) - copyFileSync(src, dest, options) - } else if (stat.isDirectory()) { - fs.readdirSync(src).forEach(content => { - copySync(path.join(src, content), path.join(dest, content), options) - }) +function copySync(src, dest, opts) { + const options = Object.assign({filter: () => true}, opts || {}) + const stat = fs.lstatSync(src) + if (options.filter(src)) { + if (stat.isFile()) { + const destDirPath = path.dirname(dest) + if (!fs.existsSync(destDirPath)) { + fs.mkdirpSync(destDirPath) } + copyFileSync(src, dest, options) + } else if (stat.isDirectory()) { + if (!fs.existsSync(dest)) { + fs.mkdirpSync(dest) + } + fs.readdirSync(src).forEach(content => { + copySync(path.join(src, content), path.join(dest, content), options) + }) + } else if (stat.isSymbolicLink()) { + fs.symlinkSync(fs.readlinkSync(src), dest) } - } else { - console.log(`Skipping copy of "${src}" because it doesn't exist`.gray) } }