Skip to content

Commit

Permalink
Deno import maps
Browse files Browse the repository at this point in the history
  • Loading branch information
ccalamos committed May 12, 2021
1 parent a2786f3 commit 6cc0f9b
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 41 deletions.
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<p align="center" class="badges-container">
<a href="https://github.com/ccalamos/barrel-cli/releases">
<img alt="Version" src="https://img.shields.io/github/v/release/ccalamos/barrel-cli?logo=github&color=blue" />
<img alt="Version" src="https://img.shields.io/github/v/release/ccalamos/barrel-cli?logo=github&include_prereleases" />
</a>
<a href="https://deno.land/">
<img alt="Deno version" src="https://img.shields.io/badge/deno-^1.9.2-blue?logo=deno" />
<img alt="Deno version" src="https://img.shields.io/badge/deno-^1.10.1-blue?logo=deno" />
</a>
<a href="./LICENSE">
<img alt="License" src="https://img.shields.io/github/license/ccalamos/barrel-cli?logo=github" />
Expand All @@ -25,24 +25,12 @@

This CLI tool can be installed in the following ways:

Deno:
Deno (Requires Deno v1.10 or higher):

```zsh
deno run -A https://deno.land/x/barrel/install.ts
```

HomeBrew:

```zsh
brew install barrel
```

GitHub:

```zsh
gh clone barrel-cli
```

## ❯ License

[MIT](LICENSE)
4 changes: 2 additions & 2 deletions commands/command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command as CLIMod } from "https://deno.land/x/cliffy@v0.18.2/command/mod.ts";
import type { ICommand } from "../types.ts";
import { Command as CLIMod } from "cliffy/command/mod.ts";
import type { ICommand } from "types";

export default class Command implements ICommand {
public name!: string;
Expand Down
6 changes: 3 additions & 3 deletions commands/login/getUserCode.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Request } from "../../utils/index.ts";
import { post } from "utils";
import type {
IGitHubGetUserCodePayload,
IGitHubGetUserCodeResponse,
} from "../../types.ts";
} from "types";

const PAYLOAD: IGitHubGetUserCodePayload = {
// deno-lint-ignore camelcase
client_id: "44d84527b1f7f3af59ed",
};

export default async function (): Promise<IGitHubGetUserCodeResponse> {
return await Request.post<IGitHubGetUserCodeResponse>(
return await post<IGitHubGetUserCodeResponse>(
"https://github.com/login/device/code",
PAYLOAD,
);
Expand Down
5 changes: 5 additions & 0 deletions commands/login/pollAuth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function () {
const _timeExpired = setTimeout(() => {
console.log("Done");
});
}
8 changes: 4 additions & 4 deletions commands/login/promptOpen.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { IGitHubGetUserCodeResponse } from "../../types.ts";
import { Open } from "../../utils/index.ts";
import { IGitHubGetUserCodeResponse } from "types";
import { open } from "utils";

function getPrompt(code: string): Uint8Array {
return new TextEncoder().encode([
"Allow `barrel` to access GitHub.",
"Please copy the code below and paste it into the redirect.",
`User Code: ${code}`,
"",
"Press Enter to Open GitHub:",
"Press Enter to Open the GitHub Redirect:",
].join("\n"));
}

Expand All @@ -16,7 +16,7 @@ export default async function (
) {
await Deno.stdout.write(getPrompt(gResponse.user_code));
await Deno.stdin.read(new Uint8Array(1024));
const status = await Open.url(gResponse.verification_uri);
const status = await open(gResponse.verification_uri);

if (!status.success) {
console.log("Failed to open GitHub...");
Expand Down
9 changes: 7 additions & 2 deletions commands/update/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getVersion } from "../../utils/version.ts";
import { getVersion } from "utils";

export default async function (isUpdate = false): Promise<void> {
export default async function updateCLI(isUpdate = false): Promise<void> {
console.log("Looking up latest version...");

const versionMetaUrl = "https://cdn.deno.land/barrel/meta/versions.json";
Expand All @@ -19,6 +19,7 @@ export default async function (isUpdate = false): Promise<void> {
"install",
"-A",
"--unstable",
`--import-map=https://deno.land/x/barrel@${latest}/import_map.json`,
"--location",
"http://0.0.0.0/",
"-n",
Expand All @@ -40,3 +41,7 @@ export default async function (isUpdate = false): Promise<void> {
}
Deno.exit(status.code);
}

if (import.meta.main) {
updateCLI(false);
}
3 changes: 2 additions & 1 deletion import_map.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"imports": {
"types": "./types.ts",
"utils/": "./utils/",
"utils": "./utils/index.ts",
"commands/": "./commands/",
"cliffy/": "https://deno.land/x/cliffy@v0.18.2/"
}
}
17 changes: 14 additions & 3 deletions install.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import InstallOrUpgrade from "./commands/update/upgrade.ts";

if (import.meta.main) {
await InstallOrUpgrade();
const installProcess = Deno.run({
cmd: [
Deno.execPath(),
"run",
"-A",
`--import-map=./import_map.json`,
`./commands/update/upgrade.ts`,
],
stdout: "inherit",
stderr: "inherit",
});
const status = await installProcess.status();

Deno.exit(status.code);
}
8 changes: 4 additions & 4 deletions program.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Command as CLIMod } from "https://deno.land/x/cliffy@v0.18.2/command/mod.ts";
import { Command as CLIMod } from "cliffy/command/mod.ts";

import Commands from "./commands/index.ts";
import { Version } from "./utils/index.ts";
import Commands from "commands/index.ts";
import { getVersion } from "utils";

const Program = new CLIMod();
Program.name("barrel");
Program.version(Version.getVersion());
Program.version(getVersion());
Program.description("Mono-Repo for Multi-Repos");
Program.allowEmpty(false);

Expand Down
6 changes: 3 additions & 3 deletions utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * as Version from "./version.ts";
export * as Request from "./request.ts";
export * as Open from "./open.ts";
export * from "./version.ts";
export * from "./request.ts";
export * from "./open.ts";
2 changes: 1 addition & 1 deletion utils/open.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export async function url(url: string): Promise<Deno.ProcessStatus> {
export async function open(url: string): Promise<Deno.ProcessStatus> {
const programAliases: Record<symbol | string, string> = {
windows: "explorer",
darwin: "open",
Expand Down
6 changes: 3 additions & 3 deletions utils/version.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IVersion, ValidVersion } from "../types.ts";
import { IVersion, ValidVersion } from "types";

const VERSION_INFO: IVersion = {
year: "21",
month: "05",
minor: "0",
patch: "11",
minor: "1",
patch: "0",
separator: ".",
prefix: "v",
};
Expand Down

0 comments on commit 6cc0f9b

Please sign in to comment.