Finished new asset pipeline using gulp

This commit is contained in:
Nelson LaQuet 2015-04-23 04:17:05 -05:00
parent 842dbee5b7
commit f0fc0ec0bf
192 changed files with 270 additions and 199 deletions

2
.gitignore vendored
View file

@ -38,6 +38,8 @@ intermediate
publish publish
.idea .idea
node_modules
/public/build/
/bootstrap/compiled.php /bootstrap/compiled.php
/vendor /vendor
/app/config/production /app/config/production

View file

@ -6,138 +6,100 @@
class Assets { class Assets {
public static function scriptIncludes($area = 'app') { public static function scriptIncludes($area = 'app') {
$js = self::scriptAssetCollection($area); if (!Config::get("app.debug"))
return '<script src="/build/scripts/' . $area . '.js?' . filemtime("./build/scripts/" . $area . ".js") . '"></script>';
if (Config::get('app.debug')) { $scripts = self::mergeGlobs(self::getScriptsForArea($area));
$retVal = ''; $retVal = "";
foreach ($js as $script) { foreach ($scripts as $script) {
$retVal .= '<script src="/' . $script->getSourceRoot() . '/' . $script->getSourcePath() . '?' . gmdate($js->getLastModified()) . '"></script>'; $filename = self::replaceExtensionWith($script, ".coffee", ".js");
} $retVal .= "<script src='/build/$filename?" . filemtime('./build/' . $filename) . "'></script>";
return $retVal;
} }
return '<script src="/asset.php?area=' . $area . '&type=coffee&' . gmdate($js->getLastModified()) . '"></script>'; return $retVal;
} }
public static function styleIncludes($area = 'app') { public static function styleIncludes($area = 'app') {
$css = self::styleAssetCollection($area); if (!Config::get("app.debug"))
return '<script>document.write(\'<link rel="stylesheet" href="build/styles/' . $area . '.css?' . filemtime("build/styles/" . $area . ".css") . ' />"\');</script>';
if (Config::get('app.debug')) { $styles = self::mergeGlobs(self::getStylesForArea($area));
$retVal = ''; $retVal = "";
foreach ($css as $style) { foreach ($styles as $style) {
if ($style instanceof CacheBusterAsset) $filename = self::replaceExtensionWith($style, ".less", ".css");
continue; $retVal .= "<link rel='stylesheet' href='/build/$filename?" . filemtime('./build/' . $filename) . "' />";
$retVal .= '<link rel="stylesheet" href="/' . $style->getSourceRoot() . '/' . $style->getSourcePath() . '?' . gmdate($css->getLastModified()) . '" />';
}
return $retVal;
} }
return '<script>document.write(\'<link rel="stylesheet" href="asset.php?area=' . $area . '&type=less&' . gmdate($css->getLastModified()) . '" />\');</script>'; return $retVal;
} }
public static function scriptAssetCollection($area) { private static function replaceExtensionWith($filename, $fromExtension, $toExtension) {
$coffeeScript = new CoffeeScriptFilter(Config::get('app.coffee'), Config::get('app.node')); $fromLength = strlen($fromExtension);
return substr($filename, -$fromLength) == $fromExtension
? substr($filename, 0, strlen($filename) - $fromLength) . $toExtension
: $filename;
}
if ($area == 'app') { /** Merges an array of paths that are passed into "glob" into a list of unique filenames.
$collection = new AssetCollection([ * Note that this method assumes the globs should be relative to the "app" folder of this project */
new FileAsset('scripts/base/jquery-2.0.2.js'), private static function mergeGlobs($globs) {
new FileAsset('scripts/base/jquery-ui.js'), $files = [];
new FileAsset('scripts/base/jquery.cookie.js'), $filesFound = [];
new FileAsset('scripts/base/jquery.colorbox.js'), foreach ($globs as $glob) {
new FileAsset('scripts/base/jquery.viewport.js'), foreach (glob("../app/" . $glob, GLOB_BRACE) as $file) {
new FileAsset('scripts/base/underscore.js'), if (isset($filesFound[$file]))
new FileAsset('scripts/base/moment.js'), continue;
new FileAsset('scripts/base/soundmanager2-nodebug.js'),
new FileAsset('scripts/base/angular.js'),
new FileAsset('scripts/base/bindonce.js'),
new FileAsset('scripts/base/ui-bootstrap-tpls-0.4.0.js'),
new FileAsset('scripts/base/angular-ui-sortable.js'),
new FileAsset('scripts/base/angular-ui-date.js'),
new FileAsset('scripts/base/angular-ui-router.js'),
new FileAsset('scripts/base/angularytics.js'),
new FileAsset('scripts/base/tumblr.js'),
new AssetCollection([
new GlobAsset('scripts/shared/*.coffee'),
], [
$coffeeScript
]),
new GlobAsset('scripts/shared/*.js'),
new AssetCollection([
new GlobAsset('scripts/app/*.coffee'),
new GlobAsset('scripts/app/services/*.coffee'),
new GlobAsset('scripts/app/filters/*.coffee'),
], [
$coffeeScript
]),
new GlobAsset('scripts/app/filters/*.js'),
new AssetCollection([
new GlobAsset('scripts/app/directives/*.coffee'),
new GlobAsset('scripts/app/controllers/*.coffee'),
], [
$coffeeScript
])
]);
if (Config::get('app.debug')) { $filesFound[$file] = true;
$collection->add(new GlobAsset('scripts/debug/*.js')); $files[] = substr($file, 7); // chop off ../app/
$collection->add(new AssetCollection([
new GlobAsset('scripts/debug/*.coffee'),
], [
$coffeeScript
]));
} }
}
return $collection; return $files;
}
private static function getScriptsForArea($area) {
if ($area == 'app') {
return [
"scripts/base/jquery-2.0.2.js",
"scripts/base/angular.js",
"scripts/base/*.{coffee,js}",
"scripts/shared/*.{coffee,js}",
"scripts/app/*.{coffee,js}",
"scripts/app/services/*.{coffee,js}",
"scripts/app/filters/*.{coffee,js}",
"scripts/app/directives/*.{coffee,js}",
"scripts/app/controllers/*.{coffee,js}",
"scripts/**/*.{coffee,js}"
];
} else if ($area == 'embed') { } else if ($area == 'embed') {
$collection = new AssetCollection([ return [
new FileAsset('scripts/base/jquery-2.0.2.js'), "scripts/base/jquery-2.0.2.js",
new FileAsset('scripts/base/jquery.viewport.js'), "scripts/base/jquery.viewport.js",
new FileAsset('scripts/base/underscore.js'), "scripts/base/underscore.js",
new FileAsset('scripts/base/moment.js'), "scripts/base/moment.js",
new FileAsset('scripts/base/jquery.timeago.js'), "scripts/base/jquery.timeago.js",
new FileAsset('scripts/base/soundmanager2-nodebug.js'), "scripts/base/soundmanager2-nodebug.js",
new AssetCollection([ "scripts/embed/*.coffee"];
new GlobAsset('scripts/embed/*.coffee'),
], [
$coffeeScript
])
]);
return $collection;
} }
throw new Exception(); throw new Exception();
} }
public static function styleAssetCollection($area) { private static function getStylesForArea($area) {
if ($area == 'app') { if ($area == 'app') {
$lastModifiedCollection = new AssetCollection([new GlobAsset("styles/*.less")]); return [
"styles/base/jquery-ui.css",
$css = new AssetCollection([ "styles/base/colorbox.css",
new FileAsset('styles/base/jquery-ui.css'), "styles/app.less",
new FileAsset('styles/base/colorbox.css'), "styles/profiler.less"
new FileAsset('styles/app.less'), ];
new CacheBusterAsset($lastModifiedCollection->getLastModified())
], [new \Assetic\Filter\LessFilter('node', Config::get('app.node_paths'))]);
if (Config::get('app.debug')) {
$css->add(new FileAsset('styles/profiler.less'));
$css->add(new FileAsset('styles/prettify.css'));
}
return $css;
} else if ($area == 'embed') { } else if ($area == 'embed') {
$css = new AssetCollection([ return [
new FileAsset('styles/embed.less'), "styles/embed.less"
], [new \Assetic\Filter\LessFilter('node', Config::get('app.node_paths'))]); ];
return $css;
} }
throw new Exception(); throw new Exception();

View file

@ -7,6 +7,7 @@ window.pfm.preloaders['account-albums'] = [
angular.module('ponyfm').controller "account-albums", [ angular.module('ponyfm').controller "account-albums", [
'$scope', '$state', 'account-albums', 'account-tracks' '$scope', '$state', 'account-albums', 'account-tracks'
($scope, $state, albums, tracks) -> ($scope, $state, albums, tracks) ->
$scope.albums = [] $scope.albums = []
$scope.data = $scope.data =
isEditorOpen: false isEditorOpen: false

Some files were not shown because too many files have changed in this diff Show more