91 lines
2.1 KiB
JavaScript
91 lines
2.1 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const path_1 = __importDefault(require("path"));
|
|
const immutable_1 = __importDefault(require("immutable"));
|
|
const parsers_1 = __importDefault(require("../parsers"));
|
|
class File extends immutable_1.default.Record({
|
|
// Path of the file, relative to the FS
|
|
path: String(),
|
|
// Time when file data last modified
|
|
mtime: Date()
|
|
}) {
|
|
getPath() {
|
|
return this.get("path");
|
|
}
|
|
getMTime() {
|
|
return this.get("mtime");
|
|
}
|
|
/**
|
|
Does the file exists / is set
|
|
|
|
@return {boolean}
|
|
*/
|
|
exists() {
|
|
return Boolean(this.getPath());
|
|
}
|
|
/**
|
|
Return type of file ('markdown' or 'asciidoc')
|
|
|
|
@return {string}
|
|
*/
|
|
getType() {
|
|
const parser = this.getParser();
|
|
if (parser) {
|
|
return parser.getName();
|
|
}
|
|
else {
|
|
return undefined;
|
|
}
|
|
}
|
|
/**
|
|
Return extension of this file (lowercased)
|
|
|
|
@return {string}
|
|
*/
|
|
getExtension() {
|
|
return path_1.default.extname(this.getPath()).toLowerCase();
|
|
}
|
|
/**
|
|
Return parser for this file
|
|
|
|
@return {Parsers}
|
|
*/
|
|
getParser() {
|
|
return parsers_1.default.getByExt(this.getExtension());
|
|
}
|
|
/**
|
|
Return basedirectory of this file
|
|
@return {string}
|
|
*/
|
|
getBaseDirectory() {
|
|
return path_1.default.dirname(this.getPath());
|
|
}
|
|
/**
|
|
Create a file from stats informations
|
|
|
|
@param {string} filepath
|
|
@param {Object|fs.Stats} stat
|
|
@return {File}
|
|
*/
|
|
static createFromStat(filepath, stat) {
|
|
return new File({
|
|
path: filepath,
|
|
mtime: stat.mtime
|
|
});
|
|
}
|
|
/**
|
|
Create a file with only a path
|
|
@param {string} filepath
|
|
@return {File}
|
|
*/
|
|
static createWithFilepath(filepath) {
|
|
return new File({
|
|
path: filepath
|
|
});
|
|
}
|
|
}
|
|
exports.default = File;
|