-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deno install does not support deno.json imports
- Loading branch information
Showing
13 changed files
with
146 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
|
@@ -18,6 +14,7 @@ interface ProjectOptions { | |
description: string; | ||
} | ||
|
||
const decoder = new TextDecoder(); | ||
const defaultPalette = "myblue: '#99ccff'"; | ||
|
||
export async function createProject(projectPath: string, noQuestions: boolean) { | ||
|
@@ -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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
|
@@ -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", { | ||
|
@@ -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, | ||
|
@@ -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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
|
@@ -12,6 +12,8 @@ import { | |
StatusSyntax, | ||
} from "./types.ts"; | ||
|
||
const version = denojson.version; | ||
|
||
function parseStatusColors( | ||
syntax: StatusSyntax, | ||
palette: Palette, | ||
|