From eab8fe2d642b1c508ecd13ce3d2cca9686d89402 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Tue, 5 Oct 2021 11:34:25 +0200 Subject: [PATCH] Fixed: Divided 'jake install' into 'jake dist' and 'jake install' 'jake dist' will do everything that 'jake install' does but creating the global symlinks for the 'dist' binaries at the 'npm prefix' path. --- Jakefile | 19 +++++++++++++++++-- common.jake | 44 ++++++++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/Jakefile b/Jakefile index 58d8fa918..79f0474fc 100644 --- a/Jakefile +++ b/Jakefile @@ -45,18 +45,33 @@ filedir ($BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS, ["debug", "release"], function( task ("CommonJS", [$BUILD_CJS_OBJECTIVE_J_DEBUG_FRAMEWORKS, $BUILD_CJS_CAPPUCCINO_DEBUG_FRAMEWORKS, "debug", "release"], function() { }); -task ("install", ["CommonJS"], function() +// Install everything in the dist directory +task ("dist", ["CommonJS"], function() { installCopy($BUILD_CJS_OBJECTIVE_J, false); installCopy($BUILD_CJS_CAPPUCCINO, false); }); -task ("sudo-install", ["CommonJS"], function() +task ("sudo-dist", ["CommonJS"], function() { installCopy($BUILD_CJS_OBJECTIVE_J, true); installCopy($BUILD_CJS_CAPPUCCINO, true); }); +// Install everything in the dist directory (task dist) and +// create symlinks to the 'dist' binaries in the global 'npm prefix' path +task ("install", ["dist"], function() +{ + installGlobal($BUILD_CJS_OBJECTIVE_J, false); + installGlobal($BUILD_CJS_CAPPUCCINO, false); +}); + +task ("sudo-install", ["sudo-dist"], function() +{ + installGlobal($BUILD_CJS_OBJECTIVE_J, true); + installGlobal($BUILD_CJS_CAPPUCCINO, true); +}); + task ("install-symlinks", function() { installSymlink($BUILD_CJS_OBJECTIVE_J); diff --git a/common.jake b/common.jake index c3aba6d7e..466430737 100644 --- a/common.jake +++ b/common.jake @@ -365,7 +365,8 @@ global.installCopy = function(sourcePath, useSudo) return; var packageName = path.basename(sourcePath), - targetPath = path.join(__dirname, "dist", packageName); + targetPath = path.join(__dirname, "dist", packageName), + binPath = path.resolve(path.join(targetPath, "bin")); // create the dist directory if it does not exist if (!fs.existsSync(targetPath)) { @@ -381,12 +382,10 @@ global.installCopy = function(sourcePath, useSudo) // hacky way to do a sudo copy. if (useSudo) - child_process.execSync(["sudo", "cp", "-Rf", sourcePath, path.dirname(targetPath)].join(" ")); + child_process.execSync(["sudo", "cp", "-Rf", sourcePath, path.dirname(targetPath)].map(utilsFile.enquote).join(" ")); else utilsFile.copyRecursiveSync(sourcePath, targetPath); - var binPath = path.resolve(path.join(targetPath, "bin")) - // create the bin directory if it does not exist if (!fs.existsSync(binPath)) { fs.mkdirSync(targetPath) @@ -399,19 +398,39 @@ global.installCopy = function(sourcePath, useSudo) var binary = path.join(binPath, name); if (useSudo) { - child_process.execSync(["sudo", "chmod", "755", binary].join(" ")); + child_process.execSync(["sudo", "chmod", "755", binary].map(utilsFile.enquote).join(" ")); } else { fs.chmodSync(binary, 0o755); } }); } - fs.readdirSync(binPath).forEach(function (name) - { - var prefix = child_process.execSync("npm prefix -g").toString().trim(); - child_process.execSync( (useSudo ? "sudo " : "") + "ln -sf " + path.join(binPath, name) + " " + path.join(prefix, "bin", name)); - }); }; +global.installGlobal = function(sourcePath, useSudo) +{ + if (!fs.existsSync(sourcePath)) + return; + + var packageName = path.basename(sourcePath), + targetPath = path.join(__dirname, "dist", packageName), + binPath = path.resolve(path.join(targetPath, "bin")); + + // create the dist directory if it does not exist + if (!fs.existsSync(targetPath)) { + fs.mkdirSync(targetPath, { recursive: true }); + } + + var prefix = child_process.execSync("npm prefix -g").toString().trim(); + + fs.readdirSync(binPath).forEach(function (name) + { + var p = path.join(binPath, name), + prefixBinPath = path.join(prefix, "bin", name); + + stream.print("Symlink \0cyan(" + prefixBinPath + "\0) ==> \0cyan(" + p + "\0)"); + child_process.execSync( (useSudo ? "sudo " : "") + "ln -sf " + utilsFile.enquote(p) + " " + utilsFile.enquote(prefixBinPath)); + }); +} global.spawnJake = function(/*String*/ aTaskName) { @@ -424,10 +443,7 @@ global.spawnJake = function(/*String*/ aTaskName) var normalizeCommand = function(/*Array or String*/ command) { if (Array.isArray(command)) - return command.map(function (arg) - { - return utilsFile.enquote(arg); - }).join(" "); + return command.map(utilsFile.enquote).join(" "); else return command; };