Skip to content

Commit

Permalink
Use inline imports
Browse files Browse the repository at this point in the history
Deno install does not support deno.json imports
  • Loading branch information
jacoborus committed Mar 13, 2024
1 parent 11d7d81 commit a8bb9ed
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 125 deletions.
18 changes: 1 addition & 17 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
{
"name": "@jacoborus/estilo",
"version": "2.0.0-beta.9",
"version": "2.0.0-beta.10",
"exports": "./estilo.ts",
"tasks": {
"bundle-assets": "deno run --allow-read --allow-write src/bundle-assets.ts",
"install": "deno task bundle-assets && deno install --allow-read --allow-write --allow-net --allow-env estilo.ts"
},
"test": {
"files": {
"include": [
"test/"
]
}
},
"imports": {
"eta/": "npm:[email protected]",
"@std/fs": "jsr:@std/[email protected]",
"@std/path": "jsr:@std/[email protected]",
"@std/yaml": "jsr:@std/[email protected]",
"cliffy/": "https://deno.land/x/[email protected]/",
"hexterm/": "npm:[email protected]/",
"@std/testing": "jsr:@std/[email protected]"
}
}
41 changes: 41 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions jsr.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/bundle-assets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { basename, extname, resolve } from "./deps.ts";
import { basename, extname, resolve } from "jsr:@std/[email protected]";

const __dirname = new URL(".", import.meta.url).pathname;

Expand Down
79 changes: 49 additions & 30 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,59 @@
import { Command, HelpCommand, resolve } from "../deps.ts";
import { resolve } from "jsr:@std/[email protected]";

import { version } from "../../jsr.json" with { type: "json" };
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";

const estiloCommand = new Command();

await estiloCommand
.command("help", new HelpCommand().global())
.reset()
.name("estilo")
.version(version)
.description("Generate colorschemes for (neo)vim, airline and lightline")
.command("create [folder]")
.description("Initialize an estilo project in [folder] or current folder")
.option("-y, --yes", "Skip questions")
.action((options: Record<string, boolean>, folder = ".") => {
createProject(resolve(folder), !!options.yes);
})
.reset()
.command("render [folder]")
.description("Render project")
.action((_: unknown, folder = ".") => {
const projectPath = resolve(folder);
checkProject(projectPath);
const project = loadProjectFiles(projectPath);
renderProject(project);
})
.reset()
.parse(Deno.args);

