Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: PHP tests

on:
pull_request:
branches: [ main ]

jobs:
build:

strategy:
matrix:
php: ['8.2', '8.3', '8.4']
symfony: ['6.4', '7.3']

runs-on: ubuntu-latest

name: On PHP ${{ matrix.php }} and Symfony ${{ matrix.symfony }}
steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout
uses: actions/checkout@v5

# https://github.com/marketplace/actions/setup-php-action
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl
ini-values: post_max_size=256M, max_execution_time=180
tools: composer

- name: Check PHP version
run: php -v

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Install Symfony ${{ matrix.symfony }} packages
run: |
composer update symfony/console:${{ matrix.symfony }}
composer update symfony/stopwatch:${{ matrix.symfony }}

- name: Code lint PHP files
run: ./vendor/bin/phplint

- name: Coding standards
run: ./vendor/bin/phpcs

- name: PHPUnit
run: ./vendor/bin/phpunit
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
vendor
.phpunit.result.cache
package-lock.json
tests/example/apollo
composer.lock
var/cache/*
var/cache/*
.phpunit.cache
.phpunit.result.cache
.phplint.cache
31 changes: 31 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>

<!-- see https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset -->
<ruleset name="Studio 24">

<!-- One or more files and/or directories to check -->
<file>src</file>
<file>tests</file>

<!-- Ignore files that match this pattern -->
<!-- <exclude-pattern>path/to/*</exclude-pattern> -->

<!-- Command line options -->
<!-- see https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<arg name="extensions" value="php" />
<arg name="basepath" value="."/>
<arg name="colors"/>
<arg name="parallel" value="75"/>
<arg value="np"/>

<!-- Coding standards rules to test for -->
<rule ref="PSR12" />

<!-- Namespaces and classes MUST follow PSR-0.
This means each class is in a file by itself, and is in a namespace of at least one level: a top-level vendor name. -->
<!-- Exclude tests from this rule -->
<rule ref="PSR1.Classes.ClassDeclaration">
<exclude-pattern>tests/*</exclude-pattern>
</rule>

</ruleset>
6 changes: 6 additions & 0 deletions .phplint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
path: ./
jobs: 10
extensions:
- php
exclude:
- vendor
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Key features:

## Requirements

* PHP 7.4+
* PHP 8.1+
* [Composer](https://getcomposer.org/)

## Installation
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
"type": "library",
"license": "MIT",
"require": {
"php": ">7.4.0",
"php": ">=8.2",
"twig/twig": "^3.0",
"symfony/console": "^5.0",
"symfony/stopwatch": "^5.0",
"league/flysystem": "^2.2",
"symfony/console": "^6.4|^7.1",
"symfony/stopwatch": "^6.4|^7.1",
"league/flysystem": "^3.3",
"masterminds/html5": "^2.7",
"league/commonmark": "^2.0",
"alchemy/zippy": "^1.0"
"league/commonmark": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^8",
"overtrue/phplint": "^9.0",
"phpunit/phpunit": ">=10.0",
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
Expand Down
16 changes: 11 additions & 5 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,24 @@ configuration via the `src/Config.php` class.

You can test your changes by using the example project.

Build files:
Run Composer install in the root:

```shell
composer install
```
cd tests/example
../../bin/design-system

If you have errors with this delete your local `composer.lock` file and try again.

Build files:

```shell
bin/design-system --path=tests/example
```

Serve:

```
cd _dist/
php -S localhost:8000
php -S localhost:8000 -t tests/example/_dist/
```

Test at: http://localhost:8000
38 changes: 15 additions & 23 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.readthedocs.io/en/8.0/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
backupGlobals="false"
colors="true"
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="display_errors" value="1" />
</php>

<testsuites>
<testsuite name="Apollo Build Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.3/phpunit.xsd" backupGlobals="false" colors="true" cacheDirectory=".phpunit.cache">
<php>
<ini name="error_reporting" value="-1"/>
<ini name="display_errors" value="1"/>
</php>
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
62 changes: 36 additions & 26 deletions src/Build.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

declare(strict_types=1);

namespace Studio24\DesignSystem;

use Alchemy\Zippy\Zippy;
use League\Flysystem\FileAttributes;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemException;
Expand All @@ -20,6 +20,9 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Twig\Loader\FilesystemLoader;
use Twig\Environment;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ZipArchive;

class Build
{
Expand All @@ -43,7 +46,8 @@ public function __construct(Config $config, SymfonyStyle $output)
$this->output = $output;

// Set default file permissions
$visibility = PortableVisibilityConverter::fromArray([
$visibility = PortableVisibilityConverter::fromArray(
[
'file' => [
'public' => 0644,
'private' => 0600,
Expand All @@ -52,8 +56,9 @@ public function __construct(Config $config, SymfonyStyle $output)
'public' => 0755,
'private' => 0700,
],
],
Visibility::PUBLIC);
],
Visibility::PUBLIC
);
$adapter = new LocalFilesystemAdapter($config->getRootPath(), $visibility);
$this->filesystem = new Filesystem($adapter);
$this->markdown = new Markdown();
Expand Down Expand Up @@ -110,7 +115,6 @@ public function cleanDestination(): void
try {
$this->filesystem->deleteDirectory($destination);
$this->filesystem->createDirectory($destination);

} catch (FilesystemException | UnableToDeleteDirectory $exception) {
throw new BuildException(sprintf('Cannot clean destination folder, error: %s', $exception->getMessage()));
}
Expand All @@ -130,13 +134,13 @@ public function buildAssets(bool $passthru = false)
}

// Change dir, then run command
$command = sprintf('cd %s && %s',$this->config->getRootPath(), $command);
$command = sprintf('cd %s && %s', $this->config->getRootPath(), $command);
$output = '';

if ($passthru) {
passthru($command,$status);
passthru($command, $status);
} else {
exec($command,$output,$status);
exec($command, $output, $status);
}

if ($status !== 0) {
Expand Down Expand Up @@ -245,7 +249,7 @@ public function buildDocs()

// Sort layouts in each sub-directory
foreach ($pages as $subDirectory => $children) {
uasort($pages[$subDirectory], function($a, $b) {
uasort($pages[$subDirectory], function ($a, $b) {
// Stick index layouts to top
if ($a['filename'] === 'index') {
return -1;
Expand Down Expand Up @@ -383,19 +387,17 @@ public function buildDocsPage(string $title, string $sourcePath, string $destina
/**
* Create ZIP file of website assets for developer use
*
* @see https://github.com/alchemy-fr/Zippy
* @see https://www.php.net/manual/en/class.ziparchive.php
*/
public function buildZipFile()
{
if (!$this->config->has('zip_folder')) {
$this->output->text('Skipping, no ZIP folder defined in config');
return false;
}

// Path to folder to add to ZIP archive (relative to project root)
$zipFolder = $this->config->get('zip_folder');
if (empty($zipFolder)) {
$this->output->text('Skipping, no ZIP folder defined in config');
$this->output->text('Skipping, no source folder to creat a ZIP defined in config');
return false;
}
$source = $this->config->getFullPath($zipFolder);
Expand All @@ -413,21 +415,29 @@ public function buildZipFile()
}
$destination = $this->config->getFullPath($this->config->buildPath(Config::ASSETS_PATH, $zipName)) . '.zip';

