@static-pages/core 7.0.0-alpha.2 → 7.0.0-alpha.3
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/cjs/create-reader.js +17 -8
- package/cjs/create-writer.js +1 -1
- package/cjs/helpers.d.ts +4 -17
- package/esm/create-reader.js +17 -8
- package/esm/create-writer.js +1 -1
- package/esm/helpers.d.ts +4 -17
- package/package.json +1 -1
package/cjs/create-reader.js
CHANGED
|
@@ -7,7 +7,6 @@ exports.createReader = void 0;
|
|
|
7
7
|
const picomatch_1 = __importDefault(require("picomatch"));
|
|
8
8
|
const autoparse_js_1 = require("./autoparse.js");
|
|
9
9
|
const helpers_js_1 = require("./helpers.js");
|
|
10
|
-
const node_path_1 = require("node:path");
|
|
11
10
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
12
11
|
async function* createReader({ fs = node_fs_1.default, cwd = 'pages', pattern, ignore, parse = autoparse_js_1.autoparse, onError = (error) => { throw error; }, } = {}) {
|
|
13
12
|
if (!(0, helpers_js_1.isFilesystem)(fs))
|
|
@@ -25,13 +24,23 @@ async function* createReader({ fs = node_fs_1.default, cwd = 'pages', pattern, i
|
|
|
25
24
|
if (typeof onError !== 'function')
|
|
26
25
|
throw new TypeError(`Expected 'function', recieved '${(0, helpers_js_1.getType)(onError)}' at 'onError' property.`);
|
|
27
26
|
let filenames = await new Promise((resolve, reject) => {
|
|
28
|
-
fs.readdir(cwd, {
|
|
27
|
+
fs.readdir(cwd, { recursive: true, withFileTypes: false, encoding: 'utf8' }, (err, entries) => {
|
|
29
28
|
if (err)
|
|
30
|
-
reject(err);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
return reject(err);
|
|
30
|
+
let filtered = [];
|
|
31
|
+
let processed = 0;
|
|
32
|
+
for (const entry of entries) {
|
|
33
|
+
fs.stat(cwd + '/' + entry, (err, stats) => {
|
|
34
|
+
if (err)
|
|
35
|
+
return reject(err);
|
|
36
|
+
if (stats.isFile()) {
|
|
37
|
+
filtered.push(entry);
|
|
38
|
+
}
|
|
39
|
+
if (++processed === entries.length) {
|
|
40
|
+
return resolve(filtered);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
35
44
|
});
|
|
36
45
|
});
|
|
37
46
|
if (typeof pattern !== 'undefined' || typeof ignore !== 'undefined') {
|
|
@@ -47,7 +56,7 @@ async function* createReader({ fs = node_fs_1.default, cwd = 'pages', pattern, i
|
|
|
47
56
|
for (const filename of filenames) {
|
|
48
57
|
try {
|
|
49
58
|
const content = await new Promise((resolve, reject) => {
|
|
50
|
-
fs.readFile(
|
|
59
|
+
fs.readFile(cwd + '/' + filename, (err, data) => {
|
|
51
60
|
if (err)
|
|
52
61
|
reject(err);
|
|
53
62
|
else
|
package/cjs/create-writer.js
CHANGED
|
@@ -25,8 +25,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.createWriter = void 0;
|
|
27
27
|
const helpers_js_1 = require("./helpers.js");
|
|
28
|
-
const node_path_1 = require("node:path");
|
|
29
28
|
const nodeFs = __importStar(require("node:fs"));
|
|
29
|
+
const node_path_1 = require("node:path");
|
|
30
30
|
const defaultNamer = (data) => {
|
|
31
31
|
if (!!data && typeof data === 'object' && 'url' in data && typeof data.url === 'string') {
|
|
32
32
|
return data.url.concat('.html');
|
package/cjs/helpers.d.ts
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
export type MaybePromise<T> = T | Promise<T>;
|
|
2
|
-
interface Stats {
|
|
3
|
-
isFile(): boolean;
|
|
4
|
-
isDirectory(): boolean;
|
|
5
|
-
}
|
|
6
|
-
interface Dirent {
|
|
7
|
-
name: string;
|
|
8
|
-
path: string;
|
|
9
|
-
isFile(): boolean;
|
|
10
|
-
isDirectory(): boolean;
|
|
11
|
-
}
|
|
12
2
|
export interface Filesystem {
|
|
3
|
+
stat(path: string | URL, callback: (err: Error | null, stats: {
|
|
4
|
+
isFile(): boolean;
|
|
5
|
+
isDirectory(): boolean;
|
|
6
|
+
}) => void): void;
|
|
13
7
|
readdir(path: string | URL, options: {
|
|
14
8
|
encoding: 'utf8';
|
|
15
9
|
withFileTypes: false;
|
|
16
10
|
recursive: boolean;
|
|
17
11
|
}, callback: (err: Error | null, files: string[]) => void): void;
|
|
18
|
-
readdir(path: string | URL, options: {
|
|
19
|
-
encoding: 'utf8';
|
|
20
|
-
withFileTypes: true;
|
|
21
|
-
recursive: boolean;
|
|
22
|
-
}, callback: (err: Error | null, files: Dirent[]) => void): void;
|
|
23
|
-
stat(path: string | URL, callback: (err: Error | null, stats: Stats) => void): void;
|
|
24
12
|
mkdir(path: string | URL, options: {
|
|
25
13
|
recursive: true;
|
|
26
14
|
}, callback: (err: Error | null, path?: string) => void): void;
|
|
@@ -31,4 +19,3 @@ export declare const isFilesystem: (x: unknown) => x is Filesystem;
|
|
|
31
19
|
export declare const isIterable: <T>(x: unknown) => x is Iterable<T>;
|
|
32
20
|
export declare const isAsyncIterable: <T>(x: unknown) => x is AsyncIterable<T>;
|
|
33
21
|
export declare const getType: (x: unknown) => string;
|
|
34
|
-
export {};
|
package/esm/create-reader.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import picomatch from 'picomatch';
|
|
2
2
|
import { autoparse } from './autoparse.js';
|
|
3
3
|
import { getType, isIterable, isAsyncIterable, isFilesystem } from './helpers.js';
|
|
4
|
-
import { join, relative } from 'node:path';
|
|
5
4
|
import nodeFs from 'node:fs';
|
|
6
5
|
export async function* createReader({ fs = nodeFs, cwd = 'pages', pattern, ignore, parse = autoparse, onError = (error) => { throw error; }, } = {}) {
|
|
7
6
|
if (!isFilesystem(fs))
|
|
@@ -19,13 +18,23 @@ export async function* createReader({ fs = nodeFs, cwd = 'pages', pattern, ignor
|
|
|
19
18
|
if (typeof onError !== 'function')
|
|
20
19
|
throw new TypeError(`Expected 'function', recieved '${getType(onError)}' at 'onError' property.`);
|
|
21
20
|
let filenames = await new Promise((resolve, reject) => {
|
|
22
|
-
fs.readdir(cwd, {
|
|
21
|
+
fs.readdir(cwd, { recursive: true, withFileTypes: false, encoding: 'utf8' }, (err, entries) => {
|
|
23
22
|
if (err)
|
|
24
|
-
reject(err);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
return reject(err);
|
|
24
|
+
let filtered = [];
|
|
25
|
+
let processed = 0;
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
fs.stat(cwd + '/' + entry, (err, stats) => {
|
|
28
|
+
if (err)
|
|
29
|
+
return reject(err);
|
|
30
|
+
if (stats.isFile()) {
|
|
31
|
+
filtered.push(entry);
|
|
32
|
+
}
|
|
33
|
+
if (++processed === entries.length) {
|
|
34
|
+
return resolve(filtered);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
29
38
|
});
|
|
30
39
|
});
|
|
31
40
|
if (typeof pattern !== 'undefined' || typeof ignore !== 'undefined') {
|
|
@@ -41,7 +50,7 @@ export async function* createReader({ fs = nodeFs, cwd = 'pages', pattern, ignor
|
|
|
41
50
|
for (const filename of filenames) {
|
|
42
51
|
try {
|
|
43
52
|
const content = await new Promise((resolve, reject) => {
|
|
44
|
-
fs.readFile(
|
|
53
|
+
fs.readFile(cwd + '/' + filename, (err, data) => {
|
|
45
54
|
if (err)
|
|
46
55
|
reject(err);
|
|
47
56
|
else
|
package/esm/create-writer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getType, isIterable, isAsyncIterable, isFilesystem } from './helpers.js';
|
|
2
|
-
import { dirname } from 'node:path';
|
|
3
2
|
import * as nodeFs from 'node:fs';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
4
|
const defaultNamer = (data) => {
|
|
5
5
|
if (!!data && typeof data === 'object' && 'url' in data && typeof data.url === 'string') {
|
|
6
6
|
return data.url.concat('.html');
|
package/esm/helpers.d.ts
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
export type MaybePromise<T> = T | Promise<T>;
|
|
2
|
-
interface Stats {
|
|
3
|
-
isFile(): boolean;
|
|
4
|
-
isDirectory(): boolean;
|
|
5
|
-
}
|
|
6
|
-
interface Dirent {
|
|
7
|
-
name: string;
|
|
8
|
-
path: string;
|
|
9
|
-
isFile(): boolean;
|
|
10
|
-
isDirectory(): boolean;
|
|
11
|
-
}
|
|
12
2
|
export interface Filesystem {
|
|
3
|
+
stat(path: string | URL, callback: (err: Error | null, stats: {
|
|
4
|
+
isFile(): boolean;
|
|
5
|
+
isDirectory(): boolean;
|
|
6
|
+
}) => void): void;
|
|
13
7
|
readdir(path: string | URL, options: {
|
|
14
8
|
encoding: 'utf8';
|
|
15
9
|
withFileTypes: false;
|
|
16
10
|
recursive: boolean;
|
|
17
11
|
}, callback: (err: Error | null, files: string[]) => void): void;
|
|
18
|
-
readdir(path: string | URL, options: {
|
|
19
|
-
encoding: 'utf8';
|
|
20
|
-
withFileTypes: true;
|
|
21
|
-
recursive: boolean;
|
|
22
|
-
}, callback: (err: Error | null, files: Dirent[]) => void): void;
|
|
23
|
-
stat(path: string | URL, callback: (err: Error | null, stats: Stats) => void): void;
|
|
24
12
|
mkdir(path: string | URL, options: {
|
|
25
13
|
recursive: true;
|
|
26
14
|
}, callback: (err: Error | null, path?: string) => void): void;
|
|
@@ -31,4 +19,3 @@ export declare const isFilesystem: (x: unknown) => x is Filesystem;
|
|
|
31
19
|
export declare const isIterable: <T>(x: unknown) => x is Iterable<T>;
|
|
32
20
|
export declare const isAsyncIterable: <T>(x: unknown) => x is AsyncIterable<T>;
|
|
33
21
|
export declare const getType: (x: unknown) => string;
|
|
34
|
-
export {};
|