-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
43 lines (33 loc) · 1.17 KB
/
setup.js
File metadata and controls
43 lines (33 loc) · 1.17 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
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const filename = `projectId.js`;
const filepath1 = path.join(__dirname, filename);
const filepath2 = path.join(__dirname, "sanity", filename);
const filepath3 = path.join(__dirname, "comment-api", filename);
const filepaths = [filepath1, filepath2, filepath3];
const fileContent = `
const projectId = "${process.env.PROJECT_ID}" ;
export default projectId;
`;
const secretFileContent = `
const projectId = "${process.env.PROJECT_ID}" ;
const token = "${process.env.TOKEN}" ;
export { projectId, token };
`;
for (const [index, filepath] of filepaths.entries()) {
const toWrite = index !== 2 ? fileContent : secretFileContent;
if (fs.existsSync(filepath)) {
console.error(`\x1b[31mFile ${filename} at ${filepath} already exists.\x1b[0m`);
} else {
try {
fs.writeFileSync(filepath, toWrite);
console.log(`File ${filename} created successfully.`);
} catch (error) {
console.error(`Error creating file: ${error.message}`);
process.exit(1);
}
}
}