Skip to content

Commit 5c2f31e

Browse files
committed
fixed another bug with global modules
1 parent 11ce90b commit 5c2f31e

File tree

8 files changed

+97
-48
lines changed

8 files changed

+97
-48
lines changed

.github/workflows/publish.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
name: Publish
22
on:
3-
push:
4-
branches:
5-
- main
3+
push:
4+
branches:
5+
- main
66

77
jobs:
8-
publish:
9-
runs-on: ubuntu-latest
8+
publish:
9+
runs-on: ubuntu-latest
1010

11-
permissions:
12-
contents: read
13-
id-token: write
11+
permissions:
12+
contents: read
13+
id-token: write
1414

15-
steps:
16-
- name: Clone repository
17-
uses: actions/checkout@v4
15+
steps:
16+
- name: Clone repository
17+
uses: actions/checkout@v4
1818

19-
- name: Install Deno
20-
uses: denoland/setup-deno@v2
21-
with:
22-
deno-version: v2.x
19+
- name: Install Deno
20+
uses: denoland/setup-deno@v2
21+
with:
22+
deno-version: v2.x
2323

24-
- name: Format and lint
25-
run: deno task format
24+
- name: Format and lint
25+
run: deno task format
2626

27-
- name: Run tests
28-
run: deno task test
27+
- name: Run tests
28+
run: deno task test
2929

30-
- name: Publish package
31-
if: success()
32-
run: deno publish --allow-dirty
30+
- name: Publish package
31+
if: success()
32+
run: deno publish --allow-dirty

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"deno.enable": true,
3-
"deno.lint": true,
4-
}
3+
"deno.lint": true
4+
}

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,52 @@
11
## STEVE
2+
23
`STEVE` is a configurable template engine that allows JavaScript to run in files to create files. It has a plugin system to allow for custom generation and a built-in site generator.
34

4-
***ST***atic Sit***E*** Generator (***VE***ry cool)
5+
***ST***atic Sit_**E**_ Generator (***VE***ry cool)
56

67
### by AP
8+
79
#### Last Modified 11/18/24
810

911
## Features
1012

1113
`STEVE` supports many features including:
14+
1215
- Template engine that uses JavaScript to process the text
1316
- Built-in site generator plugin with highly customizable options
1417
- Plugin support to create different types of generators
1518

1619
## About The Project
20+
1721
I wanted to make a more official repository as my original goal, but I also wanted to create a file generator that I can use and expand upon because I do file generation a lot more than I thought I would. The product of this is `STEVE`, which has a template engine and plugin system.
1822

