Initial commit

This commit is contained in:
dynasofthk
2026-01-13 08:59:48 +08:00
committed by GitHub
commit 6ddce72f0e
32 changed files with 1111 additions and 0 deletions

15
.editorconfig Normal file
View File

@@ -0,0 +1,15 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2

20
.gitattributes vendored Normal file
View File

@@ -0,0 +1,20 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/art export-ignore
/docs export-ignore
/tests export-ignore
/workbench export-ignore
/.editorconfig export-ignore
/.php_cs.dist.php export-ignore
/psalm.xml export-ignore
/psalm.xml.dist export-ignore
/testbench.yaml export-ignore
/UPGRADING.md export-ignore
/phpstan.neon.dist export-ignore
/phpstan-baseline.neon export-ignore

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
github: :vendor_name

66
.github/ISSUE_TEMPLATE/bug.yml vendored Normal file
View File

@@ -0,0 +1,66 @@
name: Bug Report
description: Report an Issue or Bug with the Package
title: "[Bug]: "
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
We're sorry to hear you have a problem. Can you help us solve it by providing the following details.
- type: textarea
id: what-happened
attributes:
label: What happened?
description: What did you expect to happen?
placeholder: I cannot currently do X thing because when I do, it breaks X thing.
validations:
required: true
- type: textarea
id: how-to-reproduce
attributes:
label: How to reproduce the bug
description: How did this occur, please add any config values used and provide a set of reliable steps if possible.
placeholder: When I do X I see Y.
validations:
required: true
- type: input
id: package-version
attributes:
label: Package Version
description: What version of our Package are you running? Please be as specific as possible
placeholder: 2.0.0
validations:
required: true
- type: input
id: php-version
attributes:
label: PHP Version
description: What version of PHP are you running? Please be as specific as possible
placeholder: 8.2.0
validations:
required: true
- type: input
id: laravel-version
attributes:
label: Laravel Version
description: What version of Laravel are you running? Please be as specific as possible
placeholder: 9.0.0
validations:
required: true
- type: dropdown
id: operating-systems
attributes:
label: Which operating systems does this happen with?
description: You may select more than one.
multiple: true
options:
- macOS
- Windows
- Linux
- type: textarea
id: notes
attributes:
label: Notes
description: Use this field to provide any other notes that you feel might be relevant to the issue.
validations:
required: false

11
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://github.com/:vendor_slug/:package_name/discussions/new?category=q-a
about: Ask the community for help
- name: Request a feature
url: https://github.com/:vendor_slug/:package_name/discussions/new?category=ideas
about: Share ideas for new features
- name: Report a security issue
url: https://github.com/:vendor_slug/:package_name/security/policy
about: Learn how to notify us for sensitive bugs

19
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"

View File

@@ -0,0 +1,33 @@
name: dependabot-auto-merge
on: pull_request_target
permissions:
pull-requests: write
contents: write
jobs:
dependabot:
runs-on: ubuntu-latest
timeout-minutes: 5
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.5.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Auto-merge Dependabot PRs for semver-minor updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Auto-merge Dependabot PRs for semver-patch updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

View File

@@ -0,0 +1,28 @@
name: Fix PHP code style issues
on:
push:
paths:
- '**.php'
permissions:
contents: write
jobs:
php-code-styling:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
ref: ${{ github.head_ref }}
- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@2.6
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: Fix styling

28
.github/workflows/phpstan.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: PHPStan
on:
push:
paths:
- '**.php'
- 'phpstan.neon.dist'
- '.github/workflows/phpstan.yml'
jobs:
phpstan:
name: phpstan
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v5
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none
- name: Install composer dependencies
uses: ramsey/composer-install@v3
- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github

60
.github/workflows/run-tests.yml vendored Normal file
View File

@@ -0,0 +1,60 @@
name: run-tests
on:
push:
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.4, 8.3]
laravel: [12.*, 11.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 12.*
testbench: 10.*
- laravel: 11.*
testbench: 9.*
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none
- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: List Installed Dependencies
run: composer show -D
- name: Execute tests
run: vendor/bin/pest --ci

32
.github/workflows/update-changelog.yml vendored Normal file
View File

@@ -0,0 +1,32 @@
name: "Update Changelog"
on:
release:
types: [released]
permissions:
contents: write
jobs:
update:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
ref: main
- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}
- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v7
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md

32
.gitignore vendored Normal file
View File

