Skip to content

Commit

Permalink
Move crash and common methods to util.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoborus committed Mar 13, 2024
1 parent 45a96e4 commit 57fea9f
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 39 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for Estilo 1, please check out
### Deno users

```sh
deno install -n estilo jsr:@jacoborus/estilo
deno install -n estilo --allow-write --allow-read jsr:@jacoborus/estilo
```

### Other plaforms
Expand All @@ -34,11 +34,7 @@ Commands:

- **`create [folder]`**: Create an estilo project in [folder] or current folder
- **`render [folder]`**: Render project in [folder] or current folder
- **`add-syntax`**: Add more syntax templates
- **`add-airline [styleName]`**: Add a new Airline style
- **`add-lightline [styleName]`**: Add a new Lightline style
- **`help [command]`**: Show this help or the help of a sub-command.
- **`--version`**: Show the version number.
- **`help [command]`**: Show this help

## Guide

Expand Down
2 changes: 1 addition & 1 deletion estilo.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import "./src/cli/cli.ts";
import "./src/cli.ts";
11 changes: 5 additions & 6 deletions src/cli/cli.ts → src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { resolve } from "jsr:@std/[email protected]";

import { existsSync } from "../common.ts";
import { crash } from "../crash.ts";
import { createProject } from "./create.ts";
import { loadProjectFiles } from "../load-project.ts";
import { renderProject } from "../render-project.ts";
import denojson from "../../deno.json" with { type: "json" };
import { crash, existsSync } from "./util.ts";
import { createProject } from "./create-project.ts";
import { loadProjectFiles } from "./load-project.ts";
import { renderProject } from "./render-project.ts";
import denojson from "../deno.json" with { type: "json" };

const helpText = `
Estilo ${denojson.version}
Expand Down
14 changes: 0 additions & 14 deletions src/crash.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/cli/create.ts → src/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ensureDirSync } from "jsr:@std/[email protected]";
import { basename, resolve } from "jsr:@std/[email protected]";
import { render } from "npm:[email protected]";

import { List } from "../types.ts";
import assets from "../assets.ts";
import { List } from "./types.ts";
import assets from "./assets.ts";

interface ProjectOptions {
name: string;
Expand Down
3 changes: 1 addition & 2 deletions src/format-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
SyntaxRule,
YmlFile,
} from "./types.ts";
import { crash } from "./crash.ts";
import { assertIsList } from "./common.ts";
import { assertIsList, crash } from "./util.ts";

function formatSyntaxFile(file: YmlFile): SyntaxRule[] {
const filepath = file.filepath;
Expand Down
5 changes: 2 additions & 3 deletions src/load-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import {
import {
assertIsList,
assertIsObject,
crash,
existsSync,
isHexColor,
} from "./common.ts";

import { crash } from "./crash.ts";
} from "./util.ts";

export function loadProjectFiles(projectUrl: string): Project {
const config = loadYml(projectUrl, "estilo.yml").content as ProjectConfig;
Expand Down
3 changes: 1 addition & 2 deletions src/render-colorscheme.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { render } from "npm:[email protected]";
import { hexterm } from "jsr:@jacoborus/[email protected]";
import assets from "./assets.ts";
import { crash } from "./crash.ts";
import denojson from "../deno.json" with { type: "json" };
import { isHexColor } from "./common.ts";
import { crash, isHexColor } from "./util.ts";
import { isLegacyUi, parseLegacyUi } from "./legacy-ui.ts";

import {
Expand Down
2 changes: 1 addition & 1 deletion src/render-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function renderProject(project: Project): Promise<void> {
const { config: projectConfig } = project;

for (const config of projectConfig.colorschemes) {
const rendered = await renderColorscheme(config, project);
const rendered = renderColorscheme(config, project);
writeThing("colors", rendered, config.name, project.projectUrl);
}

Expand Down
2 changes: 1 addition & 1 deletion src/render-status.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render } from "npm:[email protected]";
import denojson from "../deno.json" with { type: "json" };
import assets from "./assets.ts";
import { crash } from "./crash.ts";
import { crash } from "./util.ts";

import {
DataRenderStatus,
Expand Down
15 changes: 14 additions & 1 deletion src/common.ts → src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
import { crash } from "./crash.ts";
export function crash(message: string, data?: Record<string, string>): never {
console.log("%cError: " + message, "color: red");

if (data) {
console.log(
"%c" +
Object.keys(data)
.map((key) => `- ${key}: ${data[key]}`)
.join("\n"),
"color: red",
);
}
Deno.exit(1);
}

export function isHexColor(color: string): boolean {
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color);
Expand Down

0 comments on commit 57fea9f

Please sign in to comment.