diff --git a/README.md b/README.md index b11cce2..7025066 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # www a "zero-config" static site builder mostly for me. write html to build sites out of html -with minimal tooling and mostly just html. +with minimal tooling and mostly just html. a companion to [www-os](https://github.com/tycobbb/www-os). it can build your site. it has a dev server that rebuilds as you make changes (though you still have to reload). it has templating (if you want it). it has build-time data (if you want it). it can change the directory it builds your site to! + ## install install [deno](#install-deno), if you haven't already. @@ -12,7 +13,7 @@ install [deno](#install-deno), if you haven't already. install the tool (this is a long one): ```sh -$ deno install --allow-env --allow-run --allow-read --allow-write --allow-net https://deno.land/x/wvvw@0.0.4/www.ts +$ deno install --allow-env --allow-run --allow-read --allow-write --allow-net https://deno.land/x/wvvw@0.0.5/www.ts ``` ### deno @@ -32,7 +33,7 @@ care about deno. to run the dev server: ```sh -$ www . --up +$ www --up . ``` to build your site @@ -44,7 +45,13 @@ $ www . to build your site for production: ```sh -$ www . --prod +$ www --prod . +``` + +to see help: + +```sh +$ www --help ``` ## structure @@ -61,8 +68,9 @@ maybe! i like it a lot. if you really just want to write html and want to repeat ## todos +- [ ] add `w-frag` (see [notes](./notes.md)) +- [ ] add `w-slot` (see [notes](./notes.md)) - [ ] init command -- [ ] cli options should be able to come after positional args - [ ] package a binary - [ ] ??? - [ ] you [tell me](https://github.com/tycobbb/www/issues) diff --git a/notes.md b/notes.md index f3cf6ff..043ca69 100644 --- a/notes.md +++ b/notes.md @@ -11,16 +11,16 @@ create a build-time include element w/ something like slots. eta's include synta down on complex partials imo, pretty cumbersome. preprocess: ```html - - +
footer
-
+ ``` into diff --git a/src/App/Config/Services/DecodeConfig.test.ts b/src/App/Config/Services/DecodeConfig.test.ts index 61feccb..3e8e5a8 100644 --- a/src/App/Config/Services/DecodeConfig.test.ts +++ b/src/App/Config/Services/DecodeConfig.test.ts @@ -5,14 +5,8 @@ import { assertEquals } from "../../../Test/mod.ts" const { test } = Deno // -- tests -- -test("it builds to a custom dir with the long arg", async () => { +test("it builds to a custom dir", async () => { const decode = new DecodeConfig({ _: ["."], dir: "test" }) const cfg = await decode.call() assertEquals(cfg.paths.dst.str, "test") -}) - -test("it builds to a custom dir with the short arg", async () => { - const decode = new DecodeConfig({ _: ["."], d: "test" }) - const cfg = await decode.call() - assertEquals(cfg.paths.dst.str, "test") }) \ No newline at end of file diff --git a/src/App/Config/Services/DecodeConfig.ts b/src/App/Config/Services/DecodeConfig.ts index 4b0351f..e43f5ea 100644 --- a/src/App/Config/Services/DecodeConfig.ts +++ b/src/App/Config/Services/DecodeConfig.ts @@ -28,7 +28,7 @@ export class DecodeConfig { // -- c/helpers #decodeEnv(): Env { const m = this - if (m.#args["p"] || m.#args["prod"] || Deno.env.get("PROD") != null) { + if (m.#args.prod || Deno.env.get("PROD") != null) { return Env.Prod } else { return Env.Dev @@ -54,7 +54,7 @@ export class DecodeConfig { } // parse dist path from cmd line args - const dist = Path.base(m.#args["d"] || m.#args["dir"] || "dist") + const dist = Path.base(m.#args.out || "dist") // produce paths return new Paths( diff --git a/src/Cli/Cli.test.ts b/src/Cli/Cli.test.ts new file mode 100644 index 0000000..ea8883c --- /dev/null +++ b/src/Cli/Cli.test.ts @@ -0,0 +1,30 @@ +import { assertEquals } from "../Test/mod.ts" +import { Cli } from "./Cli.ts" + +// -- setup -- +const { test } = Deno + +// -- tests -- +test("it parses options", () => { + const strs = ["-d", "output", "--verbose", "input", "-h"] + const args = Cli.parse(strs).args + + assertEquals(args._, [ + "input" + ]) + + assertEquals(args.help, true) + assertEquals(args.h, args.help) + + assertEquals(args.out, "output") + assertEquals(args.o, args.out) + + assertEquals(args.prod, false) + assertEquals(args.p, args.prod) + + assertEquals(args.up, false) + assertEquals(args.u, args.up) + + assertEquals(args.verbose, true) + assertEquals(args.v, args.verbose) +}) diff --git a/src/Cli/Cli.ts b/src/Cli/Cli.ts index 0dc3243..8b55cb8 100644 --- a/src/Cli/Cli.ts +++ b/src/Cli/Cli.ts @@ -51,7 +51,7 @@ export class Cli { options: -u, --up runs as a dev server -p, --prod runs production mode - -d, --dir

sets the output path + -o, --out

sets the output path -v, --verbose prints more logs -h, --help prints this message @@ -137,17 +137,17 @@ export class Cli { // if the `h/help` flag is set get isHelp(): boolean { - return this.#args.h || this.#args.help + return this.#args.help } // if the `v/verbose` flag is set get isVerbose(): boolean { - return this.#args.v || this.args.verbose + return this.#args.verbose } // if the `u/up` flag is set get isServerUp(): boolean { - return this.#args.u || this.#args.up + return this.#args.up } // draws a heredoc string; trims whitespace and leading padding @@ -178,6 +178,20 @@ export class Cli { // -- factories -- // build the cli from raw cmd line args static parse(args: string[]) { - return new Cli(parse(args)) + return new Cli(parse(args, { + alias: { + "h": "help", + "o": "out", + "p": "prod", + "u": "up", + "v": "verbose", + }, + boolean: [ + "help", + "prod", + "up", + "verbose", + ], + })) } }