burdy
Version:
Open Source Headless Platform
49 lines (48 loc) • 2.46 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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeContentTypes = exports.joinContentTypes = void 0;
const path_util_1 = __importDefault(require("./path.util"));
const date_fns_1 = require("date-fns");
const fs_extra_1 = __importDefault(require("fs-extra"));
const console_output_util_1 = __importDefault(require("./console-output.util"));
const joinContentTypes = (files) => {
const contentTypes = [];
files.forEach(({ getContentType, getContentTypes }) => {
try {
const singleContentType = getContentType === null || getContentType === void 0 ? void 0 : getContentType();
const multiContentTypes = getContentTypes === null || getContentTypes === void 0 ? void 0 : getContentTypes();
if (singleContentType) {
contentTypes.push(singleContentType);
}
if (multiContentTypes) {
contentTypes.push(...multiContentTypes);
}
}
catch (e) {
console.log(e);
}
});
return contentTypes;
};
exports.joinContentTypes = joinContentTypes;
const writeContentTypes = (contentTypes, path = undefined) => __awaiter(void 0, void 0, void 0, function* () {
if (!path) {
path = path_util_1.default.burdyRoot('content-types', `export-${(0, date_fns_1.formatISO)(new Date)}.json`);
}
yield fs_extra_1.default.ensureFile(path);
yield fs_extra_1.default.writeJson(path, contentTypes, { spaces: 2, EOL: '\n' });
console_output_util_1.default.info(`Content types exported in ${path}.`);
});
exports.writeContentTypes = writeContentTypes;