first commit
This commit is contained in:
7
node_modules/hexo-fs/LICENSE
generated
vendored
Normal file
7
node_modules/hexo-fs/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2014 Tommy Chen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
163
node_modules/hexo-fs/README.md
generated
vendored
Normal file
163
node_modules/hexo-fs/README.md
generated
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
# hexo-fs
|
||||
|
||||
[](https://github.com/hexojs/hexo-fs/actions/workflows/ci.yml)
|
||||
[](https://www.npmjs.com/package/hexo-fs)
|
||||
[](https://coveralls.io/github/hexojs/hexo-fs)
|
||||
|
||||
File system module for [Hexo].
|
||||
|
||||
## Features
|
||||
|
||||
- Support for both Promise and callback interface.
|
||||
- Use [graceful-fs] to avoid EMFILE error and various improvements.
|
||||
- Use [chokidar] for consistent file watching.
|
||||
|
||||
## Installation
|
||||
|
||||
``` bash
|
||||
$ npm install hexo-fs --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
const fs = require('hexo-fs');
|
||||
```
|
||||
|
||||
> Some methods in the original fs module are not listed below, but they're available in hexo-fs.
|
||||
|
||||
### exists(path)
|
||||
|
||||
Test whether or not the given `path` exists by checking with the file system.
|
||||
|
||||
### existsSync(path)
|
||||
|
||||
Synchronous version of `fs.exists`.
|
||||
|
||||
### mkdirs(path)
|
||||
|
||||
Creates a directory and its parent directories if they does not exist.
|
||||
|
||||
### mkdirsSync(path)
|
||||
|
||||
Synchronous version of `fs.mkdirs`.
|
||||
|
||||
### writeFile(path, data, [options])
|
||||
|
||||
Writes data to a file.
|
||||
|
||||
Option | Description | Default
|
||||
--- | --- | ---
|
||||
`encoding` | File encoding | utf8
|
||||
`mode` | Mode | 438 (0666 in octal)
|
||||
`flag` | Flag | w
|
||||
|
||||
### writeFileSync(path, data, [options])
|
||||
|
||||
Synchronous version of `fs.writeFile`.
|
||||
|
||||
### appendFile(path, data, [options])
|
||||
|
||||
Appends data to a file.
|
||||
|
||||
Option | Description | Default
|
||||
--- | --- | ---
|
||||
`encoding` | File encoding | utf8
|
||||
`mode` | Mode | 438 (0666 in octal)
|
||||
`flag` | Flag | w
|
||||
|
||||
### appendFileSync(path, data, [options])
|
||||
|
||||
Synchronous version of `fs.appendFile`.
|
||||
|
||||
### copyFile(src, dest, [callback])
|
||||
|
||||
Copies a file from `src` to `dest`.
|
||||
|
||||
### copyDir(src, dest, [options])
|
||||
|
||||
Copies a directory from `src` to `dest`. It returns an array of copied files.
|
||||
|
||||
Option | Description | Default
|
||||
--- | --- | ---
|
||||
`ignoreHidden` | Ignore hidden files | true
|
||||
`ignorePattern` | Ignore files which pass the regular expression |
|
||||
|
||||
### listDir(path, [options])
|
||||
|
||||
Lists files in a directory.
|
||||
|
||||
Option | Description | Default
|
||||
--- | --- | ---
|
||||
`ignoreHidden` | Ignore hidden files | true
|
||||
`ignorePattern` | Ignore files which pass the regular expression |
|
||||
|
||||
### listDirSync(path, [options])
|
||||
|
||||
Synchronous version of `fs.listDir`.
|
||||
|
||||
### readFile(path, [options])
|
||||
|
||||
Reads the entire contents of a file.
|
||||
|
||||
Option | Description | Default
|
||||
--- | --- | ---
|
||||
`encoding` | File encoding | utf8
|
||||
`flag` | Flag | r
|
||||
`escape` | Escape UTF BOM and line ending in the content | true
|
||||
|
||||
### readFileSync(path, [options])
|
||||
|
||||
Synchronous version of `fs.readFile`.
|
||||
|
||||
### emptyDir(path, [options])
|
||||
|
||||
Deletes all files in a directory. It returns an array of deleted files.
|
||||
|
||||
Option | Description | Default
|
||||
--- | --- | ---
|
||||
`ignoreHidden` | Ignore hidden files | true
|
||||
`ignorePattern` | Ignore files which pass the regular expression |
|
||||
`exclude` | Ignore files in the array |
|
||||
|
||||
### emptyDirSync(path, [options])
|
||||
|
||||
Synchronous version of `fs.emptyDir`.
|
||||
|
||||
### rmdir(path)
|
||||
|
||||
Removes a directory and all files in it.
|
||||
|
||||
### rmdirSync(path)
|
||||
|
||||
Synchronous version of `fs.rmdir`.
|
||||
|
||||
### watch(path, [options])
|
||||
|
||||
Watches changes of a file or a directory.
|
||||
|
||||
See [Chokidar API](https://github.com/paulmillr/chokidar#api) for more info.
|
||||
|
||||
### ensurePath(path)
|
||||
|
||||
Ensures the given path is available to use or appends a number to the path.
|
||||
|
||||
### ensurePathSync(path)
|
||||
|
||||
Synchronous version of `fs.ensurePath`.
|
||||
|
||||
### ensureWriteStream(path, [options])
|
||||
|
||||
Creates the parent directories if they does not exist and returns a writable stream.
|
||||
|
||||
### ensureWriteStreamSync(path, [options])
|
||||
|
||||
Synchronous version of `fs.ensureWriteStream`.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[graceful-fs]: https://github.com/isaacs/node-graceful-fs
|
||||
[Hexo]: https://hexo.io/
|
||||
[chokidar]: https://github.com/paulmillr/chokidar
|
||||
131
node_modules/hexo-fs/dist/fs.d.ts
generated
vendored
Normal file
131
node_modules/hexo-fs/dist/fs.d.ts
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import type { WriteFileOptions } from 'fs';
|
||||
import chokidar, { WatchOptions } from 'chokidar';
|
||||
import BlueBirdPromise from 'bluebird';
|
||||
import fs from 'graceful-fs';
|
||||
import type { Stream } from 'stream';
|
||||
export declare function exists(path: string): BlueBirdPromise<boolean>;
|
||||
export declare function existsSync(path: string): boolean;
|
||||
export declare function mkdirs(path: string): BlueBirdPromise<string>;
|
||||
export declare function mkdirsSync(path: string): void;
|
||||
export declare function writeFile(path: string, data?: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | Stream, options?: WriteFileOptions): BlueBirdPromise<void>;
|
||||
export declare function writeFileSync(path: string, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): void;
|
||||
export declare function appendFile(path: string, data: string | Uint8Array, options?: WriteFileOptions): BlueBirdPromise<void>;
|
||||
export declare function appendFileSync(path: string, data: string | Uint8Array, options?: WriteFileOptions): void;
|
||||
export declare function copyFile(src: string, dest: string, flags?: number): BlueBirdPromise<void>;
|
||||
export type ReadDirOptions = {
|
||||
encoding?: BufferEncoding | null;
|
||||
withFileTypes?: false;
|
||||
ignoreHidden?: boolean;
|
||||
ignorePattern?: RegExp;
|
||||
};
|
||||
export declare function copyDir(src: string, dest: string, options?: ReadDirOptions): BlueBirdPromise<string[]>;
|
||||
export declare function listDir(path: string, options?: ReadDirOptions): BlueBirdPromise<string[]>;
|
||||
export declare function listDirSync(path: string, options?: ReadDirOptions): string[];
|
||||
export declare function escapeEOL(str: string): string;
|
||||
export declare function escapeBOM(str: string): string;
|
||||
export declare function escapeFileContent(content: string): string;
|
||||
export type ReadFileOptions = {
|
||||
encoding?: BufferEncoding | null;
|
||||
flag?: string;
|
||||
escape?: string;
|
||||
};
|
||||
export declare function readFile(path: string): BlueBirdPromise<string>;
|
||||
export declare function readFile(path: string, options?: ReadFileOptions | null): BlueBirdPromise<string | Buffer>;
|
||||
export declare function readFileSync(path: string): string;
|
||||
export declare function readFileSync(path: string, options?: ReadFileOptions): string | Buffer;
|
||||
export declare function emptyDir(path: string, options?: ReadDirOptions & {
|
||||
exclude?: string[];
|
||||
}): BlueBirdPromise<string[]>;
|
||||
export declare function emptyDirSync(path: string, options?: ReadDirOptions & {
|
||||
exclude?: string[];
|
||||
}): string[];
|
||||
export declare function rmdir(path: string): BlueBirdPromise<void>;
|
||||
export declare function rmdirSync(path: string): void;
|
||||
export declare function watch(path: string | ReadonlyArray<string>, options?: WatchOptions): BlueBirdPromise<chokidar.FSWatcher>;
|
||||
export declare function ensurePath(path: string): BlueBirdPromise<string>;
|
||||
export declare function ensurePathSync(path: string): string;
|
||||
export declare function ensureWriteStream(path: string, options?: BufferEncoding | {
|
||||
flags?: string;
|
||||
encoding?: BufferEncoding;
|
||||
fd?: number;
|
||||
mode?: number;
|
||||
autoClose?: boolean;
|
||||
emitClose?: boolean;
|
||||
start?: number;
|
||||
highWaterMark?: number;
|
||||
}): BlueBirdPromise<fs.WriteStream>;
|
||||
export declare function ensureWriteStreamSync(path: string, options?: BufferEncoding | {
|
||||
flags?: string;
|
||||
encoding?: BufferEncoding;
|
||||
fd?: number;
|
||||
mode?: number;
|
||||
autoClose?: boolean;
|
||||
emitClose?: boolean;
|
||||
start?: number;
|
||||
highWaterMark?: number;
|
||||
}): fs.WriteStream;
|
||||
export declare const access: (arg1: fs.PathLike) => BlueBirdPromise<unknown>;
|
||||
export declare const accessSync: typeof fs.accessSync;
|
||||
export declare const chmod: (arg1: fs.PathLike, arg2: fs.Mode) => BlueBirdPromise<unknown>;
|
||||
export declare const chmodSync: typeof fs.chmodSync;
|
||||
export declare const fchmod: (arg1: number, arg2: fs.Mode) => BlueBirdPromise<unknown>;
|
||||
export declare const fchmodSync: typeof fs.fchmodSync;
|
||||
export declare const lchmod: (arg1: fs.PathLike, arg2: fs.Mode) => BlueBirdPromise<unknown>;
|
||||
export declare const lchmodSync: typeof fs.lchmodSync;
|
||||
export declare const chown: (arg1: fs.PathLike, arg2: number, arg3: number) => BlueBirdPromise<unknown>;
|
||||
export declare const chownSync: typeof fs.chownSync;
|
||||
export declare const fchown: (arg1: number, arg2: number, arg3: number) => BlueBirdPromise<unknown>;
|
||||
export declare const fchownSync: typeof fs.fchownSync;
|
||||
export declare const lchown: (arg1: fs.PathLike, arg2: number, arg3: number) => BlueBirdPromise<unknown>;
|
||||
export declare const lchownSync: typeof fs.lchownSync;
|
||||
export declare const close: (arg1: number) => BlueBirdPromise<unknown>;
|
||||
export declare const closeSync: typeof fs.closeSync;
|
||||
export declare const createReadStream: typeof fs.createReadStream;
|
||||
export declare const createWriteStream: typeof fs.createWriteStream;
|
||||
export declare const fsync: (arg1: number) => BlueBirdPromise<unknown>;
|
||||
export declare const fsyncSync: typeof fs.fsyncSync;
|
||||
export declare const link: (arg1: fs.PathLike, arg2: fs.PathLike) => BlueBirdPromise<unknown>;
|
||||
export declare const linkSync: typeof fs.linkSync;
|
||||
export declare const mkdir: (arg1: fs.PathLike) => BlueBirdPromise<unknown>;
|
||||
export declare const mkdirSync: typeof fs.mkdirSync;
|
||||
export declare const open: (arg1: fs.PathLike) => BlueBirdPromise<number>;
|
||||
export declare const openSync: typeof fs.openSync;
|
||||
export declare const symlink: (arg1: fs.PathLike, arg2: fs.PathLike) => BlueBirdPromise<unknown>;
|
||||
export declare const symlinkSync: typeof fs.symlinkSync;
|
||||
export declare const read: (arg1: number) => BlueBirdPromise<number>;
|
||||
export declare const readSync: typeof fs.readSync;
|
||||
export declare const readdir: (arg1: fs.PathLike) => BlueBirdPromise<string[]>;
|
||||
export declare const readdirSync: typeof fs.readdirSync;
|
||||
export declare const readlink: (arg1: fs.PathLike) => BlueBirdPromise<string>;
|
||||
export declare const readlinkSync: typeof fs.readlinkSync;
|
||||
export declare const realpath: (arg1: fs.PathLike) => BlueBirdPromise<string>;
|
||||
export declare const realpathSync: typeof fs.realpathSync;
|
||||
export declare const rename: (arg1: fs.PathLike, arg2: fs.PathLike) => BlueBirdPromise<void>;
|
||||
export declare const renameSync: typeof fs.renameSync;
|
||||
export declare const stat: (arg1: fs.PathLike) => BlueBirdPromise<fs.Stats>;
|
||||
export declare const statSync: fs.StatSyncFn;
|
||||
export declare const fstat: (arg1: number) => BlueBirdPromise<unknown>;
|
||||
export declare const fstatSync: typeof fs.fstatSync;
|
||||
export declare const lstat: (arg1: fs.PathLike) => BlueBirdPromise<unknown>;
|
||||
export declare const lstatSync: fs.StatSyncFn;
|
||||
export declare const truncate: (arg1: fs.PathLike) => BlueBirdPromise<unknown>;
|
||||
export declare const truncateSync: typeof fs.truncateSync;
|
||||
export declare const ftruncate: (arg1: number) => BlueBirdPromise<unknown>;
|
||||
export declare const ftruncateSync: typeof fs.ftruncateSync;
|
||||
export declare const unlink: (arg1: fs.PathLike) => BlueBirdPromise<void>;
|
||||
export declare const unlinkSync: typeof fs.unlinkSync;
|
||||
export declare const utimes: (arg1: fs.PathLike, arg2: fs.TimeLike, arg3: fs.TimeLike) => BlueBirdPromise<unknown>;
|
||||
export declare const utimesSync: typeof fs.utimesSync;
|
||||
export declare const futimes: (arg1: number, arg2: fs.TimeLike, arg3: fs.TimeLike) => BlueBirdPromise<unknown>;
|
||||
export declare const futimesSync: typeof fs.futimesSync;
|
||||
export declare const watchFile: typeof fs.watchFile;
|
||||
export declare const unwatchFile: typeof fs.unwatchFile;
|
||||
export declare const write: (arg1: number, arg2: string) => BlueBirdPromise<number>;
|
||||
export declare const writeSync: typeof fs.writeSync;
|
||||
export declare const Stats: typeof fs.Stats;
|
||||
export declare const ReadStream: typeof fs.ReadStream;
|
||||
export declare const WriteStream: typeof fs.WriteStream;
|
||||
486
node_modules/hexo-fs/dist/fs.js
generated
vendored
Normal file
486
node_modules/hexo-fs/dist/fs.js
generated
vendored
Normal file
@@ -0,0 +1,486 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.mkdirSync = exports.mkdir = exports.linkSync = exports.link = exports.fsyncSync = exports.fsync = exports.createWriteStream = exports.createReadStream = exports.closeSync = exports.close = exports.lchownSync = exports.lchown = exports.fchownSync = exports.fchown = exports.chownSync = exports.chown = exports.lchmodSync = exports.lchmod = exports.fchmodSync = exports.fchmod = exports.chmodSync = exports.chmod = exports.accessSync = exports.access = exports.ensureWriteStreamSync = exports.ensureWriteStream = exports.ensurePathSync = exports.ensurePath = exports.watch = exports.rmdirSync = exports.rmdir = exports.emptyDirSync = exports.emptyDir = exports.readFileSync = exports.readFile = exports.escapeFileContent = exports.escapeBOM = exports.escapeEOL = exports.listDirSync = exports.listDir = exports.copyDir = exports.copyFile = exports.appendFileSync = exports.appendFile = exports.writeFileSync = exports.writeFile = exports.mkdirsSync = exports.mkdirs = exports.existsSync = exports.exists = void 0;
|
||||
exports.WriteStream = exports.ReadStream = exports.Stats = exports.writeSync = exports.write = exports.unwatchFile = exports.watchFile = exports.futimesSync = exports.futimes = exports.utimesSync = exports.utimes = exports.unlinkSync = exports.unlink = exports.ftruncateSync = exports.ftruncate = exports.truncateSync = exports.truncate = exports.lstatSync = exports.lstat = exports.fstatSync = exports.fstat = exports.statSync = exports.stat = exports.renameSync = exports.rename = exports.realpathSync = exports.realpath = exports.readlinkSync = exports.readlink = exports.readdirSync = exports.readdir = exports.readSync = exports.read = exports.symlinkSync = exports.symlink = exports.openSync = exports.open = void 0;
|
||||
const chokidar_1 = __importDefault(require("chokidar"));
|
||||
const bluebird_1 = __importDefault(require("bluebird"));
|
||||
const path_1 = require("path");
|
||||
const hexo_util_1 = require("hexo-util");
|
||||
const graceful_fs_1 = __importDefault(require("graceful-fs"));
|
||||
const fsPromises = graceful_fs_1.default.promises;
|
||||
const rEOL = /\r\n/g;
|
||||
function exists(path) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
const promise = fsPromises.access(path).then(() => true, error => {
|
||||
if (error.code !== 'ENOENT')
|
||||
throw error;
|
||||
return false;
|
||||
});
|
||||
return bluebird_1.default.resolve(promise);
|
||||
}
|
||||
exports.exists = exists;
|
||||
function existsSync(path) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
try {
|
||||
graceful_fs_1.default.accessSync(path);
|
||||
}
|
||||
catch (err) {
|
||||
if (err.code !== 'ENOENT')
|
||||
throw err;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.existsSync = existsSync;
|
||||
function mkdirs(path) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
return bluebird_1.default.resolve(fsPromises.mkdir(path, { recursive: true }));
|
||||
}
|
||||
exports.mkdirs = mkdirs;
|
||||
function mkdirsSync(path) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
graceful_fs_1.default.mkdirSync(path, { recursive: true });
|
||||
}
|
||||
exports.mkdirsSync = mkdirsSync;
|
||||
function checkParent(path) {
|
||||
return bluebird_1.default.resolve(fsPromises.mkdir((0, path_1.dirname)(path), { recursive: true }));
|
||||
}
|
||||
function writeFile(path, data, options) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
if (!data)
|
||||
data = '';
|
||||
return checkParent(path)
|
||||
.then(() => fsPromises.writeFile(path, data, options));
|
||||
}
|
||||
exports.writeFile = writeFile;
|
||||
function writeFileSync(path, data, options) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
graceful_fs_1.default.mkdirSync((0, path_1.dirname)(path), { recursive: true });
|
||||
graceful_fs_1.default.writeFileSync(path, data, options);
|
||||
}
|
||||
exports.writeFileSync = writeFileSync;
|
||||
function appendFile(path, data, options) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
return checkParent(path)
|
||||
.then(() => fsPromises.appendFile(path, data, options));
|
||||
}
|
||||
exports.appendFile = appendFile;
|
||||
function appendFileSync(path, data, options) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
graceful_fs_1.default.mkdirSync((0, path_1.dirname)(path), { recursive: true });
|
||||
graceful_fs_1.default.appendFileSync(path, data, options);
|
||||
}
|
||||
exports.appendFileSync = appendFileSync;
|
||||
function copyFile(src, dest, flags) {
|
||||
if (!src)
|
||||
throw new TypeError('src is required!');
|
||||
if (!dest)
|
||||
throw new TypeError('dest is required!');
|
||||
return checkParent(dest)
|
||||
.then(() => fsPromises.copyFile(src, dest, flags));
|
||||
}
|
||||
exports.copyFile = copyFile;
|
||||
const trueFn = () => true;
|
||||
function ignoreHiddenFiles(ignore) {
|
||||
if (!ignore)
|
||||
return trueFn;
|
||||
return ({ name }) => !name.startsWith('.');
|
||||
}
|
||||
function ignoreFilesRegex(regex) {
|
||||
if (!regex)
|
||||
return trueFn;
|
||||
return ({ name }) => !regex.test(name);
|
||||
}
|
||||
function ignoreExcludeFiles(arr, parent) {
|
||||
if (!arr || !arr.length)
|
||||
return trueFn;
|
||||
const set = new Set(arr);
|
||||
return ({ name }) => !set.has((0, path_1.join)(parent, name));
|
||||
}
|
||||
function _readAndFilterDir(path_2) {
|
||||
return __awaiter(this, arguments, void 0, function* (path, options = {}) {
|
||||
const { ignoreHidden = true, ignorePattern } = options;
|
||||
return (yield fsPromises.readdir(path, Object.assign(Object.assign({}, options), { withFileTypes: true })))
|
||||
.filter(ignoreHiddenFiles(ignoreHidden))
|
||||
.filter(ignoreFilesRegex(ignorePattern));
|
||||
});
|
||||
}
|
||||
function _readAndFilterDirSync(path, options) {
|
||||
const { ignoreHidden = true, ignorePattern } = options;
|
||||
return graceful_fs_1.default.readdirSync(path, Object.assign(Object.assign({}, options), { withFileTypes: true }))
|
||||
.filter(ignoreHiddenFiles(ignoreHidden))
|
||||
.filter(ignoreFilesRegex(ignorePattern));
|
||||
}
|
||||
function _copyDirWalker(src, dest, results, parent, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return bluebird_1.default.map(_readAndFilterDir(src, options), item => {
|
||||
const childSrc = (0, path_1.join)(src, item.name);
|
||||
const childDest = (0, path_1.join)(dest, item.name);
|
||||
const currentPath = (0, path_1.join)(parent, item.name);
|
||||
if (item.isDirectory()) {
|
||||
return _copyDirWalker(childSrc, childDest, results, currentPath, options);
|
||||
}
|
||||
results.push(currentPath);
|
||||
return copyFile(childSrc, childDest, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
function copyDir(src, dest, options = {}) {
|
||||
if (!src)
|
||||
throw new TypeError('src is required!');
|
||||
if (!dest)
|
||||
throw new TypeError('dest is required!');
|
||||
const results = [];
|
||||
return checkParent(dest)
|
||||
.then(() => _copyDirWalker(src, dest, results, '', options))
|
||||
.return(results);
|
||||
}
|
||||
exports.copyDir = copyDir;
|
||||
function _listDirWalker(path, results, parent, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const promises = [];
|
||||
for (const item of yield _readAndFilterDir(path, options)) {
|
||||
const currentPath = (0, path_1.join)(parent, item.name);
|
||||
if (item.isDirectory()) {
|
||||
promises.push(_listDirWalker((0, path_1.join)(path, item.name), results, currentPath, options));
|
||||
}
|
||||
else {
|
||||
results.push(currentPath);
|
||||
}
|
||||
}
|
||||
yield bluebird_1.default.all(promises);
|
||||
});
|
||||
}
|
||||
function listDir(path, options = {}) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
const results = [];
|
||||
return bluebird_1.default.resolve(_listDirWalker(path, results, '', options))
|
||||
.return(results);
|
||||
}
|
||||
exports.listDir = listDir;
|
||||
function _listDirSyncWalker(path, results, parent, options) {
|
||||
for (const item of _readAndFilterDirSync(path, options)) {
|
||||
const currentPath = (0, path_1.join)(parent, item.name);
|
||||
if (item.isDirectory()) {
|
||||
_listDirSyncWalker((0, path_1.join)(path, item.name), results, currentPath, options);
|
||||
}
|
||||
else {
|
||||
results.push(currentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
function listDirSync(path, options = {}) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
const results = [];
|
||||
_listDirSyncWalker(path, results, '', options);
|
||||
return results;
|
||||
}
|
||||
exports.listDirSync = listDirSync;
|
||||
function escapeEOL(str) {
|
||||
return str.replace(rEOL, '\n');
|
||||
}
|
||||
exports.escapeEOL = escapeEOL;
|
||||
function escapeBOM(str) {
|
||||
return str.charCodeAt(0) === 0xFEFF ? str.substring(1) : str;
|
||||
}
|
||||
exports.escapeBOM = escapeBOM;
|
||||
function escapeFileContent(content) {
|
||||
return escapeBOM(escapeEOL(content));
|
||||
}
|
||||
exports.escapeFileContent = escapeFileContent;
|
||||
function _readFile(path_2) {
|
||||
return __awaiter(this, arguments, void 0, function* (path, options = {}) {
|
||||
if (!Object.prototype.hasOwnProperty.call(options, 'encoding'))
|
||||
options.encoding = 'utf8';
|
||||
const content = yield fsPromises.readFile(path, options);
|
||||
if (options.escape == null || options.escape) {
|
||||
return escapeFileContent(content);
|
||||
}
|
||||
return content;
|
||||
});
|
||||
}
|
||||
function readFile(path, options) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
return bluebird_1.default.resolve(_readFile(path, options));
|
||||
}
|
||||
exports.readFile = readFile;
|
||||
function readFileSync(path, options = {}) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
if (!Object.prototype.hasOwnProperty.call(options, 'encoding'))
|
||||
options.encoding = 'utf8';
|
||||
const content = graceful_fs_1.default.readFileSync(path, options);
|
||||
if (options.escape == null || options.escape) {
|
||||
return escapeFileContent(content);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
exports.readFileSync = readFileSync;
|
||||
function _emptyDir(path, parent, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const entries = (yield _readAndFilterDir(path, options)).filter(ignoreExcludeFiles(options.exclude, parent));
|
||||
const results = [];
|
||||
yield bluebird_1.default.map(entries, (item) => {
|
||||
const fullPath = (0, path_1.join)(path, item.name);
|
||||
const currentPath = (0, path_1.join)(parent, item.name);
|
||||
if (item.isDirectory()) {
|
||||
return _emptyDir(fullPath, currentPath, options).then((files) => __awaiter(this, void 0, void 0, function* () {
|
||||
results.push(...files);
|
||||
if (!(yield fsPromises.readdir(fullPath)).length) {
|
||||
return fsPromises.rmdir(fullPath);
|
||||
}
|
||||
}));
|
||||
}
|
||||
results.push(currentPath);
|
||||
return fsPromises.unlink(fullPath);
|
||||
});
|
||||
return results;
|
||||
});
|
||||
}
|
||||
function emptyDir(path, options = {}) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
return bluebird_1.default.resolve(_emptyDir(path, '', options));
|
||||
}
|
||||
exports.emptyDir = emptyDir;
|
||||
function _emptyDirSync(path, options, parent) {
|
||||
const entries = _readAndFilterDirSync(path, options)
|
||||
.filter(ignoreExcludeFiles(options.exclude, parent));
|
||||
const results = [];
|
||||
for (const item of entries) {
|
||||
const childPath = (0, path_1.join)(path, item.name);
|
||||
const currentPath = (0, path_1.join)(parent, item.name);
|
||||
if (item.isDirectory()) {
|
||||
const removed = _emptyDirSync(childPath, options, currentPath);
|
||||
if (!graceful_fs_1.default.readdirSync(childPath).length) {
|
||||
rmdirSync(childPath);
|
||||
}
|
||||
results.push(...removed);
|
||||
}
|
||||
else {
|
||||
graceful_fs_1.default.unlinkSync(childPath);
|
||||
results.push(currentPath);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
function emptyDirSync(path, options = {}) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
return _emptyDirSync(path, options, '');
|
||||
}
|
||||
exports.emptyDirSync = emptyDirSync;
|
||||
function _rmdir(path) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const files = fsPromises.readdir(path, { withFileTypes: true });
|
||||
yield bluebird_1.default.map(files, (item) => {
|
||||
const childPath = (0, path_1.join)(path, item.name);
|
||||
return item.isDirectory() ? _rmdir(childPath) : fsPromises.unlink(childPath);
|
||||
});
|
||||
return fsPromises.rmdir(path);
|
||||
});
|
||||
}
|
||||
function rmdir(path) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
return bluebird_1.default.resolve(_rmdir(path));
|
||||
}
|
||||
exports.rmdir = rmdir;
|
||||
function _rmdirSync(path) {
|
||||
const files = graceful_fs_1.default.readdirSync(path, { withFileTypes: true });
|
||||
for (let i = 0, len = files.length; i < len; i++) {
|
||||
const item = files[i];
|
||||
const childPath = (0, path_1.join)(path, item.name);
|
||||
if (item.isDirectory()) {
|
||||
_rmdirSync(childPath);
|
||||
}
|
||||
else {
|
||||
graceful_fs_1.default.unlinkSync(childPath);
|
||||
}
|
||||
}
|
||||
graceful_fs_1.default.rmdirSync(path);
|
||||
}
|
||||
function rmdirSync(path) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
_rmdirSync(path);
|
||||
}
|
||||
exports.rmdirSync = rmdirSync;
|
||||
function watch(path, options) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
const watcher = chokidar_1.default.watch(path, options);
|
||||
return new bluebird_1.default((resolve, reject) => {
|
||||
watcher.on('ready', resolve);
|
||||
watcher.on('error', reject);
|
||||
}).thenReturn(watcher);
|
||||
}
|
||||
exports.watch = watch;
|
||||
function _findUnusedPath(path, files) {
|
||||
const ext = (0, path_1.extname)(path);
|
||||
const base = (0, path_1.basename)(path, ext);
|
||||
const regex = new RegExp(`^${(0, hexo_util_1.escapeRegExp)(base)}(?:-(\\d+))?${(0, hexo_util_1.escapeRegExp)(ext)}$`);
|
||||
let num = -1;
|
||||
for (let i = 0, len = files.length; i < len; i++) {
|
||||
const item = files[i];
|
||||
const match = item.match(regex);
|
||||
if (match == null)
|
||||
continue;
|
||||
const matchNum = match[1] ? parseInt(match[1], 10) : 0;
|
||||
if (matchNum > num) {
|
||||
num = matchNum;
|
||||
}
|
||||
}
|
||||
return (0, path_1.join)((0, path_1.dirname)(path), `${base}-${num + 1}${ext}`);
|
||||
}
|
||||
function _ensurePath(path) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!(yield exists(path)))
|
||||
return path;
|
||||
const files = yield fsPromises.readdir((0, path_1.dirname)(path));
|
||||
return _findUnusedPath(path, files);
|
||||
});
|
||||
}
|
||||
function ensurePath(path) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
return bluebird_1.default.resolve(_ensurePath(path));
|
||||
}
|
||||
exports.ensurePath = ensurePath;
|
||||
function ensurePathSync(path) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
if (!graceful_fs_1.default.existsSync(path))
|
||||
return path;
|
||||
const files = graceful_fs_1.default.readdirSync((0, path_1.dirname)(path));
|
||||
return _findUnusedPath(path, files);
|
||||
}
|
||||
exports.ensurePathSync = ensurePathSync;
|
||||
function ensureWriteStream(path, options) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
return checkParent(path)
|
||||
.then(() => graceful_fs_1.default.createWriteStream(path, options));
|
||||
}
|
||||
exports.ensureWriteStream = ensureWriteStream;
|
||||
function ensureWriteStreamSync(path, options) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required!');
|
||||
graceful_fs_1.default.mkdirSync((0, path_1.dirname)(path), { recursive: true });
|
||||
return graceful_fs_1.default.createWriteStream(path, options);
|
||||
}
|
||||
exports.ensureWriteStreamSync = ensureWriteStreamSync;
|
||||
// access
|
||||
['F_OK', 'R_OK', 'W_OK', 'X_OK'].forEach(key => {
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
value: graceful_fs_1.default.constants[key],
|
||||
writable: false
|
||||
});
|
||||
});
|
||||
exports.access = bluebird_1.default.promisify(graceful_fs_1.default.access);
|
||||
exports.accessSync = graceful_fs_1.default.accessSync;
|
||||
// chmod
|
||||
exports.chmod = bluebird_1.default.promisify(graceful_fs_1.default.chmod);
|
||||
exports.chmodSync = graceful_fs_1.default.chmodSync;
|
||||
exports.fchmod = bluebird_1.default.promisify(graceful_fs_1.default.fchmod);
|
||||
exports.fchmodSync = graceful_fs_1.default.fchmodSync;
|
||||
exports.lchmod = bluebird_1.default.promisify(graceful_fs_1.default.lchmod);
|
||||
exports.lchmodSync = graceful_fs_1.default.lchmodSync;
|
||||
// chown
|
||||
exports.chown = bluebird_1.default.promisify(graceful_fs_1.default.chown);
|
||||
exports.chownSync = graceful_fs_1.default.chownSync;
|
||||
exports.fchown = bluebird_1.default.promisify(graceful_fs_1.default.fchown);
|
||||
exports.fchownSync = graceful_fs_1.default.fchownSync;
|
||||
exports.lchown = bluebird_1.default.promisify(graceful_fs_1.default.lchown);
|
||||
exports.lchownSync = graceful_fs_1.default.lchownSync;
|
||||
// close
|
||||
exports.close = bluebird_1.default.promisify(graceful_fs_1.default.close);
|
||||
exports.closeSync = graceful_fs_1.default.closeSync;
|
||||
// createStream
|
||||
exports.createReadStream = graceful_fs_1.default.createReadStream;
|
||||
exports.createWriteStream = graceful_fs_1.default.createWriteStream;
|
||||
// fsync
|
||||
exports.fsync = bluebird_1.default.promisify(graceful_fs_1.default.fsync);
|
||||
exports.fsyncSync = graceful_fs_1.default.fsyncSync;
|
||||
// link
|
||||
exports.link = bluebird_1.default.promisify(graceful_fs_1.default.link);
|
||||
exports.linkSync = graceful_fs_1.default.linkSync;
|
||||
// mkdir
|
||||
exports.mkdir = bluebird_1.default.promisify(graceful_fs_1.default.mkdir);
|
||||
exports.mkdirSync = graceful_fs_1.default.mkdirSync;
|
||||
// open
|
||||
exports.open = bluebird_1.default.promisify(graceful_fs_1.default.open);
|
||||
exports.openSync = graceful_fs_1.default.openSync;
|
||||
// symlink
|
||||
exports.symlink = bluebird_1.default.promisify(graceful_fs_1.default.symlink);
|
||||
exports.symlinkSync = graceful_fs_1.default.symlinkSync;
|
||||
// read
|
||||
exports.read = bluebird_1.default.promisify(graceful_fs_1.default.read);
|
||||
exports.readSync = graceful_fs_1.default.readSync;
|
||||
// readdir
|
||||
exports.readdir = bluebird_1.default.promisify(graceful_fs_1.default.readdir);
|
||||
exports.readdirSync = graceful_fs_1.default.readdirSync;
|
||||
// readlink
|
||||
exports.readlink = bluebird_1.default.promisify(graceful_fs_1.default.readlink);
|
||||
exports.readlinkSync = graceful_fs_1.default.readlinkSync;
|
||||
// realpath
|
||||
exports.realpath = bluebird_1.default.promisify(graceful_fs_1.default.realpath);
|
||||
exports.realpathSync = graceful_fs_1.default.realpathSync;
|
||||
// rename
|
||||
exports.rename = bluebird_1.default.promisify(graceful_fs_1.default.rename);
|
||||
exports.renameSync = graceful_fs_1.default.renameSync;
|
||||
// stat
|
||||
exports.stat = bluebird_1.default.promisify(graceful_fs_1.default.stat);
|
||||
exports.statSync = graceful_fs_1.default.statSync;
|
||||
exports.fstat = bluebird_1.default.promisify(graceful_fs_1.default.fstat);
|
||||
exports.fstatSync = graceful_fs_1.default.fstatSync;
|
||||
exports.lstat = bluebird_1.default.promisify(graceful_fs_1.default.lstat);
|
||||
exports.lstatSync = graceful_fs_1.default.lstatSync;
|
||||
// truncate
|
||||
exports.truncate = bluebird_1.default.promisify(graceful_fs_1.default.truncate);
|
||||
exports.truncateSync = graceful_fs_1.default.truncateSync;
|
||||
exports.ftruncate = bluebird_1.default.promisify(graceful_fs_1.default.ftruncate);
|
||||
exports.ftruncateSync = graceful_fs_1.default.ftruncateSync;
|
||||
// unlink
|
||||
exports.unlink = bluebird_1.default.promisify(graceful_fs_1.default.unlink);
|
||||
exports.unlinkSync = graceful_fs_1.default.unlinkSync;
|
||||
// utimes
|
||||
exports.utimes = bluebird_1.default.promisify(graceful_fs_1.default.utimes);
|
||||
exports.utimesSync = graceful_fs_1.default.utimesSync;
|
||||
exports.futimes = bluebird_1.default.promisify(graceful_fs_1.default.futimes);
|
||||
exports.futimesSync = graceful_fs_1.default.futimesSync;
|
||||
// watch
|
||||
exports.watchFile = graceful_fs_1.default.watchFile;
|
||||
exports.unwatchFile = graceful_fs_1.default.unwatchFile;
|
||||
// write
|
||||
exports.write = bluebird_1.default.promisify(graceful_fs_1.default.write);
|
||||
exports.writeSync = graceful_fs_1.default.writeSync;
|
||||
// Static classes
|
||||
exports.Stats = graceful_fs_1.default.Stats;
|
||||
exports.ReadStream = graceful_fs_1.default.ReadStream;
|
||||
exports.WriteStream = graceful_fs_1.default.WriteStream;
|
||||
//# sourceMappingURL=fs.js.map
|
||||
1
node_modules/hexo-fs/dist/fs.js.map
generated
vendored
Normal file
1
node_modules/hexo-fs/dist/fs.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
55
node_modules/hexo-fs/package.json
generated
vendored
Normal file
55
node_modules/hexo-fs/package.json
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "hexo-fs",
|
||||
"version": "4.1.3",
|
||||
"description": "File system module for Hexo.",
|
||||
"main": "./dist/fs.js",
|
||||
"scripts": {
|
||||
"prepublish ": "npm install && npm run clean && npm run build",
|
||||
"build": "tsc -b",
|
||||
"clean": "tsc -b --clean",
|
||||
"eslint": "eslint .",
|
||||
"test": "mocha test/index.ts --require ts-node/register",
|
||||
"test-cov": "c8 --reporter=lcovonly npm run test"
|
||||
},
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"types": "./dist/fs.d.ts",
|
||||
"repository": "hexojs/hexo-fs",
|
||||
"homepage": "https://hexo.io/",
|
||||
"keywords": [
|
||||
"file",
|
||||
"file system",
|
||||
"fs",
|
||||
"hexo"
|
||||
],
|
||||
"author": "Tommy Chen <tommy351@gmail.com> (https://zespia.tw)",
|
||||
"maintainers": [
|
||||
"Abner Chou <hi@abnerchou.me> (https://abnerchou.me)"
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bluebird": "^3.7.2",
|
||||
"chokidar": "^3.5.3",
|
||||
"graceful-fs": "^4.2.10",
|
||||
"hexo-util": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bluebird": "^3.5.36",
|
||||
"@types/chai": "^4.3.12",
|
||||
"@types/graceful-fs": "^4.1.5",
|
||||
"@types/mocha": "^10.0.6",
|
||||
"@types/node": "^18.7.16 <18.19.9",
|
||||
"c8": "^9.1.0",
|
||||
"chai": "^4.3.6",
|
||||
"eslint": "^8.23.0",
|
||||
"eslint-config-hexo": "^5.0.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"mocha": "^10.0.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user