-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunify-static
executable file
·54 lines (43 loc) · 1.31 KB
/
unify-static
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
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/env php
<?php
declare(strict_types=1);
\error_reporting(-1);
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/functions.php';
use Symfony\Component\Finder\Finder;
//******************************************************************************
// Update files
/**
* Any files which match `static/*.tmpl` are written to a new file in the
* correct location in the repository's file system.
*
* No token replacement occurs.
*/
$finder = Finder::create()
->ignoreDotFiles(false)
->files()
->name('.lang-php')
->depth('< 2')
->in(dirname(__DIR__))
->notPath('vendor')
;
$statics = Finder::create()
->files()
->name('*.tmpl')
->depth('< 1')
->in(__DIR__ . '/static')
;
foreach ($statics as $static) {
$source = $static->getRealPath();
$destFile = preg_replace('/^_/', '.', strip_tmpl($static->getFilename()));
// Read the content from disk once
$content = file_get_contents($source);
echo sprintf('Reading from %s…', $source) . PHP_EOL;
// Write the content multiple times
foreach ($finder as $file) {
$dirRoot = dirname($file->getRealPath());
$dirPath = sprintf('%s/%s', $dirRoot, $destFile);
file_put_contents($dirPath, $content);
echo sprintf('Writing to %s…', $dirPath) . PHP_EOL;
}
}