-
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 #100 from jolicode/gh-pages
Setup the demo on GH Pages
- Loading branch information
Showing
16 changed files
with
4,295 additions
and
0 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,48 @@ | ||
|
||
name: Build the public website, and publish to GitHub Pages | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: github-pages | ||
url: ${{steps.deployment.outputs.page_url}} | ||
steps: | ||
- name: Setup Pages | ||
uses: actions/configure-pages@v3 | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: "8.3" | ||
tools: castor | ||
|
||
- name: Build | ||
run: | | ||
set -x | ||
castor website:install | ||
castor website:wasm:export --pack --build | ||
working-directory: ./website | ||
env: | ||
BASE_URL: "/${{ github.event.repository.name }}" | ||
|
||
- name: Upload Artifact | ||
uses: actions/upload-pages-artifact@v2 | ||
with: | ||
path: 'website/public' | ||
|
||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v2 |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/.castor.stub.php | ||
/.php-cs-fixer.cache | ||
/.phpunit.result.cache | ||
/composer.lock | ||
|
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,10 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of JoliTypo - a project by JoliCode. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
Castor\import(__DIR__ . '/website/castor.php'); |
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,4 @@ | ||
/.castor.stub.php | ||
/build/ | ||
/public/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,16 @@ | ||
# JoliTypo demo | ||
|
||
## Installation | ||
|
||
```bash | ||
castor website:install | ||
castor website:wasm:export --build --pack | ||
``` | ||
|
||
Then you can test it with | ||
|
||
```bash | ||
castor website:serve | ||
``` | ||
|
||
See https://jolicode.com/blog/heberger-un-projet-php-sans-serveur-avec-webassembly for more information. |
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,117 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of JoliTypo - a project by JoliCode. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace website; | ||
|
||
use Castor\Attribute\AsTask; | ||
use Symfony\Component\Process\Process; | ||
|
||
use function Castor\fs; | ||
use function Castor\io; | ||
use function Castor\run as do_run; | ||
|
||
#[AsTask(description: 'Install dependencies')] | ||
function install() | ||
{ | ||
io()->note('Installing dependencies'); | ||
|
||
run(['composer', 'install', '--no-dev', '--optimize-autoloader']); | ||
} | ||
|
||
#[AsTask('wasm:build', description: 'Build the wasm-php binary')] | ||
function wasm_build() | ||
{ | ||
io()->note('Building wasm-php binary'); | ||
|
||
$phpWasmDir = __DIR__ . '/vendor/soyuka/php-wasm'; | ||
run(['docker', 'buildx', 'bake'], path: $phpWasmDir); | ||
fs()->mirror("{$phpWasmDir}/build", __DIR__ . '/build'); | ||
} | ||
|
||
#[AsTask('wasm:pack', description: 'Pack custom code')] | ||
function wasm_pack() | ||
{ | ||
io()->note('Packing custom code'); | ||
|
||
run(['docker', 'run', | ||
'-v', __DIR__ . ':/app', | ||
'-v', __DIR__ . '/build:/dist/build', | ||
'-w', '/dist', | ||
'soyuka/php-wasm:8.2.9', | ||
'python3', | ||
'/emsdk/upstream/emscripten/tools/file_packager.py', | ||
'build/php-web.data', | ||
'--use-preload-cache', | ||
'--lz4', | ||
'--preload', '/app', | ||
'--js-output=build/php-web.data.js', | ||
'--no-node', | ||
'--exclude', | ||
'*/.*', | ||
'*/*md', | ||
'*/castor.php', | ||
'*/CHANGELOG', | ||
'*/composer.*', | ||
'*/doc', | ||
'*/docs', | ||
'*/LICENSE', | ||
'*/tests', | ||
'*/Tests', | ||
'*/tools', | ||
'/app/build', | ||
'/app/public', | ||
'/app/vendor/jolicode/jolitypo/src/JoliTypo/Bridge', | ||
'/app/vendor/jolicode/jolitypo/vendor', | ||
'/app/vendor/jolicode/jolitypo/website', | ||
'/app/vendor/soyuka', | ||
'--export-name=createPhpModule', | ||
]); | ||
} | ||
|
||
#[AsTask('wasm:export', description: 'Export the wasm-php binary to the public folder with custom code')] | ||
function wasm_export(bool $pack = false, bool $build = false) | ||
{ | ||
if ($build) { | ||
wasm_build(); | ||
} | ||
|
||
if ($pack) { | ||
wasm_pack(); | ||
} | ||
|
||
io()->note('Exporting wasm-php'); | ||
|
||
fs()->remove(__DIR__ . '/public/build'); | ||
|
||
fs()->copy(__DIR__ . '/build/php-web.wasm', __DIR__ . '/public/build/php-web.wasm'); | ||
fs()->copy(__DIR__ . '/build/php-web.data', __DIR__ . '/public/build/php-web.data'); | ||
|
||
$data = file_get_contents(__DIR__ . '/build/php-web.data.js'); | ||
$mjs = file_get_contents(__DIR__ . '/build/php-web.mjs'); | ||
$mjs = str_replace($p = '// --pre-jses ', "{$data}\n{$p}", $mjs); | ||
$baseUrl = $_SERVER['BASE_URL'] ?? ''; | ||
// see: https://github.com/emscripten-core/emscripten/issues/21289 | ||
$mjs = str_replace("var REMOTE_PACKAGE_BASE = 'php-web.data';", "var REMOTE_PACKAGE_BASE = '{$baseUrl}/build/php-web.data';", $mjs); | ||
fs()->dumpFile(__DIR__ . '/public/build/php-web.mjs', $mjs); | ||
} | ||
|
||
#[AsTask(description: 'Run the server')] | ||
function serve(string $address = 'localhost:9999') | ||
{ | ||
io()->note("Serving on http://{$address}"); | ||
|
||
run(['php', '-S', $address, '-t', 'public']); | ||
} | ||
|
||
function run(array $command, ?string $path = __DIR__): Process | ||
{ | ||
return do_run($command, path: $path, timeout: 0, environment: [ | ||
'BUILDKIT_PROGRESS' => 'plain', | ||
]); | ||
} |
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,48 @@ | ||
{ | ||
"name": "jolicode/jolitypo-website", | ||
"description": "Demo website for jolicode/jolitypo", | ||
"type": "project", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Damien Alexandre", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Grégoire Pineau", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"repositories": [ | ||
{ | ||
"type": "package", | ||
"package": { | ||
"name": "soyuka/php-wasm", | ||
"version": "dev-main", | ||
"source": { | ||
"url": "https://github.com/soyuka/php-wasm.git", | ||
"type": "git", | ||
"reference": "main" | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "path", | ||
"url": "../", | ||
"options": { | ||
"symlink": false | ||
} | ||
} | ||
], | ||
"require": { | ||
"jolicode/jolitypo": "*@dev", | ||
"soyuka/php-wasm": "dev-main@dev" | ||
}, | ||
"config": { | ||
"optimize-autoloader": true, | ||
"preferred-install": { | ||
"*": "dist" | ||
}, | ||
"sort-packages": true | ||
} | ||
} |
Oops, something went wrong.