Skip to content

Commit

Permalink
Initial commit. (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed May 15, 2023
1 parent c700ac9 commit b3de72a
Show file tree
Hide file tree
Showing 18 changed files with 470 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.1']
['8.2']
secrets:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
52 changes: 19 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,44 @@
<a href="https://github.com/yii-tools/template" target="_blank">
<img src="https://avatars.githubusercontent.com/u/121752654?s=200&v=4" height="100px">
</a>
<h1 align="center">Template.</h1>
<a href="https://sweetalert2.github.io/#download" target="_blank">
<img src="https://sweetalert2.github.io/images/SweetAlert2.png" height="100px">
</a>
<h1 align="center">Asset SweetAlert2 for YiiFramework v. 3.0.</h1>
<br>
</p>

## Install

For use create a new repository from this template. For more information see [Creating a repository from a template](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template).

Also you can git clone this repository. For more information see [Cloning a repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository).
## Requirements

## Checking dependencies
The minimun version of PHP required by this package is PHP 8.1.

This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if all dependencies are correctly defined in `composer.json`.

To run the checker, execute the following command:

```shell
composer run check-dependencies
```
For install this package, you need [composer](https://getcomposer.org/) and [npm](https://www.npmjs.com/).

## Mutation testing
## Install

Mutation testing is checked with [Infection](https://infection.github.io/). To run it:
Preferably install with composer:

```shell
composer run mutation
composer require yii-tools/sweetalert2-asset
```

## Static analysis
## Usage

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:

```shell
composer run psalm
```
[Check the documentation docs](/docs/readme.md) to learn about usage.

## Testing

The code is tested with [PHPUnit](https://phpunit.de/). To run tests:
[Check the documentation testing](/docs/testing.md) to learn about testing.

```
composer run test
```

## CI status

[![build](https://github.com/yii-tools/template/actions/workflows/build.yml/badge.svg)](https://github.com/yii-tools/template/actions/workflows/build.yml)
[![codecov](https://codecov.io/gh/yii-tools/template/branch/main/graph/badge.svg?token=MF0XUGVLYC)](https://codecov.io/gh/yii-tools/template)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyii-tools%2Ftemplate%2Fmain)](https://dashboard.stryker-mutator.io/reports/github.com/yii-tools/template/main)
[![static analysis](https://github.com/yii-tools/template/actions/workflows/static.yml/badge.svg)](https://github.com/yii-tools/template/actions/workflows/static.yml)
[![type-coverage](https://shepherd.dev/github/yii-tools/template/coverage.svg)](https://shepherd.dev/github/yii-tools/template)
[![StyleCI](https://github.styleci.io/repos/494495136/shield?branch=main)](https://github.styleci.io/repos/494495136?branch=main)
[![build](https://github.com/yii-tools/sweetalert2-asset/actions/workflows/build.yml/badge.svg)](https://github.com/yii-tools/sweetalert2-asset/actions/workflows/build.yml)
[![codecov](https://codecov.io/gh/yii-tools/sweetalert2-asset/branch/main/graph/badge.svg?token=MF0XUGVLYC)](https://codecov.io/gh/yii-tools/sweetalert2-asset)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyii-tools%2Fsweetalert2-asset%2Fmain)](https://dashboard.stryker-mutator.io/reports/github.com/yii-tools/sweetalert2-asset/main)
[![static analysis](https://github.com/yii-tools/sweetalert2-asset/actions/workflows/static.yml/badge.svg)](https://github.com/yii-tools/sweetalert2-asset/actions/workflows/static.yml)
[![type-coverage](https://shepherd.dev/github/yii-tools/sweetalert2-asset/coverage.svg)](https://shepherd.dev/github/yii-tools/sweetalert2-asset)
[![StyleCI](https://github.styleci.io/repos/640904082/shield?branch=main)](https://github.styleci.io/repos/640904082?branch=main)

## License

Expand Down
27 changes: 18 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
{
"name": "yii-tools/template",
"type": "library",
"description": "_____",
"description": "sweetalert2-asset",
"keywords": [
"_____"
"yii-tools",
"sweetAlert2",
"asset",
"yii3"
],
"license": "mit",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.1"
"php": "^8.1",
"foxy/foxy": "^1.2",
"yiisoft/assets": "^4.0",
"yiisoft/files": "^2.0"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.3",
"phpunit/phpunit": "^9.5",
"roave/infection-static-analysis-plugin": "^1.28",
"vimeo/psalm": "^5.6"
"phpunit/phpunit": "^10.1",
"rector/rector": "^0.16",
"roave/infection-static-analysis-plugin": "^1.30",
"vimeo/psalm": "^5.8",
"yii-tools/support": "^1.0@dev"
},
"autoload": {
"psr-4": {
"Template\\": "src"
"Yii\\Assets\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Template\\Tests\\": "tests"
"Yii\\Assets\\Tests\\": "tests"
}
},
"extra": {
Expand All @@ -35,7 +43,8 @@
"config": {
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true
"infection/extension-installer": true,
"foxy/foxy": true
}
},
"scripts": {
Expand Down
58 changes: 58 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Using assets

Assets are files that are not processed by Webpack. They are copied directly to the output folder. This includes images, fonts, and any other files that you want to use in your project.

To use an asset, you need to import it from JavaScript or CSS.

```php
file: ./resources/views/layout/main.php

<?php

declare(strict_types=1);

use Yii\Assets\SweetAlert2Dev;

/**
* @var \Yiisoft\Assets\AssetManager $assetManager
*/

// Register the asset bundle with a asset manager component.
$assetManager->register(SweetAlert2Dev::class);

// Set parameters for the registered asset bundle a view component.
$this->addCssFiles($assetManager->getCssFiles());
$this->addCssStrings($assetManager->getCssStrings());
$this->addJsFiles($assetManager->getJsFiles());
$this->addJsStrings($assetManager->getJsStrings());
$this->addJsVars($assetManager->getJsVars());
```

## Registering the Asset Bundle via container configuration

Alternatively, you can register the asset bundle through the container configuration.

```php
file: ./config/params.php

<?php

declare(strict_types=1);

use Yii\Assets\SweetAlert2Cdn;

return [
'yiisoft/assets' => [
'assetManager' => [
'register' => [
SweetAlert2Cdn::class,
],
],
],
];
```

## Using npm packages

You can install [npm](https://www.npmjs.com/) packages [fxpio/foxy](https://github.com/fxpio/foxy),
and they will be available in the `node_modules` directory.
35 changes: 35 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Testing

## Checking dependencies

This package uses [composer-require-checker](https://github.com/maglnet/ComposerRequireChecker) to check if all dependencies are correctly defined in `composer.json`.

To run the checker, execute the following command:

```shell
composer run check-dependencies
```

## Mutation testing

Mutation testing is checked with [Infection](https://infection.github.io/). To run it:

```shell
composer run mutation
```

## Static analysis

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:

```shell
composer run psalm
```

## Unit tests

The code is tested with [PHPUnit](https://phpunit.de/). To run tests:

```
composer run test
```
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "sweetalert2-asset",
"version": "1.0.0",
"dependencies": {
"sweetalert2": "^11.7.5"
},
"license": "mit"
}
30 changes: 10 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>

<phpunit
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
verbose="true"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" cacheDirectory=".phpunit.cache">
<php>
<ini name="error_reporting" value="-1" />
<ini name="error_reporting" value="-1"/>
</php>

<coverage>
<coverage/>
<testsuites>
<testsuite name="SweetAlert2">
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./src</directory>
</include>
<exclude>
<directory>./vendor</directory>
</exclude>
</coverage>

<testsuites>
<testsuite name="Template">
<directory>./tests</directory>
</testsuite>
</testsuites>
</source>
</phpunit>
13 changes: 0 additions & 13 deletions src/Example.php

This file was deleted.

17 changes: 17 additions & 0 deletions src/SweetAlert2Cdn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Yii\Assets;

use Yiisoft\Assets\AssetBundle;

/**
* CDN asset bundle for the sweet alert2.
*/
final class SweetAlert2Cdn extends AssetBundle
{
public bool $cdn = true;
public array $css = ['https://cdn.jsdelivr.net/npm/sweetalert2@11.7.5/dist/sweetalert2.min.css'];
public array $js = ['https://cdn.jsdelivr.net/npm/sweetalert2@11.7.5/dist/sweetalert2.all.min.js'];
}
29 changes: 29 additions & 0 deletions src/SweetAlert2Dev.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Yii\Assets;

use Yiisoft\Assets\AssetBundle;
use Yiisoft\Files\PathMatcher\PathMatcher;

/**
* Development asset bundle for the sweet alert2.
*/
final class SweetAlert2Dev extends AssetBundle
{
public string|null $basePath = '@assets';
public string|null $baseUrl = '@assetsUrl';
public string|null $sourcePath = '@npm/sweetalert2/dist';
public array $css = ['sweetalert2.css'];
public array $js = ['sweetalert2.js'];

public function __construct()
{
$pathMatcher = new PathMatcher();

$this->publishOptions = [
'filter' => $pathMatcher->only('**sweetalert2.css', '**sweetalert2.js'),
];
}
}
29 changes: 29 additions & 0 deletions src/SweetAlert2Prod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Yii\Assets;

use Yiisoft\Assets\AssetBundle;
use Yiisoft\Files\PathMatcher\PathMatcher;

/**
* Production asset bundle for the sweet alert2.
*/
final class SweetAlert2Prod extends AssetBundle
{
public string|null $basePath = '@assets';
public string|null $baseUrl = '@assetsUrl';
public string|null $sourcePath = '@npm/sweetalert2/dist';
public array $css = ['sweetalert2.min.css'];
public array $js = ['sweetalert2.min.js'];

public function __construct()
{
$pathMatcher = new PathMatcher();

$this->publishOptions = [
'filter' => $pathMatcher->only('**sweetalert2.min.css', '**sweetalert2.min.js'),
];
}
}

0 comments on commit b3de72a

Please sign in to comment.