-
Notifications
You must be signed in to change notification settings - Fork 0
/
postinstall.js
49 lines (44 loc) · 995 Bytes
/
postinstall.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
#!/bin/node
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
const fs = require('fs');
const { resolve } = require('path');
const cwd = process.env.INIT_CWD;
console.log('cwd', cwd);
const getTemplateEnv = () => {
const envFile = resolve(
cwd,
'node_modules',
'@honestfoodcompany',
'pubsub',
'env-example.txt',
);
return envFile;
};
const copyFile = function (
source,
target,
overwrite = false,
executable = false,
) {
if (!fs.existsSync(target)) {
fs.copyFileSync(source, target);
} else if (fs.existsSync(target) && overwrite) {
fs.copyFileSync(source, target);
if (executable) {
fs.chmodSync(target, '755');
}
}
};
const copyEnv = () => {
const source = getTemplateEnv();
const target = resolve(cwd, '.env');
copyFile(source, target, false);
};
if (process.env.NODE_ENV !== 'production' || process.env.NODE_ENV !== 'prod') {
try {
copyEnv();
} catch (e) {
console.log(e);
}
}