Skip to content

Commit 1ab854a

Browse files
committed
init
0 parents  commit 1ab854a

File tree

208 files changed

+39333
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+39333
-0
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env"]
3+
}

.browserslistrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
last 2 versions
2+
>0.1%
3+
Firefox ESR
4+
not ie 10
5+
not ie_mob 10
6+
# not ie 11 # we want IE 11 for now
7+
not op_mini all

.github/workflows/default.yml

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
name: hb
2+
on: [push]
3+
jobs:
4+
build_backend:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
9+
-
10+
uses: shivammathur/setup-php@v2
11+
with:
12+
php-version: '8.0'
13+
env:
14+
fail-fast: true
15+
16+
- name: Install deps
17+
run: composer install --ansi
18+
19+
# - name: Run phpstan
20+
# run: composer phpstan
21+
22+
- name: Upload artifact
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: backend-deps
26+
path: vendor
27+
28+
build_frontend:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
-
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: 18.x
37+
38+
- name: Install external deps
39+
run: sudo apt-get update && sudo apt-get install -y pngquant imagemagick
40+
41+
- name: Install deps
42+
uses: borales/actions-yarn@v5
43+
with:
44+
cmd: install
45+
46+
- name: Build deps
47+
uses: borales/actions-yarn@v5
48+
with:
49+
cmd: build
50+
env:
51+
NODE_ENV: production
52+
53+
- name: Build hb-events
54+
working-directory: ./hb-events
55+
run: |
56+
yarn install
57+
yarn build
58+
59+
- name: Upload artifact
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: frontend-deps
63+
path: |
64+
UI/AboutStructure/assets/dist
65+
UI/Contacts/assets/dist
66+
UI/Event/assets/dist
67+
UI/Rentals/assets/dist
68+
frontend/dist
69+
hb-events/build
70+
71+
pack:
72+
runs-on: ubuntu-latest
73+
needs:
74+
- build_backend
75+
- build_frontend
76+
steps:
77+
- uses: actions/checkout@v4
78+
- name: Download backend artifact
79+
uses: actions/download-artifact@v4
80+
with:
81+
name: backend-deps
82+
83+
- name: Download frontend artifact
84+
uses: actions/download-artifact@v4
85+
with:
86+
name: frontend-deps
87+
88+
- name: Pack files for release
89+
run: |
90+
zip -r brontosaurus-theme.zip . \
91+
-i "config/*" \
92+
-i "CoordinatesResolver/*" \
93+
-i "DataContainers/*" \
94+
-i "Filters/*" \
95+
-i "frontend/*" \
96+
-x "frontend/src/*" \
97+
-i "hb-events/*" \
98+
-x "hb-events/src/*" \
99+
-i "images/*" \
100+
-i "log/*" \
101+
-i "Rewrites/*" \
102+
-i "scripts/*" \
103+
-i "template-parts/*" \
104+
-i "vendor/*" \
105+
-i "webfonts/*" \
106+
-i "Assets.php" \
107+
-i "archive-novinky.php" \
108+
-i "bootstrap.php" \
109+
-i "composer.json" \
110+
-i "composer.lock" \
111+
-i "Configuration.php" \
112+
-i "Container.php" \
113+
-i "exceptions.php" \
114+
-i "footer.php" \
115+
-i "functions.php" \
116+
-i "header.php" \
117+
-i "helpers.php" \
118+
-i "homepage-banner.php" \
119+
-i "index.php" \
120+
-i "PostTypeInitializer.php" \
121+
-i "screenshot.png" \
122+
-i "single-novinky.php" \
123+
-i "style.css"
124+
125+
- name: Upload artifact
126+
uses: actions/upload-artifact@v4
127+
with:
128+
name: deps
129+
path: brontosaurus-theme.zip
130+
131+
deploy_staging:
132+
runs-on: ubuntu-latest
133+
if: ${{ ! startsWith(github.ref_name, 'dependabot') }}
134+
needs: pack
135+
environment:
136+
name: staging
137+
url: https://dev.brontosaurus.cz
138+
139+
steps:
140+
- uses: actions/checkout@v4
141+
142+
- name: Download artifact
143+
uses: actions/download-artifact@v4
144+
with:
145+
name: deps
146+
147+
- name: Extract files to deploy
148+
run: |
149+
mkdir -p deploy/files
150+
unzip brontosaurus-theme.zip -d deploy/files
151+
152+
- name: Set up SSH connection
153+
run: |
154+
mkdir -p ~/.ssh
155+
echo "${{ secrets.SERVER_KEYSCAN }}" > ~/.ssh/known_hosts
156+
echo "${{ secrets.KEY_PRIVATE }}" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
157+
echo "${{ secrets.KEY_PUBLIC }}" > ~/.ssh/id_rsa.pub
158+
159+
- name: Deploy
160+
run: |
161+
bash deploy/deploy.sh ${{ secrets.STAGING_REMOTE_USER_AND_HOST }}:${{ secrets.STAGING_REMOTE_PROJECT_DIR }}/wp-content/themes/brontosaurus-theme
162+
ssh ${{ secrets.STAGING_REMOTE_USER_AND_HOST }} "rm -rf ${{ secrets.STAGING_REMOTE_PROJECT_DIR }}/wp-content/themes/brontosaurus-theme/temp/cache"
163+
164+
deploy_production:
165+
runs-on: ubuntu-latest
166+
if: ${{ github.ref_name == 'main' }}
167+
needs: pack
168+
environment:
169+
name: production
170+
url: https://brontosaurus.cz
171+
172+
steps:
173+
- uses: actions/checkout@v4
174+
175+
- name: Download artifact
176+
uses: actions/download-artifact@v4
177+
with:
178+
name: deps
179+
180+
- name: Extract files to deploy
181+
run: |
182+
mkdir -p deploy/files
183+
unzip brontosaurus-theme.zip -d deploy/files
184+
185+
- name: Set up SSH connection
186+
run: |
187+
mkdir -p ~/.ssh
188+
echo "${{ secrets.SERVER_KEYSCAN }}" > ~/.ssh/known_hosts
189+
echo "${{ secrets.KEY_PRIVATE }}" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
190+
echo "${{ secrets.KEY_PUBLIC }}" > ~/.ssh/id_rsa.pub
191+
192+
- name: Deploy
193+
run: |
194+
bash deploy/deploy.sh ${{ secrets.PRODUCTION_REMOTE_USER_AND_HOST }}:${{ secrets.PRODUCTION_REMOTE_PROJECT_DIR }}/wp-content/themes/brontosaurus-theme
195+
ssh ${{ secrets.PRODUCTION_REMOTE_USER_AND_HOST }} "rm -rf ${{ secrets.PRODUCTION_REMOTE_PROJECT_DIR }}/wp-content/themes/brontosaurus-theme/temp/cache"

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
vendor/

