mirror of
https://github.com/youzan/vant.git
synced 2025-10-22 20:04:09 +00:00
feat(cli): auto install all components
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
DOCS_DIR,
|
||||
DIST_DIR,
|
||||
CONFIG_FILE,
|
||||
DESKTOP_CONFIG_FILE
|
||||
DESKTOP_ENTRY_FILE
|
||||
} from '../common/constant';
|
||||
|
||||
type DocumentItem = {
|
||||
@@ -58,7 +58,7 @@ function genExportConfig() {
|
||||
return 'export { config };';
|
||||
}
|
||||
|
||||
export function genDesktopConfig() {
|
||||
export function genDesktopEntry() {
|
||||
const components = getComponents();
|
||||
const documents = resolveDocuments(components);
|
||||
|
||||
@@ -69,5 +69,5 @@ ${genExportConfig()}
|
||||
${genExportDocuments(documents)}
|
||||
`;
|
||||
|
||||
writeFileSync(DESKTOP_CONFIG_FILE, code);
|
||||
writeFileSync(DESKTOP_ENTRY_FILE, code);
|
||||
}
|
@@ -4,7 +4,7 @@ import { decamelize, pascalize, removeExt, getComponents } from '../common';
|
||||
import {
|
||||
SRC_DIR,
|
||||
DIST_DIR,
|
||||
MOBILE_CONFIG_FILE,
|
||||
MOBILE_ENTRY_FILE,
|
||||
CONFIG_FILE
|
||||
} from '../common/constant';
|
||||
|
||||
@@ -13,6 +13,14 @@ type DemoItem = {
|
||||
path: string;
|
||||
};
|
||||
|
||||
function genInstall() {
|
||||
return `import Vue from 'vue';
|
||||
import PackageEntry from './package-entry';
|
||||
|
||||
Vue.use(PackageEntry);
|
||||
`;
|
||||
}
|
||||
|
||||
function genImports(demos: DemoItem[]) {
|
||||
return demos
|
||||
.map(item => {
|
||||
@@ -49,13 +57,13 @@ function genCode(components: string[]) {
|
||||
}))
|
||||
.filter(item => existsSync(item.path));
|
||||
|
||||
return `${genImports(demos)}\n\n${genExports(demos)}\n${genConfig(demos)}\n`;
|
||||
return `${genInstall()}\n${genImports(demos)}\n\n${genExports(demos)}\n${genConfig(demos)}\n`;
|
||||
}
|
||||
|
||||
export function genMobileConfig() {
|
||||
export function genMobileEntry() {
|
||||
const components = getComponents();
|
||||
const code = genCode(components);
|
||||
|
||||
ensureDirSync(DIST_DIR);
|
||||
writeFileSync(MOBILE_CONFIG_FILE, code);
|
||||
writeFileSync(MOBILE_ENTRY_FILE, code);
|
||||
}
|
@@ -36,7 +36,7 @@ const components = [
|
||||
${names.join(',\n ')}
|
||||
];
|
||||
|
||||
function install() {
|
||||
function install(Vue) {
|
||||
components.forEach(item => {
|
||||
if (item.install) {
|
||||
Vue.use(Component);
|
||||
|
Reference in New Issue
Block a user