ffbt
Version:
Build a Typescript app without pain
41 lines (40 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.locateEntrypoint = exports.locateDirectory = exports.locateFile = void 0;
const path_1 = require("path");
const findUp = require("find-up");
const fs_1 = require("fs");
function locateFile(name, cwd = "", raiseErrorIfNotExists = true) {
const locatedPath = findUp.sync(name, {
cwd,
type: "file",
});
if (!locatedPath && raiseErrorIfNotExists) {
throw new Error(`Can't find ${name}`);
}
return locatedPath || "";
}
exports.locateFile = locateFile;
function locateDirectory(name, cwd = "", raiseErrorIfNotExists = true) {
const locatedPath = findUp.sync(name, {
cwd,
type: "directory",
});
if (!locatedPath && raiseErrorIfNotExists) {
throw new Error(`Can't find ${name}`);
}
return locatedPath || "";
}
exports.locateDirectory = locateDirectory;
function locateEntrypoint(workdirPath, tsEntrypointName) {
const tsPath = path_1.resolve(workdirPath, `${tsEntrypointName}.ts`);
const tsxPath = path_1.resolve(workdirPath, `${tsEntrypointName}.tsx`);
if (fs_1.existsSync(tsPath)) {
return tsPath;
}
if (fs_1.existsSync(tsxPath)) {
return tsxPath;
}
throw new Error(`Can't find entrypoint by path ${tsPath}(x)`);
}
exports.locateEntrypoint = locateEntrypoint;