Skip to content

Commit 2e52ea7

Browse files
committed
feat: modidy path
1 parent 2bf3dd8 commit 2e52ea7

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

docs/svg-symbole.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,14 @@ in your package.json
111111
```json
112112
{
113113
"scripts": {
114-
"build:icon": "bear-script svg-symbols --path=./public/static/plugins/iconsvg/_sources"
114+
"build:icon": "bear-script svg-symbols --path=./public/static/plugins/iconsvg",
115+
"build:icon-from-iconfont": "bear-script svg-symbols:from-iconfont --path=./public/static/plugins/iconsvg/_sources"
115116
}
116117
}
117118
```
118119

120+
> source svg default in `_sources`
121+
119122
## run
120123

121124
```bash

lib/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ module.exports = async function bearScript () {
2323
.command('svg-symbols [path] [idPrefix]', 'svg merge symbols', (yargs) => {
2424
return yargs
2525
.positional('path', {
26-
describe: 'svg source path',
27-
default: './public/static/plugins/iconsvg/_sources',
26+
describe: 'svg source path (ex: ./public/icon -> ./public/icon/_sources)',
27+
default: './public/static/plugins/iconsvg',
2828
})
2929
.positional('idPrefix', {
3030
describe: 'id prefix name (ex: icon -> icon-arrow-right)',

lib/svg-symbols/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,26 @@ function remarkSVGPaths(svgNode: Array<Node | string>): any{
3838
* @param args
3939
*/
4040
async function run(args: IArgs) {
41-
const sourcePath = typeof args.path !== 'undefined' ? args.path: './';
41+
const basePath = typeof args.path !== 'undefined' ? args.path: './';
42+
const sourceDirPath = path.join(basePath, '_sources');
4243
const idPrefix = typeof args.idPrefix !== 'undefined' ? args.idPrefix: 'icon';
4344

44-
logger.info(`svg merge symbols ${sourcePath} ...`);
45+
logger.info(`svg merge symbols ${basePath} ...`);
4546

4647
const symbol: string[] = [];
4748
const iconCodes: string[] = [];
4849

49-
const dirChildFiles = fs.readdirSync(sourcePath);
50+
const dirChildFiles = fs.readdirSync(sourceDirPath);
5051

51-
const targetSvgFile = [sourcePath,'..', 'index.svg'].join('/');
52-
const targetTypeFile = [sourcePath,'..', 'icon.d.ts'].join('/');
52+
const targetSvgFile = path.join(basePath, 'index.svg');
53+
const targetTypeFile = path.join(basePath, 'icon.d.ts');
5354

5455
dirChildFiles.forEach(file => {
5556
if (path.extname(file) == '.svg'){
5657
const filename = file.replace('.svg', '');
5758
const iconCode = [idPrefix, filename].join('-');
5859

59-
const svgFile = fs.readFileSync([sourcePath, file].join('/'),
60-
{encoding:'utf8', flag:'r'});
60+
const svgFile = fs.readFileSync(path.join(basePath, file), {encoding:'utf8', flag:'r'});
6161

6262
const svgContent = svgFile.toString();
6363
const reg = new RegExp(svgTagRule);
@@ -67,7 +67,7 @@ async function run(args: IArgs) {
6767
const result = svgTag[0];
6868
const svgString = parse(result);
6969
const svgPaths = remarkSVGPaths(svgString.children);
70-
symbol.push(` <symbol id="${[idPrefix, filename].join('-')}" viewBox="0 0 1024 1024">\n${svgPaths.join('\n')}\n </symbol>`);
70+
symbol.push(` <symbol id="${iconCode}" viewBox="0 0 1024 1024">\n${svgPaths.join('\n')}\n </symbol>`);
7171
iconCodes.push(`'${filename}'`);
7272

7373
logger.success(`${file}`);
@@ -89,7 +89,7 @@ ${symbol.join('\n\n')}\n
8989

9090

9191
// By OSX Notice
92-
bash(`osascript -e 'display notification "${sourcePath} done" with title "publish done"'`);
92+
bash(`osascript -e 'display notification "${basePath} done" with title "publish done"'`);
9393
}
9494

9595
// run({path: './example/svg-symbols/_source'});

0 commit comments

Comments
 (0)