-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7145146
commit 2f2fcc4
Showing
14 changed files
with
1,664 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use Symfony\Component\Finder\Finder; | ||
|
||
foreach ([__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php'] as $file) { | ||
if (file_exists($file)) { | ||
require $file; | ||
break; | ||
} | ||
} | ||
|
||
$files = Finder::create() | ||
->in(__DIR__ . '/../src') | ||
->name('composer.json') | ||
->files(); | ||
|
||
$require = []; | ||
$autoload = []; | ||
$autoloadFiles = []; | ||
$autoloadDev = []; | ||
$configProviders = []; | ||
foreach ($files as $file) { | ||
$component = basename(dirname($file)); | ||
$composerJson = json_decode(file_get_contents($file), true); | ||
|
||
foreach ($composerJson['autoload']['files'] ?? [] as $file) { | ||
$autoloadFiles[] = "src/{$component}/" . preg_replace('#^./#', '', $file); | ||
} | ||
foreach ($composerJson['autoload']['psr-4'] ?? [] as $ns => $dir) { | ||
$autoload[$ns] = "src/{$component}/" . trim($dir, '/') . '/'; | ||
} | ||
foreach ($composerJson['autoload-dev']['psr-4'] ?? [] as $ns => $dir) { | ||
$autoloadDev[$ns] = "src/{$component}/" . trim($dir, '/') . '/'; | ||
} | ||
if (isset($composerJson['extra']['hyperf']['config'])) { | ||
$configProviders = array_merge($configProviders, (array)$composerJson['extra']['hyperf']['config']); | ||
} | ||
} | ||
|
||
ksort($autoload); | ||
sort($autoloadFiles); | ||
ksort($autoloadDev); | ||
sort($configProviders); | ||
|
||
$json = json_decode(file_get_contents(__DIR__ . '/../composer.json')); | ||
$json->autoload->files = $autoloadFiles; | ||
$json->autoload->{'psr-4'} = $autoload; | ||
$json->{'autoload-dev'}->{'psr-4'} = $autoloadDev; | ||
$json->extra->hyperf->config = $configProviders; | ||
|
||
file_put_contents( | ||
__DIR__ . '/../composer.json', | ||
json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) . PHP_EOL | ||
); |
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,51 @@ | ||
#!/usr/bin/env sh | ||
set -e | ||
# execute `composer global require comcast/php-legal-licenses` before run this shell | ||
|
||
NOW=$(date +%s) | ||
BASEPATH=$(cd `dirname $0`; cd ../src/; pwd) | ||
|
||
repos=$(ls "$BASEPATH") | ||
echo $NOW | ||
|
||
function generate() { | ||
if [ -f "composer.json" ]; then | ||
composer update -q | ||
php-legal-licenses generate | ||
fi | ||
if [ -f "composer.lock" ]; then | ||
rm -rf ./composer.lock | ||
fi | ||
if [ -d "vendor" ]; then | ||
rm -rf ./vendor | ||
fi | ||
if [ -f "licenses.md" ]; then | ||
git add ./licenses.md | ||
fi | ||
} | ||
|
||
cd .. | ||
|
||
git checkout master && git checkout -b licenses-generate-"$NOW" | ||
|
||
echo "Generating main repository"; | ||
generate | ||
|
||
cd ./src | ||
|
||
for REPO in $repos | ||
do | ||
echo "Generating $REPO"; | ||
cd "./$REPO" | ||
|
||
generate | ||
|
||
cd ../ | ||
|
||
done | ||
|
||
git commit -m "Update licenses.md" | ||
|
||
TIME=$(echo "$(date +%s) - $NOW" | bc) | ||
|
||
printf "Execution time: %f seconds" "$TIME" |
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,91 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use Symfony\Component\Finder\Finder; | ||
|
||
foreach ([__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php'] as $file) { | ||
if (file_exists($file)) { | ||
require $file; | ||
break; | ||
} | ||
} | ||
|
||
$files = Finder::create() | ||
->in(__DIR__ . '/../docs/zh-cn') | ||
->name('*.md') | ||
->files(); | ||
|
||
foreach ($files as $file) { | ||
file_put_contents($file, replace(file_get_contents($file))); | ||
} | ||
echo count($files).' markdown files formatted!'.PHP_EOL; | ||
|
||
function replace($text) | ||
{ | ||
$cjk = '' . | ||
'\x{2e80}-\x{2eff}' . | ||
'\x{2f00}-\x{2fdf}' . | ||
'\x{3040}-\x{309f}' . | ||
'\x{30a0}-\x{30ff}' . | ||
'\x{3100}-\x{312f}' . | ||
'\x{3200}-\x{32ff}' . | ||
'\x{3400}-\x{4dbf}' . | ||
'\x{4e00}-\x{9fff}' . | ||
'\x{f900}-\x{faff}'; | ||
|
||
$patterns = [ | ||
'cjk_quote' => [ | ||
'([' . $cjk . '])(["\'])', | ||
'$1 $2', | ||
], | ||
|
||
'quote_cjk' => [ | ||
'(["\'])([' . $cjk . '])', | ||
'$1 $2', | ||
], | ||
|
||
'fix_quote' => [ | ||
'(["\']+)(\s*)(.+?)(\s*)(["\']+)', | ||
'$1$3$5', | ||
], | ||
|
||
'cjk_operator_ans' => [ | ||
'([' . $cjk . '])([A-Za-zΑ-Ωα-ω0-9])([\+\-\*\/=&\\|<>])', | ||
'$1 $2 $3', | ||
], | ||
|
||
'bracket_cjk' => [ | ||
'([' . $cjk . '])([`]+\w(.*?)\w[`]+)([' . $cjk . ',。])', | ||
'$1 $2 $4', | ||
], | ||
|
||
'ans_operator_cjk' => [ | ||
'([\+\-\*\/=&\\|<>])([A-Za-zΑ-Ωα-ω0-9])([' . $cjk . '])', | ||
'$1 $2 $3', | ||
], | ||
|
||
'cjk_ans' => [ | ||
'([' . $cjk . '])([A-Za-zΑ-Ωα-ω0-9@&%\=\$\^\\-\+\\\><])', | ||
'$1 $2', | ||
], | ||
|
||
'ans_cjk' => [ | ||
'([A-Za-zΑ-Ωα-ω0-9~!%&=;\,\.\?\$\^\\-\+\\\<>])([' . $cjk . '])', | ||
'$1 $2', | ||
], | ||
]; | ||
$code = []; | ||
$i = 0; | ||
$text = preg_replace_callback('/```(\n|.)*?\n```/m', function ($match) use (&$code, &$i) { | ||
$code[++$i] = $match[0]; | ||
return "__REPLACEMARK__{$i}__"; | ||
}, $text); | ||
foreach ($patterns as $key => $value) { | ||
$text = preg_replace('/' . $value[0] . '/iu', $value[1], $text); | ||
} | ||
$text = preg_replace_callback('/__REPLACEMARK__(\d+)__/s', function ($match) use ($code) { | ||
return $code[$match[1]]; | ||
}, $text); | ||
|
||
return $text; | ||
} |
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,51 @@ | ||
<?php | ||
/** | ||
* @notice Install https://github.com/nauxliu/opencc4php extension before use this script. | ||
* Run this PHP script to generate the zh-tw and zh-hk doucmentations via zh-cn. | ||
*/ | ||
|
||
! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1)); | ||
|
||
require BASE_PATH . '/vendor/autoload.php'; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
|
||
$config = [ | ||
'zh-tw' => [ | ||
'targetDir' => BASE_PATH . '/docs/zh-tw/', | ||
'rule' => 's2twp.json', | ||
], | ||
'zh-hk' => [ | ||
'targetDir' => BASE_PATH . '/docs/zh-hk/', | ||
'rule' => 's2hk.json', | ||
], | ||
]; | ||
|
||
$finder = new Finder(); | ||
$finder->files()->in(BASE_PATH . '/docs/zh-cn'); | ||
|
||
foreach ($config as $key => $item) { | ||
$od = opencc_open($item['rule']); | ||
foreach ($finder as $fileInfo) { | ||
$targetPath = $item['targetDir'] . $fileInfo->getRelativePath(); | ||
$isCreateDir = false; | ||
if (! is_dir($targetPath)) { | ||
mkdir($targetPath, 0777, true); | ||
chmod($targetPath, 0777); | ||
$isCreateDir = true; | ||
} | ||
if (! is_writable($targetPath)) { | ||
echo sprintf('Target path %s is not writable.' . PHP_EOL, $targetPath); | ||
} | ||
if ($fileInfo->getExtension() === 'md') { | ||
$translated = opencc_convert($fileInfo->getContents(), $od); | ||
$translated = str_replace('](zh-cn/', '](' . $key . '/', $translated); | ||
$targetTranslatedPath = $item['targetDir'] . $fileInfo->getRelativePathname(); | ||
@file_put_contents($targetTranslatedPath, $translated); | ||
} else { | ||
$targetTranslatedPath = $item['targetDir'] . $fileInfo->getRelativePathname(); | ||
@copy($fileInfo->getRealPath(), $targetTranslatedPath); | ||
} | ||
} | ||
opencc_close($od); | ||
} |
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
Oops, something went wrong.