From f1f578436b83c21ca1d23497b5b320ade5cbf3d6 Mon Sep 17 00:00:00 2001 From: Alfonso Presa Date: Sat, 4 Jul 2015 10:07:19 +0200 Subject: [PATCH] feat(build): Allow building in windows without admin priviledges Closes #2873 --- DEVELOPER.md | 3 +++ tools/broccoli/broccoli-replace.ts | 6 +++++- tools/build/linknodemodules.js | 26 ++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index e8691edf8a..4f042909e4 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -181,6 +181,9 @@ Karma is run against the new output. much easier to debug. `xit` and `xdescribe` can also be useful to exclude a test and a group of tests respectively. +**Note**: **watch mode** needs symlinks to work, so if you're using windows, ensure you have the +rights to built them in your operating system. + ### E2E tests 1. `$(npm bin)/gulp build.js.cjs` (builds benchpress and tests into `dist/js/cjs` folder). diff --git a/tools/broccoli/broccoli-replace.ts b/tools/broccoli/broccoli-replace.ts index b190b52d89..7583dd5b3b 100644 --- a/tools/broccoli/broccoli-replace.ts +++ b/tools/broccoli/broccoli-replace.ts @@ -41,7 +41,11 @@ class DiffingReplace implements DiffingBroccoliPlugin { }); fs.writeFileSync(destFilePath, content, FILE_ENCODING); } else if (!fs.existsSync(destFilePath)) { - fs.symlinkSync(sourceFilePath, destFilePath); + try { + fs.symlinkSync(sourceFilePath, destFilePath); + } catch (e) { + fs.writeFileSync(destFilePath, fs.readFileSync(sourceFilePath)); + } } }); diff --git a/tools/build/linknodemodules.js b/tools/build/linknodemodules.js index acdc3b3430..8b76c9477f 100644 --- a/tools/build/linknodemodules.js +++ b/tools/build/linknodemodules.js @@ -15,12 +15,34 @@ module.exports = function(gulp, plugins, config) { var linkDir = path.join(nodeModulesDir, relativeFolder); if (!fs.existsSync(linkDir)) { console.log('creating link', linkDir, sourceDir); - fs.symlinkSync(sourceDir, linkDir, 'dir'); + try { + fs.symlinkSync(sourceDir, linkDir, 'dir'); + } + catch(e) { + var sourceDir = path.join(config.dir, relativeFolder); + console.log('linking failed: trying to hard copy', linkDir, sourceDir); + copyRecursiveSync(sourceDir, linkDir); + } } }); }; }; +function copyRecursiveSync (src, dest) { + if (fs.existsSync(src)) { + var stats = fs.statSync(src); + if (stats.isDirectory()) { + fs.mkdirSync(dest); + fs.readdirSync(src).forEach(function(childItemName) { + copyRecursiveSync(path.join(src, childItemName), + path.join(dest, childItemName)); + }); + } else { + fs.writeFileSync(dest, fs.readFileSync(src)); + } + } +} + function getSubdirs(rootDir) { return fs.readdirSync(rootDir).filter(function(file) { if (file[0] === '.') { @@ -29,4 +51,4 @@ function getSubdirs(rootDir) { var dirPath = path.join(rootDir, file); return fs.statSync(dirPath).isDirectory(); }); -} \ No newline at end of file +}