@r_masseater/tako 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,51 @@
1
+ import { r as failWith, t as renderFigure } from "./render-y19FJtYB.mjs";
2
+ import { layer } from "@effect/platform-node/NodeServices";
3
+ import { Console, Effect, FileSystem, Option, Path, Schema } from "effect";
4
+ import { runMain } from "@effect/platform-node/NodeRuntime";
5
+ import { Argument, Command, Flag } from "effect/cli";
6
+ // package.json
7
+ var version = "0.2.2";
8
+ var description = "Draws infographics from a few lines of Typst: parts for the six kinds of element, flows, a hero number and bars, laid out automatically in light and dark.";
9
+ // src/entities/figure/model/request.ts
10
+ const THEMES = ["light", "dark"];
11
+ const FORMATS = ["svg", "pdf"];
12
+ Schema.Literals(THEMES);
13
+ Schema.Literals(FORMATS);
14
+ // src/app/cli.ts
15
+ const DEFAULT_FORMAT = "svg";
16
+ const SEQUENTIAL = { concurrency: 1 };
17
+ const writeFigures = Effect.fn("tako.render")(function* writeFigures(input) {
18
+ const path = yield* Path.Path;
19
+ const fileSystem = yield* FileSystem.FileSystem;
20
+ const { file, format } = input;
21
+ const themes = Option.match(input.theme, {
22
+ onNone: () => THEMES,
23
+ onSome: (theme) => [theme]
24
+ });
25
+ const stem = path.join(path.dirname(file), path.basename(file, path.extname(file)));
26
+ yield* Effect.forEach(themes, (theme) => Effect.gen(function* writeFigure() {
27
+ const output = yield* Effect.tryPromise({
28
+ try: () => renderFigure({
29
+ file,
30
+ theme,
31
+ format
32
+ }),
33
+ catch: failWith
34
+ });
35
+ const target = `${stem}.${theme}.${format}`;
36
+ yield* fileSystem.writeFile(target, output);
37
+ yield* Console.log(target);
38
+ }), SEQUENTIAL);
39
+ });
40
+ const render = Command.make("render", {
41
+ file: Argument.String("file").pipe(Argument.withDescription("The .typ file to draw")),
42
+ theme: Flag.Literals("theme", THEMES).pipe(Flag.withDescription("Draw only this theme (default: both)"), Flag.optional),
43
+ format: Flag.Literals("format", FORMATS).pipe(Flag.withDescription("The file format to write"), Flag.withDefault(DEFAULT_FORMAT))
44
+ }, writeFigures).pipe(Command.withDescription("Draws the figure next to the file, once for each theme"));
45
+ const tako = Command.make("tako").pipe(Command.withDescription(description), Command.withSubcommands([render]));
46
+ const runCli = () => {
47
+ runMain(Command.run(tako, { version }).pipe(Effect.provide(layer)));
48
+ };
49
+ export { runCli };
50
+
51
+ //# sourceMappingURL=cli-D2s2HM8e.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-D2s2HM8e.mjs","names":["manifest.description","manifest.version","nodeServices"],"sources":["../package.json","../src/entities/figure/model/request.ts","../src/app/cli.ts"],"sourcesContent":["","import { Schema } from \"effect\";\n\nexport const THEMES = [\"light\", \"dark\"] as const;\n\nexport const FORMATS = [\"svg\", \"pdf\"] as const;\n\nconst ThemeSchema = Schema.Literals(THEMES);\n\nconst FormatSchema = Schema.Literals(FORMATS);\n\nexport type Theme = typeof ThemeSchema.Type;\n\nexport type Format = typeof FormatSchema.Type;\n\nexport type Rendered = Uint8Array;\n\nexport interface RenderRequest {\n readonly file: string;\n readonly theme: Theme;\n readonly format: Format;\n}\n","import { runMain } from \"@effect/platform-node/NodeRuntime\";\nimport { layer as nodeServices } from \"@effect/platform-node/NodeServices\";\nimport manifest from \"@r_masseater/tako/package.json\" with { type: \"json\" };\nimport { Console, Effect, FileSystem, Option, Path } from \"effect\";\nimport { Argument, Command, Flag } from \"effect/cli\";\n\nimport { FORMATS, THEMES } from \"#/entities/figure/index.ts\";\nimport type { Format, Theme } from \"#/entities/figure/index.ts\";\nimport { failWith } from \"#/shared/lib/errors.ts\";\n\nimport { renderFigure } from \"./render.ts\";\n\nconst DEFAULT_FORMAT: Format = \"svg\";\nconst SEQUENTIAL = { concurrency: 1 } as const;\n\nconst writeFigures = Effect.fn(\"tako.render\")(function* writeFigures(input: {\n readonly file: string;\n readonly theme: Option.Option<Theme>;\n readonly format: Format;\n}) {\n const path = yield* Path.Path;\n const fileSystem = yield* FileSystem.FileSystem;\n const { file, format } = input;\n const themes = Option.match(input.theme, {\n onNone: (): readonly Theme[] => THEMES,\n onSome: (theme): readonly Theme[] => [theme],\n });\n const stem = path.join(path.dirname(file), path.basename(file, path.extname(file)));\n yield* Effect.forEach(\n themes,\n (theme) =>\n Effect.gen(function* writeFigure() {\n const output = yield* Effect.tryPromise({\n try: () => renderFigure({ file, theme, format }),\n catch: failWith,\n });\n const target = `${stem}.${theme}.${format}`;\n yield* fileSystem.writeFile(target, output);\n yield* Console.log(target);\n }),\n SEQUENTIAL,\n );\n});\n\nconst render = Command.make(\n \"render\",\n {\n file: Argument.String(\"file\").pipe(Argument.withDescription(\"The .typ file to draw\")),\n theme: Flag.Literals(\"theme\", THEMES).pipe(\n Flag.withDescription(\"Draw only this theme (default: both)\"),\n Flag.optional,\n ),\n format: Flag.Literals(\"format\", FORMATS).pipe(\n Flag.withDescription(\"The file format to write\"),\n Flag.withDefault(DEFAULT_FORMAT),\n ),\n },\n writeFigures,\n).pipe(Command.withDescription(\"Draws the figure next to the file, once for each theme\"));\n\nconst tako = Command.make(\"tako\").pipe(\n Command.withDescription(manifest.description),\n Command.withSubcommands([render]),\n);\n\nexport const runCli = (): void => {\n runMain(Command.run(tako, { version: manifest.version }).pipe(Effect.provide(nodeServices)));\n};\n"],"mappings":";;;;;;;;;ACEA,MAAa,SAAS,CAAC,SAAS,MAAM;AAEtC,MAAa,UAAU,CAAC,OAAO,KAAK;AAEhB,OAAO,SAAS,MAAM;AAErB,OAAO,SAAS,OAAO;;ACI5C,MAAM,iBAAyB;AAC/B,MAAM,aAAa,EAAE,aAAa,EAAE;AAEpC,MAAM,eAAe,OAAO,GAAG,aAAa,CAAC,CAAC,UAAU,aAAa,OAIlE;CACD,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,aAAa,OAAO,WAAW;CACrC,MAAM,EAAE,MAAM,WAAW;CACzB,MAAM,SAAS,OAAO,MAAM,MAAM,OAAO;EACvC,cAAgC;EAChC,SAAS,UAA4B,CAAC,KAAK;CAC7C,CAAC;CACD,MAAM,OAAO,KAAK,KAAK,KAAK,QAAQ,IAAI,GAAG,KAAK,SAAS,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC;CAClF,OAAO,OAAO,QACZ,SACC,UACC,OAAO,IAAI,UAAU,cAAc;EACjC,MAAM,SAAS,OAAO,OAAO,WAAW;GACtC,WAAW,aAAa;IAAE;IAAM;IAAO;GAAO,CAAC;GAC/C,OAAO;EACT,CAAC;EACD,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG;EACnC,OAAO,WAAW,UAAU,QAAQ,MAAM;EAC1C,OAAO,QAAQ,IAAI,MAAM;CAC3B,CAAC,GACH,UACF;AACF,CAAC;AAED,MAAM,SAAS,QAAQ,KACrB,UACA;CACE,MAAM,SAAS,OAAO,MAAM,CAAC,CAAC,KAAK,SAAS,gBAAgB,uBAAuB,CAAC;CACpF,OAAO,KAAK,SAAS,SAAS,MAAM,CAAC,CAAC,KACpC,KAAK,gBAAgB,sCAAsC,GAC3D,KAAK,QACP;CACA,QAAQ,KAAK,SAAS,UAAU,OAAO,CAAC,CAAC,KACvC,KAAK,gBAAgB,0BAA0B,GAC/C,KAAK,YAAY,cAAc,CACjC;AACF,GACA,YACF,CAAC,CAAC,KAAK,QAAQ,gBAAgB,wDAAwD,CAAC;AAExF,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC,CAAC,KAChC,QAAQ,gBAAgBA,WAAoB,GAC5C,QAAQ,gBAAgB,CAAC,MAAM,CAAC,CAClC;AAEA,MAAa,eAAqB;CAChC,QAAQ,QAAQ,IAAI,MAAM,EAAWC,QAAiB,CAAC,CAAC,CAAC,KAAK,OAAO,QAAQC,KAAY,CAAC,CAAC;AAC7F"}
package/dist/cli.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { enableCompileCache } from "node:module";
3
3
  // bin/tako.ts
