2016-05-19 22:31:53 +00:00
|
|
|
"use strict";
|
2017-04-27 14:48:08 +00:00
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
2017-03-04 20:10:46 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2017-05-01 20:07:25 +00:00
|
|
|
const plugins = require("./smartfile.plugins");
|
2017-04-27 14:48:08 +00:00
|
|
|
/**
|
|
|
|
* class Smartfile
|
|
|
|
* -> is vinyl file compatible
|
|
|
|
*/
|
2016-07-17 15:34:15 +00:00
|
|
|
class Smartfile {
|
2017-04-27 14:48:08 +00:00
|
|
|
/**
|
|
|
|
* the constructor of Smartfile
|
|
|
|
* @param optionsArg
|
|
|
|
*/
|
2017-03-04 20:10:46 +00:00
|
|
|
constructor(optionsArg) {
|
|
|
|
if (optionsArg.contentBuffer) {
|
2017-04-29 15:20:09 +00:00
|
|
|
this.contentBuffer = optionsArg.contentBuffer;
|
2017-03-04 20:10:46 +00:00
|
|
|
}
|
2017-04-29 15:20:09 +00:00
|
|
|
else if (optionsArg.contentString) {
|
2017-04-30 16:13:17 +00:00
|
|
|
this.setContentsFromString(optionsArg.contentString);
|
2017-04-29 15:20:09 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log('created empty Smartfile?');
|
2017-03-04 20:10:46 +00:00
|
|
|
}
|
|
|
|
this.path = optionsArg.path;
|
2017-04-30 16:13:17 +00:00
|
|
|
this.base = optionsArg.base;
|
2017-04-27 14:48:08 +00:00
|
|
|
}
|
2017-03-04 20:10:46 +00:00
|
|
|
/**
|
|
|
|
* set contents from string
|
|
|
|
* @param contentString
|
|
|
|
*/
|
2017-04-27 14:48:08 +00:00
|
|
|
setContentsFromString(contentString) {
|
2017-03-04 20:10:46 +00:00
|
|
|
this.contents = new Buffer(contentString);
|
2016-05-19 22:31:53 +00:00
|
|
|
}
|
2017-04-27 14:48:08 +00:00
|
|
|
/**
|
|
|
|
* write file to disk
|
|
|
|
*/
|
|
|
|
write() {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* read file from disk
|
|
|
|
*/
|
|
|
|
read() {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
});
|
|
|
|
}
|
2017-04-30 16:13:17 +00:00
|
|
|
// -----------------------------------------------
|
|
|
|
// vinyl compatibility
|
|
|
|
// -----------------------------------------------
|
|
|
|
/**
|
|
|
|
* vinyl-compatibility: alias of this.contentBuffer
|
|
|
|
*/
|
|
|
|
get contents() {
|
|
|
|
return this.contentBuffer;
|
|
|
|
}
|
|
|
|
set contents(contentsArg) {
|
|
|
|
this.contentBuffer = contentsArg;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* vinyl-compatibility
|
|
|
|
*/
|
|
|
|
get cwd() {
|
|
|
|
return this.base;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* return relative path of file
|
|
|
|
*/
|
|
|
|
get relative() {
|
2017-05-01 20:07:25 +00:00
|
|
|
return plugins.path.relative(this.base, this.path);
|
2017-04-30 16:13:17 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* return truw when the file has content
|
|
|
|
*/
|
|
|
|
isNull() {
|
|
|
|
if (!this.contentBuffer) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* return true if contents are Buffer
|
|
|
|
*/
|
|
|
|
isBuffer() {
|
|
|
|
if (this.contents instanceof Buffer) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
isDirectory() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
isStream() {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-01 20:07:25 +00:00
|
|
|
isSymbolic() {
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-17 15:34:15 +00:00
|
|
|
}
|
2016-05-19 22:31:53 +00:00
|
|
|
exports.Smartfile = Smartfile;
|
2017-05-01 20:07:25 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRmaWxlLmNsYXNzZXMuc21hcnRmaWxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSwrQ0FBOEM7QUFTOUM7OztHQUdHO0FBQ0g7SUFxQkU7OztPQUdHO0lBQ0gsWUFBYSxVQUF3QztRQUNuRCxFQUFFLENBQUMsQ0FBQyxVQUFVLENBQUMsYUFBYSxDQUFDLENBQUMsQ0FBQztZQUM3QixJQUFJLENBQUMsYUFBYSxHQUFHLFVBQVUsQ0FBQyxhQUFhLENBQUE7UUFDL0MsQ0FBQztRQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxVQUFVLENBQUMsYUFBYSxDQUFDLENBQUMsQ0FBQztZQUNwQyxJQUFJLENBQUMscUJBQXFCLENBQUMsVUFBVSxDQUFDLGFBQWEsQ0FBQyxDQUFBO1FBQ3RELENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLE9BQU8sQ0FBQyxHQUFHLENBQUMsMEJBQTBCLENBQUMsQ0FBQTtRQUN6QyxDQUFDO1FBQ0QsSUFBSSxDQUFDLElBQUksR0FBRyxVQUFVLENBQUMsSUFBSSxDQUFBO1F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