Skip to content

Commit

Permalink
✨ Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Nisgrak committed Jul 24, 2020
1 parent 38ab257 commit fba8559
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
with:
node-version: 12.17.0
- name: Setup package.json
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
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
- name: Install dependencies
run: npm install
- name: Release
Expand Down
50 changes: 19 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,53 @@
# 🏁 Deno Starter
# 🏁 Arch

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.
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

[![Deno CI](https://github.com/denorg/starter/workflows/Deno%20CI/badge.svg)](https://github.com/denorg/starter/actions)
[![GitHub](https://img.shields.io/github/license/denorg/starter)](https://github.com/denorg/starter/blob/master/LICENSE)
[![Contributors](https://img.shields.io/github/contributors/denorg/starter)](https://github.com/denorg/starter/graphs/contributors)
Use this package to get the actual operating system CPU architecture.

[![Deno CI](https://github.com/denorg/arch/workflows/Deno%20CI/badge.svg)](https://github.com/denorg/arch/actions)
[![GitHub](https://img.shields.io/github/license/denorg/arch)](https://github.com/denorg/arch/blob/master/LICENSE)
[![Contributors](https://img.shields.io/github/contributors/denorg/arch)](https://github.com/denorg/arch/graphs/contributors)
[![Deno Starter](https://img.shields.io/badge/deno-starter-brightgreen)](https://denorg.github.io/starter/)
[![Made by Denorg](https://img.shields.io/badge/made%20by-denorg-0082fb)](https://github.com/denorg)
[![TypeScript](https://img.shields.io/badge/types-TypeScript-blue)](https://github.com/denorg/starter)
[![TypeScript](https://img.shields.io/badge/types-TypeScript-blue)](https://github.com/denorg/arch)
[![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)

## 💡 How to use

1. [Create a new repository](https://github.com/denorg/starter/generate) using this template
2. Update the project name ("Deno Starter") from the first line in `README.md`
3. Find and replace "denorg/starter" with your "username/repository" in `README.md`
4. Update the "Getting started" guide with your exported functions' names
5. In `.github/workflows/*.yml` files, add additional permissions after `deno test`
6. Setup Semantic Release
- Add a repository secret `NPM_TOKEN` with your npm token
- In `.github/workflows/deno.yml`, find and replace "denorg/starter" with your "username/repository"
7. Remove this section ("How to use") after setting up your respoitory

If you're not building a Denorg project, the following steps are required too:

1. Remove the "A project by Denorg..." footer from `README.md`
2. Remove the "Made by Denorg" shield from the `README.md` badges section
3. Change the "Denorg" name to yours in `LICENSE` and under "License" in `README.md`

## ⭐ Getting started

Import the `mode` function and use it:
Import the default function and use it:

```ts
import { mode } from "https://raw.githubusercontent.com/denorg/starter/master/mod.ts";
import arch from "https://raw.githubusercontent.com/denorg/arch/master/mod.ts";

const result = mode();
const result = await arch();
```

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

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

```bash
dpx --allow-read starter <arguments>
dpx --allow-read arch <arguments>
```

### CLI

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

```bash
deno run --allow-read https://raw.githubusercontent.com/denorg/starter/master/cli.ts <arguments>
deno run --allow-read https://raw.githubusercontent.com/denorg/arch/master/cli.ts <arguments>
```

You can also install it globally using the following:

```bash
deno install --allow-read -n starter https://raw.githubusercontent.com/denorg/starter/master/cli.ts
deno install --allow-read -n arch https://raw.githubusercontent.com/denorg/arch/master/cli.ts
```

Then, the package is available to run:

```bash
starter <arguments>
arch <arguments>
```

### Configuration
Expand All @@ -80,6 +64,10 @@ Run tests:
deno test --allow-read
```

## ⭐ Related Work

- [feross/arch](https://github.com/feross/arch) is the Node.js project serving as inspiration for this one

## 📄 License

MIT © [Denorg](https://den.org.in)
Expand Down
4 changes: 2 additions & 2 deletions cli.ts
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());
}
}
55 changes: 52 additions & 3 deletions mod.ts
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'
}
7 changes: 4 additions & 3 deletions mod_test.ts
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");
});

0 comments on commit fba8559

Please sign in to comment.