Skip to content

Commit

Permalink
Merge pull request #28 from nestdotland/dev
Browse files Browse the repository at this point in the history
0.8.2
  • Loading branch information
SteelAlloy authored Sep 13, 2020
2 parents 182b8a2 + ded8f77 commit e6ed4d6
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Internal module to help eggs handle global updates
## Module

```ts
import * from "https://x.nest.land/hatcher@0.8.1/mod.ts"
import * from "https://x.nest.land/hatcher@0.8.1/lib/registries.ts"
import * from "https://x.nest.land/hatcher@0.8.2/mod.ts"
import * from "https://x.nest.land/hatcher@0.8.2/lib/registries.ts"

/** Install update handler cli to check for updates and notify user */
function installUpdateHandler(moduleName: string, execName: string, updateCheckInterval?: number): Promise<void>
Expand All @@ -31,5 +31,5 @@ function analyzeURL(url: string): {
## CLI

```bash
deno run https://x.nest.land/hatcher@0.8.1/cli.ts <MODULE> <UPDATE_CHECK_INTERVAL> [ARGS...]
deno run https://x.nest.land/hatcher@0.8.2/cli.ts <MODULE> <UPDATE_CHECK_INTERVAL> [ARGS...]
```
21 changes: 10 additions & 11 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
export { writeJson } from "https://x.nest.land/std@0.65.0/fs/write_json.ts";

export { readJson } from "https://x.nest.land/std@0.65.0/fs/read_json.ts";

export * as colors from "https://x.nest.land/std@0.65.0/fmt/colors.ts";

export * as semver from "https://deno.land/x/semver@v1.0.0/mod.ts";

export { Table } from "https://x.nest.land/cliffy@0.11.1/table.ts";
/**************** std ****************/
export * as colors from "https://x.nest.land/std@0.69.0/fmt/colors.ts";

export {
assertEquals,
assertMatch,
assert,
} from "https://x.nest.land/std@0.65.0/testing/asserts.ts";
} from "https://x.nest.land/std@0.69.0/testing/asserts.ts";

export * as path from "https://x.nest.land/std@0.69.0/path/mod.ts";

/**************** semver ****************/
export * as semver from "https://deno.land/x/semver@v1.0.0/mod.ts";

export * as path from "https://x.nest.land/std@0.65.0/path/mod.ts";
/**************** cliffy ****************/
export { Table, Cell } from "https://x.nest.land/cliffy@0.14.1/table/mod.ts";
2 changes: 1 addition & 1 deletion egg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hatcher",
"description": "Utility module to handle module updates",
"version": "0.8.1",
"version": "0.8.2",
"unlisted": true,
"stable": true,
"files": [
Expand Down
1 change: 1 addition & 0 deletions foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("FOO");
3 changes: 2 additions & 1 deletion lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { path, readJson, writeJson } from "../deps.ts";
import { path } from "../deps.ts";
import { readJson, writeJson } from "./utilities/json.ts";

export type GlobalModuleConfig = {
[key: string]: GlobalModule;
Expand Down
2 changes: 1 addition & 1 deletion lib/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function installUpdateHandler(
"-A",
"-n",
module,
"https://x.nest.land/hatcher@0.8.1/cli.ts",
"https://x.nest.land/hatcher@0.8.2/cli.ts",
executable,
updateCheckInterval.toString(),
],
Expand Down
84 changes: 84 additions & 0 deletions lib/utilities/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Replacer = (key: string, value: any) => any;

export interface WriteJsonOptions extends Deno.WriteFileOptions {
replacer?: Array<number | string> | Replacer;
spaces?: number | string;
}

function serialize(
filePath: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
object: any,
options: WriteJsonOptions,
): string {
try {
const jsonString = JSON.stringify(
object,
options.replacer as string[],
options.spaces,
);
return `${jsonString}\n`;
} catch (err) {
err.message = `${filePath}: ${err.message}`;
throw err;
}
}

/* Writes an object to a JSON file. */
export async function writeJson(
filePath: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
object: any,
options: WriteJsonOptions = {},
): Promise<void> {
const jsonString = serialize(filePath, object, options);
await Deno.writeTextFile(filePath, jsonString, {
append: options.append,
create: options.create,
mode: options.mode,
});
}

/* Writes an object to a JSON file. */
export function writeJsonSync(
filePath: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
object: any,
options: WriteJsonOptions = {},
): void {
const jsonString = serialize(filePath, object, options);
Deno.writeTextFileSync(filePath, jsonString, {
append: options.append,
create: options.create,
mode: options.mode,
});
}

/** Reads a JSON file and then parses it into an object */
export async function readJson(filePath: string): Promise<unknown> {
const decoder = new TextDecoder("utf-8");

const content = decoder.decode(await Deno.readFile(filePath));

try {
return JSON.parse(content);
} catch (err) {
err.message = `${filePath}: ${err.message}`;
throw err;
}
}

/** Reads a JSON file and then parses it into an object */
export function readJsonSync(filePath: string): unknown {
const decoder = new TextDecoder("utf-8");

const content = decoder.decode(Deno.readFileSync(filePath));

try {
return JSON.parse(content);
} catch (err) {
err.message = `${filePath}: ${err.message}`;
throw err;
}
}
8 changes: 4 additions & 4 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { semver, Table } from "../deps.ts";
import { semver, Table, Cell } from "../deps.ts";

export const versionSubstitute = "${version}";

Expand Down Expand Up @@ -26,9 +26,9 @@ export function latest<T>(list: T[]) {
}

export function box(text: string) {
console.log("");
Table.from([[text]])
.padding(1)
new Table()
.header([Cell.from("").border(false)])
.body([[text]])
.indent(2)
.border(true)
.render();
Expand Down

0 comments on commit e6ed4d6

Please sign in to comment.