-
Notifications
You must be signed in to change notification settings - Fork 6
/
ios.js
executable file
·45 lines (37 loc) · 1.37 KB
/
ios.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
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var xml2js = require('xml2js');
var parser = new xml2js.Parser();
module.exports = function(context) {
console.log("### QR Scanner Add Format (iOS) ======================");
// Make sure ios platform is part of build
if (!context.opts.platforms.includes('ios')) return;
// read app name from config.xml
const configXml = fs.readFileSync(path.join(context.opts.projectRoot, 'config.xml'), 'UTF-8');
parser.parseString(configXml, function (err, data) {
if(err) {
console.log(err);
return;
}
const appName = String(data.widget.name);
var filestocopy = [{
"myhooks/jacobg-cordova-plugin-qrscanner/QRScanner.swift":
"platforms/ios/" + appName + "/Plugins/cordova-plugin-qrscanner/QRScanner.swift"
}];
var rootdir = context.opts.projectRoot;
filestocopy.forEach(function(obj) {
Object.keys(obj).forEach(function(key) {
var val = obj[key];
var srcfile = path.join(rootdir, key);
var destfile = path.join(rootdir, val);
console.log("copying ["+srcfile+"]");
console.log("to ["+destfile+"]");
var destdir = path.dirname(destfile);
if (fs.existsSync(srcfile) && fs.existsSync(destdir)) {
fs.createReadStream(srcfile).pipe(fs.createWriteStream(destfile));
}
});
});
});
};