-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added scripted package skeleton template
- Loading branch information
Showing
14 changed files
with
383 additions
and
4 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,8 @@ | ||
{ | ||
"package.name": "Polymorphine/Dev", | ||
"repository.name": "polymorphine/dev", | ||
"package.description": "Development tools & coding standard scripts for Polymorphine libraries", | ||
"namespace.src": "Polymorphine\\Dev", | ||
"author.name": "Shudd3r", | ||
"author.email": "q3.shudder@gmail.com" | ||
} |
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
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,80 @@ | ||
#!/usr/bin/env php | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Polymorphine/Dev package. | ||
* | ||
* (c) Shudd3r <q3.shudder@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
use Shudd3r\Skeletons\Application; | ||
use Shudd3r\Skeletons\InputArgs; | ||
use Shudd3r\Skeletons\Environment\Files\Directory\LocalDirectory; | ||
use Shudd3r\Skeletons\Replacements\Replacement; | ||
use Shudd3r\Skeletons\Replacements\Source; | ||
use Shudd3r\Skeletons\Templates\Contents; | ||
use Shudd3r\Skeletons\Templates\Template; | ||
|
||
// This script should be executed from package root directory | ||
$rootDirectory = getcwd(); | ||
if (!file_exists($rootDirectory . '/vendor/autoload.php')) { | ||
fwrite(STDERR, 'Cannot find vendor/autoload.php file in package root directory'); | ||
die(1); | ||
} | ||
|
||
if (!file_exists($rootDirectory . '/composer.json')) { | ||
fwrite(STDERR, 'Cannot find composer.json file in package root directory'); | ||
die(1); | ||
} | ||
|
||
require_once $rootDirectory . '/vendor/autoload.php'; | ||
|
||
$args = new InputArgs($argv ?? []); | ||
|
||
$skeleton = new LocalDirectory(__DIR__ . '/template'); | ||
$package = new LocalDirectory($rootDirectory); | ||
$app = new Application($package, $skeleton); | ||
|
||
$app->backup(new LocalDirectory($rootDirectory . '/.dev/.skeleton-backup')); | ||
|
||
$app->replacement('package.name')->add(new Replacement\PackageName()); | ||
$app->replacement('repository.name')->add(new Replacement\RepositoryName('package.name')); | ||
$app->replacement('package.description')->add(new Replacement\PackageDescription('package.name')); | ||
$app->replacement('namespace.src')->add(new Replacement\SrcNamespace('package.name')); | ||
$app->replacement('author.name') | ||
->build(fn (Source $source) => $source->composer()->value('authors.0.name') ?? 'Author Name') | ||
->argumentName('author') | ||
->inputPrompt('Author\'s name') | ||
->description('Name of package author [format: non-empty string]' . PHP_EOL . 'Replaces {%s} placeholder') | ||
->validate(fn (string $value) => !empty($value)); | ||
$app->replacement('author.email') | ||
->build(fn (Source $source) => $source->composer()->value('authors.0.email') ?? 'default@example.com') | ||
->argumentName('email') | ||
->inputPrompt('Author\'s email address') | ||
->description('Email address of package author [format: <username>@<domain>]' . PHP_EOL . 'Replaces {%s} placeholder') | ||
->validate(fn (string $value) => $value === filter_var($value, FILTER_VALIDATE_EMAIL)); | ||
|
||
$isUpdate = $args->command() === 'update'; | ||
$isSelf = $rootDirectory === __DIR__; | ||
|
||
$app->template('LICENSE')->createWith(function (Contents $contents) { | ||
return new Template\BasicTemplate(str_replace('{$tpl.CURRENT_YEAR}', date('Y'), $contents->template())); | ||
}); | ||
|
||
$app->template('composer.json')->createWith(function (Contents $contents) use ($isSelf, $isUpdate) { | ||
$placeholders = ['{$tpl.REQUIRE_DEV}', '{$tpl.PHP_EXEC}']; | ||
$replacements = $isSelf ? ['null', '@php '] : ['{ "polymorphine/dev": null }', '']; | ||
$baseTemplate = new Template\BasicTemplate(str_replace($placeholders, $replacements, $contents->template())); | ||
return new Template\MergedJsonTemplate($baseTemplate, $contents->package(), $isUpdate); | ||
}); | ||
|
||
$app->template('.github/workflows/build.yml')->createWith(function (Contents $contents) use ($isSelf) { | ||
$replacement = $isSelf ? 'php ' : 'vendor/bin/'; | ||
return new Template\BasicTemplate(str_replace('${tpl.PHP_EXEC}', $replacement, $contents->template())); | ||
}); | ||
|
||
$exitCode = $app->run($args); | ||
exit($exitCode); |
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,7 @@ | ||
/.github export-ignore | ||
/tests export-ignore | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
phpunit.xml.dist export-ignore | ||
cs-fixer.php.dist export-ignore | ||
{original.content} |
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,110 @@ | ||
name: build | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
full-build: | ||
name: "Coding standards & coverage tests" | ||
runs-on: ${{ matrix.operating-system }} | ||
strategy: | ||
matrix: | ||
operating-system: ['ubuntu-latest'] | ||
php-versions: ['7.4'] | ||
env: | ||
extensions: pcov, dom, json, libxml, mbstring, pdo_sqlite, soap, xml, xmlwriter | ||
key: cache-v2 | ||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v2 | ||
- name: "Setup PHP extensions cache environment" | ||
id: cache-env | ||
uses: shivammathur/cache-extensions@v1 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
extensions: ${{ env.extensions }} | ||
key: ${{ env.key }} | ||
- name: "Cache PHP extensions" | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.cache-env.outputs.dir }} | ||
key: ${{ steps.cache-env.outputs.key }} | ||
restore-keys: ${{ steps.cache-env.outputs.key }} | ||
- name: "Install PHP with extensions" | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
coverage: pcov | ||
extensions: ${{ env.extensions }} | ||
ini-values: assert.exception=1, zend.assertions=1 | ||
- name: "Validate composer.json" | ||
run: composer validate | ||
- name: "Setup composer cache" | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.composer/cache | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
- name: "Install highest dependencies" | ||
run: composer update --no-interaction --no-ansi --no-progress --no-suggest --prefer-stable | ||
- name: "Coding standard Php-CS-Fixer checks" | ||
run: vendor/bin/php-cs-fixer --dry-run -v --config=cs-fixer.php.dist --path-mode=intersection fix src tests | ||
- name: "Coding standard CodeSniffer checks" | ||
run: | | ||
vendor/bin/phpcs --extensions=php --standard=phpcs.xml.dist src | ||
vendor/bin/phpcs --extensions=php --standard=phpcs.xml.dist --ignore=tests/CodeSamples/* tests | ||
- name: "Package skeleton validation" | ||
run: ${tpl.PHP_EXEC}polymorphine-skeleton check | ||
- name: "Run PhpUnit tests with coverage" | ||
run: | | ||
mkdir -p build/logs | ||
vendor/bin/phpunit --exclude-group integrated --coverage-clover build/logs/clover.xml | ||
- name: "Send coverage report to coveralls.io" | ||
run: vendor/bin/php-coveralls -v | ||
env: | ||
COVERALLS_RUN_LOCALLY: 1 | ||
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} | ||
|
||
php-os-builds: | ||
name: "PHP 8 tests" | ||
runs-on: ${{ matrix.operating-system }} | ||
strategy: | ||
matrix: | ||
operating-system: ['ubuntu-latest', 'windows-latest', 'macos-latest'] | ||
php-versions: ['8.0', '8.1'] | ||
env: | ||
extensions: dom, json, libxml, mbstring, pdo_sqlite, soap, xml, xmlwriter | ||
key: cache-v2 | ||
steps: | ||
- name: "Turn off git EOL conversion" | ||
run: git config --global core.autocrlf false | ||
- name: "Checkout" | ||
uses: actions/checkout@v2 | ||
- name: "Setup PHP extensions cache environment" | ||
id: cache-env | ||
uses: shivammathur/cache-extensions@v1 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
extensions: ${{ env.extensions }} | ||
key: ${{ env.key }} | ||
- name: "Cache PHP extensions" | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.cache-env.outputs.dir }} | ||
key: ${{ steps.cache-env.outputs.key }} | ||
restore-keys: ${{ steps.cache-env.outputs.key }} | ||
- name: "Install PHP with extensions" | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
coverage: none | ||
extensions: ${{ env.extensions }} | ||
ini-values: assert.exception=1, zend.assertions=1 | ||
- name: "Setup composer cache" | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.composer/cache | ||
key: ${{ runner.os }}-php${{ matrix.php-versions }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-php${{ matrix.php-versions }}-composer- | ||
- name: "Install highest dependencies" | ||
run: composer update --no-interaction --no-ansi --no-progress --no-suggest --prefer-stable | ||
- name: "Run PhpUnit tests (no coverage)" | ||
run: vendor/bin/phpunit --exclude-group integrated --no-coverage |
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 @@ | ||
/.dev/ | ||
/vendor/ | ||
/composer.lock | ||
{original.content} |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) {original.content>>>{$tpl.CURRENT_YEAR}<<<original.content} {author.name} <{author.email}> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# {package.name} | ||
[![Latest Stable Version](https://poser.pugx.org/{package.name.composer}/version)](https://packagist.org/packages/{package.name.composer}) | ||
[![Build status](https://github.com/{repository.name}/workflows/build/badge.svg)](https://github.com/{repository.name}/actions) | ||
[![Coverage status](https://coveralls.io/repos/github/{repository.name}/badge.svg?branch=develop)](https://coveralls.io/github/{repository.name}?branch=develop) | ||
[![PHP version](https://img.shields.io/packagist/php-v/{package.name.composer}.svg)](https://packagist.org/packages/{package.name.composer}) | ||
[![LICENSE](https://img.shields.io/github/license/{repository.name}.svg?color=blue)](LICENSE) | ||
### {package.description} | ||
|
||
{original.content>>>Detailed description (optional)...<<<original.content} | ||
|
||
### Installation with [Composer](https://getcomposer.org/) | ||
```bash | ||
composer require{original.content} {package.name.composer} | ||
``` | ||
|
||
{original.content>>>Your content here...<<<original.content} |
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,39 @@ | ||
{ | ||
"name": "{package.name.composer}", | ||
"description": "{package.description}", | ||
"type": null, | ||
"license": null, | ||
"authors": [ | ||
{ | ||
"name": "{author.name}", | ||
"email": "{author.email}", | ||
"homepage": null, | ||
"role": null | ||
} | ||
], | ||
"minimum-stability": null, | ||
"require": { | ||
"php": null | ||
}, | ||
"require-dev": {$tpl.REQUIRE_DEV}, | ||
"autoload": { | ||
"psr-4": { | ||
"{namespace.src.esc}\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"{namespace.src.esc}\\Tests\\": "tests/" | ||
} | ||
}, | ||
"bin": null, | ||
"scripts": { | ||
"test-cs": [ | ||
"php-cs-fixer --dry-run -v --config=cs-fixer.php.dist --path-mode=intersection fix src tests", | ||
"phpcs --extensions=php --standard=phpcs.xml.dist src", | ||
"phpcs --extensions=php --standard=phpcs.xml.dist --ignore=tests/CodeSamples/* tests" | ||
], | ||
"test-php": "phpunit", | ||
"test-skeleton": "{$tpl.PHP_EXEC}polymorphine-skeleton check" | ||
} | ||
} |
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 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of {package.name} package. | ||
* | ||
* (c) Shudd3r <q3.shudder@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
use Polymorphine\Dev\FixerFactory; | ||
|
||
{original.content} | ||
|
||
return FixerFactory::createFor('{package.name}', __DIR__{original.content}); |
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
cacheResultFile=".dev/temp/.phpunit.result.cache" | ||
colors="true" | ||
bootstrap="vendor/autoload.php" | ||
> | ||
<php> | ||
<ini name="error_reporting" value="-1" /> | ||
</php> | ||
<testsuites> | ||
<testsuite name="{package.name} tests"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory>./src/</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
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,19 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of {package.name} package. | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace {namespace.src}; | ||
|
||
|
||
class Example | ||
{ | ||
public function welcome(string $name = 'World'): string | ||
{ | ||
return 'Hello ' . $name . '!'; | ||
} | ||
} |
Oops, something went wrong.