Skip to content

Commit c9bffa3

Browse files
author
Simon he
committed
chore: update
1 parent 858251b commit c9bffa3

File tree

7 files changed

+48
-16
lines changed

7 files changed

+48
-16
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ import {
2929

3030
```
3131

32+
## writeFile
33+
- 快速修改文件内容,支持多个文件同时修改
34+
- 参数:
35+
- filePath: string | string[] 文件路径
36+
- callback: (content: string, index: number) => string 传入文件string类型的内容,可以修改后返回新的内容
37+
```js
38+
writeFile('./a.js', (content) => {
39+
return content.replace('a', 'b')
40+
})
41+
```
42+
43+
## insertUnocssInclude
44+
- unocss作为props传入的组件打包会丢失注释// @unocss-include,这个函数会自动插入到打包后的文件头部
45+
- 参数:
46+
- path: string | string[] 文件路径, 默认 ['./dist/index.js', './dist/index.mjs']
47+
```js
48+
insertUnocssInclude()
49+
```
50+
3251
## useIntersectionObserver
3352
- 监听元素重叠事件
3453
- 参数:

README_en.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ import {
2828
} from 'simon-js-tool' # Ingestion on demand
2929

3030
```
31+
32+
## writeFile
33+
- Quickly modify file content, support multiple files to modify at the same time
34+
- params:
35+
- filePath: string | string[] file path
36+
- callback: (content: string, index: number) => string Incoming file string type content can be modified to return new content
37+
```js
38+
writeFile('./a.js', (content) => {
39+
return content.replace('a', 'b')
40+
})
41+
```
42+
43+
## insertUnocssInclude
44+
- Unocss packaged components passed in as props will lose comments) @unocss-include, this function is automatically inserted into the header of the packaged file
45+
- params:
46+
- path: string | string[] File path, default is ['./dist/index.js', './dist/index.mjs']
47+
```js
48+
insertUnocssInclude()
49+
```
50+
3151
## useIntersectionObserver
3252
- Listen for element overlap events
3353
- Parameters:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"express": "^4.18.1",
6464
"htmlparser2": "^8.0.1",
6565
"pkgroll": "^1.3.1",
66-
"simon-js-tool": "workspace:^4.0.2",
66+
"simon-js-tool": "workspace:^4.0.6",
6767
"spark-md5": "^3.0.2",
6868
"three": "^0.142.0",
6969
"typescript": "^4.7.2",

playground/src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import {
66
exportExcel,
77
exportPdf,
88
fileSplice,
9+
insertUnocssInclude,
910
jsonExportExcel,
1011
jsonExportZip,
1112
picInPic,
1213
tableExportExcel,
1314
useElementBounding,
1415
useIntersectionObserver,
15-
} from '../../src'
16-
16+
} from 'simon-js-tool'
1717
const toggle = picInPic('#video')
1818
</script>
1919

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,4 @@ export { ExportPlugin } from './ExportPlugin'
112112
export { sortByOrder } from './sortByOrder'
113113
export { useIntersectionObserver } from './useIntersectionObserver'
114114
export { insertUnocssInclude } from './insertUnocssInclude'
115+
export { writeFile } from './writeFile'

src/insertUnocssInclude.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
import fs from 'fs'
2-
import { isStr } from './isStr'
3-
export async function insertUnocssInclude(paths: string[] | string = ['./dist/index.js', './dist/index.mjs']): Promise<void> {
1+
import { writeFile } from './writeFile'
2+
export function insertUnocssInclude(paths: string[] | string = ['./dist/index.js', './dist/index.mjs']): void {
43
const reg = '// @unocss-include \n'
5-
if (isStr(paths))
6-
paths = [paths as string];
7-
(paths as string[]).forEach(async (relativepath) => {
8-
const content = await fs.readFileSync('./dist/index.js', 'utf-8').replace(new RegExp(reg, 'g'), '')
9-
fs.writeFile(relativepath, `${reg}${content}`, (err) => {
10-
if (err)
11-
throw err
12-
})
4+
writeFile(paths, (content) => {
5+
return reg + content.replace(new RegExp(reg, 'g'), '')
136
})
147
}
15-

0 commit comments

Comments
 (0)