Skip to content

Commit

Permalink
build(kill-watermark): 优化 sites/index.ts 文件生成
Browse files Browse the repository at this point in the history
  • Loading branch information
maomao1996 committed Oct 14, 2023
1 parent e59d0b0 commit 730a1a1
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-eggs-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'kill-watermark': patch
---

优化 `sites/index.ts` 文件生成
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ yarn.lock

# user-specific files
libs
packages/kill-watermark/src/site/index.ts
19 changes: 16 additions & 3 deletions packages/kill-watermark/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createRollupConfig } from '@femm/shared-rollup-config'
import { readdirSync, writeFileSync } from 'node:fs'
import camelCase from 'camelcase'
import * as prettier from 'prettier'
import prettierConfig from '@femm/prettier'

import pkg from './package.json' assert { type: 'json' }

Expand All @@ -9,9 +11,9 @@ export default createRollupConfig({
postcss: { minimize: true, inject: false },
plugins: [
{
name: 'write-site-module',
name: 'write-site-default-export-module',
transform() {
const files = readdirSync('./src/site')
const files = readdirSync('./src/sites')
const exportDefault = []
const source = files.reduce((str, file) => {
if (file.endsWith('.css')) {
Expand All @@ -24,7 +26,18 @@ export default createRollupConfig({
return str
}, '')

writeFileSync('./src/site/index.ts', `${source}\nexport default [${exportDefault}]`)
const filepath = './src/sites/index.ts'
writeFileSync(
filepath,
prettier.format(`${source}\nexport default [${exportDefault}]`, {
...prettierConfig,
/**
* 配置 filepath 字段,防止控制台弹出如下提示
* No parser and no filepath given, using 'babel' the parser now but this will throw an error in the future. Please specify a parser or a filepath so one can be inferred.
*/
filepath,
}),
)
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/kill-watermark/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sites from 'src/site'
import sites from 'src/sites'

const hostname = location.hostname
const currentSite = (sites as [string, string][]).find(([url]) => hostname.includes(url))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ import { default as vQqCom } from './v.qq.com.css'
import { default as vYoukuCom } from './v.youku.com.css'
import { default as yuqueCom } from './yuque.com.css'

export default [["docs.qq.com", docsQqCom],["gaoding.com", gaodingCom],["iqiyi.com", iqiyiCom],["ke.qq.com", keQqCom],["live.bilibili.com", liveBilibiliCom],["v.qq.com", vQqCom],["v.youku.com", vYoukuCom],["yuque.com", yuqueCom]]
export default [
['docs.qq.com', docsQqCom],
['gaoding.com', gaodingCom],
['iqiyi.com', iqiyiCom],
['ke.qq.com', keQqCom],
['live.bilibili.com', liveBilibiliCom],
['v.qq.com', vQqCom],
['v.youku.com', vYoukuCom],
['yuque.com', yuqueCom],
]

0 comments on commit 730a1a1

Please sign in to comment.