mtcute/build.config.js

70 lines
2.5 KiB
JavaScript
Raw Normal View History

2024-11-16 16:00:12 +03:00
/** @type {import('@fuman/build').RootConfig} */
export default {
jsr: {
exclude: ['**/*.{test,bench,test-utils}.ts', '**/__fixtures__/**'],
sourceDir: 'src',
transformCode: (path, code) => {
2025-01-01 08:06:51 +03:00
if (!path.endsWith('.ts')) return code
if (!code.match('<deno-(insert|remove|tsignore)>')) return code
2024-11-16 16:00:12 +03:00
2025-01-01 08:06:51 +03:00
// deno is missing some types, so we have to add them manually
// i dont want to manually write types for them, so we just declare them as `any` in a comment
// and un-comment them when building for deno
//
// this way we can still have proper types in the code, while also being able to build for deno
// very much a crutch, but welp, deno sucks
2024-11-16 16:00:12 +03:00
2025-01-01 08:06:51 +03:00
let insertContent = code.match(/<deno-insert>(.*?)<\/deno-insert>/s)
while (insertContent) {
code = code.slice(0, insertContent.index)
+ insertContent[1].replace(/\/\/\s*/g, '')
+ code.slice(insertContent.index + insertContent[0].length)
2024-11-16 16:00:12 +03:00
2025-01-01 08:06:51 +03:00
insertContent = code.match(/<deno-insert>(.*?)<\/deno-insert>/s)
}
2024-11-16 16:00:12 +03:00
2025-01-01 08:06:51 +03:00
let removeContent = code.match(/<deno-remove>(.*?)<\/deno-remove>/s)
while (removeContent) {
code = code.slice(0, removeContent.index) + code.slice(removeContent.index + removeContent[0].length)
removeContent = code.match(/<deno-remove>(.*?)<\/deno-remove>/s)
2024-11-16 16:00:12 +03:00
}
2025-01-01 08:06:51 +03:00
let tsIgnoreContent = code.match(/\/\/\s*<deno-tsignore>/)
while (tsIgnoreContent) {
code = `${code.slice(0, tsIgnoreContent.index)}/* @ts-ignore */${code.slice(tsIgnoreContent.index + tsIgnoreContent[0].length)}`
tsIgnoreContent = code.match(/\/\/\s*<deno-tsignore>/)
2024-11-16 16:00:12 +03:00
}
return code
},
},
versioning: {
exclude: [
'**/*.test.ts',
'**/*.test-utils.ts',
'**/__fixtures__/**',
'**/*.md',
'typedoc.cjs',
'{scripts,dist,tests,private}/**',
],
},
typedoc: {
excludePackages: [
'@mtcute/tl',
'@mtcute/create-bot',
],
validation: {
notExported: true,
invalidLink: false,
notDocumented: false,
},
plugin: [
'./.config/typedoc/plugin-external-links.js',
'./.config/typedoc/plugin-umami.js',
],
},
2024-11-16 16:00:12 +03:00
viteConfig: '.config/vite.build.ts',
}