@iotize/cli
Version:
IoTize command line interface
35 lines • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const path_1 = require("path");
class FileHelper {
static overwrite(path, content) {
path = path_1.resolve(path);
fs_1.writeFileSync(path, content);
}
static writeAsJson(path, data) {
let json = JSON.stringify(data, null, 4);
path = path_1.resolve(path);
fs_1.writeFileSync(path, json);
}
static exists(filename) {
return fs_1.existsSync(filename);
}
static getContent(filename, format = 'string') {
if (!FileHelper.exists(filename)) {
throw new Error(`File does not exist: "${filename}"`);
}
let content = fs_1.readFileSync(filename);
if (format === 'json') {
return JSON.parse(content.toString());
}
else if (format === "string") {
return content.toString();
}
else {
return content;
}
}
}
exports.FileHelper = FileHelper;
//# sourceMappingURL=file-helper.js.map