@inst/vscode-bin-darwin
Version:
BINARY ONLY - VSCode binary deployment for macOS
88 lines (76 loc) • 2.85 kB
JavaScript
module.exports = {
zip: 'VSCode-darwin-stable.zip',
run: 'Visual Studio Code.app/Contents/MacOS/Electron',
node_modules_parent: 'Visual Studio Code.app/Contents/Resources/app'
};
if (process.mainModule === module) {
switch (process.env.npm_lifecycle_event) {
case 'prepublish':
case 'prepublishOnly':
renameSudir(true /*mangleNames*/);
break;
case 'postinstall':
renameSudir(false /*mangleNames*/);
break;
default:
var child_process = require('child_process');
child_process.spawnSync(module.exports.run, process.argv.slice(2));
break;
}
}
function renameSudir(mangleNames) {
var fs = require('fs');
var path = require('path');
var newlyConverted = []
var alreadyConverted = [];
var from = mangleNames ? 'node_modules' : 'x-node_modules';
var to = mangleNames ? 'x-node_modules' : 'node_modules';
var fromPKG = mangleNames ? 'package.json' : 'x-package.json';
var toPKG = mangleNames ? 'x-package.json' : 'package.json';
console.log('RENAMING ' + from + ' -> ' + to);
var findRoot = path.resolve(__dirname, module.exports.node_modules_parent);
var check = [findRoot];
while (check.length) {
var dir = check.pop();
try {
fs.readdirSync(dir).forEach(function (file) {
file = path.resolve(dir, file);
try {
var file_simple = path.basename(file);
if (file_simple === from || file_simple === fromPKG) {
var fileTo = path.join(path.dirname(file), file_simple === from ? to : toPKG);
fs.renameSync(file, fileTo);
newlyConverted.push(fileTo.slice(findRoot.length));
file = fileTo;
}
else if (file_simple === to || file_simple === toPKG) {
alreadyConverted.push(file.slice(findRoot.length));
}
}
catch (error) {
console.log('Renaming ' + file + ': ' + error.message);
}
try {
if (fs.statSync(file).isDirectory()) {
check.push(file);
}
}
catch (error) {
console.log('Traversing ' + file + ': ' + error.message);
}
});
}
catch (error) {
console.log('Processing ' + dir + ' directory: ' + error.message);
}
}
if (newlyConverted.length)
console.log('Renamed' + (newlyConverted.length == 1 ? '' : ' ' + newlyConverted.length) + ':' +
newlyConverted.map(function (toDir) { return ' ' + toDir; }).join('\n'));
if (alreadyConverted.length)
console.log('Ready' + (alreadyConverted.length == 1 ? '' : ' ' + alreadyConverted.length) + ':' +
alreadyConverted.map(function (toDir) { return ' ' + toDir; }).join('\n'));
if (!newlyConverted.length && !alreadyConverted.length)
console.log('No candidates for rename found in ' + findRoot);
}