Skip to content

Commit 8780980

Browse files
committed
fix(core): remove default values
Signed-off-by: 90dy <90dy@proton.me>
1 parent 729ba1b commit 8780980

File tree

12 files changed

+34
-47
lines changed

12 files changed

+34
-47
lines changed

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TypeScript Template Engine
22

3-
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/90dy/typescript-template-engine/blob/main/LICENSE)
3+
[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](https://github.com/90dy/typescript-template-engine/blob/main/LICENSE)
44
[![GitHub stars](https://img.shields.io/github/stars/90dy/typescript-template-engine)](https://github.com/90dy/typescript-template-engine/stargazers)
55
[![GitHub issues](https://img.shields.io/github/issues/90dy/typescript-template-engine)](https://github.com/90dy/typescript-template-engine/issues)
66
[![VSCode Extension](https://img.shields.io/visual-studio-marketplace/v/90dy.ts-tmpl-engine-vscode?label=VSCode%20Extension)](https://marketplace.visualstudio.com/items?itemName=90dy.ts-tmpl-engine-vscode)
@@ -240,15 +240,9 @@ make generate-syntaxes
240240
# Sync version from deno.json to all workspace files
241241
make sync-version
242242
243-
# Build all packages
244-
make build
245-
246243
# Build the VSCode extension
247244
make build-extension
248245
249-
# Clean build artifacts
250-
make clean
251-
252246
# Run the demo
253247
make demo
254248
```

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.5.18",
2+
"version": "0.5.19",
33
"author": "90dy",
44
"license": "MIT",
55
"workspace": [

src/core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# @tmpl/core
22

33
[![JSR](https://jsr.io/badges/@tmpl/core)](https://jsr.io/@tmpl/core)
4-
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/90dy/typescript-template-engine/blob/main/LICENSE)
4+
[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](https://github.com/90dy/typescript-template-engine/blob/main/LICENSE)
55
[![GitHub](https://img.shields.io/badge/github-typescript--template--engine-blue.svg)](https://github.com/90dy/typescript-template-engine)
66
[![VSCode Extension](https://img.shields.io/visual-studio-marketplace/v/90dy.ts-tmpl-engine-vscode?label=VSCode%20Extension)](https://marketplace.visualstudio.com/items?itemName=90dy.ts-tmpl-engine-vscode)
77

src/core/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
"exports": {
2121
".": "./mod.ts"
2222
},
23-
"version": "0.5.18"
23+
"version": "0.5.19"
2424
}

src/core/mod.ts

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ export const LANGUAGES: Record<string, LanguageDefinition> = {
303303
class TemplateDocument<T> extends String {
304304
public readonly type: string;
305305
public readonly raw: string;
306-
public readonly data?: T;
306+
public data?: T;
307307
private readonly error?: Error;
308+
private parser?: (text: string) => unknown;
308309
constructor(
309310
type: string,
310311
template: { raw: readonly string[] | ArrayLike<string> },
@@ -333,21 +334,10 @@ class TemplateDocument<T> extends String {
333334
str = str.replace(/^\s+/gm, "");
334335
}
335336

336-
let data: T | undefined = undefined;
337-
let error = undefined;
338-
try {
339-
data = parser?.(str) as T;
340-
} catch (error) {
341-
if (options?.throw) {
342-
throw error;
343-
}
344-
console.warn(error);
345-
}
346337
super(str);
347338
this.type = type;
348339
this.raw = raw;
349-
this.data = data;
350-
this.error = error;
340+
this.parser = parser;
351341
}
352342

353343
[Symbol.for("Deno.customInspect")](): string {
@@ -375,17 +365,15 @@ class TemplateDocument<T> extends String {
375365
return this;
376366
}
377367
parse<TParsed = T>(
378-
parser: (text: string) => unknown,
368+
parser?: (text: string) => TParsed,
379369
): TemplateDocument<TParsed> {
380-
if (this.data) {
381-
return this as unknown as TemplateDocument<TParsed>;
370+
this.parser = parser ?? this.parser;
371+
try {
372+
this.data = this.parser?.(this.raw) as T;
373+
} catch (error) {
374+
console.warn(error);
382375
}
383-
return new TemplateDocument<TParsed>(
384-
this.type,
385-
{ raw: [this.raw] },
386-
[],
387-
parser,
388-
);
376+
return this as unknown as TemplateDocument<TParsed>;
389377
}
390378
}
391379

@@ -440,9 +428,9 @@ export const sql: Ext<"sql"> = ext("sql");
440428
export const graphql: Ext<"graphql"> = ext("graphql");
441429

442430
// Shell scripting
443-
export const sh: Ext<"sh"> = ext("sh", undefined, { indent: false });
444-
export const ps1: Ext<"ps1"> = ext("ps1", undefined, { indent: false });
445-
export const bat: Ext<"bat"> = ext("bat", undefined, { indent: false });
431+
export const sh: Ext<"sh"> = ext("sh");
432+
export const ps1: Ext<"ps1"> = ext("ps1");
433+
export const bat: Ext<"bat"> = ext("bat");
446434

447435
// Programming languages
448436
export const py: Ext<"py"> = ext("py");

src/core/mod_test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Deno.test("JSON template parses correctly", () => {
161161
"name": "${name}",
162162
"version": "${version}"
163163
}
164-
`;
164+
`.parse();
165165

166166
// Test that the template has parsed data
167167
assertEquals(jsonTemplate.data !== undefined, true);
@@ -176,7 +176,7 @@ Deno.test("YAML template parses correctly", () => {
176176
const yamlTemplate = yaml<{ name: string; version: string }>`
177177
name: ${name}
178178
version: ${version}
179-
`;
179+
`.parse();
180180

181181
// Test that the template has parsed data
182182
assertEquals(yamlTemplate.data !== undefined, true);
@@ -212,7 +212,7 @@ Deno.test("Custom extension template works correctly", () => {
212212

213213
Deno.test("Template with parser works correctly", () => {
214214
const parser = (text: string) => ({ parsed: text });
215-
const customTemplate = ext("custom", parser)<{ parsed: string }>`Test content`;
215+
const customTemplate = ext("custom", parser)<{ parsed: string }>`Test content`.parse();
216216

217217
// Test that the template has parsed data
218218
assertEquals(customTemplate.data !== undefined, true);

src/gen/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# @tmpl/gen
22

33
[![JSR](https://jsr.io/badges/@tmpl/gen)](https://jsr.io/@tmpl/gen)
4-
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/90dy/typescript-template-engine/blob/main/LICENSE)
4+
[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](https://github.com/90dy/typescript-template-engine/blob/main/LICENSE)
55
[![GitHub](https://img.shields.io/badge/github-typescript--template--engine-blue.svg)](https://github.com/90dy/typescript-template-engine)
66
[![VSCode Extension](https://img.shields.io/visual-studio-marketplace/v/90dy.ts-tmpl-engine-vscode?label=VSCode%20Extension)](https://marketplace.visualstudio.com/items?itemName=90dy.ts-tmpl-engine-vscode)
77

src/gen/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
"bin": {
3030
"tmpl-gen": "./runner.ts"
3131
},
32-
"version": "0.5.18"
32+
"version": "0.5.19"
3333
}

src/gen/fixtures/test-stdin.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
12
echo "Hello, World!"

src/gen/fixtures/test-variables.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
12
#!/bin/bash
3+
24
NODE_NAME=$(hostname)
35
EXTERNAL_IP=$(hostname -I | tr ' ' '\n' | head -1)
6+
47
// # 3. Patch node status (run as cluster-admin)
5-
sudo kubectl --kubeconfig ${kubeconfigPath} patch node ${NODE_NAME} \
6-
--subresource=status \
7-
--type=json \
8-
-p="[{'op':'add','path':'/status/addresses/-','value':{'type':'ExternalIP','address':'${EXTERNAL_IP}'}}]"
8+
sudo kubectl --kubeconfig /etc/kubernetes/admin.conf patch node ${NODE_NAME} \
9+
--subresource=status \
10+
--type=json \
11+
-p="[{'op':'add','path':'/status/addresses/-','value':{'type':'ExternalIP','address':'${EXTERNAL_IP}'}}]"
12+
913
# 4. Remove cloud provider taint
10-
sudo kubectl --kubeconfig ${kubeconfigPath} taint node ${NODE_NAME} node.cloudprovider.kubernetes.io/uninitialized-
14+
sudo kubectl --kubeconfig /etc/kubernetes/admin.conf taint node ${NODE_NAME} node.cloudprovider.kubernetes.io/uninitialized-

0 commit comments

Comments
 (0)