mirror of
https://github.com/DavidHDev/vue-bits.git
synced 2026-03-07 06:29:30 -07:00
SEO, images, cleanup
This commit is contained in:
43
scripts/generateComponent.js
Normal file
43
scripts/generateComponent.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import process from "process";
|
||||
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length < 2) {
|
||||
console.error("Usage: npm run generate:component <ComponentType> <ComponentName>");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const [componentType, componentName] = args;
|
||||
const componentNameLower = componentName.charAt(0).toLowerCase() + componentName.slice(1);
|
||||
|
||||
const paths = {
|
||||
content: path.join(__dirname, "../src/content", componentType, componentName),
|
||||
demo: path.join(__dirname, "../src/demo", componentType),
|
||||
constants: path.join(__dirname, "../src/constants/code", componentType),
|
||||
};
|
||||
|
||||
Object.values(paths).forEach((dir) => {
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
const files = [
|
||||
path.join(paths.content, `${componentName}.vue`),
|
||||
path.join(paths.demo, `${componentName}Demo.jsx`),
|
||||
path.join(paths.constants, `${componentNameLower}Code.js`),
|
||||
];
|
||||
|
||||
files.forEach((file) => {
|
||||
if (!fs.existsSync(file)) {
|
||||
fs.writeFileSync(file, "");
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`Component "${componentName}" structure created successfully under "${componentType}".`);
|
||||
Reference in New Issue
Block a user