Skip to content

fix: use lodash.template directly to compile template #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions dist/module.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineNuxtModule, createResolver, addComponentsDir, addTemplate, extendPages, addLayout, addPlugin } from '@nuxt/kit';
import { extname, join, basename, resolve } from 'path';
import { promises, existsSync, mkdirSync, writeFileSync } from 'node:fs';
import { readFileSync, promises, existsSync, mkdirSync, writeFileSync } from 'node:fs';
import _ from 'lodash';
import { kebabCase } from 'scule';
import fs from 'fs';
Expand Down Expand Up @@ -435,7 +435,10 @@ const module = defineNuxtModule({
}
for (let item of docs) {
addLayout({
src: resolver.resolve(`./runtime/layout/OpenApiLayoutNuxt3.vue`),
getContents({ options }) {
const contents = readFileSync(resolver.resolve(`./runtime/layout/OpenApiLayoutNuxt3.vue`), 'utf-8')
return _.template(contents)({ options })
},
filename: `openapi/apidocs.layout.${item.filename}.vue`,
write: true,
options: {
Expand Down
7 changes: 5 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
addTemplate,
} from '@nuxt/kit'
import {resolve, extname, basename, join} from "path";
import {promises, existsSync, writeFileSync, mkdirSync} from "node:fs";
import {readFileSync, promises, existsSync, writeFileSync, mkdirSync} from "node:fs";
import _ from "lodash";
import type {Resolver} from '@nuxt/kit'
import {kebabCase} from "scule";
Expand Down Expand Up @@ -185,7 +185,10 @@ export default defineNuxtModule<ModuleOptions>({

for (let item of docs) {
addLayout({
src: resolver.resolve(`./runtime/layout/OpenApiLayoutNuxt3.vue`),
getContents({ options }) {
const contents = readFileSync(resolver.resolve(`./runtime/layout/OpenApiLayoutNuxt3.vue`), 'utf-8')
return _.template(contents)({ options })
},
filename: `openapi/apidocs.layout.${item.filename}.vue`,
write: true,
options: {
Expand Down