Skip to content

Commit

Permalink
Merge pull request #1107 from LukasGentele/npm-installer
Browse files Browse the repository at this point in the history
ci: add npx test + improvements for npx
  • Loading branch information
Lukas Gentele committed May 16, 2020
2 parents 85e15ea + 8b83cc8 commit 78b69cb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/npm.yaml
Expand Up @@ -23,6 +23,8 @@ jobs:
devspace --version
npm uninstall -g devspace
npx -p . devspace --version
export PATH=$PATH:$(yarn global bin)
yarn global add $PWD
Expand All @@ -42,6 +44,8 @@ jobs:
npm run prepare
devspace --version
npm uninstall -g devspace
npx -p . devspace --version
$yarnGlobalDir = yarn global bin
$env:Path += ";$yarnGlobalDir"
Expand Down
16 changes: 10 additions & 6 deletions dist/npm/bin/devspace
Expand Up @@ -14,15 +14,19 @@ if [ ! -f "$BINARY" ] || [ "$STAT" -lt 10000 ]; then
BASEDIR="$(dirname $0)/../lib/node_modules/devspace"

if [ ! -f "$BASEDIR/$INDEX_FILE" ]; then
BASEDIR=$(/usr/bin/env npm root -g)/devspace
BASEDIR="$(dirname $0)/node_modules/devspace"

if [ ! -f "$BASEDIR/$INDEX_FILE" ]; then
if [ ! -f "$BASEDIR/$INDEX_FILE" ]; then
BASEDIR=$(/usr/bin/env yarn global dir)/node_modules/devspace
BASEDIR=$(/usr/bin/env npm root -g)/devspace

if [ ! -f "$BASEDIR/$INDEX_FILE" ]; then
if [ ! -f "$BASEDIR/$INDEX_FILE" ]; then
echo "Unable to find global npm/yarn dir"
exit 1
BASEDIR=$(/usr/bin/env yarn global dir)/node_modules/devspace

if [ ! -f "$BASEDIR/$INDEX_FILE" ]; then
echo "Unable to find global npm/yarn dir"
exit 1
fi
fi
fi
fi
Expand All @@ -32,7 +36,7 @@ if [ ! -f "$BINARY" ] || [ "$STAT" -lt 10000 ]; then
echo "Running: node $BASEDIR/$INDEX_FILE finish-install $BINDIR"
/usr/bin/env node "$BASEDIR/$INDEX_FILE" finish-install $BINDIR;

$BINDIR/devspace "$@" 2>/dev/null || $BINDIR/devspace.exe "$@" || devspace "$@" 2>/dev/null || devspace.exe "$@";
$BINDIR/devspace.exe "$@" || $BINDIR/devspace "$@" 2>/dev/null || devspace.exe "$@" || devspace "$@" 2>/dev/null;
exit $?;
fi

Expand Down
22 changes: 14 additions & 8 deletions dist/npm/bin/devspace.cmd
Expand Up @@ -2,30 +2,36 @@
setlocal enabledelayedexpansion

WHERE devspace.exe >nul 2>nul
IF %ERRORLEVEL% EQU 0 devspace %* && exit /b %errorlevel%
IF %ERRORLEVEL% EQU 0 devspace.exe %* && exit /b %errorlevel%

echo Finishing installation of DevSpace CLI

SET bindir=%~dp0
SET basedir=%~dp0\..
SET indexFile=\index.js

echo "!basedir!\!indexFile!"

