UNPKG

ern-api-gen

Version:

Electrode Native API generator

104 lines 2.75 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /* tslint:disable:variable-name */ const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const mkdirp_1 = require("mkdirp"); function canAccess(file) { try { fs_1.default.accessSync(file); return true; } catch (e) { // Swallow } return false; } const toString = String.valueOf(); class File { constructor(file, ...args) { if (!file) { throw new Error(`File needs an argument`); } if (file instanceof File && args.length === 0) { return file; } this._filename = args.length ? path_1.default.join(toString(file), ...args.map(toString)) : toString(file); } relativeTo(file) { if (file instanceof File) { file = file._filename; } const relPath = path_1.default.relative(file, this._filename); return new File(relPath); } toAbsolutePath() { return this.getAbsoluteFile().getPath(); } getAbsolutePath() { return this.toAbsolutePath(); } isAbsolute() { return path_1.default.isAbsolute(this._filename); } toAbsolute() { return this.getAbsoluteFile(); } getAbsoluteFile() { if (this.isAbsolute()) { return this; } return new File(path_1.default.join(process.cwd(), this._filename)); } canRead() { return this.exists() && canAccess(this._filename); } exists() { return fs_1.default.existsSync(this._filename); } getName() { return this._filename; } getParentFile() { if (this._parent) { return this._parent; } this._parent = new File(path_1.default.resolve(this._filename, '..')); return this._parent; } getPath() { return this._filename; } _() { if (!this._stat) { if (!this.exists()) { return false; } this._stat = fs_1.default.statSync(this._filename); } return this._stat; } isDirectory() { const s = this._(); return s && s.isDirectory(); } isFile() { const s = this._(); return s && s.isFile(); } mkdirs() { return mkdirp_1.sync(this._filename); } toString() { return this._filename; } } File.separator = path_1.default.sep; File.separatorChar = path_1.default.sep; exports.default = File; //# sourceMappingURL=File.js.map