Skip to content

Commit

Permalink
Merge pull request #237 from stronk7/enable_mustache_check_from_phar
Browse files Browse the repository at this point in the history
Enable mustache check to run from phar
  • Loading branch information
stronk7 authored Sep 15, 2023
2 parents bfa22ca + e3c048a commit ed8d11b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions box.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
"name": [
"*.php",
"*.xml",
"*.sh"
"*.sh",
"*.jar"
],
"exclude": [
"Tests",
"tests",
"Docs",
"node_modules",
"pix"
]
}
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
The format of this change log follows the advice given at [Keep a CHANGELOG](http://keepachangelog.com).

## [Unreleased]
### Fixed
- Fix the `mustache` command to work from within the PHAR archive.

## [4.1.3] - 2023-09-08
### Changed
- Updated project dependencies to current [moodle-cs](https://github.com/moodlehq/moodle-cs), [moodle-local_moodlecheck](https://github.com/moodlehq/moodle-local_moodlecheck) and [moodle-local_ci](https://github.com/moodlehq/moodle-local_ci) versions. Also, to various internal / development tools.
Expand Down
12 changes: 9 additions & 3 deletions src/Command/MustacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$jarFile = $this->resolveJarFile();

// This is a workaround to execute mustache_lint.php file from within a phar.
// (by copying both the script and the jar file to a temporary directory)
$filesystem = new Filesystem();
$wrapper = tempnam(sys_get_temp_dir(), 'mustache-linter-wrapper');
$tmpDir = sys_get_temp_dir();
$wrapper = tempnam($tmpDir, 'mustache-linter-wrapper');
$jarTmpFile = $tmpDir . '/vnu.jar';
$filesystem->dumpFile($wrapper, sprintf('<?php include \'%s\';', $linter));
$filesystem->copy($jarFile, $jarTmpFile, true);

$code = 0;
foreach ($files as $file) {
Expand All @@ -68,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'php',
$wrapper,
'--filename=' . $file,
'--validator=' . $jarFile,
'--validator=' . $jarTmpFile,
'--basename=' . $this->moodle->directory,
];
// _JAVA_OPTIONS is something Travis CI started to set in Trusty. This breaks Mustache because
Expand All @@ -82,6 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$filesystem->remove($wrapper);
$filesystem->remove($jarTmpFile);

return $code;
}
Expand All @@ -94,7 +99,8 @@ private function resolveJarFile(): string
// Check if locally installed.
$file = __DIR__ . '/../../vendor/moodlehq/moodle-local_ci/node_modules/vnu-jar/build/dist/vnu.jar';
if (is_file($file)) {
return realpath($file);
// No need to use realpath() when running from a phar.
return (\Phar::running() !== '') ? $file : realpath($file);
}

// Check for global install.
Expand Down

0 comments on commit ed8d11b

Please sign in to comment.