Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature oleg 1528683448315 #291

Merged
merged 17 commits into from
Jul 16, 2018
Prev Previous commit
Next Next commit
pdev:set
  • Loading branch information
ORESoftware committed Jun 29, 2018
commit 2cbf20868aba1e439af10e315e9fc657564897b8
57 changes: 40 additions & 17 deletions cli/suman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#set -e;

if ! [[ -z "${LOCAL_SUMAN_ALREADY_FOUND+x}" ]]; then
if [[ -n "${LOCAL_SUMAN_ALREADY_FOUND+x}" ]]; then
echo " => \$LOCAL_SUMAN_ALREADY_FOUND ? => $LOCAL_SUMAN_ALREADY_FOUND"
fi

Expand Down Expand Up @@ -31,35 +31,58 @@ fi


echo " [suman] Original path of Suman executable => \"$0\""
DIRN="$(dirname "$0")"
RL="$(readlink "$0")";
EXECDIR="$(dirname $(dirname "$RL"))";
MYPATH="$DIRN/$EXECDIR";
X="$(cd $(dirname ${MYPATH}) && pwd)/$(basename ${MYPATH})"
NEW_NODE_PATH="${NODE_PATH}":"$HOME/.suman/global/node_modules"
NEW_PATH="${PATH}":"$HOME/.suman/global/node_modules/.bin"
dir_name="$(dirname "$0")"
read_link="$(readlink "$0")";
exec_dir="$(dirname $(dirname "$read_link"))";
my_path="$dir_name/$exec_dir";
suman_root="$(cd $(dirname ${my_path}) && pwd)/$(basename ${my_path})"
new_node_path="${NODE_PATH}":"$HOME/.suman/global/node_modules"
new_path="${PATH}":"$HOME/.suman/global/node_modules/.bin"

if [[ "${LOCAL_SUMAN_ALREADY_FOUND}" == "yes" ]]; then
# we know that this directory contains the local version of suman we want to use
echo " [suman] local suman version already found.";
NODE_PATH="${NEW_NODE_PATH}" PATH="${NEW_PATH}" SUMAN_EXTRANEOUS_EXECUTABLE="yes" \
node "${X}/dist/cli.js" "$@"
NODE_PATH="${new_node_path}" PATH="${new_path}" SUMAN_EXTRANEOUS_EXECUTABLE="yes" \
node "${suman_root}/dist/cli.js" "$@"
else

# we are probably in the global install space, so let's find the local installation given pwd/cwd
LOCAL_SUMAN="$(node ${X}/scripts/find-local-suman-executable.js)"

if [[ -z "$LOCAL_SUMAN" ]]; then
project_root="$(node ${suman_root}/scripts/find-project-root.js)"

if [[ -z "$project_root" ]]; then
echo >&2 " [suman] Could not find your project root given your current working directory:";
echo >&2 " [suman] Your pwd: '$PWD'";
exit 1;
fi

local_suman="$(node ${suman_root}/scripts/find-local-suman-executable.js)"

if [[ -z "$local_suman" ]]; then

# symlink the global suman installation to the local project

if true; then
echo "major foo.";
echo "Symlinking global suman installation to local project.";
mkdir -p "${project_root}/node_modules/suman"
rm -rf "${project_root}/node_modules/suman";
ln -sf "$suman_root" "$project_root/node_modules/suman"
fi

# no local version found, so we fallback on the version in this directory, global or not

echo " [suman] => No local Suman executable could be found, given the current directory => $PWD"
echo " [suman] => Attempting to run installed version of Suman here => '${X}/dist/cli.js'"
echo " [suman] => Attempting to run installed version of Suman here => '${suman_root}/dist/cli.js'"

GLOBAL_MODULES="${suman_global_npm_modules_path:-"$(npm root -g)"}"
NODE_PATH="${NEW_NODE_PATH}":"${GLOBAL_MODULES}" PATH="${NEW_PATH}" SUMAN_EXTRANEOUS_EXECUTABLE="yes" \
node "${X}/dist/cli.js" "$@"
NODE_PATH="${new_node_path}":"${GLOBAL_MODULES}" PATH="${new_path}" SUMAN_EXTRANEOUS_EXECUTABLE="yes" \
node "${suman_root}/dist/cli.js" "$@"

else
# local version found, so we run it
NODE_PATH="${NEW_NODE_PATH}" PATH="${NEW_PATH}" SUMAN_EXTRANEOUS_EXECUTABLE="yes" \
node "${LOCAL_SUMAN}" "$@"
NODE_PATH="${new_node_path}" PATH="${new_path}" SUMAN_EXTRANEOUS_EXECUTABLE="yes" \
node "${local_suman}" "$@"
fi

fi
1 change: 1 addition & 0 deletions scripts/create-suman-dir.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#!/usr/bin/env node
export {};
1 change: 1 addition & 0 deletions scripts/find-local-suman-executable.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#!/usr/bin/env node
export {};
7 changes: 3 additions & 4 deletions scripts/find-local-suman-executable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ try {
}
catch (err) {
}
const debugLogPath = path.resolve(process.env.HOME + '/.suman/suman-debug.log');
let p, cd;
function stat(p) {
const stat = function (p) {
try {
return fs.statSync(p).isFile();
return fs.lstatSync(p).isFile();
}
catch (err) {
if (!String(err.stack || err).match(/ENOENT: no such file or directory/i)) {
throw err;
}
return false;
}
}
};
while (true) {
cd = path.resolve(cwd + down.join(''));
if (String(cd) === String(path.sep)) {
Expand Down
9 changes: 4 additions & 5 deletions scripts/find-local-suman-executable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ try{
fs.mkdirSync(path.resolve(process.env.HOME + '/.suman'));
}
catch(err){

// ignore
}

const debugLogPath = path.resolve(process.env.HOME + '/.suman/suman-debug.log');
let p, cd;

function stat (p: string) {
const stat = function (p: string) {
try {
return fs.statSync(p).isFile();
return fs.lstatSync(p).isFile();
}
catch (err) {
if (!String(err.stack || err).match(/ENOENT: no such file or directory/i)) {
Expand All @@ -39,7 +38,7 @@ function stat (p: string) {
//explicit for your pleasure
return false;
}
}
};

while (true) {

Expand Down
7 changes: 4 additions & 3 deletions scripts/find-project-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const path = require("path");
(function findRoot(pth) {
let possiblePkgDotJsonPath = path.resolve(String(pth) + '/package.json');
try {
fs.statSync(possiblePkgDotJsonPath).isFile();
console.log(pth);
process.exit(0);
if (fs.lstatSync(possiblePkgDotJsonPath).isFile()) {
console.log(pth);
process.exit(0);
}
}
catch (err) {
let subPath = path.resolve(String(pth) + '/../');
Expand Down
32 changes: 16 additions & 16 deletions scripts/find-project-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
import fs = require('fs');
import path = require('path');

(function findRoot(pth: string): void {

(function findRoot(pth: string) : void {
let possiblePkgDotJsonPath = path.resolve(String(pth) + '/package.json');

let possiblePkgDotJsonPath = path.resolve(String(pth) + '/package.json');

try {
fs.statSync(possiblePkgDotJsonPath).isFile();
console.log(pth);
process.exit(0);
try {
if (fs.lstatSync(possiblePkgDotJsonPath).isFile()) {
console.log(pth);
process.exit(0);
}
}
catch (err) {
let subPath = path.resolve(String(pth) + '/../');
if (subPath === pth) {
console.error(' => Cannot find path to project root.');
process.exit(1);
}
catch (err) {
let subPath = path.resolve(String(pth) + '/../');
if (subPath === pth) {
console.error(' => Cannot find path to project root.');
process.exit(1);
}
else {
return findRoot(subPath);
}
else {
return findRoot(subPath);
}
}

})(process.cwd());
6 changes: 5 additions & 1 deletion scripts/suman-clis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ handle_global_suman() {
}


suman(){
suman(){

if test ${#} -eq 0; then

echo "[suman] using suman-shell instead of suman executable.";
suman-shell "$@"; # note we should have no arguments so passing "$@" to suman-shell should be pointless

else

suman_inspect="no";
Expand All @@ -68,10 +70,12 @@ handle_global_suman() {
NEW_PATH="${PATH}":"$HOME/.suman/global/node_modules/.bin";

if [[ "${SUMAN_FORCE_GLOBAL}" == "yes" || -z "$LOCAL_SUMAN" ]]; then

echo "[suman] => No local Suman executable could be found, given the present working directory => $PWD";
echo "[suman] => Warning...attempting to run a globally installed version of Suman...";
local -a node_exec_args=( );
handle_global_suman node_exec_args "$@";

else
NODE_PATH="${NEW_NODE_PATH}" PATH="${NEW_PATH}" node "$LOCAL_SUMAN" "$@";
fi
Expand Down