2024-06-06 13:16:59 +00:00
|
|
|
import { copyFile, existsSync, mkdirSync, readdirSync } from 'node:fs';
|
|
|
|
import path from 'node:path';
|
|
|
|
import process from 'node:process';
|
2023-03-19 23:07:18 +00:00
|
|
|
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
|
2021-11-03 16:40:31 +00:00
|
|
|
import vue from '@vitejs/plugin-vue';
|
2024-06-29 09:11:29 +00:00
|
|
|
import { replaceInFileSync } from 'replace-in-file';
|
2024-06-06 13:16:59 +00:00
|
|
|
import type { Plugin } from 'vite';
|
2022-08-09 15:39:45 +00:00
|
|
|
import prismjs from 'vite-plugin-prismjs';
|
2021-11-03 16:40:31 +00:00
|
|
|
import WindiCSS from 'vite-plugin-windicss';
|
|
|
|
import svgLoader from 'vite-svg-loader';
|
2024-04-29 19:33:45 +00:00
|
|
|
import { defineConfig } from 'vitest/config';
|
2021-11-03 16:40:31 +00:00
|
|
|
|
2024-06-06 13:16:59 +00:00
|
|
|
function woodpeckerInfoPlugin(): Plugin {
|
2021-12-21 09:52:10 +00:00
|
|
|
return {
|
|
|
|
name: 'woodpecker-info',
|
|
|
|
configureServer() {
|
|
|
|
const info =
|
2023-07-16 19:31:36 +00:00
|
|
|
'1) Please add `WOODPECKER_DEV_WWW_PROXY=http://localhost:8010` to your `.env` file.\n' +
|
|
|
|
'After starting the woodpecker server as well you should now be able to access the UI at http://localhost:8000/\n\n' +
|
|
|
|
'2) If you want to run the vite dev server (`pnpm start`) within a container please set `VITE_DEV_SERVER_HOST=0.0.0.0`.';
|
2021-12-21 09:52:10 +00:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log(info);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-06-06 13:16:59 +00:00
|
|
|
function externalCSSPlugin(): Plugin {
|
2023-11-09 13:13:11 +00:00
|
|
|
return {
|
|
|
|
name: 'external-css',
|
|
|
|
transformIndexHtml: {
|
2023-11-29 12:40:51 +00:00
|
|
|
order: 'post',
|
|
|
|
handler() {
|
2023-11-09 13:13:11 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
tag: 'link',
|
|
|
|
attrs: { rel: 'stylesheet', type: 'text/css', href: '/assets/custom.css' },
|
|
|
|
injectTo: 'head',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-03 16:40:31 +00:00
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default defineConfig({
|
|
|
|
plugins: [
|
|
|
|
vue(),
|
2023-03-19 23:07:18 +00:00
|
|
|
VueI18nPlugin({
|
2022-05-16 19:18:48 +00:00
|
|
|
include: path.resolve(__dirname, 'src/assets/locales/**'),
|
|
|
|
}),
|
2022-12-29 12:41:59 +00:00
|
|
|
(() => {
|
|
|
|
const virtualModuleId = 'virtual:vue-i18n-supported-locales';
|
|
|
|
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
|
|
|
|
|
|
const filenames = readdirSync('src/assets/locales/').map((filename) => filename.replace('.json', ''));
|
|
|
|
|
2023-12-04 11:46:24 +00:00
|
|
|
if (!existsSync('src/assets/dayjsLocales')) {
|
|
|
|
mkdirSync('src/assets/dayjsLocales');
|
2023-08-03 17:25:12 +00:00
|
|
|
}
|
|
|
|
|
2024-06-06 13:16:59 +00:00
|
|
|
filenames.forEach((name) => {
|
2023-12-04 11:46:24 +00:00
|
|
|
// English is always directly loaded (compiled by Vite) and thus not copied
|
|
|
|
if (name === 'en') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let langName = name;
|
|
|
|
|
|
|
|
// copy dayjs language
|
2023-08-03 17:25:12 +00:00
|
|
|
if (name === 'zh-Hans') {
|
2023-12-04 11:46:24 +00:00
|
|
|
// zh-Hans is called zh in dayjs
|
|
|
|
langName = 'zh';
|
|
|
|
} else if (name === 'zh-Hant') {
|
|
|
|
// zh-Hant is called zh-cn in dayjs
|
|
|
|
langName = 'zh-cn';
|
2023-08-03 17:25:12 +00:00
|
|
|
}
|
2023-12-04 11:46:24 +00:00
|
|
|
|
|
|
|
copyFile(
|
|
|
|
`node_modules/dayjs/esm/locale/${langName}.js`,
|
|
|
|
`src/assets/dayjsLocales/${name}.js`,
|
2024-06-06 13:16:59 +00:00
|
|
|
// TODO enable with eslint-plugin-promise eslint-disable-next-line promise/prefer-await-to-callbacks
|
2023-12-04 11:46:24 +00:00
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2024-06-29 09:11:29 +00:00
|
|
|
replaceInFileSync({
|
2023-12-04 11:46:24 +00:00
|
|
|
files: 'src/assets/dayjsLocales/*.js',
|
|
|
|
// remove any dayjs import and any dayjs.locale call
|
|
|
|
from: /(?:import dayjs.*'|dayjs\.locale.*);/g,
|
|
|
|
to: '',
|
2023-08-03 17:25:12 +00:00
|
|
|
});
|
|
|
|
|
2022-12-29 12:41:59 +00:00
|
|
|
return {
|
|
|
|
name: 'vue-i18n-supported-locales',
|
2024-06-06 13:16:59 +00:00
|
|
|
|
2022-12-29 12:41:59 +00:00
|
|
|
resolveId(id) {
|
|
|
|
if (id === virtualModuleId) {
|
|
|
|
return resolvedVirtualModuleId;
|
|
|
|
}
|
|
|
|
},
|
2024-06-06 13:16:59 +00:00
|
|
|
|
2022-12-29 12:41:59 +00:00
|
|
|
load(id) {
|
|
|
|
if (id === resolvedVirtualModuleId) {
|
|
|
|
return `export const SUPPORTED_LOCALES = ${JSON.stringify(filenames)}`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
})(),
|
2021-11-03 16:40:31 +00:00
|
|
|
WindiCSS(),
|
|
|
|
svgLoader(),
|
2023-11-09 13:13:11 +00:00
|
|
|
externalCSSPlugin(),
|
2021-12-21 09:52:10 +00:00
|
|
|
woodpeckerInfoPlugin(),
|
2022-08-09 15:39:45 +00:00
|
|
|
prismjs({
|
|
|
|
languages: ['yaml'],
|
|
|
|
}),
|
2021-11-03 16:40:31 +00:00
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'~/': `${path.resolve(__dirname, 'src')}/`,
|
|
|
|
},
|
|
|
|
},
|
2021-12-21 09:52:10 +00:00
|
|
|
logLevel: 'warn',
|
|
|
|
server: {
|
2024-06-06 13:16:59 +00:00
|
|
|
host: process.env.VITE_DEV_SERVER_HOST ?? '127.0.0.1',
|
2021-12-21 09:52:10 +00:00
|
|
|
port: 8010,
|
|
|
|
},
|
2024-04-29 19:33:45 +00:00
|
|
|
test: {
|
|
|
|
globals: true,
|
|
|
|
environment: 'jsdom',
|
|
|
|
},
|
2021-11-03 16:40:31 +00:00
|
|
|
});
|