-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-plugins
executable file
·79 lines (63 loc) · 2.48 KB
/
update-plugins
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
#!/usr/bin/env node
console.log('Getting list of plugin updates...');
const spawnSync = require('child_process').spawnSync;
const updatePath = spawnSync('wp', ['plugin', 'path'], { encoding : 'utf8' });
// const gitPath = spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding : 'utf8' });
// const gitAddPath = `${gitPath.stdout.trim()}/${updatePath.stdout.trim().split('./')[1]}`;
const gitAddPath = updatePath.stdout.trim();
const updateJSON = spawnSync('wp', ['plugin', 'update', '--all', '--dry-run', '--format=json'], { encoding : 'utf8' });
let updateData = [];
let updateList = [];
let errorList = [];
try {
updateData = JSON.parse(updateJSON.stdout);
} catch (e) {
console.log('Error getting list of plugin updates.');
console.log(e);
// console.log(updateJSON);
console.log(updateJSON.stdout);
}
console.log('Updating plugins...\n');
for (let plugin of updateData) {
let updateJSON = spawnSync('wp', ['plugin', 'update', plugin.name, '--format=json'], { encoding : 'utf8' });
let resultData;
try {
resultData = JSON.parse(updateJSON.stdout);
} catch (e) {
console.log(`Error updating plugin ${plugin.name} from ${plugin.version} to ${plugin.update_version}`);
console.log(e);
console.log(updateJSON.stdout);
continue;
}
if (resultData[0].status == 'Updated') {
const gitAdd = spawnSync('git', ['add', `${gitAddPath}/${plugin.name}`], { encoding : 'utf8' });
let gitAddData;
try {
gitAddData = gitAdd;
// gitAddData = JSON.parse(gitAdd.stdout);
} catch (e) {
// console.log(e);
console.log('Error commiting plugin update.');
console.log(gitAddData);
console.log(gitAddData.stdout);
}
spawnSync('git', ['commit', '-m', `Update plugin ${plugin.name} from ${plugin.version} to ${plugin.update_version}`]);
console.log(`Update plugin ${plugin.name} from ${plugin.version} to ${plugin.update_version}`);
updateList.push(plugin);
} else {
console.log(`Error updating plugin ${plugin.name} from ${plugin.version} to ${plugin.update_version}`);
errorList.push(plugin);
}
}
console.log(`\n${updateList.length} Plugins Updated`);
if (updateList.length) {
for (let plugin of updateList) {
console.log(`${plugin.name} from ${plugin.version} to ${plugin.update_version}`);
}
}
if (errorList.length) {
console.log(`\n${errorList.length} Plugin Update Errors`);
for (let plugin of errorList) {
console.log(`${plugin.name} from ${plugin.version} to ${plugin.update_version}`);
}
}