4
4
  enableCompileCache();
5
- const { runCli } = await import("./cli-CSX4cCgd.mjs");
5
+ const { runCli } = await import("./cli-D2s2HM8e.mjs");
6
6
  runCli();
7
7
  export {};
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r_masseater/tako",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Draws infographics from a few lines of Typst: parts for the six kinds of element, flows, a hero number and bars, laid out automatically in light and dark.",
5
5
  "keywords": [
6
6
  "diagram",
@@ -1,70 +0,0 @@
1
- import { n as RenderError, r as failWith, t as renderFigure } from "./render-y19FJtYB.mjs";
2
- import { layer } from "@effect/platform-node/NodeServices";
3
- import { Array, Console, Effect, FileSystem, Option, Path, Schema } from "effect";
4
- import { parseArgs } from "node:util";
5
- import { runMain } from "@effect/platform-node/NodeRuntime";
6
- // src/entities/figure/model/request.ts
7
- const ThemeSchema = Schema.Literals(["light", "dark"]);
8
- const FormatSchema = Schema.Literals(["svg", "pdf"]);
9
- // src/app/cli.ts
10
- const ARGUMENTS_START = 2;
11
- const FILE_POSITION = 1;
12
- const SUBCOMMAND = "render";
13
- const DEFAULT_FORMAT = "svg";
14
- const SEQUENTIAL = { concurrency: 1 };
15
- const ALL_THEMES = ["light", "dark"];
16
- const USAGE = "usage: tako render <file.typ> [--theme light|dark] [--format svg|pdf]";
17
- const Flags = Schema.Struct({
18
- theme: Schema.optional(ThemeSchema),
19
- format: Schema.optional(FormatSchema)
20
- });
21
- const usageFailure = (reason) => RenderError.make({ message: `${reason}\n${USAGE}` });
22
- const parseFlags = (argv) => Effect.try({
23
- try: () => parseArgs({
24
- args: [...argv],
25
- allowPositionals: true,
26
- options: {
27
- theme: { type: "string" },
28
- format: { type: "string" }
29
- }
30
- }),
31
- catch: failWith
32
- }).pipe(Effect.flatMap(({ positionals, values }) => Schema.decodeUnknownEffect(Flags)(values).pipe(Effect.mapBoth({
33
- onSuccess: (flags) => ({
34
- positionals,
35
- flags
36
- }),
37
- onFailure: () => usageFailure("theme is light or dark and format is svg or pdf")
38
- }))));
39
- const program = Effect.gen(function* runProgram() {
40
- const path = yield* Path.Path;
41
- const fileSystem = yield* FileSystem.FileSystem;
42
- const { positionals, flags } = yield* parseFlags(process.argv.slice(ARGUMENTS_START));
43
- const file = yield* Array.get(positionals, FILE_POSITION).pipe(Effect.fromOption, Effect.mapError(() => usageFailure("missing file")));
44
- yield* Effect.filterOrFail(Effect.succeed(Array.head(positionals)), Option.contains(SUBCOMMAND), () => usageFailure("unknown command"));
45
- const format = Option.getOrElse(Option.fromNullishOr(flags.format), () => DEFAULT_FORMAT);
46
- const themes = Option.match(Option.fromNullishOr(flags.theme), {
47
- onNone: () => ALL_THEMES,
48
- onSome: (theme) => [theme]
49
- });
50
- const stem = path.join(path.dirname(file), path.basename(file, path.extname(file)));
51
- yield* Effect.forEach(themes, (theme) => Effect.gen(function* writeFigure() {
52
- const output = yield* Effect.tryPromise({
53
- try: () => renderFigure({
54
- file,
55
- theme,
56
- format
57
- }),
58
- catch: failWith
59
- });
60
- const target = `${stem}.${theme}.${format}`;
61
- yield* fileSystem.writeFile(target, output);
62
- yield* Console.log(target);
63
- }), SEQUENTIAL);
64
- }).pipe(Effect.catchTag("RenderError", (failure) => Console.error(failure.message)));
65
- const runCli = () => {
66
- runMain(program.pipe(Effect.provide(layer)));
67
- };
68
- export { runCli };
69
-
70
- //# sourceMappingURL=cli-CSX4cCgd.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli-CSX4cCgd.mjs","names":["Arr","nodeServices"],"sources":["../src/entities/figure/model/request.ts","../src/app/cli.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nexport const ThemeSchema = Schema.Literals([\"light\", \"dark\"]);\n\nexport const FormatSchema = Schema.Literals([\"svg\", \"pdf\"]);\n\nexport type Theme = typeof ThemeSchema.Type;\n\nexport type Format = typeof FormatSchema.Type;\n\nexport type Rendered = Uint8Array;\n\nexport interface RenderRequest {\n readonly file: string;\n readonly theme: Theme;\n readonly format: Format;\n}\n","import { parseArgs } from \"node:util\";\n\nimport { runMain } from \"@effect/platform-node/NodeRuntime\";\nimport { layer as nodeServices } from \"@effect/platform-node/NodeServices\";\nimport { Array as Arr, Console, Effect, FileSystem, Option, Path, Schema } from \"effect\";\n\nimport { FormatSchema, ThemeSchema } from \"#/entities/figure/index.ts\";\nimport type { Format, Theme } from \"#/entities/figure/index.ts\";\nimport { RenderError, failWith } from \"#/shared/lib/errors.ts\";\n\nimport { renderFigure } from \"./render.ts\";\n\nconst ARGUMENTS_START = 2;\nconst FILE_POSITION = 1;\nconst SUBCOMMAND = \"render\";\nconst DEFAULT_FORMAT: Format = \"svg\";\nconst SEQUENTIAL = { concurrency: 1 } as const;\nconst ALL_THEMES: readonly Theme[] = [\"light\", \"dark\"];\nconst USAGE = \"usage: tako render <file.typ> [--theme light|dark] [--format svg|pdf]\";\n\nconst Flags = Schema.Struct({\n theme: Schema.optional(ThemeSchema),\n format: Schema.optional(FormatSchema),\n});\n\nconst usageFailure = (reason: string): RenderError =>\n RenderError.make({ message: `${reason}\\n${USAGE}` });\n\nconst parseFlags = (\n argv: readonly string[],\n): Effect.Effect<\n { readonly positionals: readonly string[]; readonly flags: typeof Flags.Type },\n RenderError\n> =>\n Effect.try({\n try: () =>\n parseArgs({\n args: [...argv],\n allowPositionals: true,\n options: { theme: { type: \"string\" }, format: { type: \"string\" } },\n }),\n catch: failWith,\n }).pipe(\n Effect.flatMap(({ positionals, values }) =>\n Schema.decodeUnknownEffect(Flags)(values).pipe(\n Effect.mapBoth({\n onSuccess: (flags) => ({ positionals, flags }),\n onFailure: () => usageFailure(\"theme is light or dark and format is svg or pdf\"),\n }),\n ),\n ),\n );\n\nconst program = Effect.gen(function* runProgram() {\n const path = yield* Path.Path;\n const fileSystem = yield* FileSystem.FileSystem;\n const { positionals, flags } = yield* parseFlags(process.argv.slice(ARGUMENTS_START));\n const file = yield* Arr.get(positionals, FILE_POSITION).pipe(\n Effect.fromOption,\n Effect.mapError(() => usageFailure(\"missing file\")),\n );\n yield* Effect.filterOrFail(\n Effect.succeed(Arr.head(positionals)),\n Option.contains(SUBCOMMAND),\n () => usageFailure(\"unknown command\"),\n );\n const format = Option.getOrElse(Option.fromNullishOr(flags.format), () => DEFAULT_FORMAT);\n const themes = Option.match(Option.fromNullishOr(flags.theme), {\n onNone: () => ALL_THEMES,\n onSome: (theme) => [theme],\n });\n const stem = path.join(path.dirname(file), path.basename(file, path.extname(file)));\n yield* Effect.forEach(\n themes,\n (theme) =>\n Effect.gen(function* writeFigure() {\n const output = yield* Effect.tryPromise({\n try: () => renderFigure({ file, theme, format }),\n catch: failWith,\n });\n const target = `${stem}.${theme}.${format}`;\n yield* fileSystem.writeFile(target, output);\n yield* Console.log(target);\n }),\n SEQUENTIAL,\n );\n}).pipe(Effect.catchTag(\"RenderError\", (failure) => Console.error(failure.message)));\n\nexport const runCli = (): void => {\n runMain(program.pipe(Effect.provide(nodeServices)));\n};\n"],"mappings":";;;;;;AAEA,MAAa,cAAc,OAAO,SAAS,CAAC,SAAS,MAAM,CAAC;AAE5D,MAAa,eAAe,OAAO,SAAS,CAAC,OAAO,KAAK,CAAC;;ACQ1D,MAAM,kBAAkB;AACxB,MAAM,gBAAgB;AACtB,MAAM,aAAa;AACnB,MAAM,iBAAyB;AAC/B,MAAM,aAAa,EAAE,aAAa,EAAE;AACpC,MAAM,aAA+B,CAAC,SAAS,MAAM;AACrD,MAAM,QAAQ;AAEd,MAAM,QAAQ,OAAO,OAAO;CAC1B,OAAO,OAAO,SAAS,WAAW;CAClC,QAAQ,OAAO,SAAS,YAAY;AACtC,CAAC;AAED,MAAM,gBAAgB,WACpB,YAAY,KAAK,EAAE,SAAS,GAAG,OAAO,IAAI,QAAQ,CAAC;AAErD,MAAM,cACJ,SAKA,OAAO,IAAI;CACT,WACE,UAAU;EACR,MAAM,CAAC,GAAG,IAAI;EACd,kBAAkB;EAClB,SAAS;GAAE,OAAO,EAAE,MAAM,SAAS;GAAG,QAAQ,EAAE,MAAM,SAAS;EAAE;CACnE,CAAC;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