Skip to content

Commit

Permalink
feat: 优化图片上传
Browse files Browse the repository at this point in the history
  • Loading branch information
moshangqi committed Mar 21, 2024
1 parent 8ce6eb1 commit a16fe25
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 109 deletions.
18 changes: 16 additions & 2 deletions tools/dev-tools/generate-svg-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@ function nameWithoutExt(name) {
.join('.');
}

function convertToCamelCase(str) {
const words = str.split('-').map(word => {
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
});
return words.join('');
}

function updateAssetsMap({
targetFilePath,
}) {
const svgMap = {};
const importArray = [];

walkDirSync(svgAssetPath, (filePath, name) => {
const key = nameWithoutExt(name);
if (!key) return;
svgMap[key] = `import('@/assets/svg/${name}')`;
const componentName = convertToCamelCase(key);
svgMap[key] = componentName;
importArray.push(`import ${componentName} from '@/assets/svg/${name}';`);
});

const generateArray = map => {
Expand All @@ -38,6 +48,10 @@ function updateAssetsMap({
return `{\n${result}}`;
};

const generateImportant = array => {
return array.join('\n');
};


// 写入文件
fs.writeFileSync(
Expand All @@ -46,9 +60,9 @@ function updateAssetsMap({
/* eslint-disable @typescript-eslint/indent */
// 本文件为自动生成,不要手动修改
// npm run update:assets
${generateImportant(importArray)}
export const SvgMaps = ${generateArray(svgMap)};
`
);

Expand Down
7 changes: 0 additions & 7 deletions tools/tools/config/common.js

This file was deleted.

76 changes: 0 additions & 76 deletions tools/tools/dev-tools/generate-svg-map.js

This file was deleted.

24 changes: 0 additions & 24 deletions tools/tools/dev-tools/tools-common.js

This file was deleted.

0 comments on commit a16fe25

Please sign in to comment.