Skip to content

Commit fba8559

Browse files
committed
✨ Initial release
1 parent 38ab257 commit fba8559

File tree

5 files changed

+78
-40
lines changed

5 files changed

+78
-40
lines changed

.github/workflows/deno.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
with:
3636
node-version: 12.17.0
3737
- name: Setup package.json
38-
run: echo '{"name":"@denorg/starter","version":"0.0.0","publishConfig":{"access":"public"},"scripts":{"semantic-release":"semantic-release"},"repository":{"type":"git","url":"https://github.com/denorg/starter.git"},"author":"Denorg<hellp@den.org.in>","license":"MIT","bugs":{"url":"https://github.com/denorg/starter/issues"},"homepage":"https://denorg.github.io/starter/","devDependencies":{"semantic-release":"^17.0.4","semantic-release-gitmoji":"^1.3.3"}}' > package.json
38+
run: echo '{"name":"@denorg/arch","version":"0.0.0","publishConfig":{"access":"public"},"scripts":{"semantic-release":"semantic-release"},"repository":{"type":"git","url":"https://github.com/denorg/arch.git"},"author":"Denorg<hellp@den.org.in>","license":"MIT","bugs":{"url":"https://github.com/denorg/arch/issues"},"homepage":"https://denorg.github.io/starter/","devDependencies":{"semantic-release":"^17.0.4","semantic-release-gitmoji":"^1.3.3"}}' > package.json
3939
- name: Install dependencies
4040
run: npm install
4141
- name: Release

README.md

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,53 @@
1-
# 🏁 Deno Starter
1+
# 🏁 Arch
22

3-
This is a starter template for building Deno packages in TypeScript, with GitHub Actions-powered CI, tests, CLI, and Semantic Release on GitHub and npm.
3+
This module is used to determine if the user is on a 32-bit vs. 64-bit operating system to offer the right app installer
44

