-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
executable file
·59 lines (40 loc) · 1.62 KB
/
script.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const projectName = path.basename(process.cwd());
const renameProjectPlaceholder = (fpath) => {
const data = fs.readFileSync(fpath, "utf8");
const result = data.replace(/<PROJECT_NAME_PLACEHOLDER>/g, projectName);
fs.writeFileSync(fpath, result);
};
const moveNarsTemplate = (name) => {
fs.renameSync(path.join(__dirname, "nars", name), path.join(process.cwd(), name));
}
const adjustNodeModulesPath = (fpath) => {
const data = fs.readFileSync(fpath, "utf8");
const result = data.replace(/node_modules/g, "../node_modules");
fs.writeFileSync(fpath, result);
};
// New line
console.log("");
const clientDir = path.join(process.cwd(), "client");
if (!fs.existsSync(clientDir)){
fs.mkdirSync(clientDir);
}
fs.readdirSync(process.cwd()).forEach(fileName => {
if (fileName !== "client") {
fs.renameSync(fileName, path.join("client", fileName));
}
})
renameProjectPlaceholder(path.join(process.cwd(), "client", "package.json"));
renameProjectPlaceholder(path.join(__dirname, "nars", "config", "package.json"));
renameProjectPlaceholder(path.join(__dirname, "nars", "server", "package.json"));
console.log(" ✔ Moving project files to client directory");
moveNarsTemplate("config");
console.log(" ✔ Creating config directory");
moveNarsTemplate("server");
console.log(" ✔ Creating server package");
renameProjectPlaceholder(path.join(__dirname, "nars", "package.json"));
renameProjectPlaceholder(path.join(process.cwd(), "client", "metro.config.js"));
moveNarsTemplate("package.json");
console.log(" ✔ Adjusting node_modules paths");