-
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.
- Loading branch information
0 parents
commit ce01315
Showing
20 changed files
with
24,599 additions
and
0 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,12 @@ | ||
# EditorConfig | ||
# See https://EditorConfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
end_of_line = lf | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
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,6 @@ | ||
# Set default behaviour to automatically normalize line endings | ||
* text=auto | ||
|
||
# Git stuff | ||
.gitattributes export-ignore | ||
.gitignore export-ignore |
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 @@ | ||
# Composer + sensitive files | ||
/composer.lock | ||
/vendor | ||
*.cache | ||
|
||
# Auto-generated | ||
/dist |
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 | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->exclude([ | ||
'tmp' | ||
]) | ||
->in(__DIR__) | ||
; | ||
|
||
return PhpCsFixer\Config::create() | ||
->setRules([ | ||
'@PSR2' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
]) | ||
->setFinder($finder) | ||
; |
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Martin Folkers | ||
|
||
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,63 @@ | ||
# php-thx | ||
[![Release](https://img.shields.io/github/release/S1SYPHOS/php-thx.svg)](https://github.com/S1SYPHOS/php-thx/releases) [![License](https://img.shields.io/github/license/S1SYPHOS/php-thx.svg)](https://github.com/S1SYPHOS/php-thx/blob/main/LICENSE) [![Issues](https://img.shields.io/github/issues/S1SYPHOS/php-thx.svg)](https://github.com/S1SYPHOS/php-thx/issues) [![Status](https://travis-ci.org/S1SYPHOS/php-thx.svg?branch=main)](https://travis-ci.org/S1SYPHOS/php-thx) | ||
|
||
A very simple PHP library for acknowledging the people behind your frontend dependencies - and giving thanks. | ||
|
||
|
||
## Getting started | ||
|
||
Install this package with [Composer](https://getcomposer.org): | ||
|
||
```text | ||
composer require S1SYPHOS/php-thx | ||
``` | ||
|
||
**Note:** | ||
For yarn v2 support, the `php-yaml` package is required! | ||
|
||
|
||
# Usage | ||
|
||
This example should get you started: | ||
|
||
```php | ||
<?php | ||
|
||
require_once('vendor/autoload.php'); | ||
|
||
use S1SYPHOS\Thx; | ||
|
||
$pkgFile = 'path/to/composer.json'; # or 'package.json' for NPM / Yarn | ||
$lockFile = 'path/to/composer.lock' # or 'package-lock.json' for NPM / 'yarn.lock' for Yarn | ||
|
||
try { | ||
$obj = new Thx($pkgFile, $lockFile); | ||
|
||
# Dump package names | ||
var_dump($obj->packages()) | ||
|
||
# Dump (raw) data extracted from lockfiles | ||
var_dump($obj->data()) | ||
|
||
} catch (Exception $e) { | ||
# No dependencies found, file not found, .. | ||
echo $e->getMessage(); | ||
} | ||
``` | ||
|
||
|
||
## Roadmap | ||
|
||
- [ ] Add (more sophisticated) tests | ||
- [ ] Gather information using public APIs | ||
- [ ] Custom `Exception`s | ||
- [ ] Provide more methods | ||
- [x] Parse yarn v1 lockfiles | ||
|
||
|
||
## Credits | ||
|
||
Most of the helper functions were taken from [Kirby](https://getkirby.com)'s excellent [`toolkit`](https://github.com/getkirby-v2/toolkit) package by [Bastian Allgeier](https://github.com/bastianallgeier) (who's just awesome, btw). | ||
|
||
|
||
**Happy coding!** |
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,35 @@ | ||
{ | ||
"name": "s1syphos/php-thx", | ||
"description": "Acknowledge the people behind your frontend dependencies - and give thanks!", | ||
"type": "library", | ||
"license": "MIT", | ||
"version": "0.1.0", | ||
"keywords": ["gratitude", "appreciation", "gratefulness", "thankfulness"], | ||
"homepage": "https://github.com/S1SYPHOS", | ||
"scripts": { | ||
"cs-dry": "php-cs-fixer fix --dry-run --diff", | ||
"cs-fix": "php-cs-fixer fix", | ||
"test": "phpunit" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Martin Folkers", | ||
"homepage": "https://twobrain.io", | ||
"role": "Maintainer" | ||
} | ||
], | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^2.14", | ||
"phpunit/phpunit": "^8.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"S1SYPHOS\\": "lib/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"S1SYPHOS\\Tests\\": "tests/" | ||
} | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
namespace S1SYPHOS; | ||
|
||
|
||
use S1SYPHOS\Traits\Helpers; | ||
|
||
|
||
abstract class Driver | ||
{ | ||
/** | ||
* Traits | ||
*/ | ||
|
||
use Helpers; | ||
|
||
|
||
/** | ||
* Properties | ||
*/ | ||
|
||
/** | ||
* Raw data as extracted from lockfile | ||
* | ||
* @var array | ||
*/ | ||
public $data = null; | ||
|
||
|
||
/** | ||
* Operating mode identifier | ||
* | ||
* @var string | ||
*/ | ||
public $mode; | ||
|
||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $dataFile Path to data file | ||
* @param string $lockFile Lockfile stream | ||
* @return void | ||
*/ | ||
public function __construct(array $pkgData, string $lockFile) | ||
{ | ||
$this->data = $this->load($pkgData, $lockFile); | ||
} | ||
|
||
|
||
/** | ||
* Methods | ||
*/ | ||
|
||
abstract protected function load(array $pkgData, string $lockFile): array; | ||
|
||
abstract public function packages(): array; | ||
} |
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,71 @@ | ||
<?php | ||
|
||
namespace S1SYPHOS\Drivers; | ||
|
||
|
||
use S1SYPHOS\Driver; | ||
|
||
|
||
class Composer extends Driver | ||
{ | ||
/** | ||
* Properties | ||
*/ | ||
|
||
/** | ||
* Operating mode identifier | ||
* | ||
* @var string | ||
*/ | ||
public $mode = 'php'; | ||
|
||
|
||
/** | ||
* Parses input files | ||
* | ||
* @param string $dataFile Path to data file | ||
* @param string $lockFile Lockfile stream | ||
* @return array | ||
*/ | ||
protected function load(array $pkgData, string $lockFile): array | ||
{ | ||
$lockData = json_decode($lockFile, true); | ||
|
||
$phpData = []; | ||
|
||
foreach ($lockData['packages'] as $pkg) { | ||
if (in_array($pkg['name'], array_keys($pkgData['require'])) === true) { | ||
$phpData[$pkg['name']] = $this->ex($pkg); | ||
} | ||
} | ||
|
||
return $phpData; | ||
} | ||
|
||
|
||
/** | ||
* Methods | ||
*/ | ||
|
||
/** | ||
* Processes raw data from lockfile | ||
* | ||
* @return array Extracted packages | ||
*/ | ||
public function packages(): array | ||
{ | ||
return []; | ||
} | ||
|
||
|
||
/** | ||
* Processes raw data from lockfile | ||
* | ||
* @param array $array The array to be processed | ||
* @return string The result array | ||
*/ | ||
protected function ex(array $array): array | ||
{ | ||
return $array; | ||
} | ||
} |
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,75 @@ | ||
<?php | ||
|
||
namespace S1SYPHOS\Drivers; | ||
|
||
|
||
use S1SYPHOS\Driver; | ||
|
||
|
||
class Node extends Driver | ||
{ | ||
/** | ||
* Properties | ||
*/ | ||
|
||
/** | ||
* Operating mode identifier | ||
* | ||
* @var string | ||
*/ | ||
public $mode = 'npm'; | ||
|
||
|
||
/** | ||
* Parses input files | ||
* | ||
* @param string $dataFile Path to data file | ||
* @param string $lockFile Lockfile stream | ||
* @return array | ||
*/ | ||
protected function load(array $pkgData, string $lockFile): array | ||
{ | ||
$npmData = []; | ||
|
||
$lockData = json_decode($lockFile, true); | ||
|
||
foreach ($lockData['packages'] as $pkgName => $pkg) { | ||
if ($this->contains($pkgName, 'node_modules/')) { | ||
$pkgName = str_replace('node_modules/', '', $pkgName); | ||
|
||
if (in_array($pkgName, array_keys($pkgData['dependencies'])) === true) { | ||
$npmData[$pkgName] = $this->ex($pkg); | ||
} | ||
} | ||
} | ||
|
||
return $npmData; | ||
} | ||
|
||
|
||
/** | ||
* Methods | ||
*/ | ||
|
||
/** | ||
* Processes raw data from lockfile | ||
* | ||
* @return array Extracted packages | ||
*/ | ||
public function packages(): array | ||
{ | ||
return []; | ||
} | ||
|
||
|
||
/** | ||
* Processes raw data from lockfile | ||
* | ||
* @param array $array The array to be processed | ||
* @return string The result array | ||
*/ | ||
protected function ex(array $array): array | ||
{ | ||
return $array; | ||
} | ||
} |
Oops, something went wrong.