IF NOT EXIST "!basedir!\!indexFile!" (
SET basedir=%~dp0\..\lib\node_modules\devspace

IF NOT EXIST "!basedir!\!indexFile!" (
FOR /F "tokens=* USEBACKQ" %%F IN (`npm root -g`) DO (
SET basedir=%%F\devspace
)
SET basedir=%~dp0\node_modules\devspace

IF NOT EXIST "!basedir!\!indexFile!" (
FOR /F "tokens=* USEBACKQ" %%F IN (`yarn global dir`) DO (
SET basedir=%%F\node_modules\devspace
FOR /F "tokens=* USEBACKQ" %%F IN (`npm root -g`) DO (
SET basedir=%%F\devspace
)

IF NOT EXIST "!basedir!\!indexFile!" (
echo "Unable to find global npm/yarn dir"
exit /b 1
FOR /F "tokens=* USEBACKQ" %%F IN (`yarn global dir`) DO (
SET basedir=%%F\node_modules\devspace
)

IF NOT EXIST "!basedir!\!indexFile!" (
echo Unable to find global npm/yarn dir
exit /b 1
)
)
)
)
Expand Down
34 changes: 17 additions & 17 deletions dist/npm/index.js
Expand Up @@ -94,7 +94,7 @@ const getLatestVersion = function(callback, includePreReleases) {
callback(latestVersion);
} else {
console.error("Unable to identify latest devspace version");
process.exit(1);
process.exit(2);
}
});
};
Expand Down Expand Up @@ -206,21 +206,10 @@ let continueProcess = function(askRemoveGlobalFolder) {
if (globalDir == null) {
if (platform == PLATFORM_MAPPING.win32) {
console.error("Error finding binary installation directory");
process.exit(1);
process.exit(3);
}
globalDir = fallbackGlobalDir;
}

cleanPathVar = process.env.PATH.replace(/(^|;)[a-z]:/gi, ';').replace(/(\\)+/g, '/');
cleanGlobalDir = globalDir.replace(/(^|;)[a-z]:/gi, '').replace(/(\\)+/g, '/').trimRight("/");

if (cleanPathVar.split(path.delimiter).indexOf(cleanGlobalDir) == -1) {
console.error("\n\n################################################\nWARNING: npm binary directory NOT in $PATH environment variable: " + globalDir + "\n################################################\n\n");

if (globalInstall) {
process.exit(1)
}
}

try {
fs.mkdirSync(globalDir, { recursive: true });
Expand Down Expand Up @@ -311,6 +300,17 @@ let continueProcess = function(askRemoveGlobalFolder) {
}
} else {
if (action == "finish-install") {
cleanPathVar = process.env.PATH.replace(/(^|;)[a-z]:/gi, ';').replace(/(\\)+/g, '/');
cleanGlobalDir = globalDir.replace(/(^|;)[a-z]:/gi, '').replace(/(\\)+/g, '/').trimRight("/");

if (cleanPathVar.split(path.delimiter).indexOf(cleanGlobalDir) == -1) {
console.error("\n\n################################################\nWARNING: npm binary directory NOT in $PATH environment variable: " + globalDir + "\n################################################\n\n");

if (globalInstall) {
process.exit(4)
}
}

const showRootError = function() {
console.error("\n############################################");
console.error(
Expand All @@ -323,7 +323,7 @@ let continueProcess = function(askRemoveGlobalFolder) {
);
console.error(" You may need to run this command using sudo.");
console.error("############################################\n");
process.exit(1);
process.exit(5);
};

const downloadRelease = function(version) {
Expand Down Expand Up @@ -356,7 +356,7 @@ let continueProcess = function(askRemoveGlobalFolder) {
.on("error", function() {
spinner.stop(true);
console.error("Error requesting URL: " + downloadPath);
process.exit(1);
process.exit(6);
})
.on("response", function(res) {
if (res.statusCode != 200) {
Expand Down Expand Up @@ -387,7 +387,7 @@ let continueProcess = function(askRemoveGlobalFolder) {
")"
);
console.error(err);
process.exit(1);
process.exit(7);
}
} else {
try {
Expand All @@ -414,7 +414,7 @@ let continueProcess = function(askRemoveGlobalFolder) {
} catch (e) {
console.log(e);
console.error("\nRenaming release binary failed. Please copy file manually:\n from: " + binaryPath + downloadExtension + "\n to: " + binaryPath + "\n");
process.exit(1);
process.exit(8);
}

removeScripts(true);
Expand Down

0 comments on commit 78b69cb

Please sign in to comment.