Skip to content

Instantly share code, notes, and snippets.

@wlkns
Created February 1, 2021 11:19
Show Gist options
  • Select an option

  • Save wlkns/125c897a9fd1e907d8d049c4e80d33e3 to your computer and use it in GitHub Desktop.

Select an option

Save wlkns/125c897a9fd1e907d8d049c4e80d33e3 to your computer and use it in GitHub Desktop.
Initialise empty .vue files with the file name (node initialise-vue-files.js)
// This file will initialise and empty .vue files with a basic name and structure.
const fs = require("fs");
const { exec } = require("child_process");
exec('find src -type f -iname "*.vue"', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
const files = stdout.split("\n").filter((v) => v && v.length);
files
.filter((file) => {
// make sure file is empty empty
let data = fs.readFileSync(file, { encoding: "utf-8" });
return !data || data.length < 5;
})
.map((file) => {
let name = file.substring(file.lastIndexOf("/") + 1);
name = name.substring(0, name.length - 4);
console.log(file, name);
fs.writeFileSync(
file,
`<template>
<h1>${name}</h1>
</template>
<script>
export default {
}
</script>
<style>
</style>`
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment