ffbt
Version:
Build a Typescript app without pain
94 lines (93 loc) • 3.24 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProjectPaths = void 0;
const tslib_1 = require("tslib");
const path_1 = require("path");
const locate_1 = require("../core/locate");
const memoize_decorator_1 = require("../core/memoize-decorator");
const _1 = require("./");
class ProjectPaths {
constructor(config) {
this.config = config;
}
get sourcesDirectory() {
return this.config.sourcesDirectory;
}
get env() {
return this.config.env;
}
getAll() {
return {
ffbtRoot: this.ffbtRoot,
projectConfig: this.projectConfig,
projectPackageJson: this.projectPackageJson,
projectRoot: this.projectRoot,
projectWorkingDirectory: this.projectWorkingDirectory,
projectNodeModules: this.projectNodeModules,
projectEntrypoint: this.projectEntrypoint,
projectTsConfig: this.projectTsConfig,
destination: this.destination,
};
}
get ffbtRoot() {
return path_1.dirname(locate_1.locateFile("package.json", __dirname));
}
get projectConfig() {
return _1.ProjectConfig.getPathToConfigFile(this.sourcesDirectory);
}
get projectPackageJson() {
return locate_1.locateFile("package.json", this.sourcesDirectory, false) || null;
}
get projectRoot() {
const rootsInPriority = [
this.projectConfig,
this.projectPackageJson,
this.projectWorkingDirectory,
];
const firstValidRoot = rootsInPriority.find((path) => Boolean(path));
if (!firstValidRoot) {
throw new Error("Can't determine the project's root");
}
return path_1.dirname(firstValidRoot);
}
get projectWorkingDirectory() {
return this.sourcesDirectory;
}
get projectNodeModules() {
return locate_1.locateDirectory("node_modules", this.sourcesDirectory, false) || null;
}
get projectEntrypoint() {
return locate_1.locateEntrypoint(this.sourcesDirectory, this.env.entrypointName);
}
get projectTsConfig() {
return locate_1.locateFile(this.env.tsconfigPath, this.projectRoot);
}
get destination() {
return path_1.resolve(this.projectRoot, this.env.outputPath);
}
}
tslib_1.__decorate([
memoize_decorator_1.Memoize()
], ProjectPaths.prototype, "ffbtRoot", null);
tslib_1.__decorate([
memoize_decorator_1.Memoize()
], ProjectPaths.prototype, "projectConfig", null);
tslib_1.__decorate([
memoize_decorator_1.Memoize()
], ProjectPaths.prototype, "projectPackageJson", null);
tslib_1.__decorate([
memoize_decorator_1.Memoize()
], ProjectPaths.prototype, "projectRoot", null);
tslib_1.__decorate([
memoize_decorator_1.Memoize()
], ProjectPaths.prototype, "projectNodeModules", null);
tslib_1.__decorate([
memoize_decorator_1.Memoize()
], ProjectPaths.prototype, "projectEntrypoint", null);
tslib_1.__decorate([
memoize_decorator_1.Memoize()
], ProjectPaths.prototype, "projectTsConfig", null);
tslib_1.__decorate([
memoize_decorator_1.Memoize()
], ProjectPaths.prototype, "destination", null);
exports.ProjectPaths = ProjectPaths;