Created
August 1, 2023 13:27
-
-
Save wlkns/47f93fcaf1edd360d9de767360005b29 to your computer and use it in GitHub Desktop.
Fill empty .vue files with a template.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { resolve } from 'path'; | |
import { readdir, stat, writeFile } from 'node:fs/promises'; | |
async function* getFiles(dir) { | |
const dirents = await readdir(dir, { withFileTypes: true }); | |
for (const dirent of dirents) { | |
const res = resolve(dir, dirent.name); | |
if (dirent.isDirectory()) { | |
yield* getFiles(res); | |
} else { | |
yield res; | |
} | |
} | |
} | |
for await (const file of getFiles('./src/pages/')) { | |
const { size: filesize } = await stat(file); | |
const filename = file.substring(file.lastIndexOf('/') + 1); | |
if ( filesize === 0 ) { | |
await writeFile(file, `<template> | |
<code>${filename}</code> | |
</template> | |
<script setup lang="ts"> | |
</script> | |
<style lang="postcss"> | |
</style>`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment