-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathcreate-frontend-project.js
More file actions
69 lines (61 loc) · 1.87 KB
/
Copy pathcreate-frontend-project.js
File metadata and controls
69 lines (61 loc) · 1.87 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { copyFile, getTemplateDir } from "./filemanager.js";
import path from "path";
import ora from "ora";
import { vanillaJsHandler } from "../functions/filesHandlers.js";
/**
* loader
*/
let stages = [{ message: "Creating Project ...", duration: 2000 }];
async function startSpinner() {
for (const stage of stages) {
const spinner = ora(stage.message).start();
await new Promise((resolve) => setTimeout(resolve, stage.duration));
spinner.succeed(stage.message.replace("...", " completed."));
}
stages = [{ message: "Creating Project ...", duration: 2000 }];
}
/**
* function to create frontend projects
* @param {string} framework
* @param {string} projectName
* @param {string} language - {typescript, javascript}
*/
export async function createFrontendProject(projectName, framework, language) {
try {
const destinationPath = path.join(
process.cwd(),
projectName ?? `project-starter-${framework}-template`
);
if (framework === "html-css-js") {
return await vanillaJsHandler(projectName);
}
if (framework === "reactjs") {
// copy files based on the language chosen
switch (language) {
case "javascript":
copyFile(
getTemplateDir(`frontend/reactjs/react-javascript-temp`),
destinationPath
);
break;
case "typescript":
copyFile(
getTemplateDir(`frontend/reactjs/react-typescript-temp`),
destinationPath
);
default:
break;
}
// success message
stages.push({
message: `Frontend - ReactJS project with ${
language.charAt(0).toUpperCase() + language.slice(1)
} created successfully! : ${destinationPath}`,
duration: 1000,
});
await startSpinner();
}
} catch (e) {
console.log(`Error Creating Frontend Project: ${e}`);
}
}