Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
falkenhawk committed Jun 1, 2017
0 parents commit 5c4166c
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/tests export-ignore
/docs export-ignore
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
composer.lock
vendor
.idea
23 changes: 23 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
filter:
excluded_paths: [tests/*]

checks:
php:
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true

tools:
external_code_coverage:
timeout: 600
runs: 3
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preset: psr2
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- hhvm

# This triggers builds to run on the new TravisCI infrastructure.
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
sudo: false

## Cache composer
cache:
directories:
- $HOME/.composer/cache

matrix:
include:
- php: 5.6
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'

before_script:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist

script:
- vendor/bin/phpcs --standard=psr2 src/
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- |
if [[ "$TRAVIS_PHP_VERSION" != 'hhvm' && "$TRAVIS_PHP_VERSION" != '7.0' ]]; then
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
fi
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Changelog

All Notable changes to `webpack-manifest` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## NEXT - YYYY-MM-DD

### Added
- Nothing

### Deprecated
- Nothing

### Fixed
- Nothing

### Removed
- Nothing

### Security
- Nothing
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The MIT License (MIT)

Copyright (c) 2017 <[email protected]>

> 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.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# webpack-manifest

A set of tools to help with handling manifest.json files generated by webpack plugin
[danethurber/webpack-manifest-plugin](https://github.com/danethurber/webpack-manifest-plugin).


## Install

Via Composer

``` bash
$ composer require ovos/webpack-manifest
```

## Usage

``` php
$skeleton = new Ovos\Webpack();
echo $skeleton->echoPhrase('Hello, League!');
```

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

[ico-version]: https://img.shields.io/packagist/v/ovos/webpack-manifest.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/ovos/webpack-manifest/master.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/ovos/webpack-manifest.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/ovos/webpack-manifest.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/ovos/webpack-manifest.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/ovos/webpack-manifest
[link-travis]: https://travis-ci.org/ovos/webpack-manifest
[link-scrutinizer]: https://scrutinizer-ci.com/g/ovos/webpack-manifest/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/ovos/webpack-manifest
[link-downloads]: https://packagist.org/packages/ovos/webpack-manifest
[link-author]: https://github.com/mh-ovos
46 changes: 46 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "ovos/webpack-manifest",
"type": "library",
"description": "Processing webpack manifest.json files",
"homepage": "https://github.com/ovos/webpack-manifest",
"license": "MIT",
"authors": [
{
"name": "Maciej Holyszko",
"email": "[email protected]",
"homepage": "https://github.com/mh-ovos",
"role": "Developer"
}
],
"require": {
"php": ">=5.4",
"eloquent/pathogen": "^0.6.1"
},
"require-dev": {
"phpunit/phpunit" : "~4.0||~5.0||~6.0",
"squizlabs/php_codesniffer": "^2.3"
},
"autoload": {
"psr-4": {
"Ovos\\Webpack\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Ovos\\Webpack\\": "tests"
}
},
"scripts": {
"test": "phpunit",
"check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
"fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests"
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"sort-packages": true
}
}
29 changes: 29 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="ovos Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
69 changes: 69 additions & 0 deletions src/Manifest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
namespace Ovos\Webpack;

use Eloquent\Pathogen\FileSystem\FileSystemPath;
use Eloquent\Pathogen\Path;
use Eloquent\Pathogen\Resolver\BasePathResolver;

class Manifest
{
const MANIFEST_FILENAME = 'manifest.json';

/**
* [manifest file dirname => [src file => target file]]
* @var array[]
*/
protected static $manifests = [];

/**
* Resolve path to the file from manifest.json
*
* @param string $path
* @param string $base base dir which should be prepended to $path
* @param string $manifestFilename
*
* @return string
*/
public static function resolve($path, $base = null, $manifestFilename = self::MANIFEST_FILENAME)
{
$relativePath = Path::fromString($path);
$basePath = FileSystemPath::fromString($base ? $base : getcwd());

$resolver = new BasePathResolver;
$fullPath = $resolver->resolve($basePath, $relativePath);

$dirname = dirname($fullPath->string());
$manifest = self::getManifest($dirname, $manifestFilename);

$filename = $relativePath->name();
if (isset($manifest[$filename])) {
$path = $relativePath->replaceName($manifest[$filename])->string();
}

return $path;
}

/**
* Return contents of manifest file from a given dir
*
* @param string $dir
* @param string $manifestFilename
* @return array
*/
public static function getManifest($dir, $manifestFilename = MANIFEST_FILENAME)
{
$manifestPath = $dir . DIRECTORY_SEPARATOR . $manifestFilename;
// normalize slashes
$manifestPath = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $manifestPath);
if (!isset(self::$manifests[$manifestPath])) {
$manifest = [];
if (file_exists($manifestPath)) {
$manifest = json_decode(file_get_contents($manifestPath), true);
}

self::$manifests[$manifestPath] = $manifest;
}

return self::$manifests[$manifestPath];
}
}
13 changes: 13 additions & 0 deletions tests/ManifestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Ovos\Webpack;

class ManifestTest extends \PHPUnit_Framework_TestCase
{
public function testResolve()
{
$src = 'assets/test.js';
$target = Manifest::resolve($src, __DIR__);
$this->assertEquals('assets/test.12345.js', $target);
}
}
4 changes: 4 additions & 0 deletions tests/assets/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"test.js": "test.12345.js",
"test2.js": "test2.67890.js"
}

0 comments on commit 5c4166c

Please sign in to comment.