mirror of
https://github.com/sern-handler/cli
synced 2026-06-28 02:32:20 +00:00
feat: build app (#112)
* chore: start publish work * chore: more debug... who overwrote! permalink: http://whatthecommit.com/2e6bbd4fd1a21e16039ce52216c3c0b4 * update node version requirement (#106) * update node version requirement * publish progress * progress on publish * style: pretty pretty * chore: some progress i guess? * more progress on publish command * chore: remove magicast * more progress on command data * fix: adding extra fields to json output * fix: stringify again * rest field cli * style: run prettier * chore: friday 5pm permalink: http://whatthecommit.com/502256b954264d50f29967e1fef8394b * prettier and more progress on publish * progress on publishing * config can be function and publishing seems to be working correctly * fix, made mistakes * fix guild command publishing * fix guild ids not publishing correctly * edit correctly * upgrade fire readiers * refactor and separate some stuff * ^ * add default_member_permissions * refator * refactors * publish functionality done * seems like attachment loading works correctly * extrapolate * code splitting and faster startup * fix up bugs * forgot to merge prompts/plugin * remove unneeded esbuild plugin for simple define * build auto generate typings * fix: template dir after switching commands to dynamic imports * update preprocessor * fix: add experimental warning to publish and build * fix vulnerability * oops, false alarm * better sern.build.js config support * chore: remove pnpm lock * cleaner build and also some cli options * fix regression * add more cli options * optimize * no any --------- Co-authored-by: EvolutionX <evolutionx9777@gmail.com>
This commit is contained in:
40
src/plugins/imageLoader.ts
Normal file
40
src/plugins/imageLoader.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import fs from 'fs/promises'
|
||||
import path from 'node:path'
|
||||
import { require } from '../utilities/require.js'
|
||||
import { type Plugin } from 'esbuild'
|
||||
import { basename } from 'node:path'
|
||||
|
||||
export const validExtensions = ['.ts','.js', '.json', '.png', '.jpg', '.jpeg', '.webp']
|
||||
|
||||
//https://github.com/evanw/esbuild/issues/1051
|
||||
export const imageLoader = {
|
||||
name: 'attachment-loader',
|
||||
setup: b => {
|
||||
const filter = new RegExp(`\.${validExtensions.slice(3).join('|')}$`)
|
||||
b.onResolve({ filter }, args => {
|
||||
//if the module is being imported, resolve the path and transform to the js stub
|
||||
if(args.importer) {
|
||||
const newPath = path
|
||||
.format({ ...path.parse(args.path), base: '', ext: '.js' })
|
||||
.split(path.sep)
|
||||
.join(path.posix.sep)
|
||||
return { path: newPath, namespace: 'attachment-loader', external: true }
|
||||
}
|
||||
// if the file is actually the attachment, resolve the full dir
|
||||
return { path: require.resolve(args.path, { paths: [args.resolveDir] }), namespace: 'attachment-loader' }
|
||||
})
|
||||
|
||||
b.onLoad({ filter: /.*/, namespace: 'attachment-loader' },
|
||||
async (args) => {
|
||||
const base64 = await fs.readFile(args.path).then(s => s.toString('base64'))
|
||||
return {
|
||||
contents: `
|
||||
var __toBuffer = (base64) => Buffer.from(base64, "base64");
|
||||
module.exports = {
|
||||
name: '${basename(args.path)}',
|
||||
attachment: __toBuffer("${base64}")
|
||||
}`,
|
||||
}
|
||||
})
|
||||
}
|
||||
} satisfies Plugin
|
||||
Reference in New Issue
Block a user