UNPKG

xweb-templating

Version:

A cli tool for converting 'tags' to regular html, php or some other format

171 lines (170 loc) 6.47 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import inquirer from "inquirer"; import fs from "fs"; import { info, large_info, status } from "../log.js"; import path from "path"; export function run(argv) { return __awaiter(this, void 0, void 0, function* () { const CONFIG = { folder: { src: "./src", out: "./out", tags: "./xweb_tags" }, extension: { src: ".xweb", out: ".html" }, use: { inline: true, tags: true }, inline: { from: { start: "{{", end: "}}", }, to: { start: "<?=", end: "?>" } }, tags: [] }; if (!argv.yes) { const ANSWERS = yield inquirer.prompt([ { name: "source_folder", message: "Source folder:", type: "input", default: "./src" }, { name: "output_folder", message: "Output folder:", type: "input", default: "./out" }, { name: "tags_folder", message: "Tags folder:", type: "input", default: "./xweb_tags" }, { name: "src_extension", message: "Source file extension:", type: "input", default: ".xweb" }, { name: "out_extension", message: "Output file extension:", type: "input", default: ".html" }, { name: "use_inline", message: "Use inline xweb:", type: "list", choices: ["yes", "no"], default: "yes" }, { name: "use_tags", message: "Use xweb tags:", type: "list", choices: ["yes", "no"], default: "yes" } ]); CONFIG.folder.src = ANSWERS.source_folder; CONFIG.folder.out = ANSWERS.output_folder; CONFIG.folder.tags = ANSWERS.tags_folder; CONFIG.extension.src = ANSWERS.src_extension; CONFIG.extension.out = ANSWERS.out_extension; CONFIG.use.inline = ANSWERS.use_inline == "yes"; CONFIG.use.tags = ANSWERS.use_tags == "yes"; if (CONFIG.use.tags) { const TAGSETS = yield inquirer.prompt([{ name: "import_tags", message: "Tagset names seperated by comma:", type: "input", }]); CONFIG.tags = TAGSETS.import_tags.split(",").map((tagset) => tagset.trim()).filter((tagset) => tagset != ""); } if (CONFIG.use.inline) { const INLINE_USE = yield inquirer.prompt([ { name: "from_start", message: "Inline xweb start (src):", type: "input", default: "{{" }, { name: "from_end", message: "Inline xweb end (src):", type: "input", default: "}}" }, { name: "to_start", message: "Inline xweb start (out):", type: "input", default: "<?=" }, { name: "to_end", message: "Inline xweb end (out):", type: "input", default: "?>" } ]); if (CONFIG.inline == undefined) CONFIG.inline = { from: { start: "{{", end: "}}" }, to: { start: "<?=", end: "?>" } }; CONFIG.inline.from.start = INLINE_USE.from_start; CONFIG.inline.from.end = INLINE_USE.from_end; CONFIG.inline.to.start = INLINE_USE.to_start; CONFIG.inline.to.end = INLINE_USE.to_end; } else { delete CONFIG.inline; } } large_info("init/config", "Generated output", JSON.stringify(CONFIG, null, 4)); if (!argv.yes) { const IS_OK = yield inquirer.prompt([{ name: "config_ok", message: "Is this ok?", type: "list", choices: ["yes", "no"], default: "yes" }]); if (IS_OK.config_ok != "yes") { info("init/config", "Rerun init command to generate config file"); return null; } } const CONFIG_FILE_PATH = path.join(process.cwd(), "xwebconfig.json"); fs.writeFileSync(CONFIG_FILE_PATH, JSON.stringify(CONFIG, null, 4)); status("init/config", "Created file 'xwebconfig.json'"); return CONFIG; }); }