refactor(ui-templates): use fdir

This commit is contained in:
Daniel Roe 2024-06-24 14:34:07 +01:00
parent 0ef8febb8c
commit d9e55546d9
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
3 changed files with 7 additions and 8 deletions

View File

@ -1,14 +1,12 @@
import { join, resolve } from 'node:path' import { join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { promises as fsp } from 'node:fs' import { promises as fsp } from 'node:fs'
import { globby } from 'globby' import { fdir } from 'fdir'
const templatesRoot = fileURLToPath(new URL('..', import.meta.url)) const templatesRoot = fileURLToPath(new URL('..', import.meta.url))
const r = (...path: string[]) => resolve(join(templatesRoot, ...path))
async function main () { async function main () {
const templates = await globby(r('dist/templates/*.js')) const templates = new fdir().glob('*.js').crawl(join(templatesRoot, 'dist/templates')).sync()
for (const file of templates) { for (const file of templates) {
const { template } = await import(file) const { template } = await import(file)
const updated = template({ const updated = template({

View File

@ -1,13 +1,13 @@
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { readFileSync, rmdirSync, unlinkSync, writeFileSync } from 'node:fs' import { readFileSync, rmdirSync, unlinkSync, writeFileSync } from 'node:fs'
import { copyFile } from 'node:fs/promises' import { copyFile } from 'node:fs/promises'
import { basename, dirname, join, resolve } from 'pathe' import { basename, dirname, join } from 'pathe'
import type { Plugin } from 'vite' import type { Plugin } from 'vite'
// @ts-expect-error https://github.com/GoogleChromeLabs/critters/pull/151 // @ts-expect-error https://github.com/GoogleChromeLabs/critters/pull/151
import Critters from 'critters' import Critters from 'critters'
import { genObjectFromRawEntries } from 'knitwork' import { genObjectFromRawEntries } from 'knitwork'
import htmlMinifier from 'html-minifier' import htmlMinifier from 'html-minifier'
import { globby } from 'globby' import { fdir } from 'fdir'
import { camelCase } from 'scule' import { camelCase } from 'scule'
import genericMessages from '../templates/messages.json' import genericMessages from '../templates/messages.json'
@ -25,7 +25,7 @@ export const RenderPlugin = () => {
enforce: 'post', enforce: 'post',
async writeBundle () { async writeBundle () {
const critters = new Critters({ path: outputDir }) const critters = new Critters({ path: outputDir })
const htmlFiles = await globby(resolve(outputDir, 'templates/**/*.html'), { absolute: true }) const htmlFiles = new fdir().withFullPaths().glob('**/*.html').crawl(join(outputDir, 'templates')).sync()
const templateExports: Array<{ const templateExports: Array<{
exportName: string exportName: string

View File

@ -23,11 +23,12 @@
"@unocss/reset": "0.61.0", "@unocss/reset": "0.61.0",
"critters": "0.0.22", "critters": "0.0.22",
"execa": "9.2.0", "execa": "9.2.0",
"globby": "14.0.1", "fdir": "6.1.1",
"html-minifier": "4.0.0", "html-minifier": "4.0.0",
"jiti": "1.21.6", "jiti": "1.21.6",
"knitwork": "1.1.0", "knitwork": "1.1.0",
"pathe": "1.1.2", "pathe": "1.1.2",
"picomatch": "4.0.2",
"prettier": "3.3.2", "prettier": "3.3.2",
"scule": "1.3.0", "scule": "1.3.0",
"unocss": "0.61.0", "unocss": "0.61.0",