-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from jolicode/phar
Add a support for PHAR building
- Loading branch information
Showing
11 changed files
with
3,639 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Compile PHAR | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php-versions: ['7.4', '8.0'] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/[email protected] | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
|
||
- name: Install dependencies (lib) | ||
run: composer install --prefer-dist --no-progress --no-dev --optimize-autoloader --classmap-authoritative | ||
|
||
- name: Install dependencies (phar builder) | ||
run: composer install --prefer-dist --no-progress --optimize-autoloader --classmap-authoritative | ||
working-directory: tools/phar | ||
|
||
- name: Compile PHAR | ||
run: vendor/bin/box compile | ||
working-directory: tools/phar | ||
|
||
- name: Ensure PHAR is OK | ||
run: build/jolitypo.phar fr_FR README.md | ||
working-directory: tools/phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/build/ | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# JoliTypo PHAR building | ||
|
||
## Usage | ||
|
||
```bash | ||
composer install | ||
vendor/bin/box compile | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use JoliTypo\Fixer; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\SingleCommandApplication; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
require __DIR__ . '/../../../vendor/autoload.php'; | ||
|
||
$help = <<<EOTXT | ||
JoliTypo is a tool fixing Microtypography glitches inside your HTML content. | ||
# Usages | ||
## Get the list of all available fixers: | ||
<comment>%command.name% --list-rules foo bar</> | ||
## Run the fixer on one file | ||
<comment>%command.name% fr_FR index.html</> | ||
## Run the fixer on one directory | ||
<comment>%command.name% fr_FR directory/</> | ||
## Specify some rules: | ||
<comment>%command.name% fr_FR index.html --rule=FrenchQuotes --rule=Dash</> | ||
EOTXT; | ||
|
||
(new SingleCommandApplication('JoliTypo')) | ||
->addArgument('locale', InputArgument::REQUIRED, 'Locale of the content to fix.') | ||
->addArgument('path', InputArgument::REQUIRED, 'Path of file(s) to fix.') | ||
->addOption('rule', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Rules used to fix the content') | ||
->addOption('list-rules', null, InputOption::VALUE_NONE, 'List available rules') | ||
->setHelp($help) | ||
->setCode(function (InputInterface $input, OutputInterface $output): int { | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
if ($input->getOption('list-rules')) { | ||
$list = []; | ||
foreach ((new Finder())->in(__DIR__ . '/../../../src/JoliTypo/Fixer')->sortByName()->files() as $file) { | ||
$list[] = $file->getFilenameWithoutExtension(); | ||
} | ||
$io->listing($list); | ||
|
||
return 0; | ||
} | ||
|
||
$locale = $input->getArgument('locale'); | ||
$path = $input->getArgument('path'); | ||
$rules = $input->getOption('rule'); | ||
|
||
if (!$rules) { | ||
if (!array_key_exists($locale, Fixer::RECOMMENDED_RULES_BY_LOCALE)) { | ||
throw new \InvalidArgumentException(sprintf('There is no recommended rules for "%s" locale. Please specify manually the rules to apply.', $locale)); | ||
} | ||
|
||
$rules = Fixer::RECOMMENDED_RULES_BY_LOCALE[$locale]; | ||
} | ||
|
||
|
||
$fixer = new Fixer($rules); | ||
$fixer->setLocale($locale); | ||
|
||
if (is_dir($path)) { | ||
foreach ((new Finder())->in($path)->files() as $file) { | ||
if ($output->isVerbose()) { | ||
$io->comment(sprintf('Fixing <comment>%s</comment>', $file->getRealPath())); | ||
} | ||
$fixedContent = $fixer->fix(file_get_contents($file->getRealPath())); | ||
file_put_contents($file->getRealPath(), $fixedContent); | ||
} | ||
|
||
$io->success(sprintf('All files in "%s" has been fixed with success!', $path)); | ||
} elseif (is_file($path)) { | ||
$fixedContent = $fixer->fix(file_get_contents($path)); | ||
file_put_contents($path, $fixedContent); | ||
|
||
$io->success(sprintf('"%s" content has been fixed with success!', $path)); | ||
} else { | ||
throw new \InvalidArgumentException(sprintf('The path "%s" does not exist.', $path)); | ||
} | ||
|
||
return 0; | ||
}) | ||
->run() | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"base-path": "../../", | ||
"finder": [ | ||
{ | ||
"in": ".", | ||
"name": [ | ||
"*.php", | ||
"*.txt", | ||
"*.properties", | ||
"*.ini", | ||
"*.dic" | ||
], | ||
"exclude": ["tests", "Tests", "phpunit"] | ||
} | ||
], | ||
"git-version": "package_version", | ||
"main": "tools/phar/bin/jolitypo", | ||
"output": "tools/phar/build/jolitypo.phar" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "jolicode/jolitypo-phar", | ||
"description": "Tooling for building JoliTypo PHAR", | ||
"type": "project", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Grégoire Pineau", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Mathieu Santostefano", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"symfony/console": "^5.3", | ||
"symfony/finder": "^5.3" | ||
}, | ||
"require-dev": { | ||
"humbug/box": "^3.13", | ||
"humbug/php-scoper": "dev-master#d3c7b5cde60ce6e269a202d96ba0549ac7528319 as 0.14.0" | ||
}, | ||
"config": { | ||
"optimize-autoloader": true, | ||
"preferred-install": "dist", | ||
"sort-packages": true | ||
} | ||
} |
Oops, something went wrong.