diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..84745e3 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,19 @@ +/** + * {} + * @author yutent + * @date 2025/01/03 10:39:13 + */ + +import Smarty from 'smartyx' + +declare interface SmartyConfig { + dir: string + ext?: string +} + +declare interface Engine { + name: 'smarty' + install(conf?: SmartyConfig): Smarty +} + +export function createSmartyEngine(): Engine diff --git a/index.js b/index.js index 78b4bfa..a79289b 100644 --- a/index.js +++ b/index.js @@ -11,22 +11,24 @@ const DEFAULT_CONFIG = { ext: '.htm' } -export const ViewsModule = { - name: 'views', - install(conf = {}) { - if (!conf.dir) { - throw new Error('Please make sure to set the `dir` field') +export function createSmartyEngine() { + return { + name: 'smarty', + install(conf = {}) { + if (!conf.dir) { + throw new Error("Smarty template's dir is required") + } + let views = Object.assign({}, DEFAULT_CONFIG, conf) + let engine = new Smarty() + + this.set({ views }) + + engine.config('path', views.dir) + + if (views.ext) { + engine.config('ext', views.ext) + } + return engine } - let engine = new Smarty() - - let views = Object.assign({}, DEFAULT_CONFIG, conf) - this.set({ views }) - - engine.config('path', views.dir) - - if (views.ext) { - engine.config('ext', views.ext) - } - return engine } } diff --git a/package.json b/package.json index cb076a0..638192c 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "@gm5/views", - "version": "2.0.0", + "version": "3.0.0", "description": "@gm5框架的模板引擎拓展包", "type": "module", - "main": "index.js", "author": "yutent ", "repository": "https://git.wkit.fun/gm5/views.git", + "main": "index.js", + "types": "index.d.ts", "keywords": [ "fivejs", "gm5",