update: 支持柯里化
This commit is contained in:
parent
2c7692ddc3
commit
d70cc61570
|
@ -1,3 +1,4 @@
|
|||
import '../src/init/require.js'
|
||||
import '../src/init/config.js'
|
||||
import '../src/init/logger.js'
|
||||
import '../src/init/redis.js'
|
||||
|
@ -28,20 +29,35 @@ for (const flie of flies) {
|
|||
console.log('flie.name', flie.name, '识别错误')
|
||||
continue
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const plugins = readdirSync(join(dir, flie.name), {
|
||||
withFileTypes: true
|
||||
}).filter(flie => flie.isFile())
|
||||
for (const plugin of plugins) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (/^(routes.jsx|routes.tsx)$/.test(plugin.name)) {
|
||||
const routes = (await import(`file://${join(plugin.path, plugin.name)}`))
|
||||
?.default
|
||||
if (!routes) continue
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (Array.isArray(routes)) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
for (const item of routes) {
|
||||
const url = `/${flie.name}${item.url}`
|
||||
console.log(`http://127.0.0.1:${Port}${url}`)
|
||||
const options = item?.options ?? {}
|
||||
/**
|
||||
* 推送接口
|
||||
*/
|
||||
router.get(url, ctx => {
|
||||
const options = item?.options ?? {}
|
||||
const HTML = Com.create(item.element, {
|
||||
...options,
|
||||
html_head: options?.html_head ?? '',
|
||||
|
@ -68,5 +84,5 @@ app.use(router.routes())
|
|||
// listen 8000
|
||||
app.listen(Port, () => {
|
||||
console.log('Server is running on port ' + Port)
|
||||
console.log('自行调整默认浏览器尺寸 800 X 1280 100%')
|
||||
console.log('默认浏览器尺寸 800 X 1280 100%')
|
||||
})
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import './init/require.js'
|
||||
import './init/config.js'
|
||||
import './init/logger.js'
|
||||
import './init/redis.js'
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
import { createRequire } from 'module'
|
||||
import path from 'path'
|
||||
const require = createRequire(import.meta.url)
|
||||
/**
|
||||
* 常用扩展名
|
||||
*/
|
||||
const CustomExtensions = [
|
||||
'.css',
|
||||
'.apng',
|
||||
'.png',
|
||||
'.jpg',
|
||||
'.jpeg',
|
||||
'.jfif',
|
||||
'.pjpeg',
|
||||
'.pjp',
|
||||
'.gif',
|
||||
'.svg',
|
||||
'.ico',
|
||||
'.webp',
|
||||
'.avif',
|
||||
'.mp4',
|
||||
'.webm',
|
||||
'.ogg',
|
||||
'.mp3',
|
||||
'.wav',
|
||||
'.flac',
|
||||
'.aac',
|
||||
'.opus',
|
||||
'.mov',
|
||||
'.m4a',
|
||||
'.vtt',
|
||||
'.woff',
|
||||
'.woff2',
|
||||
'.eot',
|
||||
'.ttf',
|
||||
'.otf'
|
||||
]
|
||||
/**
|
||||
* 扩展引入
|
||||
*/
|
||||
for (const ext of CustomExtensions) {
|
||||
require.extensions[ext] = (module, filename) => {
|
||||
module.exports = path.resolve(filename)
|
||||
}
|
||||
}
|
|
@ -1,55 +1,18 @@
|
|||
import { createRequire as cRequire } from 'module'
|
||||
import path from 'path'
|
||||
|
||||
const CustomExtensions = [
|
||||
//
|
||||
'.css',
|
||||
//
|
||||
'.apng',
|
||||
'.png',
|
||||
'.jpg',
|
||||
'.jpeg',
|
||||
'.jfif',
|
||||
'.pjpeg',
|
||||
'.pjp',
|
||||
'.gif',
|
||||
'.svg',
|
||||
'.ico',
|
||||
'.webp',
|
||||
'.avif',
|
||||
'.mp4',
|
||||
'.webm',
|
||||
'.ogg',
|
||||
'.mp3',
|
||||
'.wav',
|
||||
'.flac',
|
||||
'.aac',
|
||||
'.opus',
|
||||
'.mov',
|
||||
'.m4a',
|
||||
'.vtt',
|
||||
'.woff',
|
||||
'.woff2',
|
||||
'.eot',
|
||||
'.ttf',
|
||||
'.otf'
|
||||
]
|
||||
|
||||
/**
|
||||
* 加载指定资源的本地路径
|
||||
* @param basePath 引入模块地址
|
||||
* @param customExtensions
|
||||
* @deprecated 已废弃
|
||||
* @param basePath
|
||||
*/
|
||||
export function createRequire(basePath: string) {
|
||||
return cRequire(basePath)
|
||||
}
|
||||
/**
|
||||
* 引入资源并返回地址
|
||||
* @param path
|
||||
* @returns
|
||||
*/
|
||||
export function createRequire(
|
||||
basePath: string,
|
||||
customExtensions = CustomExtensions
|
||||
) {
|
||||
const require = cRequire(basePath)
|
||||
for (const ext of customExtensions) {
|
||||
require.extensions[ext] = (module, filename) => {
|
||||
module.exports = path.resolve(filename)
|
||||
export function require(path: string) {
|
||||
return (url: string) => {
|
||||
return cRequire(url)(path)
|
||||
}
|
||||
}
|
||||
return require
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue