forked from sourcefuse/arc-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-env.js
34 lines (27 loc) · 1.03 KB
/
create-env.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
const fs = require("fs");
const path = require("path");
const glob = require("glob");
//extract workspaces from package.json
const packageJsonPath = path.join(__dirname, "package.json");
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
const workspaces = packageJson.workspaces;
//Get all the directories that matches the workspaces' patterns
let directories = [];
workspaces.forEach((pattern) => {
const folders = glob.sync(pattern);
directories = directories.concat(folders);
});
//File pattern for getting the env schema (e.g. .env.example or .env.schema)
const envPattern = ".env.*";
directories.forEach((dirPath) => {
const filePath = path.join(dirPath, ".env");
//If .env doesn't already exist, make env
if (!fs.existsSync(filePath)) {
const files = glob.sync(path.join(dirPath, envPattern));
if (files.length > 0) {
const fileContent = fs.readFileSync(files[0], "utf8");
fs.writeFileSync(filePath, fileContent);
console.log(`.env created in ${dirPath}`); // NOSONAR
}
}
});