@ppramanik62/lab-works
Version:
A comprehensive command-line toolkit for hydraulic turbine calculations, supporting Francis Turbine and Pelton Wheel computations with interactive mode and validation.
208 lines ⢠8.64 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Main CLI entry point for Hydraulic Turbine Lab Toolkit
*/
const commander_1 = require("commander");
const francis_1 = require("../calculators/francis");
const kaplan_1 = require("../calculators/kaplan");
const pelton_1 = require("../calculators/pelton");
const error_1 = require("../shared/error");
const program = new commander_1.Command();
program
.name("lab-work")
.description("Hydraulic Turbine Lab Toolkit")
.version("1.0.0");
// Francis Turbine subcommand
program
.command("francis")
.description("Run Francis Turbine calculations")
.option("--ppg <value>", "Positive pressure gauge reading")
.option("--npg <value>", "Negative pressure gauge reading")
.option("--w1 <value>", "Weight 1 (kg)")
.option("--w2 <value>", "Weight 2 (kg)")
.option("--rpm <value>", "RPM (revolutions per minute)")
.option("--json", "Output results in JSON format")
.action(async (options) => {
try {
await (0, francis_1.runFrancis)({
ppg: options.ppg ? Number(options.ppg) : undefined,
npg: options.npg ? Number(options.npg) : undefined,
w1: options.w1 ? Number(options.w1) : undefined,
w2: options.w2 ? Number(options.w2) : undefined,
rpm: options.rpm ? Number(options.rpm) : undefined,
json: options.json,
});
}
catch (error) {
(0, error_1.handleError)(error);
}
});
// Pelton Wheel subcommand
program
.command("pelton")
.description("Run Pelton Wheel calculations")
.option("--pg <value>", "Pressure gauge reading")
.option("--w1 <value>", "Weight 1 (kg)")
.option("--w2 <value>", "Weight 2 (kg)")
.option("--rpm <value>", "RPM (revolutions per minute)")
.option("--hf <value>", "Height hf (mm)")
.option("--json", "Output results in JSON format")
.action(async (options) => {
try {
await (0, pelton_1.runPelton)({
pg: options.pg ? Number(options.pg) : undefined,
w1: options.w1 ? Number(options.w1) : undefined,
w2: options.w2 ? Number(options.w2) : undefined,
rpm: options.rpm ? Number(options.rpm) : undefined,
hf: options.hf ? Number(options.hf) : undefined,
json: options.json,
});
}
catch (error) {
(0, error_1.handleError)(error);
}
});
// Kaplan Turbine subcommand
program
.command("kaplan")
.description("Run Kaplan Turbine calculations")
.option("--pg <value>", "Pressure gauge reading")
.option("--w1 <value>", "Weight 1 (kg)")
.option("--w2 <value>", "Weight 2 (kg)")
.option("--rpm <value>", "RPM (revolutions per minute)")
.option("--lhs-mercury <value>", "Left hand side manometer reading")
.option("--rhs-mercury <value>", "Right hand side manometer reading")
.option("--json", "Output results in JSON format")
.action(async (options) => {
try {
await (0, kaplan_1.runKaplan)({
pg: options.pg ? Number(options.pg) : undefined,
w1: options.w1 ? Number(options.w1) : undefined,
w2: options.w2 ? Number(options.w2) : undefined,
rpm: options.rpm ? Number(options.rpm) : undefined,
lhs_mercury: options.lhsMercury
? Number(options.lhsMercury)
: undefined,
rhs_mercury: options.rhsMercury
? Number(options.rhsMercury)
: undefined,
json: options.json,
});
}
catch (error) {
(0, error_1.handleError)(error);
}
});
// Help command - list available calculators
program
.command("list")
.description("List available calculators")
.action(async () => {
const { theme, safeColorize } = await Promise.resolve().then(() => __importStar(require("../shared/colors")));
const title = safeColorize("š§ Available Hydraulic Turbine Calculators:", theme.title);
const francis = safeColorize("francis", theme.accent);
const pelton = safeColorize("pelton", theme.accent);
const kaplan = safeColorize("kaplan", theme.accent);
const francisDesc = safeColorize("Francis Turbine Calculator", theme.info);
const peltonDesc = safeColorize("Pelton Wheel Calculator", theme.info);
const kaplanDesc = safeColorize("Kaplan Turbine Calculator", theme.info);
const usage = safeColorize('Use "lab-work <calculator> --help" for usage information.', theme.subtle);
console.log(`\n${title}\n`);
console.log(` ${francis} - ${francisDesc}`);
console.log(` ${pelton} - ${peltonDesc}`);
console.log(` ${kaplan} - ${kaplanDesc}`);
console.log(`\n${usage}\n`);
});
// Interactive mode - let user choose calculator
program
.command("interactive")
.alias("i")
.description("Start interactive mode to choose calculator")
.action(async () => {
const { Prompt } = await Promise.resolve().then(() => __importStar(require("../shared/prompt")));
const { theme, safeColorize } = await Promise.resolve().then(() => __importStar(require("../shared/colors")));
const prompt = new Prompt();
try {
const title = safeColorize("š§ Hydraulic Turbine Lab Toolkit", theme.title);
const availableText = safeColorize("Available calculators:", theme.info);
const francis = safeColorize("1. Francis Turbine", theme.accent);
const pelton = safeColorize("2. Pelton Wheel", theme.accent);
const kaplan = safeColorize("3. Kaplan Turbine", theme.accent);
console.log(`\n${title}\n`);
console.log(availableText);
console.log(` ${francis}`);
console.log(` ${pelton}`);
console.log(` ${kaplan}`);
const choice = await prompt.ask(safeColorize("\nChoose calculator (1-3): ", theme.prompt));
switch (choice.trim()) {
case "1":
const startingFrancis = safeColorize("Starting Francis Turbine calculator...", theme.success);
console.log(`\n${startingFrancis}\n`);
await (0, francis_1.runFrancis)({});
break;
case "2":
const startingPelton = safeColorize("Starting Pelton Wheel calculator...", theme.success);
console.log(`\n${startingPelton}\n`);
await (0, pelton_1.runPelton)({});
break;
case "3":
const startingKaplan = safeColorize("Starting Kaplan Turbine calculator...", theme.success);
console.log(`\n${startingKaplan}\n`);
await (0, kaplan_1.runKaplan)({});
break;
default:
const errorMsg = safeColorize("ā Invalid choice. Please select 1, 2, or 3.", theme.error);
console.log(errorMsg);
process.exit(1);
}
}
catch (error) {
(0, error_1.handleError)(error);
}
finally {
prompt.close();
}
});
// Default action when no subcommand is provided
if (process.argv.length <= 2) {
program.outputHelp();
console.log('\nš” Tip: Use "lab-work interactive" to start interactive mode\n');
}
// Parse command line arguments
program.parse();
//# sourceMappingURL=main.js.map