-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmynode.js
32 lines (27 loc) · 917 Bytes
/
mynode.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
import { writeFile } from 'fs';
import { join } from 'path';
import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
// Simulate __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = join(__filename, '..'); // Move to the directory
// Load environment variables from .env
dotenv.config({ path: 'src/.env' });
// Environment file content
const envFile = `export const environment = {
API_KEY: '${process.env.API_KEY}',
};
`;
// Define the target path
const targetPath = join(__dirname, './src/environments/environment.development.ts');
// Write the file
writeFile(targetPath, envFile, (err) => {
if (err) {
console.error(err);
throw err;
} else {
const successColor = '\x1b[32m%s\x1b[0m';
const checkSign = '\u{2705}';
console.log(successColor, `${checkSign} Successfully generated environment.development.ts`);
}
});