@codeandmoney/jargal 0.0.0-rc.0 → 0.0.0-rc.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.
@@ -3,20 +3,22 @@ import { readdir, readFile } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
 
5
5
  export function loadTemplates(templatesPath: string, scope?: string): ContextAction {
6
- return async function execute() {
7
- const templates: Map<string, { fullPath: string; realativePath: string; content: string }> = new Map();
6
+ return async function execute(params) {
7
+ const record = { ...params.context.templates } as Record<string, Map<string, { fullPath: string; realativePath: string; content: string }>>;
8
+
9
+ if (scope) {
10
+ Object.assign(record, { [scope]: new Map() });
11
+ }
8
12
 
9
13
  for await (const fullPath of walkDir(templatesPath)) {
10
14
  const realativePath = path.relative(templatesPath, fullPath);
11
15
 
12
16
  const contentRaw = await readFile(path.resolve(templatesPath, fullPath));
13
17
 
14
- const key = scope ? `${scope}::${realativePath}` : realativePath;
15
-
16
- templates.set(key, { content: new TextDecoder().decode(contentRaw), fullPath, realativePath });
18
+ record[scope ? scope : "templates"]?.set(realativePath, { content: new TextDecoder().decode(contentRaw), fullPath, realativePath });
17
19
  }
18
20
 
19
- return { templates };
21
+ return record;
20
22
  };
21
23
  }
22
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeandmoney/jargal",
3
- "version": "0.0.0-rc.0",
3
+ "version": "0.0.0-rc.2",
4
4
  "description": "Renderer",
5
5
  "license": "MIT",
6
6
  "author": "Code & Money Team",
package/runner.ts CHANGED
@@ -2,7 +2,7 @@ import { Renderer } from "./renderer.ts";
2
2
  import * as v from "valibot";
3
3
  import type { Action, Config, ExecuteActionParams, GeneratorParams } from "./types.ts";
4
4
  import { selectGenerator } from "./actions/select-generator.ts";
5
- import assert from "node:assert";
5
+ import assert from "node:assert/strict";
6
6
 
7
7
  export async function runGenerator({ context, generator, renderer }: GeneratorParams): Promise<void> {
8
8
  assert(generator);
@@ -78,8 +78,8 @@ const ConfigSchema = v.object({
78
78
  ),
79
79
  });
80
80
 
81
- export async function run(config_: Config): Promise<void> {
82
- const config = v.parse(ConfigSchema, config_);
81
+ export async function run(runConfig: Config): Promise<void> {
82
+ const config = v.parse(ConfigSchema, runConfig);
83
83
 
84
84
  if (config.generators.length === 1) {
85
85
  const generator = config.generators[0];
@@ -87,18 +87,15 @@ export async function run(config_: Config): Promise<void> {
87
87
  assert(generator);
88
88
 
89
89
  return await runGenerator({
90
- context: { errors: [], answers: {} },
90
+ context: { errors: [], answers: {}, context: {} },
91
91
  renderer: new Renderer(),
92
92
  generator,
93
93
  });
94
94
  }
95
95
 
96
96
  return await runGenerator({
97
- context: { errors: [], answers: {} },
97
+ context: { errors: [], answers: {}, context: {} },
98
98
  renderer: new Renderer(),
99
- generator: {
100
- name: "select",
101
- actions: [selectGenerator(config)],
102
- },
99
+ generator: { name: "select", actions: [selectGenerator(config)] },
103
100
  });
104
101
  }
package/types.ts CHANGED
@@ -7,6 +7,7 @@ export interface Config {
7
7
  export interface Context extends Record<string, unknown> {
8
8
  answers: Record<string, string | boolean | (string | boolean)[]>;
9
9
  errors: Error[];
10
+ context: Record<string, any>;
10
11
  }
11
12
 
12
13
  export type DeepReadonly<T> = {