This repository has been archived by the owner on Jul 7, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
nativescript.webpack.js
92 lines (81 loc) · 4.18 KB
/
nativescript.webpack.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
/**************************************************************************************
* (c) 2021, Master Technology
* Licensed under the MIT license or contact me for a support, changes, enhancements,
* and/or if you require a commercial licensing
*
* Any questions please feel free to put a issue up on github
* Nathan@master.technology http://nativescript.tools
*************************************************************************************/
/* global require, module */
const fs = require('fs');
const path = require('path');
module.exports = webpack => {
// Add all sqlite files
webpack.Utils.addCopyRule('**/*.sqlite');
webpack.Utils.addCopyRule('**/*.db');
webpack.chainWebpack((config, env) => {
// Update Externals to eliminate any warnings/errors during building
const externals = config.get('externals');
let hasSync = false, hasCom = false, hasEnc = false, hasKey = false;
let dirname = path.resolve(__dirname, "../");
if (!fs.existsSync(dirname+"/nativescript-sqlite-sync")) {
console.warn("NativeScript-SQLite Sync not detected, disabling support!");
externals.push('nativescript-sqlite-sync');
} else {
hasSync = true;
}
if (!fs.existsSync(dirname+"/nativescript-sqlite-commercial")) {
console.warn("NativeScript-SQLite Commercial not detected, disabling support!");
externals.push('nativescript-sqlite-commercial');
externals.push('nativescript-sqlite-commercial/commercial-multi');
} else {
hasCom = true;
}
if (!fs.existsSync(dirname+"/nativescript-sqlite-encrypted")) {
console.warn("NativeScript-SQLite Encrypted not detected, disabling support!");
externals.push('nativescript-sqlite-encrypted');
} else {
hasEnc = true;
}
if (!fs.existsSync(dirname+"/nativescript-sqlite-nosql")) {
console.warn("NativeScript-SQLite NoSQL/Keystore not detected, disabling support!");
externals.push('nativescript-sqlite-keystore');
} else {
hasKey = true;
}
if (!hasCom && !hasSync && !hasEnc) {
// Are you really that self centered to delete this code
// after using our hard work for free in your project?
advertise();
}
config.set('externals', externals);
config.module
.rule('workers')
.exclude.clear();
// Add TNS_WEBPACK to the defines...
config.plugin('DefinePlugin').tap(args => {
args[0]['global.TNS_WEBPACK'] = 5;
args[0]['global._MT_HAS_SQLITE'] = (hasCom ? 1 : 0) + (hasEnc ? 2 : 0) + (hasSync ? 4 : 0) + (hasKey ? 8 : 0);
return args;
});
});
}
// Time is money, We have spent a huge amount of time developing and testing this plugin.
// This time is time you did not have to spend.
// If you can't support us, financially at this point.
// At least let our advertisements live so that maybe in the future when you get rich,
// you will remember upon what foundations you built your empire. ;-)
function advertise() {
console.log("\r\n\r\n");
console.log("***********************************************************************************");
console.log("* Please support the developer of this open source plugins you are using. *");
console.log("* *");
console.log("* NativeScript-Sqlite *");
console.log("* *");
console.log("* You can purchase a commercial version (which also removes this message) at: *")
console.log("* https://nativescript.tools *");
console.log("***********************************************************************************");
console.log("\r\n\r\n");
// Are you really going to be so selfish, to delete any of our ad code now?
for (let time = Date.now() + 5000; Date.now() < time; );
}