xweb-templating
Version:
A cli tool for converting 'tags' to regular html, php or some other format
52 lines (51 loc) • 2.6 kB
JavaScript
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 { read_config, save_config } from "../config/config.js";
import { error, info, warn } from "../log.js";
import path from "path";
import fs from "fs";
export default function run(argv) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const CONFIG = read_config("remove/config");
if (!CONFIG.use.tags) {
error("remove/config", "Cannot remove tagset in a project that has disabled tagsets");
return;
}
if (argv.names == undefined) {
error("remove/config", "Cannot remove tagsets without a name");
return;
}
const TAGSET_NAMES = (_a = argv.names) === null || _a === void 0 ? void 0 : _a.split(" ");
for (const REMOVE_NAME of TAGSET_NAMES) {
const INDEX_OF_TAGSET = CONFIG.tags.indexOf(REMOVE_NAME);
// if tag has not been added, warn and skip the rest
if (INDEX_OF_TAGSET < 0) {
yield warn("remove/config", `Tagset ${REMOVE_NAME} isn't added in xwebconfig.json`, argv.y);
continue;
}
CONFIG.tags.splice(INDEX_OF_TAGSET, 1);
}
save_config("remove/config", CONFIG);
let ready = 0;
for (const TAG_NAME of TAGSET_NAMES) {
info("remove/file", `Removing tagset ${ready + 1}/${CONFIG.tags.length} '${TAG_NAME}'`);
const TAGSET_FILE_PATH = path.join(process.cwd(), CONFIG.folder.tags, TAG_NAME + ".js");
// if file does not exist, warn and skip rest
if (!fs.existsSync(TAGSET_FILE_PATH)) {
yield warn("remove/file", `File for tagset '${TAG_NAME}' does not exist`, argv.y);
continue;
}
fs.unlinkSync(TAGSET_FILE_PATH);
info("remove/file", `Finished removing tagset ${ready + 1}/${CONFIG.tags.length} '${TAG_NAME}'`);
ready++;
}
});
}