diff options
Diffstat (limited to 'installer/mod.ts')
-rw-r--r-- | installer/mod.ts | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/installer/mod.ts b/installer/mod.ts index 5d907bef5..c0a11ac9e 100644 --- a/installer/mod.ts +++ b/installer/mod.ts @@ -18,7 +18,8 @@ import { exists } from "../fs/exists.ts"; const encoder = new TextEncoder(); const decoder = new TextDecoder("utf-8"); const isWindows = Deno.platform.os === "win"; -const driverLetterReg = /^[c-z]:/i; // Regular expression to test disk driver letter. eg "C:\\User\username\path\to" +// Regular expression to test disk driver letter. eg "C:\\User\username\path\to" +const driverLetterReg = /^[c-z]:/i; enum Permission { Read, @@ -101,8 +102,10 @@ function checkIfExistsInPath(filePath: string): boolean { for (const p of paths) { const pathInEnv = path.normalize(p); - // On Windows paths from env contain drive letter. (eg. C:\Users\username\.deno\bin) - // But in the path of Deno, there is no drive letter. (eg \Users\username\.deno\bin) + // On Windows paths from env contain drive letter. + // (eg. C:\Users\username\.deno\bin) + // But in the path of Deno, there is no drive letter. + // (eg \Users\username\.deno\bin) if (isWindows) { if (driverLetterReg.test(pathInEnv)) { fileAbsolutePath = HOMEDRIVE + "\\" + fileAbsolutePath; @@ -118,7 +121,8 @@ function checkIfExistsInPath(filePath: string): boolean { } function getInstallerDir(): string { - // In Windows's Powershell $HOME environmental variable maybe null, if so use $HOMEPATH instead. + // In Windows's Powershell $HOME environmental variable maybe null + // if so use $HOMEPATH instead. let { HOME, HOMEPATH } = env(); const HOME_PATH = HOME || HOMEPATH; @@ -140,7 +144,8 @@ USAGE: ARGS: EXE_NAME Name for executable SCRIPT_URL Local or remote URL of script to install - [FLAGS...] List of flags for script, both Deno permission and script specific flag can be used. + [FLAGS...] List of flags for script, both Deno permission and script specific + flag can be used. `); } @@ -148,10 +153,14 @@ async function generateExecutable( filePath: string, commands: string[] ): Promise<void> { - // On Windows if user is using Powershell .cmd extension is need to run the installed module. + // On Windows if user is using Powershell .cmd extension is need to run the + // installed module. // Generate batch script to satisfy that. + const templateHeader = + "This executable is generated by Deno. Please don't modify it unless you " + + "know what it means."; if (isWindows) { - const template = `% This executable is generated by Deno. Please don't modify it unless you know what it means. % + const template = `% ${templateHeader} % @IF EXIST "%~dp0\deno.exe" ( "%~dp0\deno.exe" ${commands.slice(1).join(" ")} %* ) ELSE ( @@ -167,7 +176,7 @@ async function generateExecutable( // generate Shell script const template = `#/bin/sh -# This executable is generated by Deno. Please don't modify it unless you know what it means. +# ${templateHeader} basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") case \`uname\` in @@ -198,7 +207,9 @@ export async function install( const filePath = path.join(installerDir, moduleName); if (await exists(filePath)) { - const msg = `⚠️ ${moduleName} is already installed, do you want to overwrite it?`; + const msg = + "⚠️ ${moduleName} is already installed, " + + "do you want to overwrite it?"; if (!(await yesNoPrompt(msg))) { return; } @@ -245,7 +256,8 @@ export async function install( if (!checkIfExistsInPath(installerDir)) { console.log("\nℹ️ Add ~/.deno/bin to PATH"); console.log( - " echo 'export PATH=\"$HOME/.deno/bin:$PATH\"' >> ~/.bashrc # change this to your shell" + " echo 'export PATH=\"$HOME/.deno/bin:$PATH\"' >> ~/.bashrc # change" + + " this to your shell" ); } } |