if (!Object.entries(Deno.args).length) {
estiloCommand.showHelp();
const helpText = `
Estilo: 2.0.0-beta-7
Generate colorschemes for (neo)vim, airline and lightline
Usage:
estilo create [folder] - Initialize an estilo project in [folder] or current directory
estilo create [folder] -y - Initialize with no questions
estilo render [folder] - Render project in [folder] or current directory
estilo help - Show instructions
`;

const command = Deno.args[0];
const target = Deno.args[1];

if (command === "help" || command === undefined) {
console.log(helpText);
Deno.exit();
}

if (command !== "render" && command !== "create") {
console.log("%cInvalid command", "color: red");
console.log(helpText);
}

if (command === "render") {
const projectPath = resolve(target ?? ".");
checkProject(projectPath);
const project = loadProjectFiles(projectPath);
await renderProject(project);
Deno.exit();
}

let projectPath = "";

let auto = false;
if (target === undefined || target === "-y") {
projectPath = resolve(".");
} else {
projectPath = resolve(target);
}
if (target === "-y") {
auto = true;
}

if (command === "create") {
createProject(projectPath, auto);
}

function checkProject(projectPath: string) {
Expand Down
78 changes: 35 additions & 43 deletions src/cli/create.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {
basename,
ensureDirSync,
Input,
prompt,
render,
resolve,
} from "../deps.ts";
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";

Expand All @@ -18,6 +14,7 @@ interface ProjectOptions {
description: string;
}

const decoder = new TextDecoder();
const defaultPalette = "myblue: '#99ccff'";

export async function createProject(projectPath: string, noQuestions: boolean) {
Expand All @@ -38,43 +35,38 @@ function getDefaultConfig(projectPath: string): ProjectOptions {
};
}

async function ask(question: string, defaultAnswer = "") {
console.log(
`%c${question}%c${defaultAnswer ? " (" + defaultAnswer + ")" : ""}`,
"font-weight: bold",
"font-weight: normal",
);
const buffer = new Uint8Array(1024);
await Deno.stdin.read(buffer);
const answer = decoder.decode(buffer);
return answer.split("\n")[0].trim() || defaultAnswer;
}

async function askConfig(projectPath: string) {
const folderName = basename(projectPath);
return await prompt([
{
type: Input,
name: "name",
message: "Project name:",
default: folderName,
},
{
type: Input,
name: "version",
message: "Version:",
default: "1.0.0",
},
{
type: Input,
name: "license",
message: "License:",
default: "MIT",
},
{
type: Input,
name: "author",
message: "Author:",
},
{
type: Input,
name: "url",
message: "Project url:",
},
{
type: Input,
name: "description",
message: "Description:",
},
]);
const defConfig = {
name: folderName,
author: "",
version: "1.0.0",
url: "",
license: "MIT",
description: "A (neo)vim colorscheme",
};

const config = {
name: await ask("Project name:", defConfig.name as string),
description: await ask("Description:"),
version: await ask("Version:", defConfig.version),
license: await ask("License:", defConfig.license),
author: await ask("Author:"),
url: await ask("URL:"),
};
return config;
}

async function createBoilerplate(projectPath: string, options: ProjectOptions) {
Expand Down
1 change: 0 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { crash } from "./crash.ts";
import jsr from "../jsr.json" with { type: "json" };

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

This file was deleted.

2 changes: 1 addition & 1 deletion src/format-project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { basename } from "./deps.ts";
import { basename } from "jsr:@std/[email protected]";

import {
List,
Expand Down
4 changes: 3 additions & 1 deletion src/load-project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { basename, hexterm, parse as yamlParse, resolve } from "./deps.ts";
import { parse as yamlParse } from "jsr:@std/[email protected]";
import { basename, resolve } from "jsr:@std/[email protected]";
import { hexterm } from "jsr:@jacoborus/hexterm";

import {
ColorObj,
Expand Down
15 changes: 9 additions & 6 deletions src/render-colorscheme.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { hexterm, render } from "./deps.ts";
import { render } from "npm:[email protected]";
import { hexterm } from "jsr:@jacoborus/hexterm";
import assets from "./assets.ts";
import { crash } from "./crash.ts";
import { version } from "../jsr.json" with { type: "json" };
import denojson from "../deno.json" with { type: "json" };
import { isHexColor } from "./common.ts";
import { isLegacyUi, parseLegacyUi } from "./legacy-ui.ts";

Expand All @@ -27,10 +28,12 @@ interface LinkValue {
link: string;
}

export async function renderColorscheme(
const version = denojson.version;

export function renderColorscheme(
config: SchemeConfig,
project: Project,
): Promise<string> {
): string {
const palette = project.palettes[config.palette];
if (!palette) {
crash("Colorscheme palette does not exist", {
Expand All @@ -39,7 +42,7 @@ export async function renderColorscheme(
});
}

return (await render(assets.mustaches["colorscheme"] as string, {
return render(assets.mustaches["colorscheme"] as string, {
info: {
name: config.name,
description: config.description,
Expand All @@ -51,7 +54,7 @@ export async function renderColorscheme(
},
stacks: parseSyntaxColors(project.syntax, palette),
term: parseTermColors(project.terminalSyntax, palette),
})) as string;
}) as string;
}

function parseTermColors(termSyntax: List, palette: Palette) {
Expand Down
3 changes: 2 additions & 1 deletion src/render-project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ensureDirSync, resolve } from "./deps.ts";
import { ensureDirSync } from "jsr:@std/[email protected]";
import { resolve } from "jsr:@std/[email protected]";
import { Project } from "./types.ts";
import { renderColorscheme } from "./render-colorscheme.ts";
import { renderStatus } from "./render-status.ts";
Expand Down
6 changes: 4 additions & 2 deletions src/render-status.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render } from "./deps.ts";
import { version } from "../jsr.json" with { type: "json" };
import { render } from "npm:[email protected]";
import denojson from "../deno.json" with { type: "json" };
import assets from "./assets.ts";
import { crash } from "./crash.ts";

Expand All @@ -12,6 +12,8 @@ import {
StatusSyntax,
} from "./types.ts";

const version = denojson.version;

function parseStatusColors(
syntax: StatusSyntax,
palette: Palette,
Expand Down

0 comments on commit a8bb9ed

Please sign in to comment.