Skip to content
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

Fix path resolution #282

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
10 changes: 5 additions & 5 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ export default defineNuxtModule<ModuleOptions>({
}

nuxt.hook('nitro:init', async (nitro) => {
const input = options.input.replace(/~|\.\//, 'root').replace(/\//g, ':')
const output = options.output.replace(/~\/|\.\//, '')
const input = `root/${inputDir.replace(nuxt.options.rootDir, '')}`.replace(/\//g, ':')
const output = outDir.replace(nuxt.options.rootDir, "~")
obulat marked this conversation as resolved.
Show resolved Hide resolved

// Make sure output directory exists and contains .gitignore to ignore sprite files
if (!await nitro.storage.hasItem(`${output}:.gitignore`)) {
// await nitro.storage.setItem(`${output}:.gitignore`, '*')
await fsp.mkdir(`${nuxt.options.rootDir}/${output}`, { recursive: true })
await fsp.writeFile(`${nuxt.options.rootDir}/${output}/.gitignore`, '*')
await fsp.mkdir(`${outDir}`, { recursive: true })
await fsp.writeFile(`${outDir}/.gitignore`, '*')
}

const svgsFiles = await nitro.storage.getKeys(input)
Expand All @@ -153,7 +153,7 @@ export default defineNuxtModule<ModuleOptions>({
)

const writeSprite = async (sprite: string) => {
await fsp.writeFile(`${nuxt.options.rootDir}/${output}/${sprite}.svg`, generateSprite(sprite))
await fsp.writeFile(`${outDir}/${sprite}.svg`, generateSprite(sprite))
// return nitro.storage.setItem(`${output}:${sprite}.svg`, generateSprite(sprite))
}
await Promise.all(Object.keys(sprites).map(writeSprite))
Expand Down