mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 10:44:59 +00:00
chore(cli): rename some files
This commit is contained in:
68
packages/vant-cli/src/compiler/gen-site-desktop-shared.ts
Normal file
68
packages/vant-cli/src/compiler/gen-site-desktop-shared.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import glob from 'fast-glob';
|
||||
import { join, parse } from 'path';
|
||||
import { existsSync, writeFileSync } from 'fs-extra';
|
||||
import { pascalize, removeExt, getComponents } from '../common';
|
||||
import {
|
||||
SRC_DIR,
|
||||
DOCS_DIR,
|
||||
CONFIG_FILE,
|
||||
DESKTOP_ENTRY_FILE
|
||||
} from '../common/constant';
|
||||
|
||||
type DocumentItem = {
|
||||
name: string;
|
||||
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(DOCS_DIR, '**/*.md')).map(path => ({
|
||||
name: pascalize(parse(path).name),
|
||||
path
|
||||
}));
|
||||
|
||||
return [...componentDocs, ...staticDocs];
|
||||
}
|
||||
|
||||
function genImportDocuments(items: DocumentItem[]) {
|
||||
return items
|
||||
.map(item => `import ${item.name} from '${item.path}';`)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
function genExportDocuments(items: DocumentItem[]) {
|
||||
return `export const documents = {
|
||||
${items.map(item => item.name).join(',\n ')}
|
||||
};`;
|
||||
}
|
||||
|
||||
function genImportConfig() {
|
||||
return `import config from '${removeExt(CONFIG_FILE)}';`;
|
||||
}
|
||||
|
||||
function genExportConfig() {
|
||||
return 'export { config };';
|
||||
}
|
||||
|
||||
export function genSiteDesktopShared() {
|
||||
const components = getComponents();
|
||||
const documents = resolveDocuments(components);
|
||||
|
||||
const code = `${genImportConfig()}
|
||||
${genImportDocuments(documents)}
|
||||
|
||||
${genExportConfig()}
|
||||
${genExportDocuments(documents)}
|
||||
`;
|
||||
|
||||
writeFileSync(DESKTOP_ENTRY_FILE, code);
|
||||
}
|
Reference in New Issue
Block a user