@@ -0,0 +1,32 @@
# Composer Related
composer.lock
/vendor
# Frontend Assets
/node_modules
# Logs
npm-debug.log
yarn-error.log
# Caches
.phpunit.cache
.phpunit.result.cache
/build
# IDE Helper
_ide_helper.php
_ide_helper_models.php
.phpstorm.meta.php
# Editors
/.idea
/.fleet
/.vscode
# Misc
phpunit.xml
phpstan.neon
testbench.yaml
/docs
/coverage

3
CHANGELOG.md Normal file
View File

@@ -0,0 +1,3 @@
# Changelog
All notable changes to `:package_name` will be documented in this file.

21
LICENSE.md Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) :vendor_name <author@domain.com>
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.

93
README.md Normal file
View File

@@ -0,0 +1,93 @@
# :package_description
[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
<!--delete-->
---
This repo can be used to scaffold a Laravel package. Follow these steps to get started:
1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton.
2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files.
3. Have fun creating your package.
4. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course.
---
<!--/delete-->
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
## Support us
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/:package_name.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/:package_name)
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
## Installation
You can install the package via composer:
```bash
composer require :vendor_slug/:package_slug
```
You can publish and run the migrations with:
```bash
php artisan vendor:publish --tag=":package_slug-migrations"
php artisan migrate
```
You can publish the config file with:
```bash
php artisan vendor:publish --tag=":package_slug-config"
```
This is the contents of the published config file:
```php
return [
];
```
Optionally, you can publish the views using
```bash
php artisan vendor:publish --tag=":package_slug-views"
```
## Usage
```php
$variable = new VendorName\Skeleton();
echo $variable->echoPhrase('Hello, VendorName!');
```
## Testing
```bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [:author_name](https://github.com/:author_username)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

75
composer.json Normal file
View File

@@ -0,0 +1,75 @@
{
"name": ":vendor_slug/:package_slug",
"description": ":package_description",
"keywords": [
":vendor_name",
"laravel",
":package_slug"
],
"homepage": "https://github.com/:vendor_slug/:package_slug",
"license": "MIT",
"authors": [
{
"name": ":author_name",
"email": "author@domain.com",
"role": "Developer"
}
],
"require": {
"php": "^8.4",
"spatie/laravel-package-tools": "^1.16",
"illuminate/contracts": "^11.0||^12.0"
},
"require-dev": {
"laravel/pint": "^1.14",
"nunomaduro/collision": "^8.8",
"larastan/larastan": "^3.0",
"orchestra/testbench": "^10.0.0||^9.0.0",
"pestphp/pest": "^4.0",
"pestphp/pest-plugin-arch": "^4.0",
"pestphp/pest-plugin-laravel": "^4.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"spatie/laravel-ray": "^1.35"
},
"autoload": {
"psr-4": {
"VendorName\\Skeleton\\": "src/",
"VendorName\\Skeleton\\Database\\Factories\\": "database/factories/"
}
},
"autoload-dev": {
"psr-4": {
"VendorName\\Skeleton\\Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/"
}
},
"scripts": {
"post-autoload-dump": "@composer run prepare",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
"providers": [
"VendorName\\Skeleton\\SkeletonServiceProvider"
],
"aliases": {
"Skeleton": "VendorName\\Skeleton\\Facades\\Skeleton"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}

6
config/skeleton.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
// config for VendorName/Skeleton
return [
];

370
configure.php Normal file
View File

@@ -0,0 +1,370 @@
#!/usr/bin/env php
<?php
function ask(string $question, string $default = ''): string
{
$answer = readline($question.($default ? " ({$default})" : null).': ');
if (! $answer) {
return $default;
}
return $answer;
}
function confirm(string $question, bool $default = false): bool
{
$answer = ask($question.' ('.($default ? 'Y/n' : 'y/N').')');
if (! $answer) {
return $default;
}
return strtolower($answer) === 'y';
}
function writeln(string $line): void
{
echo $line.PHP_EOL;
}
function run(string $command): string
{
return trim((string) shell_exec($command));
}
function str_after(string $subject, string $search): string
{
$pos = strrpos($subject, $search);
if ($pos === false) {
return $subject;
}
return substr($subject, $pos + strlen($search));
}
function slugify(string $subject): string
{
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $subject), '-'));
}
function title_case(string $subject): string
{
return str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $subject)));
}
function title_snake(string $subject, string $replace = '_'): string
{
return str_replace(['-', '_'], $replace, $subject);
}
function replace_in_file(string $file, array $replacements): void
{
$contents = file_get_contents($file);
file_put_contents(
$file,
str_replace(
array_keys($replacements),
array_values($replacements),
$contents
)
);
}
function remove_prefix(string $prefix, string $content): string
{
if (str_starts_with($content, $prefix)) {
return substr($content, strlen($prefix));
}
return $content;
}
function remove_composer_deps(array $names)
{
$data = json_decode(file_get_contents(__DIR__.'/composer.json'), true);
foreach ($data['require-dev'] as $name => $version) {
if (in_array($name, $names, true)) {
unset($data['require-dev'][$name]);
}
}
file_put_contents(__DIR__.'/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
}
function remove_composer_script($scriptName)
{
$data = json_decode(file_get_contents(__DIR__.'/composer.json'), true);
foreach ($data['scripts'] as $name => $script) {
if ($scriptName === $name) {
unset($data['scripts'][$name]);
break;
}
}
file_put_contents(__DIR__.'/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
}
function remove_readme_paragraphs(string $file): void
{
$contents = file_get_contents($file);
file_put_contents(
$file,
preg_replace('/<!--delete-->.*<!--\/delete-->/s', '', $contents) ?: $contents
);
}
function safeUnlink(string $filename)
{
if (file_exists($filename) && is_file($filename)) {
unlink($filename);
}
}
function determineSeparator(string $path): string
{
return str_replace('/', DIRECTORY_SEPARATOR, $path);
}
function replaceForWindows(): array
{
return preg_split('/\\r\\n|\\r|\\n/', run('dir /S /B * | findstr /v /i .git\ | findstr /v /i .vendor\ | findstr /v /i '.basename(__FILE__).' | findstr /r /i /M /F:/ ":author :vendor :package VendorName skeleton migration_table_name vendor_name vendor_slug author@domain.com"'));
}
function replaceForAllOtherOSes(): array
{
return explode(PHP_EOL, run('grep -E -r -l -i ":author|:vendor|:package|VendorName|skeleton|migration_table_name|vendor_name|vendor_slug|author@domain.com" --exclude-dir=vendor ./* ./.github/* | grep -v '.basename(__FILE__)));
}
function getGitHubApiEndpoint(string $endpoint): ?stdClass
{
try {
$curl = curl_init("https://api.github.com/{$endpoint}");
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPGET => true,
CURLOPT_HTTPHEADER => [
'User-Agent: spatie-configure-script/1.0',
],
]);
$response = curl_exec($curl);
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($statusCode === 200) {
return json_decode($response);
}
} catch (Exception $e) {
// ignore
}
return null;
}
function searchCommitsForGitHubUsername(): string
{
$authorName = strtolower(trim(shell_exec('git config user.name')));
$committersRaw = shell_exec("git log --author='@users.noreply.github.com' --pretty='%an:%ae' --reverse");
$committersLines = explode("\n", $committersRaw ?? '');
$committers = array_filter(array_map(function ($line) use ($authorName) {
$line = trim($line);
[$name, $email] = explode(':', $line) + [null, null];
return [
'name' => $name,
'email' => $email,
'isMatch' => strtolower($name) === $authorName && ! str_contains($name, '[bot]'),
];
}, $committersLines), fn ($item) => $item['isMatch']);
if (empty($committers)) {
return '';
}
$firstCommitter = reset($committers);
return explode('@', $firstCommitter['email'])[0] ?? '';
}
function guessGitHubUsernameUsingCli()
{
try {
if (preg_match('/ogged in to github\.com as ([a-zA-Z-_]+).+/', shell_exec('gh auth status -h github.com 2>&1'), $matches)) {
return $matches[1];
}
} catch (Exception $e) {
// ignore
}
return '';
}
function guessGitHubUsername(): string
{
$username = searchCommitsForGitHubUsername();
if (! empty($username)) {
return $username;
}
$username = guessGitHubUsernameUsingCli();
if (! empty($username)) {
return $username;
}
// fall back to using the username from the git remote
$remoteUrl = shell_exec('git config remote.origin.url') ?? '';
$remoteUrlParts = explode('/', str_replace(':', '/', trim($remoteUrl)));
return $remoteUrlParts[1] ?? '';
}
function guessGitHubVendorInfo($authorName, $username): array
{
$remoteUrl = shell_exec('git config remote.origin.url') ?? '';
$remoteUrlParts = explode('/', str_replace(':', '/', trim($remoteUrl)));
if (! isset($remoteUrlParts[1])) {
return [$authorName, $username];
}
$response = getGitHubApiEndpoint("orgs/{$remoteUrlParts[1]}");
if ($response === null) {
return [$authorName, $username];
}
return [$response->name ?? $authorName, $response->login ?? $username];
}
$gitName = run('git config user.name');
$authorName = ask('Author name', $gitName);
$gitEmail = run('git config user.email');
$authorEmail = ask('Author email', $gitEmail);
$authorUsername = ask('Author username', guessGitHubUsername());
$guessGitHubVendorInfo = guessGitHubVendorInfo($authorName, $authorUsername);
$vendorName = ask('Vendor name', $guessGitHubVendorInfo[0]);
$vendorUsername = ask('Vendor username', $guessGitHubVendorInfo[1] ?? slugify($vendorName));
$vendorSlug = slugify($vendorUsername);
$vendorNamespace = str_replace('-', '', ucwords($vendorName));
$vendorNamespace = ask('Vendor namespace', $vendorNamespace);
$currentDirectory = getcwd();
$folderName = basename($currentDirectory);
$packageName = ask('Package name', $folderName);
$packageSlug = slugify($packageName);
$packageSlugWithoutPrefix = remove_prefix('laravel-', $packageSlug);
$className = title_case($packageName);
$className = ask('Class name', $className);
$variableName = lcfirst($className);
$description = ask('Package description', "This is my package {$packageSlug}");
$usePhpStan = confirm('Enable PhpStan?', true);
$useLaravelPint = confirm('Enable Laravel Pint?', true);
$useDependabot = confirm('Enable Dependabot?', true);
$useLaravelRay = confirm('Use Ray for debugging?', true);
$useUpdateChangelogWorkflow = confirm('Use automatic changelog updater workflow?', true);
writeln('------');
writeln("Author : {$authorName} ({$authorUsername}, {$authorEmail})");
writeln("Vendor : {$vendorName} ({$vendorSlug})");
writeln("Package : {$packageSlug} <{$description}>");
writeln("Namespace : {$vendorNamespace}\\{$className}");
writeln("Class name : {$className}");
writeln('---');
writeln('Packages & Utilities');
writeln('Use Laravel/Pint : '.($useLaravelPint ? 'yes' : 'no'));
writeln('Use Larastan/PhpStan : '.($usePhpStan ? 'yes' : 'no'));
writeln('Use Dependabot : '.($useDependabot ? 'yes' : 'no'));
writeln('Use Ray App : '.($useLaravelRay ? 'yes' : 'no'));
writeln('Use Auto-Changelog : '.($useUpdateChangelogWorkflow ? 'yes' : 'no'));
writeln('------');
writeln('This script will replace the above values in all relevant files in the project directory.');
if (! confirm('Modify files?', true)) {
exit(1);
}
$files = (str_starts_with(strtoupper(PHP_OS), 'WIN') ? replaceForWindows() : replaceForAllOtherOSes());
foreach ($files as $file) {
replace_in_file($file, [
':author_name' => $authorName,
':author_username' => $authorUsername,
'author@domain.com' => $authorEmail,
':vendor_name' => $vendorName,
':vendor_slug' => $vendorSlug,
'VendorName' => $vendorNamespace,
':package_name' => $packageName,
':package_slug' => $packageSlug,
':package_slug_without_prefix' => $packageSlugWithoutPrefix,
'Skeleton' => $className,
'skeleton' => $packageSlug,
'migration_table_name' => title_snake($packageSlug),
'variable' => $variableName,
':package_description' => $description,
]);
match (true) {
str_contains($file, determineSeparator('src/Skeleton.php')) => rename($file, determineSeparator('./src/'.$className.'.php')),
str_contains($file, determineSeparator('src/SkeletonServiceProvider.php')) => rename($file, determineSeparator('./src/'.$className.'ServiceProvider.php')),
str_contains($file, determineSeparator('src/Facades/Skeleton.php')) => rename($file, determineSeparator('./src/Facades/'.$className.'.php')),
str_contains($file, determineSeparator('src/Commands/SkeletonCommand.php')) => rename($file, determineSeparator('./src/Commands/'.$className.'Command.php')),
str_contains($file, determineSeparator('database/migrations/create_skeleton_table.php.stub')) => rename($file, determineSeparator('./database/migrations/create_'.title_snake($packageSlugWithoutPrefix).'_table.php.stub')),
str_contains($file, determineSeparator('config/skeleton.php')) => rename($file, determineSeparator('./config/'.$packageSlugWithoutPrefix.'.php')),
str_contains($file, 'README.md') => remove_readme_paragraphs($file),
default => [],
};
}
if (! $useLaravelPint) {
safeUnlink(__DIR__.'/.github/workflows/fix-php-code-style-issues.yml');
safeUnlink(__DIR__.'/pint.json');
}
if (! $usePhpStan) {
safeUnlink(__DIR__.'/phpstan.neon.dist');
safeUnlink(__DIR__.'/phpstan-baseline.neon');
safeUnlink(__DIR__.'/.github/workflows/phpstan.yml');
remove_composer_deps([
'phpstan/extension-installer',
'phpstan/phpstan-deprecation-rules',
'phpstan/phpstan-phpunit',
'larastan/larastan',
]);
remove_composer_script('phpstan');
}
if (! $useDependabot) {
safeUnlink(__DIR__.'/.github/dependabot.yml');
safeUnlink(__DIR__.'/.github/workflows/dependabot-auto-merge.yml');
}
if (! $useLaravelRay) {
remove_composer_deps(['spatie/laravel-ray']);
}
if (! $useUpdateChangelogWorkflow) {
safeUnlink(__DIR__.'/.github/workflows/update-changelog.yml');
}
confirm('Execute `composer install` and run tests?') && run('composer install && composer test');
confirm('Let this script delete itself?', true) && unlink(__FILE__);

View File

@@ -0,0 +1,19 @@
<?php
namespace VendorName\Skeleton\Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/*
class ModelFactory extends Factory
{
protected $model = YourModel::class;
public function definition()
{
return [
];
}
}
*/

View File

@@ -0,0 +1,19 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('migration_table_name_table', function (Blueprint $table) {
$table->id();
// add fields
$table->timestamps();
});
}
};

0
phpstan-baseline.neon Normal file
View File

12
phpstan.neon.dist Normal file
View File

@@ -0,0 +1,12 @@
includes:
- phpstan-baseline.neon
parameters:
level: 5
paths:
- src
- config
- database
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true

31
phpunit.xml.dist Normal file
View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="VendorName Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>

0
resources/views/.gitkeep Normal file
View File

View File

@@ -0,0 +1,19 @@
<?php
namespace VendorName\Skeleton\Commands;
use Illuminate\Console\Command;
class SkeletonCommand extends Command
{
public $signature = 'skeleton';
public $description = 'My command';
public function handle(): int
{
$this->comment('All done');
return self::SUCCESS;
}
}

16
src/Facades/Skeleton.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
namespace VendorName\Skeleton\Facades;
use Illuminate\Support\Facades\Facade;
/**
* @see \VendorName\Skeleton\Skeleton
*/
class Skeleton extends Facade
{
protected static function getFacadeAccessor(): string
{
return \VendorName\Skeleton\Skeleton::class;
}
}

5
src/Skeleton.php Executable file
View File

@@ -0,0 +1,5 @@
<?php
namespace VendorName\Skeleton;
class Skeleton {}

View File

@@ -0,0 +1,25 @@
<?php
namespace VendorName\Skeleton;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use VendorName\Skeleton\Commands\SkeletonCommand;
class SkeletonServiceProvider extends PackageServiceProvider
{
public function configurePackage(Package $package): void
{
/*
* This class is a Package Service Provider
*
* More info: https://github.com/spatie/laravel-package-tools
*/
$package
->name('skeleton')
->hasConfigFile()
->hasViews()
->hasMigration('create_migration_table_name_table')
->hasCommand(SkeletonCommand::class);
}
}

5
tests/ArchTest.php Normal file
View File

@@ -0,0 +1,5 @@
<?php
arch('it will not use debugging functions')
->expect(['dd', 'dump', 'ray'])
->each->not->toBeUsed();

5
tests/ExampleTest.php Normal file
View File

@@ -0,0 +1,5 @@
<?php
it('can test', function () {
expect(true)->toBeTrue();
});

5
tests/Pest.php Normal file
View File

@@ -0,0 +1,5 @@
<?php
use VendorName\Skeleton\Tests\TestCase;
uses(TestCase::class)->in(__DIR__);

37
tests/TestCase.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
namespace VendorName\Skeleton\Tests;
use Illuminate\Database\Eloquent\Factories\Factory;
use Orchestra\Testbench\TestCase as Orchestra;
use VendorName\Skeleton\SkeletonServiceProvider;
class TestCase extends Orchestra
{
protected function setUp(): void
{
parent::setUp();
Factory::guessFactoryNamesUsing(
fn (string $modelName) => 'VendorName\\Skeleton\\Database\\Factories\\'.class_basename($modelName).'Factory'
);
}
protected function getPackageProviders($app)
{
return [
SkeletonServiceProvider::class,
];
}
public function getEnvironmentSetUp($app)
{
config()->set('database.default', 'testing');
/*
foreach (\Illuminate\Support\Facades\File::allFiles(__DIR__ . '/../database/migrations') as $migration) {
(include $migration->getRealPath())->up();
}
*/
}
}