Skip to content

Instantly share code, notes, and snippets.

@wlkns
Created August 1, 2023 13:27
Show Gist options
  • Save wlkns/47f93fcaf1edd360d9de767360005b29 to your computer and use it in GitHub Desktop.
Save wlkns/47f93fcaf1edd360d9de767360005b29 to your computer and use it in GitHub Desktop.
Fill empty .vue files with a template.
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