-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathbasic-react-app.command.js
More file actions
90 lines (74 loc) · 2.21 KB
/
basic-react-app.command.js
File metadata and controls
90 lines (74 loc) · 2.21 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const shell = require("shelljs");
const path = require("path");
const details = require("configure-react/commands/details.json");
const fs = require("fs");
// console.log(details.reactApp.appJsData.join("\n"))
const installreactRouter = () => {
shell.exec(`npm i react-router-dom`);
shell.exec(`npm i react-dom`);
};
const editRouterJs = () => {
routerFileCode = details.reactApp.routerFileCode.join("\n");
fs.writeFileSync(
path.join(shell.pwd() + "/src/router/RoutesLink.js"),
routerFileCode,
(err, data) => {}
);
};
const createRouterFolder = () => {
shell.exec("mkdir " + path.join(shell.pwd() + "/src/router"));
shell.exec("mkdir " + path.join(shell.pwd() + "/src/components"));
shell.exec("touch " + path.join(shell.pwd() + "/src/router/index.js"));
shell.exec("touch " + path.join(shell.pwd() + "/src/router/RoutesLink.js"));
editRouterJs();
};
const editAppJs = () => {
appJsData = details.reactApp.appJsFileCode.join("\n");
shell.exec("rm -rf " + path.join(shell.pwd() + "/src/App.css"));
fs.writeFileSync(
path.join(shell.pwd() + "/src/App.js"),
appJsData,
(err, data) => {}
);
installreactRouter();
createRouterFolder();
shell.exec("npm run start");
};
const runBuild = () => {
editAppJs();
};
const editTaiwindConfig = () => {
tailwindReactConfigData = details.tailwindReactConfigData.join("\n");
srcIndexCSSData = details.srcIndexCSSData.join("\n");
fs.writeFileSync(
path.join(shell.pwd() + "/tailwind.config.js"),
tailwindReactConfigData,
(err, data) => {}
);
fs.writeFileSync(
path.join(shell.pwd() + "/src/index.css"),
srcIndexCSSData,
(err, data) => {}
);
runBuild();
};
const configureForTailwind = () => {
shell.exec("npm install -D tailwindcss postcss autoprefixer");
shell.touch("tailwind.config.js");
editTaiwindConfig();
};
const createTailwindReactApp = (name) => {
const projectExist = require("configure-react/commands/projectExist");
if (projectExist(name) == true) {
shell.exit();
}
try {
shell.exec(`npx create-react-app ${name}`);
shell.cd(name);
configureForTailwind();
} catch (err) {
console.log(err.message);
shell.exit();
}
};
module.exports = createTailwindReactApp;