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
63
64
65
66
67
68
69
70
71
72
73
74
|
var replace = require('replace-in-file');
var buildDate = new Date();
var copyrightYear = buildDate.getFullYear();
const optionsNewYear = {
files:[
'src/environments/environment.ts',
'src/environments/environment.prod.ts'
],
from: /{COPYRIGHT_YEAR}/g,
to: copyrightYear,
allowEmptyPaths: false,
};
const optionsOldYear = {
files:[
'src/environments/environment.ts',
'src/environments/environment.prod.ts'
],
from: /year: '(.*)'/g,
to: "year: '{COPYRIGHT_YEAR}'",
allowEmptyPaths: false,
};
const optionsNewProd = {
files:[
'src/environments/environment.prod.ts'
],
from: /'{PRODUCTION}'/g,
to: true,
allowEmptyPaths: false,
};
const optionsNewDev = {
files:[
'src/environments/environment.ts'
],
from: /'{PRODUCTION}'/g,
to: false,
allowEmptyPaths: false,
};
const optionsOldProd = {
files:[
'src/environments/environment.prod.ts',
'src/environments/environment.ts'
],
from: /production: (.*)/g,
to: "production: '{PRODUCTION}',",
allowEmptyPaths: false,
};
const optionsDefaultLang = {
files: [
'src/environments/environment.prod.ts',
'src/environments/environment.ts'
],
from: /'{DEFAULT_LANG}'/g,
to: `'${process.env.npm_package_config_locale}'`,
allowEmptyPaths: false
}
try {
let changeOldYearFiles = replace.sync(optionsOldYear);
let changeNewYearFiles = replace.sync(optionsNewYear);
let changeOldProdFiles = replace.sync(optionsOldProd);
let changeProdFiles = replace.sync(optionsNewProd);
let changeDevFiles = replace.sync(optionsNewDev);
let changeDefaultLangFiles = replace.sync(optionsDefaultLang);
console.log('Environment variables have been set');
}
catch (error) {
console.error('Error occurred:', error);
throw error
}
|