@static-pages/core 7.0.0-alpha.4 → 7.0.0-alpha.5
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/CHANGELOG.md +6 -6
- package/README.md +2 -2
- package/cjs/create-writer.d.ts +1 -1
- package/cjs/create-writer.js +31 -35
- package/cjs/static-pages.d.ts +1 -1
- package/cjs/static-pages.js +11 -12
- package/esm/create-writer.d.ts +1 -1
- package/esm/create-writer.js +32 -36
- package/esm/static-pages.d.ts +1 -1
- package/esm/static-pages.js +10 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
## 7.0.0
|
|
4
|
-
- New `CreateReader` and `CreateWriter` utilities available as `from` and `to` prop values.
|
|
5
|
-
-
|
|
3
|
+
## 7.0.0
|
|
4
|
+
- New `CreateReader` and `CreateWriter` utilities available as `route.from` and `route.to` prop values.
|
|
5
|
+
- Reverted `route.to` callbacks to work as it was in `v4.0.0`. The function is called per doucument, recieving the current page data.
|
|
6
6
|
- Type defintion improvements.
|
|
7
7
|
- Test suite switched from tap to mocha for now.
|
|
8
8
|
- Coverage reports switched from nyc to c8.
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
## 6.0.0
|
|
12
|
-
-
|
|
13
|
-
- Removed the `.teardown()` call on the
|
|
12
|
+
- Use JS iterator protocol for the `route.to` callbacks.
|
|
13
|
+
- Removed the `.teardown()` call on the `route.to` when iteration finished.
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
## 5.0.3
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
- Updated maintenance badge in README.md.
|
|
24
24
|
|
|
25
25
|
## 5.0.0
|
|
26
|
-
- Added a `.teardown()` call on the
|
|
26
|
+
- Added a `.teardown()` call on the `route.to` which is executed when iteration finished.
|
|
27
27
|
- Provided better type definitions.
|
|
28
28
|
|
|
29
29
|
|
package/README.md
CHANGED
|
@@ -93,8 +93,8 @@ Each route consists of a `from`, `to` and a `controller` property matching the d
|
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
95
|
interface Route<F, T> {
|
|
96
|
-
from?: Iterable<F> | AsyncIterable<F> |
|
|
97
|
-
to?: { (data:
|
|
96
|
+
from?: Iterable<F> | AsyncIterable<F> | createReader.Options<F>;
|
|
97
|
+
to?: { (data: T): MaybePromise<void>; } | createWriter.Options<T>;
|
|
98
98
|
controller?(data: F): MaybePromise<undefined | T | Iterable<T> | AsyncIterable<T>>;
|
|
99
99
|
}
|
|
100
100
|
|
package/cjs/create-writer.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare namespace createWriter {
|
|
|
8
8
|
onError?(error: unknown): MaybePromise<void>;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
export declare function createWriter<T>({ fs, cwd, name, render, onError, }?: createWriter.Options<T>): (
|
|
11
|
+
export declare function createWriter<T>({ fs, cwd, name, render, onError, }?: createWriter.Options<T>): (data: T) => Promise<void>;
|
|
12
12
|
export declare namespace createWriter {
|
|
13
13
|
var isOptions: <T>(x: unknown) => x is Options<T>;
|
|
14
14
|
}
|
package/cjs/create-writer.js
CHANGED
|
@@ -52,43 +52,39 @@ function createWriter({ fs = nodeFs, cwd = 'public', name = defaultNamer, render
|
|
|
52
52
|
throw new TypeError(`Expected 'function', recieved '${(0, helpers_js_1.getType)(name)}' at 'name' property.`);
|
|
53
53
|
if (typeof onError !== 'function')
|
|
54
54
|
throw new TypeError(`Expected 'function', recieved '${(0, helpers_js_1.getType)(onError)}' at 'onError' property.`);
|
|
55
|
-
return async function (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
else {
|
|
75
|
-
resolve(undefined);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
55
|
+
return async function (data) {
|
|
56
|
+
try {
|
|
57
|
+
const filepath = cwd + '/' + await name(data);
|
|
58
|
+
const dirpath = (0, node_path_1.dirname)(filepath);
|
|
59
|
+
await new Promise((resolve, reject) => {
|
|
60
|
+
fs.stat(dirpath, (err, stats) => {
|
|
61
|
+
if (err) {
|
|
62
|
+
fs.mkdir(dirpath, { recursive: true }, (err) => {
|
|
63
|
+
if (err) {
|
|
64
|
+
reject(err);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
resolve(undefined);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
resolve(undefined);
|
|
73
|
+
}
|
|
78
74
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
});
|
|
76
|
+
const content = await render(data);
|
|
77
|
+
await new Promise((resolve, reject) => {
|
|
78
|
+
fs.writeFile(filepath, content, (err) => {
|
|
79
|
+
if (err)
|
|
80
|
+
reject(err);
|
|
81
|
+
else
|
|
82
|
+
resolve(undefined);
|
|
87
83
|
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
await onError(error);
|
|
92
88
|
}
|
|
93
89
|
};
|
|
94
90
|
}
|
package/cjs/static-pages.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare namespace staticPages {
|
|
|
5
5
|
interface Route<F = unknown, T = unknown> {
|
|
6
6
|
from?: Iterable<F> | AsyncIterable<F> | createReader.Options<F>;
|
|
7
7
|
to?: {
|
|
8
|
-
(data:
|
|
8
|
+
(data: T): MaybePromise<void>;
|
|
9
9
|
} | createWriter.Options<T>;
|
|
10
10
|
controller?(data: F): MaybePromise<undefined | T | Iterable<T> | AsyncIterable<T>>;
|
|
11
11
|
}
|
package/cjs/static-pages.js
CHANGED
|
@@ -19,21 +19,20 @@ async function staticPages(...routes) {
|
|
|
19
19
|
throw new TypeError(`Expected 'function', recieved '${(0, helpers_js_1.getType)(to)}' at 'to' property.`);
|
|
20
20
|
if (typeof controller !== 'undefined' && typeof controller !== 'function')
|
|
21
21
|
throw new TypeError(`Expected 'function', recieved '${(0, helpers_js_1.getType)(controller)}' at 'controller' property.`);
|
|
22
|
-
await
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
else if (typeof data !== 'undefined') {
|
|
33
|
-
yield data;
|
|
22
|
+
for await (const data of from) {
|
|
23
|
+
const finalData = controller ? await controller(data) : data;
|
|
24
|
+
if ((0, helpers_js_1.isIterable)(finalData) || (0, helpers_js_1.isAsyncIterable)(finalData)) {
|
|
25
|
+
for await (const finalDataItem of finalData) {
|
|
26
|
+
await to(finalDataItem);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (typeof finalData !== 'undefined') {
|
|
30
|
+
await to(finalData);
|
|
31
|
+
}
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
34
|
}
|
|
35
|
+
exports.staticPages = staticPages;
|
|
37
36
|
staticPages.with = ({ from, to, controller }) => {
|
|
38
37
|
const withFunction = (newValue) => staticPages.with({
|
|
39
38
|
from: determineFrom(from, newValue.from),
|
package/esm/create-writer.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare namespace createWriter {
|
|
|
8
8
|
onError?(error: unknown): MaybePromise<void>;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
export declare function createWriter<T>({ fs, cwd, name, render, onError, }?: createWriter.Options<T>): (
|
|
11
|
+
export declare function createWriter<T>({ fs, cwd, name, render, onError, }?: createWriter.Options<T>): (data: T) => Promise<void>;
|
|
12
12
|
export declare namespace createWriter {
|
|
13
13
|
var isOptions: <T>(x: unknown) => x is Options<T>;
|
|
14
14
|
}
|
package/esm/create-writer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getType,
|
|
1
|
+
import { getType, isFilesystem } from './helpers.js';
|
|
2
2
|
import * as nodeFs from 'node:fs';
|
|
3
3
|
import { dirname } from 'node:path';
|
|
4
4
|
const defaultNamer = (data) => {
|
|
@@ -26,43 +26,39 @@ export function createWriter({ fs = nodeFs, cwd = 'public', name = defaultNamer,
|
|
|
26
26
|
throw new TypeError(`Expected 'function', recieved '${getType(name)}' at 'name' property.`);
|
|
27
27
|
if (typeof onError !== 'function')
|
|
28
28
|
throw new TypeError(`Expected 'function', recieved '${getType(onError)}' at 'onError' property.`);
|
|
29
|
-
return async function (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
else {
|
|
49
|
-
resolve(undefined);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
29
|
+
return async function (data) {
|
|
30
|
+
try {
|
|
31
|
+
const filepath = cwd + '/' + await name(data);
|
|
32
|
+
const dirpath = dirname(filepath);
|
|
33
|
+
await new Promise((resolve, reject) => {
|
|
34
|
+
fs.stat(dirpath, (err, stats) => {
|
|
35
|
+
if (err) {
|
|
36
|
+
fs.mkdir(dirpath, { recursive: true }, (err) => {
|
|
37
|
+
if (err) {
|
|
38
|
+
reject(err);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
resolve(undefined);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
resolve(undefined);
|
|
47
|
+
}
|
|
52
48
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
});
|
|
50
|
+
const content = await render(data);
|
|
51
|
+
await new Promise((resolve, reject) => {
|
|
52
|
+
fs.writeFile(filepath, content, (err) => {
|
|
53
|
+
if (err)
|
|
54
|
+
reject(err);
|
|
55
|
+
else
|
|
56
|
+
resolve(undefined);
|
|
61
57
|
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
await onError(error);
|
|
66
62
|
}
|
|
67
63
|
};
|
|
68
64
|
}
|
package/esm/static-pages.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare namespace staticPages {
|
|
|
5
5
|
interface Route<F = unknown, T = unknown> {
|
|
6
6
|
from?: Iterable<F> | AsyncIterable<F> | createReader.Options<F>;
|
|
7
7
|
to?: {
|
|
8
|
-
(data:
|
|
8
|
+
(data: T): MaybePromise<void>;
|
|
9
9
|
} | createWriter.Options<T>;
|
|
10
10
|
controller?(data: F): MaybePromise<undefined | T | Iterable<T> | AsyncIterable<T>>;
|
|
11
11
|
}
|
package/esm/static-pages.js
CHANGED
|
@@ -16,17 +16,16 @@ export async function staticPages(...routes) {
|
|
|
16
16
|
throw new TypeError(`Expected 'function', recieved '${getType(to)}' at 'to' property.`);
|
|
17
17
|
if (typeof controller !== 'undefined' && typeof controller !== 'function')
|
|
18
18
|
throw new TypeError(`Expected 'function', recieved '${getType(controller)}' at 'controller' property.`);
|
|
19
|
-
await
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
yield data;
|
|
19
|
+
for await (const data of from) {
|
|
20
|
+
const finalData = controller ? await controller(data) : data;
|
|
21
|
+
if (isIterable(finalData) || isAsyncIterable(finalData)) {
|
|
22
|
+
for await (const finalDataItem of finalData) {
|
|
23
|
+
await to(finalDataItem);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (typeof finalData !== 'undefined') {
|
|
27
|
+
await to(finalData);
|
|
28
|
+
}
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
}
|