try {
$zippy = Zippy::load();
$archive = $zippy->create($destination, [
$zipName => $source
], true);

if ($this->output->isVerbose()) {
$this->output->text('* ' . $destination);
}
// Setup ZIP archive
$zip = new ZipArchive();
if ($zip->open($destination, ZipArchive::CREATE) !== true) {
throw new BuildException(sprintf('Cannot create ZIP archive at %s', $destination));
}

return true;
// ZIP folders
$info = pathinfo($source);
$zipFolderRegex = '/^' . preg_quote($info["dirname"] . '/' . $info["basename"], '/') . '/';

// Add all files in source folder to ZIP
$flags = \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_SELF;
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, $flags));
/** @var RecursiveDirectoryIterator $file */
foreach ($files as $file) {
$filepath = $file->getPathname();
$zipPath = preg_replace($zipFolderRegex, '', $filepath);
$zip->addFile($filepath, $zipPath);
}

} catch (\Alchemy\Zippy\Exception\ExceptionInterface $exception) {
throw new BuildException(sprintf('Cannot build ZIP archive for folder %s, destination %s, error: %s', $zipFolder, $destination, $exception->getMessage()));
if (!$zip->close()) {
throw new BuildException(sprintf('Cannot save ZIP archive at %s', $destination));
}
return true;
}

}
Loading
Loading