From 38ccd8e483a8396eee3ae81f7118c5ed4dfbf474 Mon Sep 17 00:00:00 2001 From: sawirricardo Date: Fri, 27 May 2022 13:11:37 +0700 Subject: [PATCH] initial commit --- .github/ISSUE_TEMPLATE/config.yml | 8 +- CHANGELOG.md | 2 +- LICENSE.md | 2 +- README.md | 53 ++-- composer.json | 35 +-- config/api2pdf.php | 6 + config/skeleton.php | 5 - configure.php | 237 ------------------ database/factories/ModelFactory.php | 19 -- .../migrations/create_skeleton_table.php.stub | 19 -- phpunit.xml.dist | 2 +- resources/views/.gitkeep | 0 src/Api2pdf.php | 16 ++ src/Api2pdfServiceProvider.php | 31 +++ ...SkeletonCommand.php => Api2pdfCommand.php} | 6 +- src/Facades/Api2pdf.php | 16 ++ src/Facades/Skeleton.php | 16 -- src/Skeleton.php | 7 - src/SkeletonServiceProvider.php | 25 -- src/helpers.php | 11 + tests/Pest.php | 2 +- tests/TestCase.php | 10 +- 22 files changed, 132 insertions(+), 396 deletions(-) create mode 100644 config/api2pdf.php delete mode 100644 config/skeleton.php delete mode 100644 configure.php delete mode 100644 database/factories/ModelFactory.php delete mode 100644 database/migrations/create_skeleton_table.php.stub delete mode 100644 resources/views/.gitkeep create mode 100755 src/Api2pdf.php create mode 100644 src/Api2pdfServiceProvider.php rename src/Commands/{SkeletonCommand.php => Api2pdfCommand.php} (62%) create mode 100644 src/Facades/Api2pdf.php delete mode 100644 src/Facades/Skeleton.php delete mode 100755 src/Skeleton.php delete mode 100644 src/SkeletonServiceProvider.php create mode 100644 src/helpers.php diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 80a788c..d04a776 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,14 +1,14 @@ blank_issues_enabled: false contact_links: - name: Ask a question - url: https://github.com/:vendor_name/:package_name/discussions/new?category=q-a + url: https://github.com/sawirricardo/laravel-api2pdf/discussions/new?category=q-a about: Ask the community for help - name: Request a feature - url: https://github.com/:vendor_name/:package_name/discussions/new?category=ideas + url: https://github.com/sawirricardo/laravel-api2pdf/discussions/new?category=ideas about: Share ideas for new features - name: Report a security issue - url: https://github.com/:vendor_name/:package_name/security/policy + url: https://github.com/sawirricardo/laravel-api2pdf/security/policy about: Learn how to notify us for sensitive bugs - name: Report a bug - url: https://github.com/:vendor_name/:package_name/issues/new + url: https://github.com/sawirricardo/laravel-api2pdf/issues/new about: Report a reproducable bug diff --git a/CHANGELOG.md b/CHANGELOG.md index 87b3242..6421ae4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ # Changelog -All notable changes to `:package_name` will be documented in this file. +All notable changes to `laravel-api2pdf` will be documented in this file. diff --git a/LICENSE.md b/LICENSE.md index 58c9ad4..e5f9585 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) :vendor_name +Copyright (c) sawirricardo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 8b6478d..13222ea 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,17 @@ - [](https://supportukrainenow.org) -# :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/workflow/status/:vendor_slug/:package_slug/run-tests?label=tests)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain) -[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/:vendor_slug/:package_slug/Check%20&%20fix%20styling?label=code%20style)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Check+%26+fix+styling"+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) - ---- -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 Laravel Package Training video course. ---- - +# [Api2pdf](https://api2pdf.com) wrapper + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/sawirricardo/laravel-api2pdf.svg?style=flat-square)](https://packagist.org/packages/sawirricardo/laravel-api2pdf) +[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/sawirricardo/laravel-api2pdf/run-tests?label=tests)](https://github.com/sawirricardo/laravel-api2pdf/actions?query=workflow%3Arun-tests+branch%3Amain) +[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/sawirricardo/laravel-api2pdf/Check%20&%20fix%20styling?label=code%20style)](https://github.com/sawirricardo/laravel-api2pdf/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain) +[![Total Downloads](https://img.shields.io/packagist/dt/sawirricardo/laravel-api2pdf.svg?style=flat-square)](https://packagist.org/packages/sawirricardo/laravel-api2pdf) + This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. ## Support us -[](https://spatie.be/github-ad-click/:package_name) +[](https://spatie.be/github-ad-click/laravel-api2pdf) 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). @@ -32,40 +22,29 @@ We highly appreciate you sending us a postcard from your hometown, mentioning wh 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 +composer require sawirricardo/laravel-api2pdf ``` You can publish the config file with: ```bash -php artisan vendor:publish --tag=":package_slug-config" +php artisan vendor:publish --tag="laravel-api2pdf-config" ``` This is the contents of the published config file: ```php return [ + 'api_key'=> env('API2PDF_API_KEY'), ]; ``` -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!'); +// @see https://github.com/Api2Pdf/api2pdf.php +$result = api2pdf()->chromeHtmlToPdf('