1923
### Documentation
24+
2025
All the features and explanations are in the documentation markdown file.
2126
[Documentation Link](https://github.com/CodingAP/steve/blob/main/documentation.md)
2227

2328
## How to Run
2429

25-
Node installation:
26-
`npx jsr add @codingap/steve`
30+
Node installation: `npx jsr add @codingap/steve`
31+
32+
Deno installation: `deno add jsr:@codingap/steve`
2733

28-
Deno installation:
29-
`deno add jsr:@codingap/steve`
34+
Bun installation: `bunx jsr add @codingap/steve`
3035

31-
Bun installation:
32-
`bunx jsr add @codingap/steve`
33-
3436
### Usage
3537

3638
```javascript
3739
import { STEVE } from '@codingap/steve';
3840

39-
STEVE.render('Hello <steve> return steve.data.name; </steve>!', { name: 'STEVE' });
41+
STEVE.render('Hello <steve> return steve.data.name; </steve>!', {
42+
name: 'STEVE',
43+
});
4044
```
4145

4246
Output:
47+
4348
```
4449
Hello STEVE!
4550
```
4651

47-
To see more instances of `STEVE` being used, go to the [Documentation](https://github.com/CodingAP/steve/blob/main/documentation.md)
52+
To see more instances of `STEVE` being used, go to the [Documentation](https://github.com/CodingAP/steve/blob/main/documentation.md)

deno.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codingap/steve",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"exports": "./index.ts",
55
"description": "STEVE is a configurable template engine that allows JavaScript to run in files to create files. It has a plugin system to allow for custom generation and a built-in site generator.",
66
"tasks": {
@@ -13,6 +13,7 @@
1313
},
1414
"fmt": {
1515
"indentWidth": 4,
16-
"singleQuote": true
16+
"singleQuote": true,
17+
"exclude": ["*.md"]
1718
}
1819
}

deno.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/steve.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,16 @@ class STEVE {
184184
augment = this.plugins[this.activePlugin].augment();
185185
}
186186

187+
const globalSTEVE: { [key: string]: unknown } = {
188+
include,
189+
data: _data,
190+
};
191+
187192
Object.keys(augment).forEach((key) => {
188193
const value = augment[key];
189194
if (typeof value === 'function') {
190195
// replace all instances of 'this' with 'this.plugins[this.activePlugin]'
191-
augment[key] = eval(
196+
globalSTEVE[key] = eval(
192197
value.toString().replace(
193198
/this/g,
194199
'this.plugins[this.activePlugin]',
@@ -197,12 +202,6 @@ class STEVE {
197202
}
198203
});
199204

200-
const globalSTEVE: { [key: string]: unknown } = {
201-
include,
202-
data: _data,
203-
...augment,
204-
};
205-
206205
return globalSTEVE;
207206
}
208207

src/plugin/site-generator.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ class SiteGenerator extends STEVEPlugin {
160160
if (existsSync(this.#outputDirectory)) {
161161
for (const file of walkSync(this.#outputDirectory)) {
162162
if (
163-
this.#ignoredFiles?.filter(filename => resolve(file.path).includes(filename)).length > 0 ||
163+
this.#ignoredFiles?.filter((filename) =>
164+
resolve(file.path).includes(filename)
165+
).length > 0 ||
164166
file.name.startsWith('.') ||
165167
resolve(this.#outputDirectory) === file.path
166168
) continue;
@@ -268,6 +270,13 @@ class SiteGenerator extends STEVEPlugin {
268270
* @returns the URL to the static file
269271
*/
270272
const staticFile = (file: string): string => {
273+
const existsSync = STEVE.globalModules.existsSync as (
274+
path: string,
275+
) => boolean;
276+
const join = STEVE.globalModules.join as (
277+
...paths: string[]
278+
) => string;
279+
271280
if (!this.staticDirectory) {
272281
throw new Error(
273282
"there is no 'staticDirectory' defined to get static file!",
@@ -285,12 +294,15 @@ class SiteGenerator extends STEVEPlugin {
285294
};
286295

287296
/**
288-
* joins paths together, ensuring a valid and consistent file
297+
* joins paths together, ensuring a valid and consistent file
289298
*
290299
* @param paths - the list of path segments to join
291300
* @returns the final joined path
292301
*/
293302
const joinPaths = (...paths: string[]): string => {
303+
const join = STEVE.globalModules.join as (
304+
...paths: string[]
305+
) => string;
294306
return join(...paths);
295307
};
296308

test/site-generator.test.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import { assertEquals, assertThrows } from 'jsr:@std/assert';
1111
import { ensureDir, exists } from 'jsr:@std/fs';
12-
import { GeneratorRoute, SingleRoute, SiteGenerator } from '../index.ts';
12+
import { GeneratorRoute, SingleRoute, SiteGenerator, STEVE } from '../index.ts';
1313

1414
// ~~~~~ SingleRoute testing ~~~~~
1515
Deno.test('SingleRoute: generates a single route with render content', () => {
@@ -277,10 +277,8 @@ Deno.test('SiteGenerator: handles ignored files correctly', async () => {
277277

278278
// Create SiteGenerator instance
279279
const generator = new SiteGenerator({
280-
staticDirectory: '',
281280
outputDirectory: outputDir,
282281
ignoredFiles: ['ignore.txt'],
283-
showExtension: false,
284282
});
285283

286284
// Define routes (empty for simplicity)
@@ -330,3 +328,30 @@ Deno.test('SiteGenerator: throws error when outputDirectory is not provided', ()
330328
"please provide an 'outputDirectory' for the files to go to!",
331329
);
332330
});
331+
332+
Deno.test('SiteGenerator: check to see if global modules work', async () => {
333+
const tempDir = await Deno.makeTempDir();
334+
const outputDir = `${tempDir}/output`;
335+
336+
// Create SiteGenerator instance
337+
STEVE.addPlugin(
338+
new SiteGenerator({
339+
outputDirectory: outputDir,
340+
}),
341+
);
342+
343+
// Generate the site
344+
STEVE.generate({
345+
root: new SingleRoute({
346+
render:
347+
'<steve> return steve.joinPaths(...steve.data.paths); </steve>',
348+
data: { paths: ['hello', 'world'] },
349+
}),
350+
});
351+
352+
const text = await Deno.readTextFile(`${outputDir}/index.html`);
353+
assertEquals(text.includes('hello\\world'), true);
354+
355+
// Cleanup
356+
await Deno.remove(tempDir, { recursive: true });
357+
});

0 commit comments

Comments
 (0)