43 lines
1.8 KiB
JavaScript
43 lines
1.8 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getMarketplaceHomepageContent = getMarketplaceHomepageContent;
|
|
exports.saveMarketplaceHomepageContent = saveMarketplaceHomepageContent;
|
|
const promises_1 = require("fs/promises");
|
|
const path_1 = __importDefault(require("path"));
|
|
const types_1 = require("@rentaldrivego/types");
|
|
function resolveContentPath() {
|
|
const cwd = process.cwd();
|
|
const appScoped = path_1.default.resolve(cwd, 'src/data/platform-content.json');
|
|
const repoScoped = path_1.default.resolve(cwd, 'apps/api/src/data/platform-content.json');
|
|
return cwd.includes('/apps/api') ? appScoped : repoScoped;
|
|
}
|
|
const platformContentPath = resolveContentPath();
|
|
async function readPlatformContentFile() {
|
|
try {
|
|
const raw = await (0, promises_1.readFile)(platformContentPath, 'utf8');
|
|
return JSON.parse(raw);
|
|
}
|
|
catch {
|
|
return {};
|
|
}
|
|
}
|
|
async function writePlatformContentFile(content) {
|
|
await (0, promises_1.mkdir)(path_1.default.dirname(platformContentPath), { recursive: true });
|
|
await (0, promises_1.writeFile)(platformContentPath, JSON.stringify(content, null, 2));
|
|
}
|
|
async function getMarketplaceHomepageContent() {
|
|
const content = await readPlatformContentFile();
|
|
return content.marketplaceHomepage ?? (0, types_1.cloneMarketplaceHomepageContent)();
|
|
}
|
|
async function saveMarketplaceHomepageContent(homepage) {
|
|
const content = await readPlatformContentFile();
|
|
await writePlatformContentFile({
|
|
...content,
|
|
marketplaceHomepage: homepage,
|
|
});
|
|
return homepage;
|
|
}
|
|
//# sourceMappingURL=platformContentService.js.map
|