5-
[![Deno CI](https://github.com/denorg/starter/workflows/Deno%20CI/badge.svg)](https://github.com/denorg/starter/actions)
6-
[![GitHub](https://img.shields.io/github/license/denorg/starter)](https://github.com/denorg/starter/blob/master/LICENSE)
7-
[![Contributors](https://img.shields.io/github/contributors/denorg/starter)](https://github.com/denorg/starter/graphs/contributors)
5+
Use this package to get the actual operating system CPU architecture.
6+
7+
[![Deno CI](https://github.com/denorg/arch/workflows/Deno%20CI/badge.svg)](https://github.com/denorg/arch/actions)
8+
[![GitHub](https://img.shields.io/github/license/denorg/arch)](https://github.com/denorg/arch/blob/master/LICENSE)
9+
[![Contributors](https://img.shields.io/github/contributors/denorg/arch)](https://github.com/denorg/arch/graphs/contributors)
810
[![Deno Starter](https://img.shields.io/badge/deno-starter-brightgreen)](https://denorg.github.io/starter/)
911
[![Made by Denorg](https://img.shields.io/badge/made%20by-denorg-0082fb)](https://github.com/denorg)
10-
[![TypeScript](https://img.shields.io/badge/types-TypeScript-blue)](https://github.com/denorg/starter)
12+
[![TypeScript](https://img.shields.io/badge/types-TypeScript-blue)](https://github.com/denorg/arch)
1113
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
1214

13-
## 💡 How to use
14-
15-
1. [Create a new repository](https://github.com/denorg/starter/generate) using this template
16-
2. Update the project name ("Deno Starter") from the first line in `README.md`
17-
3. Find and replace "denorg/starter" with your "username/repository" in `README.md`
18-
4. Update the "Getting started" guide with your exported functions' names
19-
5. In `.github/workflows/*.yml` files, add additional permissions after `deno test`
20-
6. Setup Semantic Release
21-
- Add a repository secret `NPM_TOKEN` with your npm token
22-
- In `.github/workflows/deno.yml`, find and replace "denorg/starter" with your "username/repository"
23-
7. Remove this section ("How to use") after setting up your respoitory
24-
25-
If you're not building a Denorg project, the following steps are required too:
26-
27-
1. Remove the "A project by Denorg..." footer from `README.md`
28-
2. Remove the "Made by Denorg" shield from the `README.md` badges section
29-
3. Change the "Denorg" name to yours in `LICENSE` and under "License" in `README.md`
30-
3115
## ⭐ Getting started
3216

33-
Import the `mode` function and use it:
17+
Import the default function and use it:
3418

3519
```ts
36-
import { mode } from "https://raw.githubusercontent.com/denorg/starter/master/mod.ts";
20+
import arch from "https://raw.githubusercontent.com/denorg/arch/master/mod.ts";
3721

38-
const result = mode();
22+
const result = await arch();
3923
```
4024

4125
### CLI with [DPX](https://github.com/denorg/dpx)
4226

4327
After [installing DPX](https://github.com/denorg/dpx), you can directly use the CLI using the `dpx` command:
4428

4529
```bash
46-
dpx --allow-read starter <arguments>
30+
dpx --allow-read arch <arguments>
4731
```
4832

4933
### CLI
5034

5135
Alternatively, you can use it directly from the CLI by using `deno run`:
5236

5337
```bash
54-
deno run --allow-read https://raw.githubusercontent.com/denorg/starter/master/cli.ts <arguments>
38+
deno run --allow-read https://raw.githubusercontent.com/denorg/arch/master/cli.ts <arguments>
5539
```
5640

5741
You can also install it globally using the following:
5842

5943
```bash
60-
deno install --allow-read -n starter https://raw.githubusercontent.com/denorg/starter/master/cli.ts
44+
deno install --allow-read -n arch https://raw.githubusercontent.com/denorg/arch/master/cli.ts
6145
```
6246

6347
Then, the package is available to run:
6448

6549
```bash
66-
starter <arguments>
50+
arch <arguments>
6751
```
6852

6953
### Configuration
@@ -80,6 +64,10 @@ Run tests:
8064
deno test --allow-read
8165
```
8266

67+
## ⭐ Related Work
68+
69+
- [feross/arch](https://github.com/feross/arch) is the Node.js project serving as inspiration for this one
70+
8371
## 📄 License
8472

8573
MIT © [Denorg](https://den.org.in)

cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { mode } from "./mod.ts";
1+
import arch from "./mod.ts";
22

33
// https://deno.land/manual/tools/script_installer
44
if (import.meta.main) {
55
for (let arg of Deno.args) {
6-
console.log(arg, mode());
6+
console.log(arg, arch());
77
}
88
}

mod.ts

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,53 @@
1-
/** JSDoc for this line */
2-
export function mode() {
3-
return 0;
1+
import * as path from "https://deno.land/std@0.61.0/path/mod.ts";
2+
var decoder = new TextDecoder("utf-8");
3+
4+
/**
5+
* Returns the operating system's CPU architecture.
6+
*/
7+
export default async function arch() {
8+
/**
9+
* The running binary is 64-bit, so the OS is clearly 64-bit.
10+
*/
11+
if (Deno.build.arch === 'x86_64') {
12+
return 'x64'
13+
}
14+
15+
/**
16+
* All recent versions of Mac OS are 64-bit.
17+
*/
18+
if (Deno.build.os === 'darwin') {
19+
return 'x64'
20+
}
21+
22+
/**
23+
* On Windows, the most reliable way to detect a 64-bit OS from within a 32-bit
24+
* app is based on the presence of a WOW64 file: %SystemRoot%\SysNative.
25+
* See: https://twitter.com/feross/status/776949077208510464
26+
*/
27+
if (Deno.build.os === 'windows') {
28+
let systemRoot = Deno.env.get("SystemRoot");
29+
var sysRoot = systemRoot && Deno.statSync(systemRoot) ? systemRoot : 'C:\\Windows'
30+
31+
// If %SystemRoot%\SysNative exists, we are in a WOW64 FS Redirected application.
32+
var isWOW64 = false
33+
try {
34+
isWOW64 = sysRoot ? !!Deno.statSync(path.join(sysRoot, 'sysnative')) : false
35+
} catch (err) { }
36+
37+
return isWOW64 ? 'x64' : 'x86'
38+
}
39+
40+
/**
41+
* On Linux, use the `getconf` command to get the architecture.
42+
*/
43+
if (Deno.build.os === 'linux') {
44+
var process = Deno.run({ cmd: ['getconf', 'LONG_BIT'], stdout: "piped" });
45+
var output = decoder.decode(await process.output());
46+
return output === '64\n' ? 'x64' : 'x86'
47+
}
48+
49+
/**
50+
* If none of the above, assume the architecture is 32-bit.
51+
*/
52+
return 'x86'
453
}

mod_test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
2-
import { mode } from "./mod.ts";
2+
import arch from "./mod.ts";
33

4-
Deno.test("test starter function", async (): Promise<void> => {
5-
assertEquals(mode(), 0);
4+
Deno.test("test default function", async (): Promise<void> => {
5+
console.log(arch());
6+
assertEquals(await arch(), "x64");
67
});

0 commit comments

Comments
 (0)