-
Notifications
You must be signed in to change notification settings - Fork 0
/
pageConstractor.js
executable file
·44 lines (41 loc) · 1.32 KB
/
pageConstractor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node
const fs = require("node:fs").promises;
const path = require("node:path");
const { getConfig } = require("./finder.js");
const { routeManager } = require("./routeManager.js");
const projectPath = getConfig().paths.project;
let pageName = process.argv[2]
? process.argv[2].trim().toUpperCase()
: (console.error("Usage: page <page-name>"), process.exit(1));
const pagePath = path.join(projectPath, "frontend/src/pages");
const jsTemplatePath = path.join(__dirname, "component-template.js");
routeManager(pageName);
(async () => {
try {
try {
await fs.access(pagePath);
} catch {
await fs.mkdir(pagePath, { recursive: true });
}
await fs.writeFile(
path.join(
projectPath,
"frontend/src/assets/style/",
`${pageName.toLowerCase()}-page.css`
),
`/****** ${pageName}.css ******/`
);
const jsTemplate = await fs.readFile(jsTemplatePath, "utf8");
const processedJsTemplate = jsTemplate
.replace(/__COMPONENT_NAME__/g, pageName)
.replace(/__COMPONENT_TAG__/g, `${pageName.toLowerCase()}-page`);
await fs.writeFile(
`${pagePath}/${pageName.toLowerCase()}.js`,
processedJsTemplate
);
console.info(`Page ${pageName} created successfully!`);
} catch (error) {
console.log(error);
process.exit(1);
}
})();