mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
4b8dd7a9ca
* feat: Office viewer 支持 Excel * 修复类型报错 * 修复类型报错
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
/**
|
|
* 生成示例文件列表
|
|
*/
|
|
|
|
import {readdir} from 'node:fs/promises';
|
|
import {writeFileSync} from 'fs';
|
|
import prettier from 'prettier';
|
|
|
|
async function genFiles(path: string) {
|
|
const fileLists: Record<string, string[]> = {};
|
|
const dirs = (await readdir(path)).filter(
|
|
item => !/(^|\/)\.[^\/\.]/g.test(item)
|
|
);
|
|
for (const dir of dirs) {
|
|
fileLists[dir] = (await readdir(path + '/' + dir)).filter(
|
|
item =>
|
|
(item.endsWith('.xlsx') ||
|
|
item.endsWith('.csv') ||
|
|
item.endsWith('.tsv')) &&
|
|
!item.startsWith('~')
|
|
);
|
|
}
|
|
return fileLists;
|
|
}
|
|
|
|
function writeFile(fileName: string, content: string) {
|
|
prettier.resolveConfig('../../../.prettierrc').then(options => {
|
|
const formatted = prettier.format(content, {
|
|
...options,
|
|
parser: 'typescript'
|
|
});
|
|
writeFileSync(fileName, formatted);
|
|
});
|
|
}
|
|
|
|
(async () => {
|
|
const excelFiles = genFiles('__tests__/xlsx/');
|
|
writeFile(
|
|
'examples/excelFileList.ts',
|
|
`export default ${JSON.stringify(await excelFiles, null, 2)};`
|
|
);
|
|
})();
|