← Files RivetARCHIVED FILE
node_modules/rivet-design/dist/services/staticProjectTarget.js
3.78 KB · Nov 5, 2026 · 12:09 UTC
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveStaticProjectTarget = exports.listStaticHtmlEntryFiles = exports.isStaticHtmlFilePath = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const pathContainment_1 = require("../utils/pathContainment");
const STATIC_HTML_EXTENSIONS = new Set(['.html', '.htm']);
const DEFAULT_STATIC_ENTRY = 'index.html';
const isStaticHtmlFilePath = (filePath) => STATIC_HTML_EXTENSIONS.has(path_1.default.extname(filePath).toLowerCase());
exports.isStaticHtmlFilePath = isStaticHtmlFilePath;
const listStaticHtmlEntryFiles = (projectPath) => {
if (!fs_1.default.existsSync(projectPath))
return [];
const stats = fs_1.default.statSync(projectPath);
if (!stats.isDirectory())
return [];
return fs_1.default
.readdirSync(projectPath, { withFileTypes: true })
.filter((entry) => entry.isFile() && (0, exports.isStaticHtmlFilePath)(entry.name))
.map((entry) => entry.name)
.sort((left, right) => left.localeCompare(right));
};
exports.listStaticHtmlEntryFiles = listStaticHtmlEntryFiles;
const normalizeEntryPath = (entryPath) => entryPath.split(path_1.default.sep).join('/');
const resolveEntryPath = (projectPath, entryPath) => {
const resolvedProjectPath = path_1.default.resolve(projectPath);
const resolvedEntryPath = path_1.default.isAbsolute(entryPath)
? path_1.default.resolve(entryPath)
: path_1.default.resolve(resolvedProjectPath, entryPath);
if (!(0, pathContainment_1.isPathStrictlyInsideRoot)(resolvedProjectPath, resolvedEntryPath)) {
throw new Error(`Static entry must be inside projectPath: ${entryPath}`);
}
return normalizeEntryPath(path_1.default.relative(resolvedProjectPath, resolvedEntryPath));
};
const resolveStaticProjectTarget = ({ targetPath, entryPath, }) => {
const resolvedTargetPath = path_1.default.resolve(targetPath);
if (!fs_1.default.existsSync(resolvedTargetPath)) {
throw new Error(`Project path does not exist: ${resolvedTargetPath}`);
}
const targetStats = fs_1.default.statSync(resolvedTargetPath);
if (targetStats.isFile()) {
if (!(0, exports.isStaticHtmlFilePath)(resolvedTargetPath)) {
throw new Error(`Static project file must be an HTML file: ${targetPath}`);
}
const projectPath = path_1.default.dirname(resolvedTargetPath);
return {
projectPath,
entryPath: path_1.default.basename(resolvedTargetPath),
htmlEntryFiles: (0, exports.listStaticHtmlEntryFiles)(projectPath),
};
}
if (!targetStats.isDirectory()) {
throw new Error(`Project path must be a directory or HTML file: ${targetPath}`);
}
const htmlEntryFiles = (0, exports.listStaticHtmlEntryFiles)(resolvedTargetPath);
if (entryPath) {
return {
projectPath: resolvedTargetPath,
entryPath: resolveEntryPath(resolvedTargetPath, entryPath),
htmlEntryFiles,
};
}
if (htmlEntryFiles.includes(DEFAULT_STATIC_ENTRY)) {
return {
projectPath: resolvedTargetPath,
entryPath: DEFAULT_STATIC_ENTRY,
htmlEntryFiles,
};
}
if (htmlEntryFiles.length === 1) {
return {
projectPath: resolvedTargetPath,
entryPath: htmlEntryFiles[0],
htmlEntryFiles,
};
}
return {
projectPath: resolvedTargetPath,
entryPath: DEFAULT_STATIC_ENTRY,
htmlEntryFiles,
};
};
exports.resolveStaticProjectTarget = resolveStaticProjectTarget;
//# sourceMappingURL=staticProjectTarget.js.mapSHA-256: f2aef08a81a2c0141c0b18169e00e9fe4ba6bdfbabf6429739dbdc40a8e19178