pricing4ts
Version:
 Pricing4TS is a TypeScript-based toolkit designed to enhance the server-side functionality of a pricing-driven SaaS by enabling the seamless integration of pricing plans into the application logic. T
52 lines (51 loc) • 2.61 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DZNKeywords = void 0;
exports.saveDZNfile = saveDZNfile;
var node_path_1 = __importDefault(require("node:path"));
var server_1 = require("../../server");
var pricing_dzn_exporter_1 = require("../../../server/utils/dzn-exporter/pricing-dzn-exporter");
var node_fs_1 = __importDefault(require("node:fs"));
var DZNKeywords;
(function (DZNKeywords) {
DZNKeywords["NumberOfFeatures"] = "num_features";
DZNKeywords["NumberOfUsageLimits"] = "num_usage_limits";
DZNKeywords["NumberOfPlans"] = "num_plans";
DZNKeywords["NumberOfAddOns"] = "num_addons";
DZNKeywords["Features"] = "features";
DZNKeywords["UsageLimits"] = "usage_limits";
DZNKeywords["Plans"] = "plans";
DZNKeywords["AddOns"] = "addons";
DZNKeywords["PlansPrices"] = "plans_prices";
DZNKeywords["AddOnsPrices"] = "addons_prices";
DZNKeywords["BooleanUsageLimits"] = "boolean_usage_limits";
DZNKeywords["PlansFeatures"] = "plans_features";
DZNKeywords["PlansUsageLimits"] = "plans_usage_limits";
DZNKeywords["LinkedFeatures"] = "linked_features";
DZNKeywords["AddOnsFeatures"] = "addons_features";
DZNKeywords["AddOnsUsageLimits"] = "addons_usage_limits";
DZNKeywords["AddOnsUsageLimitsExtensions"] = "addons_usage_limits_extensions";
DZNKeywords["AddOnsAvailableFor"] = "addons_available_for";
DZNKeywords["AddOnsDependsOn"] = "addons_depends_on";
DZNKeywords["AddOnsExcludes"] = "addons_excludes";
})(DZNKeywords || (exports.DZNKeywords = DZNKeywords = {}));
function saveDZNfile(source, savePath) {
try {
var pricing = (0, server_1.retrievePricingFromPath)(node_path_1.default.resolve(source));
var file = (0, pricing_dzn_exporter_1.pricing2DZN)(pricing);
var dznFolder = node_path_1.default.resolve(savePath);
if (!node_fs_1.default.existsSync(dznFolder)) {
console.log("Creating folder ".concat(dznFolder, "..."));
node_fs_1.default.mkdirSync(savePath, { recursive: true });
}
var filename = node_path_1.default.basename(source, ".yml") + '.dzn';
node_fs_1.default.writeFileSync(node_path_1.default.join(savePath, filename), file);
console.log("\t DZN File Saved in ./".concat(node_path_1.default.join(savePath, filename)));
}
catch (err) {
console.error("Error while parsing file '".concat(source, "'. Error: ").concat(err));
}
}