Created
February 1, 2021 11:19
-
-
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 contains hidden or 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
| // 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