2015-02-11 14:40:29 -05:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
module.exports = function(gulp, plugins, config) {
|
2016-04-29 00:57:16 -04:00
|
|
|
function symlink(relativeFolder, linkDir) {
|
|
|
|
var sourceDir = path.join('..', relativeFolder);
|
|
|
|
if (!fs.existsSync(linkDir)) {
|
|
|
|
console.log('creating link', linkDir, sourceDir);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 14:40:29 -05:00
|
|
|
return function() {
|
|
|
|
var nodeModulesDir = path.join(config.dir, 'node_modules');
|
|
|
|
if (!fs.existsSync(nodeModulesDir)) {
|
|
|
|
fs.mkdirSync(nodeModulesDir);
|
|
|
|
}
|
|
|
|
getSubdirs(config.dir).forEach(function(relativeFolder) {
|
|
|
|
if (relativeFolder === 'node_modules') {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-29 00:57:16 -04:00
|
|
|
|
2015-02-11 14:40:29 -05:00
|
|
|
var linkDir = path.join(nodeModulesDir, relativeFolder);
|
2016-04-29 00:57:16 -04:00
|
|
|
symlink(relativeFolder, linkDir);
|
2015-02-11 14:40:29 -05:00
|
|
|
});
|
2016-04-29 00:57:16 -04:00
|
|
|
// Also symlink tools we release independently to NPM, so tests can require metadata, etc.
|
2016-05-24 13:53:48 -04:00
|
|
|
symlink('../../tools/metadata', path.join(nodeModulesDir, 'tsc-wrapped'));
|
2015-02-11 14:40:29 -05:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-07-04 04:07:19 -04:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 14:40:29 -05:00
|
|
|
function getSubdirs(rootDir) {
|
|
|
|
return fs.readdirSync(rootDir).filter(function(file) {
|
|
|
|
if (file[0] === '.') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var dirPath = path.join(rootDir, file);
|
|
|
|
return fs.statSync(dirPath).isDirectory();
|
|
|
|
});
|
2015-07-04 04:07:19 -04:00
|
|
|
}
|