Skip to content

Commit

Permalink
Merge branch 'release/1.0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jan 1, 2018
2 parents 855b462 + 4e7e2f9 commit 500d900
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 69 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# nystudio107/craft Change Log

## 1.0.8 - 2018.01.01
### Added
* Added a better PurgeCSS pipeline
* Added a `purgecssWhitelist` to `package.json`
* Execute JavaScript when doing Critical CSS
* Added a `criticalWhitelist` to `package.json`
* Added SiteModule framework to nystudio107/craft
* Added a `post-update-cmd` to `composer.json` to recreate any symlinks that may have been removed after a `composer update` or `composer install`

## 1.0.7 - 2017.12.16
### Added
* Added `purgecss` to production builds
Expand Down
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"nystudio107/craft3-minify": "^1.2.5",
"nystudio107/craft3-typogrify": "^1.1.1"
},
"autoload": {
"psr-4": {
"modules\\": "modules/"
}
},
"config": {
"optimize-autoloader": true
},
Expand All @@ -41,6 +46,9 @@
"post-create-project-cmd": [
"@php craft setup/welcome",
"@php nys-setup welcome"
],
"post-update-cmd": [
"@php nys-setup update"
]
}
}
4 changes: 2 additions & 2 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
// All environments
'*' => [
'modules' => [
'my-module' => \modules\Module::class,
'site-module' => \modules\nystudio107\sitemodule\SiteModule::class,
],
//'bootstrap' => ['my-module'],
'bootstrap' => ['site-module'],
],

// Live (production) environment
Expand Down
62 changes: 27 additions & 35 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ gulp.task("tailwind", () => {
$.tailwindcss(pkg.paths.tailwindcss.conf),
require("autoprefixer"),
]))
.pipe($.if(process.env.NODE_ENV === "production",
$.purgecss({
extractors: [{
extractor: TailwindExtractor,
extensions: ["html", "twig", "css", "js"]
}],
whitelist: pkg.globs.purgecssWhitelist,
content: pkg.globs.purgecss
})
))
.pipe(gulp.dest(pkg.paths.build.css));
});

Expand All @@ -78,48 +88,26 @@ class TailwindExtractor {
}
}

// purgecss task
gulp.task("purgecss", ["tailwind", "scss"], () => {
switch (process.env.NODE_ENV) {
case "development":
$.fancyLog("-> Copying CSS");
return gulp.src(pkg.globs.distCss)
.pipe(gulp.dest(pkg.paths.build.css));
break;

case "production":
$.fancyLog("-> Running purgecss");
return gulp.src(pkg.globs.distCss)
.pipe($.purgecss({
extractors: [{
extractor: TailwindExtractor,
extensions: ["html", "twig", "css", "js"]
}],
content: pkg.globs.purgecss
}))
.pipe(gulp.dest(pkg.paths.build.css));
break;
}
});