Hello, World

'); +echo $result->getFile(); ``` ## Testing @@ -88,8 +67,8 @@ Please review [our security policy](../../security/policy) on how to report secu ## Credits -- [:author_name](https://github.com/:author_username) -- [All Contributors](../../contributors) +- [sawirricardo](https://github.com/sawirricardo) +- [All Contributors](../../contributors) ## License diff --git a/composer.json b/composer.json index e860a22..3906b18 100644 --- a/composer.json +++ b/composer.json @@ -1,24 +1,25 @@ { - "name": ":vendor_slug/:package_slug", - "description": ":package_description", + "name": "sawirricardo/laravel-api2pdf", + "description": "This is my package laravel-api2pdf", "keywords": [ - ":vendor_name", + "sawirricardo", "laravel", - ":package_slug" + "laravel-api2pdf" ], - "homepage": "https://github.com/:vendor_slug/:package_slug", + "homepage": "https://github.com/sawirricardo/laravel-api2pdf", "license": "MIT", "authors": [ { - "name": ":author_name", - "email": "author@domain.com", + "name": "sawirricardo", + "email": "sawir.ricardo@gmail.com", "role": "Developer" } ], "require": { "php": "^8.1", - "spatie/laravel-package-tools": "^1.9.2", - "illuminate/contracts": "^9.0" + "api2pdf/api2pdf.php": "^2.0", + "illuminate/contracts": "^9.0", + "spatie/laravel-package-tools": "^1.9.2" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.8", @@ -35,13 +36,13 @@ }, "autoload": { "psr-4": { - "VendorName\\Skeleton\\": "src", - "VendorName\\Skeleton\\Database\\Factories\\": "database/factories" + "Sawirricardo\\Laravel\\Api2pdf\\": "src", + "Sawirricardo\\Laravel\\Api2pdf\\Database\\Factories\\": "database/factories" } }, "autoload-dev": { "psr-4": { - "VendorName\\Skeleton\\Tests\\": "tests" + "Sawirricardo\\Laravel\\Api2pdf\\Tests\\": "tests" } }, "scripts": { @@ -51,15 +52,19 @@ "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true, + "phpstan/extension-installer": true + } }, "extra": { "laravel": { "providers": [ - "VendorName\\Skeleton\\SkeletonServiceProvider" + "Sawirricardo\\Api2pdf\\Api2pdfServiceProvider" ], "aliases": { - "Skeleton": "VendorName\\Skeleton\\Facades\\Skeleton" + "Api2pdf": "Sawirricardo\\Api2pdf\\Facades\\Api2pdf" } } }, diff --git a/config/api2pdf.php b/config/api2pdf.php new file mode 100644 index 0000000..b0a6394 --- /dev/null +++ b/config/api2pdf.php @@ -0,0 +1,6 @@ + env('API2PDF_API_KEY'), +]; diff --git a/config/skeleton.php b/config/skeleton.php deleted file mode 100644 index fbb0e4c..0000000 --- a/config/skeleton.php +++ /dev/null @@ -1,5 +0,0 @@ - $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('/.*/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__))); -} - -$gitName = run('git config user.name'); -$authorName = ask('Author name', $gitName); - -$gitEmail = run('git config user.email'); -$authorEmail = ask('Author email', $gitEmail); - -$usernameGuess = explode(':', run('git config remote.origin.url'))[1]; -$usernameGuess = dirname($usernameGuess); -$usernameGuess = basename($usernameGuess); -$authorUsername = ask('Author username', $usernameGuess); - -$vendorName = ask('Vendor name', $authorUsername); -$vendorSlug = slugify($vendorName); -$vendorNamespace = 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); -$usePhpCsFixer = confirm('Enable PhpCsFixer?', 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 PhpCsFixer : " . ($usePhpCsFixer ? 'yes' : 'no')); -writeln("Use Larastan/PhpStan : " . ($usePhpStan ? '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 (! $usePhpCsFixer) { - safeUnlink(__DIR__ . '/.php_cs.dist.php'); - safeUnlink(__DIR__ . '/.github/workflows/php-cs-fixer.yml'); -} - -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', - 'nunomaduro/larastan', - ]); - - remove_composer_script('phpstan'); -} - -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__); diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php deleted file mode 100644 index c51604f..0000000 --- a/database/factories/ModelFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -id(); - - // add fields - - $table->timestamps(); - }); - } -}; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3bbe22a..b26c0dc 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,7 +19,7 @@ verbose="true" > - + tests diff --git a/resources/views/.gitkeep b/resources/views/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/Api2pdf.php b/src/Api2pdf.php new file mode 100755 index 0000000..2c91fb0 --- /dev/null +++ b/src/Api2pdf.php @@ -0,0 +1,16 @@ +name('laravel-api2pdf') + ->hasConfigFile() + ->hasCommand(Api2pdfCommand::class); + } + + public function registeringPackage() + { + $this->app->singleton(Api2pdf::class, function () { + return new Api2pdf(config('api2pdf')); + }); + } +} diff --git a/src/Commands/SkeletonCommand.php b/src/Commands/Api2pdfCommand.php similarity index 62% rename from src/Commands/SkeletonCommand.php rename to src/Commands/Api2pdfCommand.php index 3e5f628..3ed5c92 100644 --- a/src/Commands/SkeletonCommand.php +++ b/src/Commands/Api2pdfCommand.php @@ -1,12 +1,12 @@ name('skeleton') - ->hasConfigFile() - ->hasViews() - ->hasMigration('create_skeleton_table') - ->hasCommand(SkeletonCommand::class); - } -} diff --git a/src/helpers.php b/src/helpers.php new file mode 100644 index 0000000..db88505 --- /dev/null +++ b/src/helpers.php @@ -0,0 +1,11 @@ +in(__DIR__); diff --git a/tests/TestCase.php b/tests/TestCase.php index d04fb0c..1f337a4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,10 +1,10 @@ 'VendorName\\Skeleton\\Database\\Factories\\'.class_basename($modelName).'Factory' + fn (string $modelName) => 'Sawirricardo\\Api2pdf\\Database\\Factories\\'.class_basename($modelName).'Factory' ); } protected function getPackageProviders($app) { return [ - SkeletonServiceProvider::class, + Api2pdfServiceProvider::class, ]; } @@ -29,7 +29,7 @@ public function getEnvironmentSetUp($app) config()->set('database.default', 'testing'); /* - $migration = include __DIR__.'/../database/migrations/create_skeleton_table.php.stub'; + $migration = include __DIR__.'/../database/migrations/create_laravel-api2pdf_table.php.stub'; $migration->up(); */ }