mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
75 lines
1.6 KiB
JavaScript
75 lines
1.6 KiB
JavaScript
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
const Components = require('./get-components')();
|
|
const packageJson = require('../package.json');
|
|
|
|
const camelizeRE = /-(\w)/g;
|
|
const pascalizeRE = /(\w)(\w*)/g;
|
|
|
|
function camelize(str) {
|
|
return str.replace(camelizeRE, (_, c) => c.toUpperCase());
|
|
}
|
|
|
|
function pascalize(str) {
|
|
return camelize(str).replace(
|
|
pascalizeRE,
|
|
(_, c1, c2) => c1.toUpperCase() + c2
|
|
);
|
|
}
|
|
|
|
const version = process.env.VERSION || packageJson.version;
|
|
const tips = '// This file is auto generated by build/build-entry.js';
|
|
|
|
function buildEntry() {
|
|
const uninstallComponents = [
|
|
'Locale',
|
|
'Lazyload',
|
|
'Waterfall'
|
|
];
|
|
|
|
const importList = Components.map(name => `import ${pascalize(name)} from './${name}';`);
|
|
const exportList = Components.map(name => `${pascalize(name)}`);
|
|
const installList = exportList.filter(name => !~uninstallComponents.indexOf(pascalize(name)));
|
|
const content = `${tips}
|
|
import { VueConstructor } from 'vue/types';
|
|
${importList.join('\n')}
|
|
|
|
declare global {
|
|
interface Window {
|
|
Vue?: VueConstructor;
|
|
}
|
|
}
|
|
|
|
const version = '${version}';
|
|
const components = [
|
|
${installList.join(',\n ')}
|
|
];
|
|
|
|
const install = (Vue: VueConstructor) => {
|
|
components.forEach(Component => {
|
|
Vue.use(Component);
|
|
});
|
|
};
|
|
|
|
/* istanbul ignore if */
|
|
if (typeof window !== 'undefined' && window.Vue) {
|
|
install(window.Vue);
|
|
}
|
|
|
|
export {
|
|
install,
|
|
version,
|
|
${exportList.join(',\n ')}
|
|
};
|
|
|
|
export default {
|
|
install,
|
|
version
|
|
};
|
|
`;
|
|
|
|
fs.writeFileSync(path.join(__dirname, '../src/index.ts'), content);
|
|
}
|
|
|
|
buildEntry();
|