writr 4.3.0 → 4.4.0
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.
- package/README.md +25 -4
- package/dist/writr.d.ts +1 -1
- package/dist/writr.js +25 -5
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -366,9 +366,8 @@ console.log(result); // Hello, Universe!
|
|
|
366
366
|
For `beforeRender` the data object is a `renderData` object. Here is the interface for `renderData`:
|
|
367
367
|
|
|
368
368
|
```typescript
|
|
369
|
-
export type renderData {
|
|
370
|
-
body: string
|
|
371
|
-
content: string;
|
|
369
|
+
export type renderData = {
|
|
370
|
+
body: string
|
|
372
371
|
options: RenderOptions;
|
|
373
372
|
}
|
|
374
373
|
```
|
|
@@ -376,11 +375,33 @@ export type renderData {
|
|
|
376
375
|
For `afterRender` the data object is a `resultData` object. Here is the interface for `resultData`:
|
|
377
376
|
|
|
378
377
|
```typescript
|
|
379
|
-
export type resultData {
|
|
378
|
+
export type resultData = {
|
|
380
379
|
result: string;
|
|
381
380
|
}
|
|
382
381
|
```
|
|
383
382
|
|
|
383
|
+
For `beforeSaveToFile` the data object is an object with the `filePath` and `content`. Here is the interface for `saveToFileData`:
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
export type saveToFileData = {
|
|
387
|
+
filePath: string;
|
|
388
|
+
content: string;
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
This is called when you call `saveToFile`, `saveToFileSync`.
|
|
393
|
+
|
|
394
|
+
For `beforeRenderToFile` the data object is an object with the `filePath` and `content`. Here is the interface for `renderToFileData`:
|
|
395
|
+
|
|
396
|
+
```typescript
|
|
397
|
+
export type renderToFileData = {
|
|
398
|
+
filePath: string;
|
|
399
|
+
content: string;
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
This is called when you call `renderToFile`, `renderToFileSync`.
|
|
404
|
+
|
|
384
405
|
# Code of Conduct and Contributing
|
|
385
406
|
[Code of Conduct](CODE_OF_CONDUCT.md) and [Contributing](CONTRIBUTING.md) guidelines.
|
|
386
407
|
|
package/dist/writr.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ declare enum WritrHooks {
|
|
|
53
53
|
beforeRender = "beforeRender",
|
|
54
54
|
afterRender = "afterRender",
|
|
55
55
|
beforeSaveToFile = "beforeSaveToFile",
|
|
56
|
-
|
|
56
|
+
beforeRenderToFile = "beforeRenderToFile",
|
|
57
57
|
beforeLoadFromFile = "beforeLoadFromFile",
|
|
58
58
|
afterLoadFromFile = "afterLoadFromFile"
|
|
59
59
|
}
|
package/dist/writr.js
CHANGED
|
@@ -58,7 +58,7 @@ var WritrHooks = /* @__PURE__ */ ((WritrHooks2) => {
|
|
|
58
58
|
WritrHooks2["beforeRender"] = "beforeRender";
|
|
59
59
|
WritrHooks2["afterRender"] = "afterRender";
|
|
60
60
|
WritrHooks2["beforeSaveToFile"] = "beforeSaveToFile";
|
|
61
|
-
WritrHooks2["
|
|
61
|
+
WritrHooks2["beforeRenderToFile"] = "beforeRenderToFile";
|
|
62
62
|
WritrHooks2["beforeLoadFromFile"] = "beforeLoadFromFile";
|
|
63
63
|
WritrHooks2["afterLoadFromFile"] = "afterLoadFromFile";
|
|
64
64
|
return WritrHooks2;
|
|
@@ -290,7 +290,12 @@ ${yamlString}---
|
|
|
290
290
|
const directoryPath = dirname(filePath);
|
|
291
291
|
const content = await this.render(options);
|
|
292
292
|
await mkdir(directoryPath, { recursive: true });
|
|
293
|
-
|
|
293
|
+
const data = {
|
|
294
|
+
filePath,
|
|
295
|
+
content
|
|
296
|
+
};
|
|
297
|
+
await this.hook("beforeRenderToFile" /* beforeRenderToFile */, data);
|
|
298
|
+
await writeFile(data.filePath, data.content);
|
|
294
299
|
} catch (error) {
|
|
295
300
|
this.emit("error", error);
|
|
296
301
|
if (this._options.throwErrors) {
|
|
@@ -308,7 +313,12 @@ ${yamlString}---
|
|
|
308
313
|
const directoryPath = dirname(filePath);
|
|
309
314
|
const content = this.renderSync(options);
|
|
310
315
|
fs.mkdirSync(directoryPath, { recursive: true });
|
|
311
|
-
|
|
316
|
+
const data = {
|
|
317
|
+
filePath,
|
|
318
|
+
content
|
|
319
|
+
};
|
|
320
|
+
this.hook("beforeRenderToFile" /* beforeRenderToFile */, data);
|
|
321
|
+
fs.writeFileSync(data.filePath, data.content);
|
|
312
322
|
} catch (error) {
|
|
313
323
|
this.emit("error", error);
|
|
314
324
|
if (this._options.throwErrors) {
|
|
@@ -363,7 +373,12 @@ ${yamlString}---
|
|
|
363
373
|
const { writeFile, mkdir } = fs.promises;
|
|
364
374
|
const directoryPath = dirname(filePath);
|
|
365
375
|
await mkdir(directoryPath, { recursive: true });
|
|
366
|
-
|
|
376
|
+
const data = {
|
|
377
|
+
filePath,
|
|
378
|
+
content: this._content
|
|
379
|
+
};
|
|
380
|
+
await this.hook("beforeSaveToFile" /* beforeSaveToFile */, data);
|
|
381
|
+
await writeFile(data.filePath, data.content);
|
|
367
382
|
} catch (error) {
|
|
368
383
|
this.emit("error", error);
|
|
369
384
|
if (this._options.throwErrors) {
|
|
@@ -380,7 +395,12 @@ ${yamlString}---
|
|
|
380
395
|
try {
|
|
381
396
|
const directoryPath = dirname(filePath);
|
|
382
397
|
fs.mkdirSync(directoryPath, { recursive: true });
|
|
383
|
-
|
|
398
|
+
const data = {
|
|
399
|
+
filePath,
|
|
400
|
+
content: this._content
|
|
401
|
+
};
|
|
402
|
+
this.hook("beforeSaveToFile" /* beforeSaveToFile */, data);
|
|
403
|
+
fs.writeFileSync(data.filePath, data.content);
|
|
384
404
|
} catch (error) {
|
|
385
405
|
this.emit("error", error);
|
|
386
406
|
if (this._options.throwErrors) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "writr",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "Markdown Rendering Simplified",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/writr.js",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"website:serve": "rimraf ./site/README.md ./site/dist && npx docula serve -s ./site -o ./site/dist"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"cacheable": "^1.8.
|
|
57
|
-
"hookified": "^1.
|
|
56
|
+
"cacheable": "^1.8.8",
|
|
57
|
+
"hookified": "^1.7.0",
|
|
58
58
|
"html-react-parser": "^5.2.2",
|
|
59
59
|
"js-yaml": "^4.1.0",
|
|
60
60
|
"react": "^19.0.0",
|
|
@@ -73,15 +73,15 @@
|
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/js-yaml": "^4.0.9",
|
|
76
|
-
"@types/node": "^22.
|
|
77
|
-
"@types/react": "^19.0.
|
|
78
|
-
"@vitest/coverage-v8": "^
|
|
79
|
-
"docula": "^0.
|
|
76
|
+
"@types/node": "^22.12.0",
|
|
77
|
+
"@types/react": "^19.0.8",
|
|
78
|
+
"@vitest/coverage-v8": "^3.0.4",
|
|
79
|
+
"docula": "^0.10.0",
|
|
80
80
|
"rimraf": "^6.0.1",
|
|
81
81
|
"ts-node": "^10.9.2",
|
|
82
|
-
"tsup": "^8.3.
|
|
83
|
-
"typescript": "^5.7.
|
|
84
|
-
"vitest": "^
|
|
82
|
+
"tsup": "^8.3.6",
|
|
83
|
+
"typescript": "^5.7.3",
|
|
84
|
+
"vitest": "^3.0.4",
|
|
85
85
|
"webpack": "^5.97.1",
|
|
86
86
|
"xo": "^0.60.0"
|
|
87
87
|
},
|