🔧 ci: update vite script, auto remove trivial files under dist/
This commit is contained in:
parent
591cf2e95e
commit
38b19fdb88
2 changed files with 75 additions and 1 deletions
12
public/i18n/README.md
Normal file
12
public/i18n/README.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
思源支持的 i18n 文件范围,可以在控制台 `siyuan.config.langs` 中查看。以下是目前(2024-10-24)支持的语言方案:
|
||||
|
||||
The range of i18n files supported by SiYuan can be viewed in the console under `siyuan.config.langs`. Below are the language schemes currently supported as of now (October 24, 2024) :
|
||||
|
||||
```js
|
||||
>>> siyuan.config.langs.map( lang => lang.name)
|
||||
['de_DE', 'en_US', 'es_ES', 'fr_FR', 'he_IL', 'it_IT', 'ja_JP', 'pl_PL', 'ru_RU', 'zh_CHT', 'zh_CN']
|
||||
```
|
||||
|
||||
在插件开发中,默认使用 JSON 格式作为国际化(i18n)的载体文件。如果您更喜欢使用 YAML 语法,可以将 JSON 文件替换为 YAML 文件(例如 `en_US.yaml`),并在其中编写 i18n 文本。本模板提供了相关的 Vite 插件,可以在编译时自动将 YAML 文件转换为 JSON 文件(请参见 `/yaml-plugin.js`)。本 MD 文件 和 YAML 文件会在 `npm run build` 时自动从 `dist` 目录下删除,仅保留必要的 JSON 文件共插件系统使用。
|
||||
|
||||
In plugin development, JSON format is used by default as the carrier file for internationalization (i18n). If you prefer to use YAML syntax, you can replace the JSON file with a YAML file (e.g., `en_US.yaml`) and write the i18n text within it. This template provides a related Vite plugin that can automatically convert YAML files to JSON files during the compilation process (see `/yaml-plugin.js`). This markdown file and YAML files will be automatically removed from the `dist` directory during `npm run build`, leaving only the necessary JSON files for plugin system to use.
|
|
@ -41,6 +41,7 @@ export default defineConfig({
|
|||
{ src: "./icon.png", dest: "./" }
|
||||
],
|
||||
}),
|
||||
|
||||
],
|
||||
|
||||
define: {
|
||||
|
@ -77,6 +78,11 @@ export default defineConfig({
|
|||
}
|
||||
}
|
||||
] : [
|
||||
// Clean up unnecessary files under dist dir
|
||||
cleanupDistFiles({
|
||||
patterns: ['i18n/*.yaml', 'i18n/*.md'],
|
||||
distDir: outputDir
|
||||
}),
|
||||
zipPack({
|
||||
inDir: './dist',
|
||||
outDir: './',
|
||||
|
@ -98,4 +104,60 @@ export default defineConfig({
|
|||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Clean up some dist files after compiled
|
||||
* @author frostime
|
||||
* @param options:
|
||||
* @returns
|
||||
*/
|
||||
function cleanupDistFiles(options: { patterns: string[], distDir: string }) {
|
||||
const {
|
||||
patterns,
|
||||
distDir
|
||||
} = options;
|
||||
|
||||
return {
|
||||
name: 'rollup-plugin-cleanup',
|
||||
enforce: 'post',
|
||||
writeBundle: {
|
||||
sequential: true,
|
||||
order: 'post' as 'post',
|
||||
async handler() {
|
||||
const fg = await import('fast-glob');
|
||||
const fs = await import('fs');
|
||||
// const path = await import('path');
|
||||
|
||||
// 使用 glob 语法,确保能匹配到文件
|
||||
const distPatterns = patterns.map(pat => `${distDir}/${pat}`);
|
||||
console.debug('Cleanup searching patterns:', distPatterns);
|
||||
|
||||
const files = await fg.default(distPatterns, {
|
||||
dot: true,
|
||||
absolute: true,
|
||||
onlyFiles: false
|
||||
});
|
||||
|
||||
// console.info('Files to be cleaned up:', files);
|
||||
|
||||
for (const file of files) {
|
||||
try {
|
||||
if (fs.default.existsSync(file)) {
|
||||
const stat = fs.default.statSync(file);
|
||||
if (stat.isDirectory()) {
|
||||
fs.default.rmSync(file, { recursive: true });
|
||||
} else {
|
||||
fs.default.unlinkSync(file);
|
||||
}
|
||||
console.log(`Cleaned up: ${file}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Failed to clean up ${file}:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue