-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.js
More file actions
97 lines (74 loc) · 2.15 KB
/
update.js
File metadata and controls
97 lines (74 loc) · 2.15 KB
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
var task = module.exports,
path = require('path'),
fs = require('fs'),
os = require('os'),
utils = null,
Q = null,
semver = null,
shelljs = null;
task.run = function run(cli, targetPath, projectData) {
var task = new UpdateTask(cli, targetPath, projectData);
return task.run();
};
class UpdateTask {
constructor(cli, targetPath, projectData) {
this.cli = cli;
this.projectDir = targetPath;
this.projectData = projectData;
shelljs = cli.require('shelljs');
Q = cli.require('q');
semver = cli.require('semver');
utils = cli.utils;
}
run() {
return Q()
.then(() => {
var remove = require('./remove');
return remove.run(cli, this.projectDir, this.projectData);
})
.then(() => {
var restoreTask = require('./restore');
return restoreTask.run(cli, this.projectDir, this.projectData);
})
.then(() => {
let platforms = (this.projectData.platform || {});
if (platforms.android) {
let platformVersion = semver.coerce(platforms.android);
if (semver.lt(platformVersion, '0.2.0')) {
return this.renameSources();
}
}
});
}
renameSources() {
var srcPath = path.join(this.projectDir, 'src', 'android', 'build.gradle');
if (fs.existsSync(srcPath)) {
let targetPath = srcPath + '.old';
if (fs.existsSync(targetPath)) {
var count = 1;
while (fs.existsSync(targetPath + '.' + count)) {
count++;
}
targetPath += '.' + count;
}
console.log('');
console.log('Renaming your android build file (' + srcPath + ') to (' + targetPath + ').');
console.log('If you have made any changes, be sure to merge into the new file.');
console.log('');
shelljs.mv(srcPath, targetPath);
return this.copySources();
}
}
copySources() {
var gradleFile = path.join(__dirname, 'src', 'android', 'build.gradle'),
targetDir = path.join(this.projectDir, 'src', 'android'),
tempFolder = path.join(os.tmpdir(), 'cloudbridge-' + new Date().getTime());
shelljs.mkdir('-p', tempFolder);
shelljs.cp(gradleFile, tempFolder);
utils.copyTemplate(tempFolder, targetDir, {
project: this.projectData
}, /\.gradle/);
shelljs.rm('-rf', tempFolder);
return Q();
}
}