diff --git a/.changeset/bright-eggs-pump.md b/.changeset/bright-eggs-pump.md new file mode 100644 index 0000000..03bdd0b --- /dev/null +++ b/.changeset/bright-eggs-pump.md @@ -0,0 +1,5 @@ +--- +'kill-watermark': patch +--- + +优化 `sites/index.ts` 文件生成 diff --git a/.prettierignore b/.prettierignore index 521ca45..084cc8a 100644 --- a/.prettierignore +++ b/.prettierignore @@ -19,4 +19,3 @@ yarn.lock # user-specific files libs -packages/kill-watermark/src/site/index.ts diff --git a/packages/kill-watermark/rollup.config.js b/packages/kill-watermark/rollup.config.js index e362b3b..72306c8 100644 --- a/packages/kill-watermark/rollup.config.js +++ b/packages/kill-watermark/rollup.config.js @@ -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' } @@ -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')) { @@ -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, + }), + ) }, }, ], diff --git a/packages/kill-watermark/src/index.ts b/packages/kill-watermark/src/index.ts index 831cc66..5c989fd 100644 --- a/packages/kill-watermark/src/index.ts +++ b/packages/kill-watermark/src/index.ts @@ -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)) diff --git a/packages/kill-watermark/src/site/docs.qq.com.css b/packages/kill-watermark/src/sites/docs.qq.com.css similarity index 100% rename from packages/kill-watermark/src/site/docs.qq.com.css rename to packages/kill-watermark/src/sites/docs.qq.com.css diff --git a/packages/kill-watermark/src/site/gaoding.com.css b/packages/kill-watermark/src/sites/gaoding.com.css similarity index 100% rename from packages/kill-watermark/src/site/gaoding.com.css rename to packages/kill-watermark/src/sites/gaoding.com.css diff --git a/packages/kill-watermark/src/site/index.ts b/packages/kill-watermark/src/sites/index.ts similarity index 63% rename from packages/kill-watermark/src/site/index.ts rename to packages/kill-watermark/src/sites/index.ts index b9af95c..046f945 100644 --- a/packages/kill-watermark/src/site/index.ts +++ b/packages/kill-watermark/src/sites/index.ts @@ -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]] \ No newline at end of file +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], +] diff --git a/packages/kill-watermark/src/site/iqiyi.com.css b/packages/kill-watermark/src/sites/iqiyi.com.css similarity index 100% rename from packages/kill-watermark/src/site/iqiyi.com.css rename to packages/kill-watermark/src/sites/iqiyi.com.css diff --git a/packages/kill-watermark/src/site/ke.qq.com.css b/packages/kill-watermark/src/sites/ke.qq.com.css similarity index 100% rename from packages/kill-watermark/src/site/ke.qq.com.css rename to packages/kill-watermark/src/sites/ke.qq.com.css diff --git a/packages/kill-watermark/src/site/live.bilibili.com.css b/packages/kill-watermark/src/sites/live.bilibili.com.css similarity index 100% rename from packages/kill-watermark/src/site/live.bilibili.com.css rename to packages/kill-watermark/src/sites/live.bilibili.com.css diff --git a/packages/kill-watermark/src/site/v.qq.com.css b/packages/kill-watermark/src/sites/v.qq.com.css similarity index 100% rename from packages/kill-watermark/src/site/v.qq.com.css rename to packages/kill-watermark/src/sites/v.qq.com.css diff --git a/packages/kill-watermark/src/site/v.youku.com.css b/packages/kill-watermark/src/sites/v.youku.com.css similarity index 100% rename from packages/kill-watermark/src/site/v.youku.com.css rename to packages/kill-watermark/src/sites/v.youku.com.css diff --git a/packages/kill-watermark/src/site/yuque.com.css b/packages/kill-watermark/src/sites/yuque.com.css similarity index 100% rename from packages/kill-watermark/src/site/yuque.com.css rename to packages/kill-watermark/src/sites/yuque.com.css