-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure.js
executable file
·114 lines (86 loc) · 3.47 KB
/
configure.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const fs = require('fs-extra');
const glob = require('glob');
const path = require('path');
const f_angular = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';
const f_typeorm = 'node_modules/typeorm/typeorm-class-transformer-shim.js';
const f_datepicker = 'node_modules/@nebular/theme/components/datepicker/datepicker.component.js';
const f_datbase = 'backend/autoload.ts';
const args = process.argv.slice(1);
const isElectronConfigure = args.some(val => val === '--electron');
const isWebConfigure = args.some(val => val === '--web');
const isClearConfigure = args.some(val => val === '--clear');
const isDatabaseAutoload = args.some(val => val === '--dbauto');
if (isClearConfigure) {
fs.removeSync('out-tsc');
fs.removeSync('release');
fs.removeSync('dist');
}
if (isDatabaseAutoload) {
var importString = '';
var executeString = '';
glob(__dirname + '/backend/**/*.slot.ts', {}, (err, files) => {
files.forEach((file) => {
const pfad = path.join(__dirname, '/backend').replace(/\\/g, '/');
let fileRelPath = file.replace(pfad, '');
fileRelPath = fileRelPath.replace('.ts', '');
if (fileRelPath === '/slots/database.slot') { return; }
let fileName = fileRelPath.replace('.slot', '');
fileName = 'slot' + fileName.replace(/\//g, '_');
importString += `import { init as ${fileName} } from '.${fileRelPath}';\n`;
executeString += ` ${fileName}();\n`;
});
importString = `<import>\n${importString}\n// </import>`;
executeString = `<execute>\n${executeString} // </execute>`;
fs.readFile(f_datbase, 'utf8', function (err, data) {
if (err) return console.log(err);
var result = data.replace(/<import>(.*?)<\/import>/s, importString);
result = result.replace(/<execute>(.*?)<\/execute>/s, executeString);
fs.writeFile(f_datbase, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
});
}
// Allow angular using electron module (native node modules)
if (isElectronConfigure || isWebConfigure) {
// add BaseEntity to typeorm-model-shim
const search = `exports.Entity = Entity;
/* export */`;
const toPlace = `exports.Entity = Entity;
exports.Unique = Entity;
exports.BaseEntity = function(){};
/* export */`;
fs.readFile(f_typeorm, 'utf8', function (err, data) {
if (err) return console.log(err);
var result = data.replace(search, toPlace);
fs.writeFile(f_typeorm, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
// end add BaseEntity to typeorm-model-shim
/**
* Datepicker fix
*/
fs.readFile(f_datepicker, 'utf8', function (err, data) {
if (err) return console.log(err);
var result = data.replace(/NbBasePicker\.prototype\.ngOnChanges = function \(\) \{(.*?)\};/s, '');
fs.writeFile(f_datepicker, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
// Datepicker fix end
fs.readFile(f_angular, 'utf8', function (err, data) {
if (err) return console.log(err);
var result = data.replace(/target: "electron-renderer",/g, '');
result = result.replace(/target: "web",/g, '');
if (isElectronConfigure) {
var regPlace = 'return {target: "electron-renderer",';
} else {
var regPlace = 'return {target: "web",';
}
result = result.replace(/return \{/g, regPlace);
fs.writeFile(f_angular, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
}