mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(cli): support resolve static documents
This commit is contained in:
parent
b7d142322b
commit
df213cd1f8
@ -1,26 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="van-doc-nav" :style="style">
|
<div class="van-doc-nav" :style="style">
|
||||||
<div v-for="(item, index) in navConfig" class="van-doc-nav__item" :key="index">
|
<div
|
||||||
<van-doc-nav-link :item="item" :base="base" />
|
v-for="(group, index) in navConfig"
|
||||||
<div v-if="item.children">
|
class="van-doc-nav__group"
|
||||||
<div
|
:key="index"
|
||||||
class="nav-item van-doc-nav__group-title van-doc-nav__group-title"
|
>
|
||||||
v-for="(navItem, navIndex) in item.children"
|
<div class="van-doc-nav__title">
|
||||||
:key="navIndex"
|
{{ group.title }}
|
||||||
>
|
|
||||||
<van-doc-nav-link :item="navItem" :base="base" />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<template v-if="item.groups">
|
<template v-if="group.items">
|
||||||
<div v-for="(group, groupIndex) in item.groups" :key="groupIndex">
|
<div
|
||||||
<div class="van-doc-nav__group-title">{{ group.groupName }}</div>
|
v-for="(item, groupIndex) in group.items"
|
||||||
<div>
|
:key="groupIndex"
|
||||||
<template v-for="(navItem, navItemIndex) in group.list">
|
class="van-doc-nav__item"
|
||||||
<div v-if="!navItem.disabled" :key="navItemIndex" class="van-doc-nav__subitem">
|
>
|
||||||
<van-doc-nav-link :item="navItem" :base="base" />
|
<van-doc-nav-link :item="item" :base="base" />
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
@ -86,10 +80,9 @@ export default {
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
min-width: @van-doc-nav-width;
|
min-width: @van-doc-nav-width;
|
||||||
max-width: @van-doc-nav-width;
|
max-width: @van-doc-nav-width;
|
||||||
padding: 25px 0 75px;
|
padding: 24px 0 72px;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border-right: 1px solid @van-doc-border-color;
|
|
||||||
box-shadow: 0 8px 12px #ebedf0;
|
box-shadow: 0 8px 12px #ebedf0;
|
||||||
|
|
||||||
@media (min-width: @van-doc-row-max-width) {
|
@media (min-width: @van-doc-row-max-width) {
|
||||||
@ -112,64 +105,46 @@ export default {
|
|||||||
background-color: rgba(69, 90, 100, 0.2);
|
background-color: rgba(69, 90, 100, 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
&__item,
|
&__group {
|
||||||
&__subitem {
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
padding: 8px 0 8px @van-doc-padding;
|
||||||
|
color: #455a64;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__item {
|
||||||
a {
|
a {
|
||||||
display: block;
|
display: block;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 10px 0 10px @van-doc-padding;
|
padding: 8px 0 8px @van-doc-padding;
|
||||||
color: #455a64;
|
color: #455a64;
|
||||||
font-size: 16px;
|
font-size: 14px;
|
||||||
line-height: 24px;
|
line-height: 28px;
|
||||||
transition: all 0.3s;
|
transition: all 0.3s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
color: #000;
|
color: #000;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__item {
|
span {
|
||||||
> a {
|
font-size: 13px;
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__subitem {
|
|
||||||
a {
|
|
||||||
font-size: 14px;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
color: #000;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
span {
|
|
||||||
font-size: 13px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__group-title {
|
|
||||||
padding-left: @van-doc-padding;
|
|
||||||
color: @van-doc-text-light-blue;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 40px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 1300px) {
|
@media (max-width: 1300px) {
|
||||||
min-width: 220px;
|
&__item {
|
||||||
max-width: 220px;
|
|
||||||
|
|
||||||
&__item,
|
|
||||||
&__subitem {
|
|
||||||
a {
|
|
||||||
line-height: 22px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__subitem {
|
|
||||||
a {
|
a {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
export const CWD = process.cwd();
|
export const CWD = process.cwd();
|
||||||
export const SRC_DIR = join(CWD, 'src');
|
|
||||||
export const CONFIG_FILE = join(CWD, 'components.config.js');
|
|
||||||
export const ES_DIR = join(CWD, 'es');
|
export const ES_DIR = join(CWD, 'es');
|
||||||
export const LIB_DIR = join(CWD, 'lib');
|
export const LIB_DIR = join(CWD, 'lib');
|
||||||
|
export const SRC_DIR = join(CWD, 'src');
|
||||||
|
export const DOC_DIR = join(CWD, 'doc');
|
||||||
|
export const CONFIG_FILE = join(CWD, 'components.config.js');
|
||||||
export const DIST_DIR = join(__dirname, '../../dist');
|
export const DIST_DIR = join(__dirname, '../../dist');
|
||||||
export const CONFIG_DIR = join(__dirname, '../config');
|
export const CONFIG_DIR = join(__dirname, '../config');
|
||||||
export const MOBILE_CONFIG_FILE = join(DIST_DIR, 'mobile-config.js');
|
export const MOBILE_CONFIG_FILE = join(DIST_DIR, 'mobile-config.js');
|
||||||
|
@ -1,35 +1,51 @@
|
|||||||
import { join, relative } from 'path';
|
import glob from 'fast-glob';
|
||||||
|
import { join, parse, relative } from 'path';
|
||||||
import { existsSync, writeFileSync } from 'fs-extra';
|
import { existsSync, writeFileSync } from 'fs-extra';
|
||||||
import { pascalize, removeExt, getComponents } from '../common';
|
import { pascalize, removeExt, getComponents } from '../common';
|
||||||
import {
|
import {
|
||||||
SRC_DIR,
|
SRC_DIR,
|
||||||
CONFIG_FILE,
|
DOC_DIR,
|
||||||
DIST_DIR,
|
DIST_DIR,
|
||||||
|
CONFIG_FILE,
|
||||||
DESKTOP_CONFIG_FILE
|
DESKTOP_CONFIG_FILE
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
|
|
||||||
function checkDocumentExists(component: string) {
|
type DocumentItem = {
|
||||||
const absolutePath = join(SRC_DIR, component, 'README.md');
|
name: string;
|
||||||
return existsSync(absolutePath);
|
path: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function resolveDocuments(components: string[]): DocumentItem[] {
|
||||||
|
const componentDocs = components
|
||||||
|
.filter(component => {
|
||||||
|
const absolutePath = join(SRC_DIR, component, 'README.md');
|
||||||
|
return existsSync(absolutePath);
|
||||||
|
})
|
||||||
|
.map(component => ({
|
||||||
|
name: pascalize(component),
|
||||||
|
path: join(SRC_DIR, component, 'README.md')
|
||||||
|
}));
|
||||||
|
|
||||||
|
const staticDocs = glob.sync(join(DOC_DIR, '**/*.md')).map(path => ({
|
||||||
|
name: pascalize(parse(path).name),
|
||||||
|
path
|
||||||
|
}));
|
||||||
|
|
||||||
|
return [...componentDocs, ...staticDocs];
|
||||||
}
|
}
|
||||||
|
|
||||||
function genImportDocuments(components: string[]) {
|
function genImportDocuments(items: DocumentItem[]) {
|
||||||
return components
|
return items
|
||||||
.filter(component => checkDocumentExists(component))
|
.map(item => {
|
||||||
.map(component => {
|
const relativePath = relative(DIST_DIR, item.path);
|
||||||
const absolutePath = join(SRC_DIR, component, 'README.md');
|
return `import ${item.name} from '${relativePath}';`;
|
||||||
const relativePath = relative(DIST_DIR, absolutePath);
|
|
||||||
return `import ${pascalize(component)} from '${relativePath}';`;
|
|
||||||
})
|
})
|
||||||
.join('\n');
|
.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
function genExportDocuments(components: string[]) {
|
function genExportDocuments(items: DocumentItem[]) {
|
||||||
return `export const documents = {
|
return `export const documents = {
|
||||||
${components
|
${items.map(item => item.name).join(',\n ')}
|
||||||
.filter(component => checkDocumentExists(component))
|
|
||||||
.map(component => pascalize(component))
|
|
||||||
.join(',\n ')}
|
|
||||||
};`;
|
};`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,11 +60,13 @@ function genExportConfig() {
|
|||||||
|
|
||||||
export function genDesktopConfig() {
|
export function genDesktopConfig() {
|
||||||
const components = getComponents();
|
const components = getComponents();
|
||||||
|
const documents = resolveDocuments(components);
|
||||||
|
|
||||||
const code = `${genImportConfig()}
|
const code = `${genImportConfig()}
|
||||||
${genImportDocuments(components)}
|
${genImportDocuments(documents)}
|
||||||
|
|
||||||
${genExportConfig()}
|
${genExportConfig()}
|
||||||
${genExportDocuments(components)}
|
${genExportDocuments(documents)}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
writeFileSync(DESKTOP_CONFIG_FILE, code);
|
writeFileSync(DESKTOP_CONFIG_FILE, code);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user