-
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 02fbf39
Showing
31 changed files
with
1,227 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,6 @@ | ||
*.hack linguist-language=Hack | ||
|
||
/tests export-ignore | ||
/docs export-ignore | ||
.travis.sh export-ignore | ||
.travis.yml 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,3 @@ | ||
composer.lock | ||
vendor/ | ||
*.hhast.parser-cache |
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,5 @@ | ||
assume_php=false | ||
safe_array = true | ||
safe_vector_array = true | ||
unsafe_rx = false | ||
ignored_paths = [ "vendor/.+/tests/.+", "vendor/.+/bin/.+" ] |
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,30 @@ | ||
#!/bin/sh | ||
set -ex | ||
apt update -y | ||
DEBIAN_FRONTEND=noninteractive apt install -y php-cli zip unzip | ||
hhvm --version | ||
php --version | ||
if [ ! -e .git/refs/heads/master ]; then | ||
# - Travis clones with `--branch`, then moves to a detached HEAD state | ||
# - if we're on a detached HEAD, Composer uses master to resolve branch | ||
# aliases. | ||
# So, create the master branch :p | ||
git branch master HEAD | ||
fi | ||
|
||
( | ||
cd $(mktemp -d) | ||
curl https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | ||
) | ||
|
||
if (hhvm --version | grep -q -- -dev); then | ||
# Doesn't exist in master, but keep it here so that we can test release | ||
# branches on nightlies too | ||
rm -f composer.lock | ||
fi | ||
|
||
composer --version | ||
|
||
composer install | ||
|
||
composer check |
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,18 @@ | ||
sudo: false | ||
dist: trusty | ||
language: generic | ||
services: docker | ||
env: | ||
- HHVM_VERSION=4.25-latest | ||
- HHVM_VERSION=latest | ||
- HHVM_VERSION=nightly | ||
matrix: | ||
allow_failures: | ||
- env: HHVM_VERSION=nightly | ||
install: | ||
- docker pull hhvm/hhvm:$HHVM_VERSION | ||
script: | ||
- docker run --rm -w /var/source -v $(pwd):/var/source hhvm/hhvm:$HHVM_VERSION ./.travis.sh | ||
notifications: | ||
slack: | ||
secure: fZ74Yt9xxelrIZiWBe74X6zCNV+RCbI2aD0EjB8P6d3ovIdyHc+JOe/AFDwUwU8tuKBYt1DpiMnw/rFQQwu2Y6CQnAjgGtG+ScCCVhy5OJvHqFTmMt/XMs9Hrgdylak3IofaI6D/4Du+E9ZMXHgXGVgjQQr0SNMsj1s70sSd97oiW4t4Kn5hxlAbZK7EWCs2BWwyTtVJD96UOEJrBK59lD0wQvfv0wSV948Wwnms70cPgO26Fa+pdBGsv4Ho475Dzu/y4JuO/kqMMzodZtMSm7FNDrppwqgX3qYkfGBI/foQ5IpBn5gGcG5w3RhZLXsNhLDrULcEHtF1Ptfo5PQGUArN8KPRf91Mju2CGICg3wy6GMEm+iXHdPWzUkCaQPhw4ty6ix+fm2ELatXW4BGGXANJzL6UNUGuQPh4Z2oVeX8zEFpUAA+PJRzd6FPYdQDdI3Xj8P445x/KQ+Mg4f2wCR/YKTkjWbkYKzqvjvssgrDGkbQfhXWAOr5/NgKj0/vRovT66Tra14UncjZdM6yHUOqeMq5KfDboEBXoj7+jZG1cQmtSErUoFF2CUyI/Jqva7symsJbjOYSVTKv6BAgoL+CncdLcTPGFLzavLiavkqp4Gd3ErWoeOWqFY0ZYByY4cLcnwLtL0TrY6Y9fdzFeJLmN6xhxTteuw3Ils66K/fw= |
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) 2018-2019 Saif Eddin Gmati | ||
|
||
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,59 @@ | ||
<p align="center"><img src="https://avatars3.githubusercontent.com/u/45311177?s=200&v=4"></p> | ||
|
||
<p align="center"> | ||
<a href="https://travis-ci.org/nuxed/asset"><img src="https://travis-ci.org/nuxed/asset.svg" alt="Build Status"></a> | ||
<a href="https://packagist.org/packages/nuxed/asset"><img src="https://poser.pugx.org/nuxed/asset/d/total.svg" alt="Total Downloads"></a> | ||
<a href="https://packagist.org/packages/nuxed/asset"><img src="https://poser.pugx.org/nuxed/asset/v/stable.svg" alt="Latest Stable Version"></a> | ||
<a href="https://packagist.org/packages/nuxed/asset"><img src="https://poser.pugx.org/nuxed/asset/license.svg" alt="License"></a> | ||
</p> | ||
|
||
# Nuxed Asset | ||
|
||
The Nuxed Asset component manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files. | ||
|
||
### Installation | ||
|
||
This package can be installed with [Composer](https://getcomposer.org). | ||
|
||
```console | ||
$ composer require nuxed/asset | ||
``` | ||
|
||
### Example | ||
|
||
```hack | ||
use namespace Nuxed\Asset; | ||
use namespace Nuxed\Asset\VersionStrategy; | ||
<<__EntryPoint>> | ||
async function main(): Awaitable<void> { | ||
// For example, the manifest file might look like this: | ||
// { | ||
// "main.js": "main.abc123.js", | ||
// "css/styles.css": "css/styles.555abc.css" | ||
// } | ||
$versionStrategy = new VersionStrategy\JsonManifestVersionStrategy('/path/to/manifest.json'); | ||
$cdns = vec[ | ||
'https://asset-s1.example.com/', | ||
'https://asset-s2.example.com/', | ||
]; | ||
$package = new Asset\UrlPackage($cdns, $version); | ||
// https://asset-s2.example.com/css/styles.555abc.css | ||
echo await $package->getUrl('css/styles.css'); | ||
} | ||
``` | ||
|
||
--- | ||
|
||
### Security | ||
|
||
For information on reporting security vulnerabilities in Nuxed, see [SECURITY.md](SECURITY.md). | ||
|
||
--- | ||
|
||
### License | ||
|
||
Nuxed is open-sourced software licensed under the MIT-licensed. |
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 @@ | ||
# Security | ||
|
||
If you discover a security vulnerability within Nuxed, please send an e-mail to Saif Eddin Gmati via [email protected]. | ||
|
||
Please withhold public disclosure until after we have addressed the vulnerability. | ||
|
||
There are no hard and fast rules to determine if a bug is worth reporting as a security issue. |
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,37 @@ | ||
{ | ||
"name": "nuxed/asset", | ||
"type": "library", | ||
"description": "Nuxed Asset", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "azjezz", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Nuxed Community", | ||
"homepage": "https://github.com/nuxed/asset/graphs/contributors" | ||
} | ||
], | ||
"require": { | ||
"hhvm": "^4.25", | ||
"hhvm/hsl": "^4.25", | ||
"nuxed/filesystem": "^1.2", | ||
"nuxed/json": "^1.0" | ||
}, | ||
"require-dev": { | ||
"facebook/fbexpect": "^2.7", | ||
"hhvm/hacktest": "^2.0", | ||
"hhvm/hhast": "^4.25" | ||
}, | ||
"scripts": { | ||
"check": [ | ||
"@type-check", | ||
"@lint", | ||
"@test" | ||
], | ||
"lint": "hhast-lint -v src/", | ||
"test": "hacktest tests/", | ||
"type-check": "hh_client src/" | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"roots": [ | ||
"src/" | ||
], | ||
"devRoots": [ | ||
"tests/" | ||
], | ||
"devFailureHandler": "Facebook\\AutoloadMap\\HHClientFallbackHandler" | ||
} |
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,9 @@ | ||
{ | ||
"roots": [ "src/" ], | ||
"builtinLinters": "all", | ||
"disableAllAutoFixes": false, | ||
"disabledLinters": [ | ||
"Facebook\\HHAST\\Linters\\AsyncFunctionAndMethodLinter" | ||
], | ||
"overrides": [] | ||
} |
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,19 @@ | ||
namespace Nuxed\Asset\Context; | ||
|
||
class Context implements IContext { | ||
public function __construct(private string $basePath, private bool $secure) {} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBasePath(): string { | ||
return $this->basePath; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isSecure(): bool { | ||
return $this->secure; | ||
} | ||
} |
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,17 @@ | ||
namespace Nuxed\Asset\Context; | ||
|
||
interface IContext { | ||
/** | ||
* Gets the base path. | ||
* | ||
* @return string The base path | ||
*/ | ||
public function getBasePath(): string; | ||
|
||
/** | ||
* Checks whether the request is secure or not. | ||
* | ||
* @return bool true if the request is secure, false otherwise | ||
*/ | ||
public function isSecure(): bool; | ||
} |
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,17 @@ | ||
namespace Nuxed\Asset\Context; | ||
|
||
class NullContext implements IContext { | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBasePath(): string { | ||
return ''; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isSecure(): bool { | ||
return false; | ||
} | ||
} |
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,5 @@ | ||
namespace Nuxed\Asset\Exception; | ||
|
||
interface IException { | ||
require extends \Exception; | ||
} |
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 @@ | ||
namespace Nuxed\Asset\Exception; | ||
|
||
final class InvalidArgumentException | ||
extends \InvalidArgumentException | ||
implements IException { | ||
} |
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,4 @@ | ||
namespace Nuxed\Asset\Exception; | ||
|
||
final class LogicException extends \LogicException implements IException { | ||
} |
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,4 @@ | ||
namespace Nuxed\Asset\Exception; | ||
|
||
final class RuntimeException extends \RuntimeException implements IException { | ||
} |
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,13 @@ | ||
namespace Nuxed\Asset; | ||
|
||
interface IPackage { | ||
/** | ||
* Returns the asset version for an asset. | ||
*/ | ||
public function getVersion(string $asset): Awaitable<string>; | ||
|
||
/** | ||
* Returns an absolute or root-relative public path. | ||
*/ | ||
public function getUrl(string $path): Awaitable<string>; | ||
} |
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,44 @@ | ||
namespace Nuxed\Asset; | ||
|
||
use namespace HH\Lib\Str; | ||
|
||
/** | ||
* Basic package that adds a version to asset URLs. | ||
*/ | ||
class Package implements IPackage { | ||
public function __construct( | ||
private VersionStrategy\IVersionStrategy $versionStrategy, | ||
private Context\IContext $context = new Context\NullContext(), | ||
) { | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public async function getVersion(string $asset): Awaitable<string> { | ||
return await $this->versionStrategy->getVersion($asset); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public async function getUrl(string $path): Awaitable<string> { | ||
if ($this->isAbsoluteUrl($path)) { | ||
return $path; | ||
} | ||
|
||
return await $this->versionStrategy->applyVersion($path); | ||
} | ||
|
||
protected function getContext(): Context\IContext { | ||
return $this->context; | ||
} | ||
|
||
protected function getVersionStrategy(): VersionStrategy\IVersionStrategy { | ||
return $this->versionStrategy; | ||
} | ||
|
||
protected function isAbsoluteUrl(string $url): bool { | ||
return Str\contains($url, '://') || Str\starts_with($url, '//'); | ||
} | ||
} |
Oops, something went wrong.