@docuify/engine
Version:
A flexible, pluggable engine for building and transforming documentation content from source files.
82 lines (78 loc) • 3.03 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// lib/sources/localfile.ts
var localfile_exports = {};
__export(localfile_exports, {
LocalFile: () => LocalFile
});
module.exports = __toCommonJS(localfile_exports);
// lib/base/baseSource.ts
var BaseSource = class {
};
// lib/sources/localfile.ts
var import_promises = __toESM(require("fs/promises"));
var import_path = __toESM(require("path"));
var LocalFile = class extends BaseSource {
constructor(rootDir) {
super();
this.rootDir = rootDir;
this.rootDir = import_path.default.resolve(process.cwd(), rootDir);
}
name = "local-file-source";
// Recursively fetch files from the local directory
async fetch() {
const files = [];
await this._readDirRecursive(this.rootDir, files);
return files;
}
async _readDirRecursive(dir, files, parentPath = "") {
const entries = await import_promises.default.readdir(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = import_path.default.join(dir, entry.name);
const relativePath = parentPath ? `${parentPath}/${entry.name}` : entry.name;
if (entry.isDirectory()) {
await this._readDirRecursive(fullPath, files, relativePath);
} else if (entry.isFile()) {
files.push({
path: relativePath,
type: "file",
extension: import_path.default.extname(entry.name).slice(1),
// remove dot
loadContent: async () => {
return import_promises.default.readFile(fullPath, "utf-8");
}
});
}
}
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
LocalFile
});