-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpm_update.php
More file actions
43 lines (35 loc) · 1.66 KB
/
npm_update.php
File metadata and controls
43 lines (35 loc) · 1.66 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
<?php
namespace Deployer;
use Deployer\Exception\Exception;
task('dev:release:npm_update', function () {
if (!checkStepIsEnabled('dev:release:npm_update')) { return; }
info("npm update");
runLocally("npx npm-check-updates --target=semver --upgrade --prefix " . get('npm_path_app') . " >> _tmp.txt 2>&1");
runLocally("npm install --prefix " . get('npm_path_app'));
// @ToDo: why is the complete output not be generated by the runLocally command, only getting the last 500 chars, so need to perform this workaround to collection dependency information
$result = runLocally("cat _tmp.txt");
runLocally("rm -f _tmp.txt");
$message = get("dev_git_message_npm_update") . "\n\n";
preg_match_all(get('dev_npm_regex'), $result, $matches);
if (empty($matches[1])) {
info("no npm updates found");
add('dev_empty_tasks', ["dev:release:npm_update"]);
return;
}
foreach ($matches[1] as $index => $package) {
$message .= " - $package (" . $matches[2][$index] . " => " . $matches[3][$index] . ")\n";
}
info("npm audit");
try {
$result = runLocally("npm audit --prefix " . get('npm_path_app') . " | grep vulnerabilities");
preg_match(get('dev_npm_audit_regex'), $result, $matches);
if (isset($matches[1]) && intval($matches[1]) > 0) {
$warning = "⚠️ Found " . $matches[1] . " npm package vulnerabilities, fix them manually using \"npm audit fix\"";
$warning($warning);
add('dev_additional_warnings', [$warning]);
}
} catch (Exception) {}
info($message);
info("commit updates");
commit($message);
})->desc('Update npm dependencies');