@tobiastengler/create-relay-app
Version:
Easy configuration of Relay for existing projects
26 lines (25 loc) • 915 B
JavaScript
import path from "path";
import { PACKAGE_FILE } from "../consts.js";
import { PackageJsonFile } from "./PackageJsonFile.js";
import { RelativePath } from "./RelativePath.js";
export class Environment {
constructor(cwd, ownPackageJsonFilepath, fs) {
this.cwd = cwd;
this.fs = fs;
this.packageJson = null;
this.ownPackageDirectory = fs.getParent(ownPackageJsonFilepath);
this.ownPackageJson = new PackageJsonFile(ownPackageJsonFilepath, this.fs);
}
async init() {
const packageJsonFilepath = path.join(this.cwd, PACKAGE_FILE);
if (!this.fs.exists(packageJsonFilepath)) {
throw new MissingPackageJsonError();
}
this.packageJson = new PackageJsonFile(packageJsonFilepath, this.fs);
}
rel(relPath) {
return new RelativePath(this.cwd, relPath);
}
}
export class MissingPackageJsonError extends Error {
}