@compass-docgen/server
Version:
This is a package to run your doc mate server
55 lines (54 loc) • 2.24 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@compass-docgen/core");
const core_2 = require("@compass-docgen/core");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const ComponentResolver = {
Query: {
components: async () => {
var componentService = new core_1.ComponentService();
const COMPONENTS = await componentService.readCache();
const KEYS = Object.keys(COMPONENTS?.components || {});
return KEYS.map((KEYS) => COMPONENTS?.components[KEYS]);
},
component: async (_, { filePath }) => {
var componentService = new core_1.ComponentService();
const COMPONENTS = await componentService.readCache();
const KEYS = Object.keys(COMPONENTS?.components || {});
let component = null;
KEYS.every((KEYS) => {
const COMPONENT = COMPONENTS?.components[KEYS];
if (COMPONENT.basePath === `/${filePath}`) {
component = COMPONENT;
return false;
}
return true;
});
return component;
},
documentationDefault: async () => {
var componentService = new core_1.ComponentService();
return await componentService.getDocumentationDefault();
},
documentation: async (_, { filePath }) => {
if (!filePath) {
return null;
}
if (!filePath || filePath.indexOf('.md') === -1) {
return null;
}
if (!fs_1.default.existsSync(path_1.default.resolve('./build', filePath))) {
return fs_1.default.readFileSync(filePath, 'utf8');
}
return fs_1.default.readFileSync(path_1.default.resolve('./build', filePath), 'utf8');
},
documentationName: async () => {
return (await core_2.AppConfig.read()).name;
},
},
};
exports.default = ComponentResolver;