UNPKG

vue-docgen-cli

Version:

Generate documentation markdown files from VueJs components using the vue-docgen-api.

110 lines 4.92 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const path = __importStar(require("path")); const fs = __importStar(require("fs")); const vue_docgen_api_1 = require("vue-docgen-api"); const log = __importStar(require("loglevel")); const compileTemplates_1 = require("./compileTemplates"); const utils_1 = require("./utils"); exports.default = async (cwd, watch = false, configFileFromCmd, pathArray = [], verbose = false, logLevel) => { // the first thing we do, is to set the log level if (logLevel) { log.setLevel(logLevel); } else if (verbose) { log.setLevel('debug'); } const configFilePath = configFileFromCmd ? path.resolve(cwd, configFileFromCmd) : path.join(cwd, 'docgen.config.js'); const [componentsFromCmd, outDirFromCmd] = pathArray; log.debug('[vue-docgen-cli] extractConfig ', { configFilePath }); const userConfigOrFunction = fs.existsSync(configFilePath) ? (await import(`file://${configFilePath}`)).default : {}; const rootConfig = { cwd, watch, propsParser: vue_docgen_api_1.parseMulti, componentsRoot: path.dirname(configFilePath), components: componentsFromCmd || 'src/components/**/[a-zA-Z]*.{vue,js,jsx,ts,tsx}', outDir: outDirFromCmd, getDocFileName: (componentPath) => { const files = [ path.join(path.dirname(componentPath), 'Readme.md'), // ComponentName.md componentPath.replace(path.extname(componentPath), '.md'), // FolderName.md when component definition file is index.js path.join(path.dirname(componentPath), path.basename(path.dirname(componentPath)) + '.md') ]; for (const file of files) { const existingFile = (0, utils_1.findFileCaseInsensitive)(file); if (existingFile) { return existingFile; } } return false; }, getDestFile: (file, conf) => path.resolve(conf.outDir, file).replace(/\.\w+$/, '.md'), editLinkLabel: 'edit on github' }; const config = typeof userConfigOrFunction === 'function' ? await Promise.resolve(userConfigOrFunction(rootConfig)) : { ...rootConfig, ...userConfigOrFunction }; log.debug('[vue-docgen-cli]', { config }); if (!config.getRepoEditUrl && config.docsRepo) { const branch = config.docsBranch || 'master'; const dir = config.docsFolder || ''; config.getRepoEditUrl = (p) => `https://github.com/${config.docsRepo}/edit/${branch}/${dir}/${p}`; } // only default outDir if `outFile` is null to avoid confusion config.outDir = config.outDir || (config.outFile ? '.' : 'docs'); // priority is given to the CLI over the config file if (!logLevel && !verbose) { if (config.logLevel) { log.setLevel(config.logLevel); } else if (config.verbose) { log.setLevel('debug'); } } config.templates = { header: config.templates?.header ?? compileTemplates_1.header, component: config.templates?.component ?? compileTemplates_1.component, events: config.templates?.events ?? compileTemplates_1.events, methods: config.templates?.methods ?? compileTemplates_1.methods, props: config.templates?.props ?? compileTemplates_1.props, slots: config.templates?.slots ?? compileTemplates_1.slots, expose: config.templates?.expose ?? compileTemplates_1.expose, defaultExample: config.templates?.defaultExample ?? compileTemplates_1.defaultExample, functionalTag: config.templates?.functionalTag ?? compileTemplates_1.functionalTag }; return config; }; //# sourceMappingURL=extractConfig.js.map