Skip to content

Commit

Permalink
refactor(create-symlink): Consistent argument names
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Jul 22, 2019
1 parent 60d1100 commit 3f60aca
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions utils/create-symlink/create-symlink.js
Expand Up @@ -29,18 +29,19 @@ function createSymbolicLink(src, dest, type) {
.then(() => fs.symlink(src, dest, type));
}

function createPosixSymlink(origin, dest, _type) {
function createPosixSymlink(src, dest, _type) {
const type = _type === "exec" ? "file" : _type;
const relativeSymlink = path.relative(path.dirname(dest), origin);
const relativeSymlink = path.relative(path.dirname(dest), src);

if (_type === "exec") {
// If the target exists, create real symlink. If the target doesn't exist yet,
// create a shim shell script.
return fs.pathExists(origin).then(exists => {
// If the src exists, create a real symlink.
// If the src doesn't exist yet, create a shim shell script.
return fs.pathExists(src).then(exists => {
if (exists) {
return createSymbolicLink(relativeSymlink, dest, type).then(() => fs.chmod(origin, "755"));
return createSymbolicLink(relativeSymlink, dest, type).then(() => fs.chmod(src, "755"));
}
return shShim(origin, dest, type).then(() => fs.chmod(dest, "755"));

return shShim(src, dest, type).then(() => fs.chmod(dest, "755"));
});
}

Expand All @@ -55,12 +56,11 @@ function createWindowsSymlink(src, dest, type) {
return createSymbolicLink(src, dest, type);
}

function shShim(target, script, type) {
log.silly("shShim", [target, script, type]);

const absTarget = path.resolve(path.dirname(script), target);
function shShim(src, dest, type) {
log.silly("shShim", [src, dest, type]);

const absTarget = path.resolve(path.dirname(dest), src);
const scriptLines = ["#!/bin/sh", `chmod +x ${absTarget} && exec ${absTarget} "$@"`];

return fs.writeFile(script, scriptLines.join("\n"));
return fs.writeFile(dest, scriptLines.join("\n"));
}

0 comments on commit 3f60aca

Please sign in to comment.