|
|
@@ -5,6 +5,7 @@ import {
|
|
|
getCleanPath,
|
|
|
getHref,
|
|
|
slugifyString,
|
|
|
+ writeFile,
|
|
|
} from "./util.js"
|
|
|
import fs from "fs/promises"
|
|
|
import handlebars from "handlebars"
|
|
|
@@ -94,44 +95,55 @@ export async function renderMarkdownWithTemplate({
|
|
|
minifyJS: true,
|
|
|
})
|
|
|
|
|
|
+ await writeFile(fileOutputPath, minifiedHtml)
|
|
|
+
|
|
|
return {
|
|
|
detail: { ...data, href },
|
|
|
- result: minifiedHtml,
|
|
|
+ paths: [fileOutputPath],
|
|
|
deps: {
|
|
|
paths: [template.path],
|
|
|
},
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export async function compileSass({ filePath }) {
|
|
|
+export async function compileSass({ filePath, fileOutputPath, meta }) {
|
|
|
const result = await sass.compileAsync(filePath, { style: "compressed" })
|
|
|
+ await writeFile(fileOutputPath, result.css)
|
|
|
return {
|
|
|
- result: result.css,
|
|
|
+ paths: [fileOutputPath],
|
|
|
+ detail: {
|
|
|
+ href: fileOutputPath.replace(meta.opts.outDir, "")
|
|
|
+ },
|
|
|
deps: {
|
|
|
paths: [...result.loadedUrls.map(item => item.pathname)],
|
|
|
},
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export async function optimiseSvg({ filePath }) {
|
|
|
+export async function optimiseSvg({ filePath, fileOutputPath }) {
|
|
|
const svgString = await fs.readFile(filePath, "utf8")
|
|
|
const result = optimize(svgString, {
|
|
|
plugins: ["preset-default"],
|
|
|
})
|
|
|
+ await writeFile(fileOutputPath, result.data)
|
|
|
return {
|
|
|
- result: result.data,
|
|
|
+ paths: [fileOutputPath],
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export async function copy({ filePath }) {
|
|
|
+export async function copy({ filePath, fileOutputPath }) {
|
|
|
const fileContent = await fs.readFile(filePath, "utf8")
|
|
|
- return { result: fileContent }
|
|
|
+ await writeFile(fileOutputPath, fileContent)
|
|
|
+ return {
|
|
|
+ paths: [fileOutputPath],
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export async function imageToWebP({ filePath, meta, fileOutputDir, config }) {
|
|
|
const sourceExtension = path.extname(filePath)
|
|
|
const outputExtension = config.outputFileExtension
|
|
|
const base = path.basename(filePath, sourceExtension)
|
|
|
+ await fs.mkdir(fileOutputDir, { recursive: true })
|
|
|
|
|
|
const original = sharp(filePath)
|
|
|
const metadata = await original.metadata()
|
|
|
@@ -164,9 +176,8 @@ export async function imageToWebP({ filePath, meta, fileOutputDir, config }) {
|
|
|
const imageRef = getCleanPath(path.join(filePath), meta)
|
|
|
|
|
|
return {
|
|
|
- result: srcSet.map(src => src[0]),
|
|
|
+ paths: srcSet.map(src => src[0]),
|
|
|
detail: { imageRef, srcSet, aspectRatio },
|
|
|
- written: true,
|
|
|
ref: imageRef,
|
|
|
}
|
|
|
}
|
|
|
@@ -210,7 +221,7 @@ export async function generateFavicons({ filePath, meta, fileOutputDir }) {
|
|
|
await Promise.all(
|
|
|
response.images.map(async image => {
|
|
|
const outputPath = path.join(fileOutputDir, image.name)
|
|
|
- await fs.writeFile(outputPath, image.contents)
|
|
|
+ await writeFile(outputPath, image.contents)
|
|
|
}),
|
|
|
)
|
|
|
|
|
|
@@ -218,7 +229,7 @@ export async function generateFavicons({ filePath, meta, fileOutputDir }) {
|
|
|
await Promise.all(
|
|
|
response.files.map(async file => {
|
|
|
const outputPath = path.join(fileOutputDir, file.name)
|
|
|
- await fs.writeFile(outputPath, file.contents)
|
|
|
+ await writeFile(outputPath, file.contents)
|
|
|
}),
|
|
|
)
|
|
|
|
|
|
@@ -228,7 +239,7 @@ export async function generateFavicons({ filePath, meta, fileOutputDir }) {
|
|
|
detail: {
|
|
|
htmlMeta,
|
|
|
},
|
|
|
- result: [
|
|
|
+ paths: [
|
|
|
...response.images.map(img =>
|
|
|
getCleanPath(path.join(fileOutputDir, img.name), meta),
|
|
|
),
|
|
|
@@ -236,7 +247,6 @@ export async function generateFavicons({ filePath, meta, fileOutputDir }) {
|
|
|
getCleanPath(path.join(fileOutputDir, file.name), meta),
|
|
|
),
|
|
|
],
|
|
|
- written: true,
|
|
|
ref: "metatags",
|
|
|
}
|
|
|
} catch (error) {
|