Merge pull request #17900 from aydun/wiki_changes
[civicrm-core.git] / tools / scripts / check-angular.php
CommitLineData
d1e4cc3f
TO
1#!/usr/bin/env php
2<?php
3eval(`cv php:boot`);
4
5global $civicrm_root;
6$realArgs = $argv;
7$diffCmd = FALSE;
b7c0a88f 8$files = [];
d1e4cc3f
TO
9
10array_shift($realArgs);
11foreach ($realArgs as $arg) {
12 switch ($arg) {
13 case '--diff':
14 $diffCmd = 'diff -wu';
15 break;
16
17 case '--colordiff':
18 $diffCmd = 'colordiff -wu';
19 break;
20
21 default:
22 $files[] = $arg;
23 }
24}
25
26if (empty($files)) {
27 echo "usage: cleanup-angular.php [--diff|--colordiff] <file>\n";
28 echo "example: cleanup-angular.php '/full/path/to/crmMailing/BlockSummary.html'\n";
29 echo "note: The file path must be absolute.\n";
30 exit(1);
31}
32else {
33 foreach ($files as $file) {
34 compareFile($file, $diffCmd);
35 }
36}
37
38function compareFile($file, $diffCmd) {
39 $coder = new \Civi\Angular\Coder();
40
41 if (!file_exists($file)) {
42 fwrite(STDERR, "Failed to find file $file (CWD=" . getcwd() . ")\n");
43 return;
44 }
45 $oldMarkup = file_get_contents($file);
46 if ($coder->checkConsistentHtml($oldMarkup)) {
47 echo "File \"$file\" appears sufficiently consistent.\n";
48 }
49 else {
50 $newMarkup = $coder->recode($oldMarkup);
51 $newFile = "{$file}.recoded";
52 echo "File \"$file\" appears to have consistency issues. Created $newFile.\n";
53 file_put_contents($newFile, $newMarkup);
54 if ($diffCmd) {
b7c0a88f 55 passthru($diffCmd . ' ' . escapeshellarg($file) . ' ' . escapeshellarg($newFile));
d1e4cc3f
TO
56 }
57 }
b7c0a88f 58}