-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (51 loc) · 1.66 KB
/
index.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
60
61
62
const path = require("path");
const fs = require("fs-extra");
const dotenv = require("dotenv");
const appsDir = path.join(__dirname, "apps");
const packagesDir = path.join(__dirname, "packages");
const baseAppDir = path.join(packagesDir, "base-app");
// Excluded files
const filesToKeep = [
".next",
".env",
".env.dev",
".env.tst",
".env.prd",
".gitignore",
"node_modules"
];
const filesToExclude = [
".next",
".env",
".env.dev",
".env.tst",
".env.prd",
".gitignore",
"node_modules"
];
// Iterate over each app
fs.readdirSync(appsDir).forEach(appName => {
const appPath = path.join(appsDir, appName);
// Delete all files and folders within the app directory, except for the specified files to keep
fs.readdirSync(appPath).forEach(file => {
const filePath = path.join(appPath, file);
if (!filesToKeep.includes(file)) {
fs.removeSync(filePath);
}
});
// Copy all files from the base app directory to the app directory, except for specified files to exclude
fs.readdirSync(baseAppDir).forEach(file => {
if (!filesToExclude.includes(file)) {
const filePath = path.join(baseAppDir, file);
fs.copySync(filePath, path.join(appPath, file));
}
});
// Load the .env file for the current app
const envFilePath = path.join(appPath, ".env");
const envConfig = dotenv.parse(fs.readFileSync(envFilePath));
// Update the "name" field in the app's package.json with the value from .env
const packageFilePath = path.join(appPath, "package.json");
const packageJson = fs.readJsonSync(packageFilePath);
packageJson.name = envConfig.APP_NAME;
fs.writeJsonSync(packageFilePath, packageJson, { spaces: 2 });
});