// css task - combine & minimize any distribution CSS into the public css folder, and add our banner to it
gulp.task("css", ["purgecss"], () => {
gulp.task("css", ["tailwind", "scss"], () => {
$.fancyLog("-> Building css");
return gulp.src(pkg.paths.build.css + "**/*.{css,.min.css}")
return gulp.src(pkg.globs.distCss)
.pipe($.plumber({errorHandler: onError}))
.pipe($.newer({dest: pkg.paths.dist.css + pkg.vars.siteCssName}))
.pipe($.print())
.pipe($.sourcemaps.init({loadMaps: true}))
.pipe($.concat(pkg.vars.siteCssName))
.pipe($.cssnano({
discardComments: {
removeAll: true
},
discardDuplicates: true,
discardEmpty: true,
minifyFontValues: true,
minifySelectors: true
}))
.pipe($.if(process.env.NODE_ENV === "production",
$.cssnano({
discardComments: {
removeAll: true
},
discardDuplicates: true,
discardEmpty: true,
minifyFontValues: true,
minifySelectors: true
})
))
.pipe($.header(banner, {pkg: pkg}))
.pipe($.sourcemaps.write("./"))
.pipe($.size({gzip: true, showFiles: true}))
Expand Down Expand Up @@ -256,6 +244,10 @@ function processCriticalCSS(element, i, callback) {
$.critical.generate({
src: criticalSrc,
dest: criticalDest,
penthouse: {
blockJSRequests: false,
forceInclude: pkg.globs.criticalWhitelist
},
inline: false,
ignore: [],
css: [
Expand Down
32 changes: 0 additions & 32 deletions modules/Module.php

This file was deleted.

66 changes: 66 additions & 0 deletions modules/nystudio107/sitemodule/SiteModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* SiteModule
*
* @link https://nystudio107.com
* @copyright Copyright (c) 2017 nystudio107
*/

namespace modules\nystudio107\sitemodule;

use modules\nystudio107\sitemodule\assetbundles\sitemodule\SiteModuleAsset;

use Craft;
use craft\events\TemplateEvent;
use craft\web\View;

use yii\base\Event;
use yii\base\InvalidConfigException;
use yii\base\Module;

/**
* @author nystudio107
* @package SiteModule
* @since 1.0.0
* @inheritdoc
*/
class SiteModule extends Module
{
// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
public function init()
{
Craft::setAlias('@site-module', $this->getBasePath());
parent::init();

// Only respond to AdminCP requests
$request = Craft::$app->getRequest();
if ($request->getIsCpRequest()) {
// Handler: View::EVENT_BEFORE_RENDER_TEMPLATE
Event::on(
View::class,
View::EVENT_BEFORE_RENDER_TEMPLATE,
function (TemplateEvent $event) {
Craft::trace(
'View::EVENT_BEFORE_RENDER_TEMPLATE',
__METHOD__
);
// Add our SiteModule AssetBundle
$view = Craft::$app->getView();
try {
$view->registerAssetBundle(SiteModuleAsset::class);
} catch (InvalidConfigException $e) {
Craft::error(
'Error registering AssetBundle - '.$e->getMessage(),
__METHOD__
);
}
}
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* SiteModule AssetBundle
*
* @link https://nystudio107.com
* @copyright Copyright (c) 2017 nystudio107
*/

namespace modules\nystudio107\sitemodule\assetbundles\sitemodule;

use craft\redactor\assets\redactor\RedactorAsset;
use craft\web\AssetBundle;
use craft\web\assets\cp\CpAsset;

/**
* @author nystudio107
* @package SiteModule
* @since 1.0.0
* @inheritdoc
*/
class SiteModuleAsset extends AssetBundle
{
// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
public function init()
{
// Set the path to our AssetBundle source
$this->sourcePath = '@site-module/assetbundles/sitemodule/dist';
// Declare AssetBundles that must be loaded first
$this->depends = [
CpAsset::class,
];
// Add in our CSS
$this->css = [
'css/SiteModule.css',
];
// Add in our JS
$this->js = [
'js/SiteModule.js',
];

parent::init();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* SiteModule CSS
*
* @author nystudio107
* @copyright Copyright (c) 2017 nystudio107
* @link https://nystudio107.com
* @package SiteModule
* @since 1.0.0
*/
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* SiteModule JS
*
* @author nystudio107
* @copyright Copyright (c) 2017 nystudio107
* @link https://nystudio107.com
* @package SiteModule
* @since 1.0.0
*/
18 changes: 18 additions & 0 deletions nys-setup
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ if (empty($argv[1])) {
welcomeNysCraft();
break;

case 'update':
// Display a welcome message
updateNysCraft();
break;

default:
// Set up all the things!
setupNysCraft();
Expand All @@ -213,6 +218,19 @@ function welcomeNysCraft()
outputString(PHP_EOL.'Your setup is not complete until you run these two commands.', Console::FG_YELLOW);
}

/**
* Update our Craft-Scripts symlinks as needed!
*/
function updateNysCraft()
{
// Say hello
outputString(PHP_EOL.'Updating nys-setup', Console::FG_YELLOW);
// Set up Craft-Scripts
setupCraftScripts();
// Say goodbye
outputString(PHP_EOL.'Update complete. Have a nice day!', Console::FG_YELLOW);
}

/**
* Set up all the things!
*/
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
"purgecss": [
"./templates/**/*.{html,twig}"
],
"purgecssWhitelist": [
],
"critical": [
{
"url": "",
Expand All @@ -96,6 +98,8 @@
"template": "404"
}
],
"criticalWhitelist": [
],
"download": [
{
"url": "https://www.google-analytics.com/analytics.js",
Expand Down

0 comments on commit 500d900

Please sign in to comment.