generated from denorg/starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { mode } from "./mod.ts"; | ||
import arch from "./mod.ts"; | ||
|
||
// https://deno.land/manual/tools/script_installer | ||
if (import.meta.main) { | ||
for (let arg of Deno.args) { | ||
console.log(arg, mode()); | ||
console.log(arg, arch()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,53 @@ | ||
/** JSDoc for this line */ | ||
export function mode() { | ||
return 0; | ||
import * as path from "https://deno.land/std@0.61.0/path/mod.ts"; | ||
var decoder = new TextDecoder("utf-8"); | ||
|
||
/** | ||
* Returns the operating system's CPU architecture. | ||
*/ | ||
export default async function arch() { | ||
/** | ||
* The running binary is 64-bit, so the OS is clearly 64-bit. | ||
*/ | ||
if (Deno.build.arch === 'x86_64') { | ||
return 'x64' | ||
} | ||
|
||
/** | ||
* All recent versions of Mac OS are 64-bit. | ||
*/ | ||
if (Deno.build.os === 'darwin') { | ||
return 'x64' | ||
} | ||
|
||
/** | ||
* On Windows, the most reliable way to detect a 64-bit OS from within a 32-bit | ||
* app is based on the presence of a WOW64 file: %SystemRoot%\SysNative. | ||
* See: https://twitter.com/feross/status/776949077208510464 | ||
*/ | ||
if (Deno.build.os === 'windows') { | ||
let systemRoot = Deno.env.get("SystemRoot"); | ||
var sysRoot = systemRoot && Deno.statSync(systemRoot) ? systemRoot : 'C:\\Windows' | ||
|
||
// If %SystemRoot%\SysNative exists, we are in a WOW64 FS Redirected application. | ||
var isWOW64 = false | ||
try { | ||
isWOW64 = sysRoot ? !!Deno.statSync(path.join(sysRoot, 'sysnative')) : false | ||
} catch (err) { } | ||
|
||
return isWOW64 ? 'x64' : 'x86' | ||
} | ||
|
||
/** | ||
* On Linux, use the `getconf` command to get the architecture. | ||
*/ | ||
if (Deno.build.os === 'linux') { | ||
var process = Deno.run({ cmd: ['getconf', 'LONG_BIT'], stdout: "piped" }); | ||
var output = decoder.decode(await process.output()); | ||
return output === '64\n' ? 'x64' : 'x86' | ||
} | ||
|
||
/** | ||
* If none of the above, assume the architecture is 32-bit. | ||
*/ | ||
return 'x86' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
import { mode } from "./mod.ts"; | ||
import arch from "./mod.ts"; | ||
|
||
Deno.test("test starter function", async (): Promise<void> => { | ||
assertEquals(mode(), 0); | ||
Deno.test("test default function", async (): Promise<void> => { | ||
console.log(arch()); | ||
assertEquals(await arch(), "x64"); | ||
}); |