@lightweightform/kotlin-cli
Version:
LF Kotlin CLI Plugin
78 lines • 2.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/*
* @license
* Copyright Lightweightform. All Rights Reserved.
*
* Use of this source code is governed by an Apache2.0-style license that can be
* found at https://www.apache.org/licenses/LICENSE-2.0
*/
var mkdirp_1 = require("mkdirp");
var _a = require('winston'), createLogger = _a.createLogger, format = _a.format, transports = _a.transports;
var combine = format.combine, colorize = format.colorize, timestamp = format.timestamp, label = format.label, printf = format.printf;
var fs_1 = require("fs");
var camelcase_1 = require("camelcase");
// Logger configuration
var loggerFormat = printf(function (info) {
return info.timestamp + " [" + info.label + "] " + info.level + ": " + info.message;
});
var logger = createLogger({
format: combine(colorize({ all: true }), label({ label: 'LF-KOTLIN' }), timestamp(), loggerFormat),
transports: [new transports.Console()],
});
function createDirectory(path) {
var made = mkdirp_1.default.sync(path, {});
if (made) {
logger.info("Directory " + path + " was created!");
}
else {
var error = "Failed to create directory " + path;
logger.error(error);
throw new Error(error);
}
}
exports.createDirectory = createDirectory;
function writeFile(path, content) {
fs_1.default.writeFile(path, content, function (err) {
if (err) {
logger.error("Failed to create file " + path);
return;
}
logger.info("File " + path + " was created!");
});
}
exports.writeFile = writeFile;
function camelCase(word, pascalCase) {
if (pascalCase === void 0) { pascalCase = true; }
// @ts-ignore
return camelcase_1.default(word, { pascalCase: pascalCase });
}
exports.camelCase = camelCase;
function createIfCondition(condition, directory) {
if (condition) {
// whether the record isn't root record creates the directory of that level
createDirectory(directory);
}
}
exports.createIfCondition = createIfCondition;
function throwIfCondition(condition, message) {
if (condition) {
throw new Error(message);
}
}
exports.throwIfCondition = throwIfCondition;
function stringify(ctx, path, transform) {
if (path === void 0) { path = ''; }
if (ctx.get(path) !== null) {
var value = ctx.getAsJSON(path);
if (transform) {
value = transform(value);
}
return JSON.stringify(value);
}
else {
return ctx.get(path);
}
}
exports.stringify = stringify;
//# sourceMappingURL=utils.js.map