Assets.php

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace HnutiBrontosaurus\Theme;
4+
5+
use WP_Theme;
6+
use function filemtime;
7+
use function sprintf;
8+
use function wp_enqueue_script;
9+
use function wp_enqueue_style;
10+
11+
12+
final class Assets
13+
{
14+
15+
public static function script(string $name, WP_Theme $theme): void
16+
{
17+
wp_enqueue_script(
18+
handle: 'hb-' . $name,
19+
src: self::src($name, self::JS_PATTERN, $theme),
20+
ver: self::ver($name, self::JS_PATTERN, $theme),
21+
);
22+
}
23+
24+
public static function staticScript(string $name, WP_Theme $theme): void
25+
{
26+
wp_enqueue_script(
27+
handle: 'hb-' . $name,
28+
src: self::src($name, self::STATIC_JS_PATTERN, $theme),
29+
ver: self::ver($name, self::STATIC_JS_PATTERN, $theme),
30+
);
31+
}
32+
33+
public static function style(string $name, WP_Theme $theme): void
34+
{
35+
wp_enqueue_style(
36+
handle: 'hb-' . $name,
37+
src: self::src($name, self::CSS_PATTERN, $theme),
38+
ver: self::ver($name, self::CSS_PATTERN, $theme),
39+
);
40+
}
41+
42+
private const CSS_PATTERN = '%s/frontend/dist/css/%s.css';
43+
private const JS_PATTERN = '%s/frontend/dist/js/%s.js';
44+
private const STATIC_JS_PATTERN = '%s/scripts/%s.js';
45+
46+
private static function src(string $for, string $pattern, WP_Theme $theme): string
47+
{
48+
return sprintf($pattern, $theme->get_template_directory_uri(), $for);
49+
}
50+
51+
private static function ver(string $for, string $pattern, WP_Theme $theme): int
52+
{
53+
$path = sprintf($pattern, $theme->get_template_directory(), $for);
54+
return filemtime($path);
55+
}
56+
57+
}

Configuration.php

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace HnutiBrontosaurus\Theme;
4+
5+
use Nette\Neon\Neon;
6+
7+
8+
final class Configuration
9+
{
10+
private const ROOT_KEY_PARAMETERS = 'parameters';
11+
12+
private array $configuration = [];
13+
14+
/**
15+
* @throws \Exception
16+
*/
17+
public function __construct(array $configFiles)
18+
{
19+
foreach ($configFiles as $file) {
20+
if (!\file_exists($file)) {
21+
throw new \Exception('Config file `' . $file . '` does not exist.');
22+
}
23+
24+
$fileContent = \file_get_contents($file);
25+
$configuration = Neon::decode($fileContent);
26+
27+
if (!\array_key_exists(self::ROOT_KEY_PARAMETERS, $configuration)) {
28+
throw new \Exception('Only `' . self::ROOT_KEY_PARAMETERS . '` root key is supported in config files.');
29+
}
30+
31+
$this->configuration = \array_merge($this->configuration, $configuration[self::ROOT_KEY_PARAMETERS]);
32+
}
33+
}
34+
35+
36+
public function has(string $name): bool
37+
{
38+
try {
39+
$this->get($name);
40+
return true;
41+
42+
} catch (\Exception) {
43+
return false;
44+
}
45+
}
46+
47+
48+
/**
49+
* Gets single item of configuration. You can use `:` separator to target nested keys.
50+
* @throws \Exception
51+
*/
52+
public function get(string $name): mixed
53+
{
54+
$keyList = \explode(':', $name);
55+
$currentDimension = $this->configuration;
56+
foreach ($keyList as $key) {
57+
if (!\array_key_exists($key, $currentDimension)) {
58+
throw new \Exception('Key `' . $name . '` was not found in configuration.');
59+
}
60+
61+
$value = $currentDimension[$key];
62+
$currentDimension = $currentDimension[$key];
63+
}
64+
65+
return $value;
66+
}
67+
68+
69+
public function getAll(): array
70+
{
71+
return $this->configuration;
72+
}
73+
74+
}

0 commit comments

Comments
 (0)