chore(cli): rename some files
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { join } from 'path';
|
||||
import { existsSync, ensureDirSync, writeFileSync } from 'fs-extra';
|
||||
import { decamelize, pascalize, removeExt, getComponents } from '../common';
|
||||
import {
|
||||
CONFIG,
|
||||
SRC_DIR,
|
||||
DIST_DIR,
|
||||
MOBILE_ENTRY_FILE
|
||||
} from '../common/constant';
|
||||
|
||||
type DemoItem = {
|
||||
name: string;
|
||||
path: string;
|
||||
};
|
||||
|
||||
function genInstall() {
|
||||
return `import Vue from 'vue';
|
||||
import PackageEntry from './package-entry';
|
||||
import './package-style';
|
||||
|
||||
Vue.use(PackageEntry);
|
||||
`;
|
||||
}
|
||||
|
||||
function genImports(demos: DemoItem[]) {
|
||||
return demos
|
||||
.map(item => `import ${item.name} from '${removeExt(item.path)}';`)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
function genExports(demos: DemoItem[]) {
|
||||
return `export const demos = {\n ${demos
|
||||
.map(item => item.name)
|
||||
.join(',\n ')}\n};`;
|
||||
}
|
||||
|
||||
function genConfig(demos: DemoItem[]) {
|
||||
// eslint-disable-next-line
|
||||
const demoNames = demos.map(item => decamelize(item.name, '-'));
|
||||
|
||||
CONFIG.site.nav = CONFIG.site.nav.filter((group: any) => {
|
||||
group.items = group.items.filter((item: any) =>
|
||||
demoNames.includes(item.path)
|
||||
);
|
||||
return group.items.length;
|
||||
});
|
||||
|
||||
return `export const config = ${JSON.stringify(CONFIG, null, 2)}`;
|
||||
}
|
||||
|
||||
function genCode(components: string[]) {
|
||||
const demos = components
|
||||
.map(component => ({
|
||||
name: pascalize(component),
|
||||
path: join(SRC_DIR, component, 'demo/index.vue')
|
||||
}))
|
||||
.filter(item => existsSync(item.path));
|
||||
|
||||
return `${genInstall()}\n${genImports(demos)}\n\n${genExports(
|
||||
demos
|
||||
)}\n${genConfig(demos)}\n`;
|
||||
}
|
||||
|
||||
export function genSiteMobileShared() {
|
||||
const components = getComponents();
|
||||
const code = genCode(components);
|
||||
|
||||
ensureDirSync(DIST_DIR);
|
||||
writeFileSync(MOBILE_ENTRY_FILE, code);
|
||||
}
|
||||
Reference in New Issue
Block a user