Skip to content

Commit 60d5672

Browse files
author
Emmanuel Campait
committed
Initial release
0 parents  commit 60d5672

File tree

6 files changed

+226
-0
lines changed

6 files changed

+226
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
/composer.lock

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) domProjects
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# domProjects CodeIgniter 4 Bootstrap Icons
2+
3+
Bootstrap Icons asset publisher for CodeIgniter 4 projects.
4+
5+
## Features
6+
7+
- Adds a Spark command: `assets:publish-bootstrap-icons`
8+
- Publishes Bootstrap Icons assets to `public/assets/bootstrap-icons`
9+
- Publishes the minified CSS file and font files
10+
- Supports `--force` to overwrite existing files
11+
- Compatible with CodeIgniter 4.7.2+
12+
13+
## Requirements
14+
15+
- PHP 8.2+
16+
- CodeIgniter 4.7.2+
17+
- `twbs/bootstrap-icons`
18+
19+
## Installation
20+
21+
Install the package with Composer:
22+
23+
```bash
24+
composer require domprojects/codeigniter4-bootstrap-icons
25+
```
26+
27+
## Usage
28+
29+
Publish the assets manually:
30+
31+
```bash
32+
php spark assets:publish-bootstrap-icons
33+
```
34+
35+
Overwrite existing files:
36+
37+
```bash
38+
php spark assets:publish-bootstrap-icons --force
39+
```
40+
41+
Published files:
42+
43+
- `public/assets/bootstrap-icons/bootstrap-icons.min.css`
44+
- `public/assets/bootstrap-icons/fonts/*`
45+
46+
## Automation
47+
48+
If you want automatic publishing after `composer install` and `composer update`, use the companion package:
49+
50+
```bash
51+
composer require domprojects/codeigniter4-bootstrap-icons-plugin
52+
```
53+
54+
## Package Structure
55+
56+
```text
57+
src/
58+
Commands/
59+
PublishBootstrapIcons.php
60+
Publishers/
61+
BootstrapIconsPublisher.php
62+
```
63+
64+
## License
65+
66+
MIT

composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "domprojects/codeigniter4-bootstrap-icons",
3+
"description": "Bootstrap Icons asset publisher for CodeIgniter 4 projects.",
4+
"type": "library",
5+
"license": "MIT",
6+
"keywords": [
7+
"codeigniter4",
8+
"codeigniter",
9+
"bootstrap-icons",
10+
"icons",
11+
"assets",
12+
"publisher"
13+
],
14+
"homepage": "https://github.com/domProjects/codeigniter4-bootstrap-icons",
15+
"support": {
16+
"issues": "https://github.com/domProjects/codeigniter4-bootstrap-icons/issues",
17+
"source": "https://github.com/domProjects/codeigniter4-bootstrap-icons"
18+
},
19+
"authors": [
20+
{
21+
"name": "domProjects",
22+
"homepage": "https://github.com/domProjects",
23+
"role": "Maintainer"
24+
}
25+
],
26+
"require": {
27+
"php": "^8.2",
28+
"codeigniter4/framework": "^4.7.2",
29+
"twbs/bootstrap-icons": "^1.13"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"domProjects\\CodeIgniterBootstrapIcons\\": "src/"
34+
}
35+
},
36+
"extra": {
37+
"branch-alias": {
38+
"dev-main": "1.x-dev"
39+
}
40+
}
41+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace domProjects\CodeIgniterBootstrapIcons\Commands;
4+
5+
use CodeIgniter\CLI\BaseCommand;
6+
use CodeIgniter\CLI\CLI;
7+
use domProjects\CodeIgniterBootstrapIcons\Publishers\BootstrapIconsPublisher;
8+
use Throwable;
9+
10+
class PublishBootstrapIcons extends BaseCommand
11+
{
12+
protected $group = 'Bootstrap Icons';
13+
protected $name = 'assets:publish-bootstrap-icons';
14+
protected $description = 'Publishes Bootstrap Icons assets to public/assets/bootstrap-icons.';
15+
protected $usage = 'assets:publish-bootstrap-icons [--force]';
16+
protected $options = [
17+
'--force' => 'Overwrite existing files.',
18+
'-f' => 'Alias of --force.',
19+
];
20+
21+
public function run(array $params)
22+
{
23+
$force = array_key_exists('force', $params)
24+
|| array_key_exists('f', $params)
25+
|| CLI::getOption('force') !== null
26+
|| CLI::getOption('f') !== null;
27+
28+
$publisher = (new BootstrapIconsPublisher())->setReplace($force);
29+
30+
CLI::write(
31+
'Publishing Bootstrap Icons assets to ' . $publisher->getDestination() . ($force ? ' with overwrite...' : '...'),
32+
'yellow'
33+
);
34+
35+
try {
36+
if (! $publisher->publish()) {
37+
CLI::error('Bootstrap Icons publish failed.');
38+
39+
foreach ($publisher->getErrors() as $file => $exception) {
40+
CLI::write($file);
41+
CLI::error($exception->getMessage());
42+
CLI::newLine();
43+
}
44+
45+
return EXIT_ERROR;
46+
}
47+
} catch (Throwable $e) {
48+
$this->showError($e);
49+
50+
return EXIT_ERROR;
51+
}
52+
53+
CLI::write('Bootstrap Icons assets published successfully.', 'green');
54+
55+
return EXIT_SUCCESS;
56+
}
57+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace domProjects\CodeIgniterBootstrapIcons\Publishers;
4+
5+
use CodeIgniter\Publisher\Publisher;
6+
use RuntimeException;
7+
8+
class BootstrapIconsPublisher extends Publisher
9+
{
10+
protected $source = VENDORPATH . 'twbs/bootstrap-icons/font';
11+
protected $destination = FCPATH . 'assets/bootstrap-icons';
12+
protected bool $replace = false;
13+
14+
public function __construct(?string $source = null, ?string $destination = null)
15+
{
16+
$destination ??= $this->destination;
17+
18+
if (! is_dir($destination) && ! mkdir($destination, 0775, true) && ! is_dir($destination)) {
19+
throw new RuntimeException('Unable to create Bootstrap Icons asset destination: ' . $destination);
20+
}
21+
22+
parent::__construct($source ?? $this->source, $destination);
23+
}
24+
25+
public function setReplace(bool $replace): self
26+
{
27+
$this->replace = $replace;
28+
29+
return $this;
30+
}
31+
32+
public function publish(): bool
33+
{
34+
return $this->addPaths([
35+
'bootstrap-icons.min.css',
36+
'fonts',
37+
])->merge($this->replace);
38+
}
39+
}

0 commit comments

Comments
 (0)