primevue-mirror/packages/primevue/scripts/prebuild.mjs

145 lines
4.3 KiB
JavaScript
Raw Normal View History

2024-06-11 12:21:12 +00:00
import fs from 'fs-extra';
import path from 'path';
import { removeBuild, resolvePath, updatePackageJson } from '../../../scripts/build-helper.mjs';
removeBuild(import.meta.url);
const { __dirname, INPUT_DIR } = resolvePath(import.meta.url);
const __root = path.resolve(__dirname, '../');
const pkg = path.resolve(__root, './package.json');
updatePackageJson(pkg);
// update package.json > "exports" for local
let exports = {};
let modules = {
ignoredFolders: ['useconfirm', 'usedialog', 'usetoast', 'usestyle', 'editor', 'chart'],
umd: [
2024-11-01 06:21:35 +00:00
`/***************** PrimeVue (Auto-Generated) *****************/
// API
2024-06-12 13:37:30 +00:00
export * from '@primevue/core';
// BaseIcon
export { default as BaseIcon } from '@primevue/icons/baseicon';
export { default as BaseIconStyle } from '@primevue/icons/baseicon/style';
// Themes
export * from '@primeuix/styled';
2024-06-12 13:37:30 +00:00
// UseConfirm
export * from '../useconfirm/UseConfirm.js';
// UseDialog
export * from '../usedialog/UseDialog.js';
// UseToast
export * from '../usetoast/UseToast.js';
// UseStyle
export * from '../usestyle/UseStyle.js';
// Editor
export * from '../editor/Editor.vue';
export { default as Editor } from '../editor/Editor.vue';
export * from '../editor/style/EditorStyle.js';
export { default as EditorStyle } from '../editor/style/EditorStyle.js';
// Chart
export * from '../chart/Chart.vue';
export { default as Chart } from '../chart/Chart.vue';
export * from '../chart/style/ChartStyle.js';
export { default as ChartStyle } from '../chart/style/ChartStyle.js';
`
],
esm: [
`/***************** PrimeVue (Auto-Generated) *****************/
// UseConfirm
export * from 'primevue/useconfirm';
2024-06-12 13:37:30 +00:00
// UseDialog
export * from 'primevue/usedialog';
2024-06-12 13:37:30 +00:00
// UseToast
export * from 'primevue/usetoast';
2024-06-12 13:37:30 +00:00
// UseStyle
export * from 'primevue/usestyle';
2024-06-12 13:37:30 +00:00
`
]
};
2024-06-11 12:21:12 +00:00
fs.readdirSync(path.resolve(__root, INPUT_DIR), { withFileTypes: true })
.filter((dir) => dir.isDirectory())
.forEach(({ name: folderName }) => {
2024-06-12 13:37:30 +00:00
const folderPath = path.resolve(__root, INPUT_DIR + folderName);
fs.readdirSync(folderPath).forEach((file) => {
2024-06-11 12:21:12 +00:00
let fileName = file.split(/(.vue)$|(.js)$/)[0];
let name = fileName.toLowerCase();
if (name === folderName) {
const validModuleFolder = !modules.ignoredFolders.includes(folderName);
2024-06-12 13:37:30 +00:00
2024-06-11 12:21:12 +00:00
exports[`./${folderName}`] = `./${INPUT_DIR}${folderName}/${file}`;
if (validModuleFolder) {
modules.umd.push(
`
// ${fileName}
export * from '../${folderName}/${file}';
export { default as ${fileName} } from '../${folderName}/${file}';
`
);
modules.esm.push(
2024-06-12 13:37:30 +00:00
`
// ${fileName}
export * from 'primevue/${folderName}';
export { default as ${fileName} } from 'primevue/${folderName}';
2024-06-12 13:37:30 +00:00
`
);
}
2024-06-12 13:37:30 +00:00
try {
fs.readdirSync(folderPath + '/style').forEach((file) => {
let subFileName = file.split(/(.js)$/)[0];
let subName = subFileName.toLowerCase();
if (subName === `${folderName}style`) {
exports[`./${folderName}/style`] = `./${INPUT_DIR}${folderName}/style/${file}`;
if (validModuleFolder) {
modules.umd.push(
`export * from '../${folderName}/style/${file}';
export { default as ${subFileName} } from '../${folderName}/style/${file}';
`
);
modules.esm.push(
`export * from 'primevue/${folderName}/style';
export { default as ${subFileName} } from 'primevue/${folderName}/style';
2024-06-12 13:37:30 +00:00
`
);
}
2024-06-12 13:37:30 +00:00
}
});
} catch {}
2024-06-11 12:21:12 +00:00
}
});
});
exports['./*'] = './*';
2024-06-12 13:37:30 +00:00
// package.json
2024-06-11 12:21:12 +00:00
const pkgJson = JSON.parse(fs.readFileSync(pkg, { encoding: 'utf8', flag: 'r' }));
pkgJson.exports = exports;
fs.writeFileSync(pkg, JSON.stringify(pkgJson, null, 4));
2024-06-12 13:37:30 +00:00
// UMD
fs.writeFileSync(INPUT_DIR + 'umd/primevue.js', modules.umd.join(''));
// ESM
fs.writeFileSync(INPUT_DIR + 'index.js', modules.esm.join(''));
fs.writeFileSync(INPUT_DIR + 'index.d.ts', modules.esm.join(''));