@dbpath/files
Advanced tools
Comparing version 0.1.1 to 0.2.0
import { ErrorsAnd } from "@dbpath/utils"; | ||
export declare function findInParent(directory: string, acceptor: (filename: string) => boolean): string | undefined; | ||
export declare function findDirectoryHoldingFileOrError(directory: string, file: string): ErrorsAnd<string>; | ||
export declare function loadFileInDirectory(cwd: string, marker: string, filename: string): any; | ||
export declare function findDirectoryHoldingFileOrThrow(directory: string, file: string): string; | ||
export declare function findFileInParentsOrError(directory: string, file: string): ErrorsAnd<string>; | ||
export declare function readTestFile(dir: any, file: string): string; |
@@ -29,3 +29,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.readTestFile = exports.findFileInParentsOrError = exports.findDirectoryHoldingFileOrThrow = exports.findDirectoryHoldingFileOrError = exports.findInParent = void 0; | ||
exports.readTestFile = exports.findFileInParentsOrError = exports.findDirectoryHoldingFileOrThrow = exports.loadFileInDirectory = exports.findDirectoryHoldingFileOrError = exports.findInParent = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
@@ -54,2 +54,21 @@ const fs_1 = __importDefault(require("fs")); | ||
exports.findDirectoryHoldingFileOrError = findDirectoryHoldingFileOrError; | ||
function loadFileInDirectory(cwd, marker, filename) { | ||
const dir = findDirectoryHoldingFileOrError(cwd, marker); | ||
if ((0, utils_1.hasErrors)(dir)) | ||
return dir; | ||
const file = Path.join(dir, filename); | ||
try { | ||
const contents = fs_1.default.readFileSync(file).toString('utf-8'); | ||
try { | ||
return JSON.parse(contents).currentEnvironment; | ||
} | ||
catch (e) { | ||
return [`Error parsing ${file}: ${e.message}`]; | ||
} | ||
} | ||
catch (e) { | ||
return [`Error reading ${file}: ${e.message}`]; | ||
} | ||
} | ||
exports.loadFileInDirectory = loadFileInDirectory; | ||
function findDirectoryHoldingFileOrThrow(directory, file) { | ||
@@ -56,0 +75,0 @@ const dir = findDirectoryHoldingFileOrError(directory, file); |
{ | ||
"name": "@dbpath/files", | ||
"description": "", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"main": "dist/index", | ||
@@ -6,0 +6,0 @@ "types": "dist/index", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9246
153