Skip to content

Commit 3e11f80

Browse files
committed
Update docs, polish for release
1 parent b4f1387 commit 3e11f80

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,30 @@ public $routes = [
6565
This tells the library to load the Bootstrap assets for every route (`''`) without having
6666
to move it from its pre-bundled subdirectory. It also will load any assets in the `dropzone`
6767
directory for the specified route.
68+
69+
## Publishing
70+
71+
**Assets** can publish resources for you. This is particularly helpful if you need files
72+
from a vendor package but don't want to host the package in your **public/** folder.
73+
The **Manifests** library uses manifest files to locate and copy matching assets into your
74+
assets folder (defined by `$config->fileBase`). This library includes a convenience command
75+
to assist with asset publication:
76+
77+
php spark assets:publish
78+
79+
By default `assets:publish` will scan all namespaces for JSON files in **{namespaceRoot}/Manifests**
80+
and (assuming they are valid) will publish the assets defined there. Behavior is
81+
customizable using **Config/Assets.php** but the default is to copy assets into
82+
**public/assets/vendor/** into the subdirectory defined in the manifest.
83+
84+
If you are using version control it is recommended to exclude your asset publish directory,
85+
for example by adding **public/assets/vendor/** to your **.gitignore** file.
86+
87+
### Manifests
88+
89+
Manifests are JSON files with at least the following three properties:
90+
* `source` - The directory (relative to `$config->publishBase`) of the assets
91+
* `destination` - The directory (relative to `$config->fileBase`) for the assets
92+
* `resources` - The list of resources to publish, each with at least its own `source`.
93+
94+
See [examples/](examples/) for some example manifest files.

bin/Assets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Assets extends \Tatter\Assets\Config\Assets
2626
public $webBase = 'https://example.com/assets/';
2727

2828
// Starting directory for manifest publication
29-
public $publishBase = ROOTPATH;
29+
public $publishBase = ROOTPATH . 'vendor/';
3030

3131
// Additional paths to load per route
3232
// Relative to fileBase, no leading/trailing slashes

src/Config/Assets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Assets extends BaseConfig
1717
public $webBase = 'assets/';
1818

1919
// Starting directory for manifest publication
20-
public $publishBase = ROOTPATH;
20+
public $publishBase = ROOTPATH . 'vendor/';
2121

2222
// Additional paths to load per route
2323
// Relative to fileBase, no leading/trailing slashes

src/Config/Services.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,20 @@ public static function assets(BaseConfig $config = null, bool $getShared = true)
2020
}
2121
return new \Tatter\Assets\Libraries\Assets($config);
2222
}
23+
24+
public static function manifests(BaseConfig $config = null, bool $getShared = true)
25+
{
26+
if ($getShared)
27+
{
28+
return static::getSharedInstance('manifests', $config);
29+
}
30+
31+
// If no config was injected then load one
32+
// Prioritizes app/Config if found
33+
if (empty($config))
34+
{
35+
$config = config('Assets');
36+
}
37+
return new \Tatter\Assets\Libraries\Manifests($config);
38+
}
2339
}

src/Libraries/Manifests.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ public function __construct($config = null)
3030
helper('filesystem');
3131
}
3232

33-
// Scan all namespaces for manifest files
33+
// Clear and return status messages
3434
public function getMessages(): array
3535
{
36-
return $this->messages;
36+
$messages = $this->messages;
37+
$this->messages = [];
38+
return $messages;
3739
}
3840

3941
// Scan all namespaces for manifest files
@@ -195,7 +197,7 @@ protected function ensureDirectory($directory): bool
195197
// Check for existence
196198
if (! file_exists($directory))
197199
{
198-
mkdir($directory, 0644, true);
200+
mkdir($directory, 0755, true);
199201
}
200202

201203
// Make sure there's a directory there now

0 commit comments

Comments
 (0)