@adrianbrs/darmogen
Advanced tools
Comparing version 1.0.4 to 1.0.5
73
cli.js
@@ -82,3 +82,2 @@ #!/usr/bin/env node | ||
function getOptions() { | ||
var _a; | ||
var optionsFile = path_1.default.resolve(process.cwd(), OPTIONS_FILENAME); | ||
@@ -89,3 +88,8 @@ if (!fs_1.default.existsSync(optionsFile)) { | ||
var options = require(optionsFile); | ||
return (_a = options.default) !== null && _a !== void 0 ? _a : options; | ||
// Update source | ||
options.parser.cwd = path_1.default.resolve(process.cwd(), options.parser.cwd); | ||
options.parser.root = path_1.default.resolve(process.cwd(), options.parser.root); | ||
// Update output | ||
options.generator.out = path_1.default.resolve(process.cwd(), options.generator.out); | ||
return options; | ||
} | ||
@@ -101,3 +105,3 @@ function showHeader(options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var parser, pgBar, entities, generator, models; | ||
var pgBar, models, parser, entities, generator, err_1; | ||
return __generator(this, function (_a) { | ||
@@ -107,4 +111,13 @@ switch (_a.label) { | ||
showHeader(options); | ||
// Check input and output | ||
if (!fs_1.default.existsSync(options.parser.cwd)) { | ||
console.error("Error: Parser \"cwd\" folder doesn't exists: " + options.parser.cwd); | ||
process.exit(1); | ||
} | ||
pgBar = new cli_progress_1.default.SingleBar(PROGRESS_OPTIONS, cli_progress_1.default.Presets.shades_classic); | ||
models = null; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 4, , 5]); | ||
parser = new parser_1.NestEntityParser(options.parser); | ||
pgBar = new cli_progress_1.default.SingleBar(PROGRESS_OPTIONS, cli_progress_1.default.Presets.shades_classic); | ||
parser.on("init", function (total, files) { | ||
@@ -122,3 +135,3 @@ console.log("\u250C Found " + files.length + " files:"); | ||
return [4 /*yield*/, parser.parse()]; | ||
case 1: | ||
case 2: | ||
entities = _a.sent(); | ||
@@ -138,7 +151,14 @@ pgBar.stop(); | ||
return [4 /*yield*/, generator.generate(entities)]; | ||
case 2: | ||
case 3: | ||
models = _a.sent(); | ||
pgBar.stop(); | ||
console.log("│"); | ||
return [2 /*return*/, models]; | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
err_1 = _a.sent(); | ||
pgBar.stop(); | ||
// Print error | ||
console.error("Error: Could not generate Dart models."); | ||
throw err_1; | ||
case 5: return [2 /*return*/, models]; | ||
} | ||
@@ -154,3 +174,5 @@ }); | ||
var e_1, _a; | ||
var width = 0; | ||
if (!models) | ||
return; | ||
var width = 20; | ||
models = models.map(function (model) { | ||
@@ -164,20 +186,33 @@ var targetFile = path_1.default.relative(process.cwd(), model.targetFile); | ||
var offset = 10; | ||
if (!models.length) { | ||
width = | ||
Math.max(options.parser.cwd.length, options.parser.ext.length) + offset; | ||
} | ||
width += offset; | ||
console.log("\u2502" + padText("", "─", width) + "\u2510"); | ||
console.log("\u2502" + padText(" Generated " + models.length + " models:", " ", width) + "\u2502"); | ||
console.log("\u251C" + padText("", "─", width) + "\u2524"); | ||
try { | ||
for (var models_1 = __values(models), models_1_1 = models_1.next(); !models_1_1.done; models_1_1 = models_1.next()) { | ||
var model = models_1_1.value; | ||
console.log("\u251C" + padText(" \u00BB " + model.name + " (" + model.targetFile + ")", " ", width) + "\u2502"); | ||
} | ||
// No entities found | ||
if (!models.length) { | ||
console.log("\u2502" + padText(" No entities found, check parser \"cwd\" and \"ext\".", " ", width) + "\u2502"); | ||
console.log("\u251C" + padText(" \u00BB cwd: " + options.parser.cwd + ")", " ", width) + "\u2502"); | ||
console.log("\u251C" + padText(" \u00BB ext: " + options.parser.ext + ")", " ", width) + "\u2502"); | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
// Generated models | ||
else { | ||
console.log("\u2502" + padText(" Generated " + models.length + " models:", " ", width) + "\u2502"); | ||
console.log("\u251C" + padText("", "─", width) + "\u2524"); | ||
try { | ||
if (models_1_1 && !models_1_1.done && (_a = models_1.return)) _a.call(models_1); | ||
for (var models_1 = __values(models), models_1_1 = models_1.next(); !models_1_1.done; models_1_1 = models_1.next()) { | ||
var model = models_1_1.value; | ||
console.log("\u251C" + padText(" \u00BB " + model.name + " (" + model.targetFile + ")", " ", width) + "\u2502"); | ||
} | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (models_1_1 && !models_1_1.done && (_a = models_1.return)) _a.call(models_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
} | ||
console.log("\u2514" + padText("", "─", width) + "\u2518"); | ||
}); |
{ | ||
"name": "@adrianbrs/darmogen", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"main": "index.js", | ||
@@ -8,3 +8,3 @@ "author": "Adrian Cerbaro <adriancerbaro@gmail.com>", | ||
"scripts": { | ||
"generate": "ts-node src/main.ts", | ||
"generate": "ts-node src/cli.ts", | ||
"build": "tsc", | ||
@@ -11,0 +11,0 @@ "deploy": "yarn build && cd dist && npm publish", |
105301
2451