Grunt-init copyAndProcess function: Can I pass in multiple values to 'noProcess' option? - gruntjs

I'm using grunt-init to build a template for a site structure I repeat regularly.
The template.js file uses the init.copyAndProcess function to customize most of files but a few of them get corrupted by the file processing (some fonts and image files) and I want to include those files in the 'noProcess' option. If these files all existed in the same directory, I could use the noProcess option as mentioned in the documentation [ See: http://gruntjs.com/project-scaffolding#copying-files ] and pass in a string like and it works:
var files = init.filesToCopy(props);
init.copyAndProcess(files, props, {noProcess: 'app/fonts/**'} );
Unfortunately the files that I need to have no processing performed on are not all in the same directory and I'd like to be able to pass in an array of them, something like the following block of code, but this does not work.
var files = init.filesToCopy(props);
init.copyAndProcess(files, props, {noProcess: ['app/fonts/**', 'app/images/*.png', 'app/images/*.jpg']} );
Any thoughts on how I can have multiple targets for the 'noProcess' option?

As soon as I posted the question, I realized that my proposed code did work. I simply had an invalid path when I'd renamed my 'app' directory to 'dev'.

Related

Laravel/blade caching css files

I am working on Nginx server, with PHP-FPM. I installed Laravel 4.1 and bootstrap v3.1.1., and here is the problem. For the last 30 minutes, I have been trying to change a css rule that I first declared to check boostrap.
.jumbotron{
background: red;
}
The first time it worked. The jumbotron container was red. So, I removed that css value and started working, but still no matter which browse I use, the container is red. I even checked the css file through the Google Chromes inspection tool, and it is showing me that first value when jumbotron had a background:red. I deleted the css file and renamed it and add new styles, I configured chrome not to cache pages. But Still the same value. I'm convinced now, that Laravel has kept a cache of the first style declaration.
Is there any way to disable this at all?
General explanation
When you access a Laravel Blade view, it will generate it to a temporary file so it doesn't have to process the Blade syntax every time you access to a view. These files are stored in app/storage/view with a filename that is the MD5 hash of the file path.
Usually when you change a view, Laravel regenerate these files automatically at the next view access and everything goes on. This is done by comparing the modification times of the generated file and the view's source file through the filemtime() function. Probably in your case there was a problem and the temporary file wasn't regenerated. In this case, you have to delete these files, so they can be regenerated. It doesn't harm anything, because they are autogenerated from your views and can be regenerated anytime. They are only for cache purposes.
Normally, they should be refreshed automatically, but you can delete these files anytime if they get stuck and you have problems like these, but as I said these should be just rare exceptions.
Code break down
All the following codes are from laravel/framerok/src/Illuminate/View/. I added some extra comments to the originals.
Get view
Starting from Engines/CompilerEngine.php we have the main code we need to understand the mechanics.
public function get($path, array $data = array())
{
// Push the path to the stack of the last compiled templates.
$this->lastCompiled[] = $path;
// If this given view has expired, which means it has simply been edited since
// it was last compiled, we will re-compile the views so we can evaluate a
// fresh copy of the view. We'll pass the compiler the path of the view.
if ($this->compiler->isExpired($path))
{
$this->compiler->compile($path);
}
// Return the MD5 hash of the path concatenated
// to the app's view storage folder path.
$compiled = $this->compiler->getCompiledPath($path);
// Once we have the path to the compiled file, we will evaluate the paths with
// typical PHP just like any other templates. We also keep a stack of views
// which have been rendered for right exception messages to be generated.
$results = $this->evaluatePath($compiled, $data);
// Remove last compiled path.
array_pop($this->lastCompiled);
return $results;
}
Check if regeneration required
This will be done in Compilers/Compiler.php. This is an important function. Depending on the result it will be decided whether the view should be recompiled. If this returns false instead of true that can be a reason for views not being regenerated.
public function isExpired($path)
{
$compiled = $this->getCompiledPath($path);
// If the compiled file doesn't exist we will indicate that the view is expired
// so that it can be re-compiled. Else, we will verify the last modification
// of the views is less than the modification times of the compiled views.
if ( ! $this->cachePath || ! $this->files->exists($compiled))
{
return true;
}
$lastModified = $this->files->lastModified($path);
return $lastModified >= $this->files->lastModified($compiled);
}
Regenerate view
If the view is expired it will be regenerated. In Compilers\BladeCompiler.php we see that the compiler will loop through all Blade keywords and finally give back a string that contains the compiled PHP code. Then it will check if the view storage path is set and save the file there with a filename that is the MD5 hash of the view's filename.
public function compile($path)
{
$contents = $this->compileString($this->files->get($path));
if ( ! is_null($this->cachePath))
{
$this->files->put($this->getCompiledPath($path), $contents);
}
}
Evaluate
Finally in Engines/PhpEngine.php the view is evaluated. It imports the data passed to the view with extract() and include the file with the passed path in a try and catch all exceptions with handleViewException() that throws the exception again. There are some output buffering too.
Same issue here. I am using VirtualBox with Shared Folders pointing to my document root.
This pointed me in the right direction:
https://stackoverflow.com/a/26583609/1036602
Which led me to this:
http://www.danhart.co.uk/blog/vagrant-virtualbox-modified-files-not-updating-via-nginx-apache
and this:
https://forums.virtualbox.org/viewtopic.php?f=1&t=24905
If you're mounting your local dev root via vboxsf Shared Folders, set EnableSendFile Off in your apache2.conf (or sendfile off if using Nginx).
For what it's worth and because this answer came up first in my google search...
I had the same problem. The CSS and JS files wouldn't update. Deleting the cache files didn't work. The timestamps were not the problem. The only way I could update them was to change the filename, load it directly to get the 404 error, and then change the name back to the original name.
In the end the problem was not related to Laravel or the browser cache at all. The problem was due to NginX using sendfile which doesn't work with remote file systems. In my case, I was using VirtualBox for the OS and the remote file system was vboxsf through Guest Additions.
I hope this saves someone else some time.
In Laravel 5.8+ you can use so:
The version method will automatically append a unique hash to the filenames of all compiled files, allowing for more convenient cache busting:
mix.js('resources/js/app.js', 'public/js').version();
After generating the versioned file, you won't know the exact file name. So, you should use Laravel's global mix function within your views to load the appropriately hashed asset. The mix function will automatically determine the current name of the hashed file:
<script src="{{ mix('/js/app.js') }}"></script>
full document: https://laravel.com/docs/5.8/mix

How to detect if a SCSS file or any of it partial files is updated

I want to run sass from within Ruby script. Compiling a scss file scss can be done by doing:
require "sass"
Sass::Engine.new(File.read(scss), options).render
with some appropriate hash assigned to options, but I want to compile it only if scss or any of its partial (imported) files if updated.
Within options, I have sass caching turned on. Caching keeps all the update information of the relevant files in a certain directory. I feel that, by doing up to:
engine = Sass::Engine.new(File.read(scss), options)
there must be information available in engine by which I can tell if scss or any of its partial files is updated. Only in such case, I should run:
engine.render
to do the compiling. How can I detect the file update based on the sass cache?
You can use:
Sass::Engine.for_file(scss, options).render
This will check whether there is a cached parse tree in the cache directory for the scss file hash. See the documentation for Sass::Engine.for_file here: http://sass-lang.com/docs/yardoc/Sass/Engine.html.
The cache lookup is performed in the Sass::Engine#_to_tree method, source code available here: https://github.com/nex3/sass/blob/stable/lib/sass/engine.rb.
EDIT
First few lines of Sass::Engine#_to_tree:
def _to_tree
if (#options[:cache] || #options[:read_cache]) &&
#options[:filename] && #options[:importer]
key = sassc_key
sha = Digest::SHA1.hexdigest(#template)
if root = #options[:cache_store].retrieve(key, sha)
root.options = #options
return root
end
end
# ...
end

Qt Installer framework component installation location

I've created an installer package based on the Qt installer framework with multiple components.
I needed to install each component in the appropriate directory.
Is it possible to specify the target directory for the individual component? I am referring to something like this:
var appData = installer.environmentVariable("AppData");
if (appData != "")
component.setValue("TargetDir", appData+ "/MyComponent");
Thank you in advance.
This question has already been answered, but I thought I would add a more detailed answer.
The documentation states that "for each component, you can specify one script that prepares the operations to be performed by the installer."
The Qt installer framework QtIFW comes with a set of examples, one of which is called modifyextract. Using this, I modified my package.xml file to include the line
<Script>installscript.qs</Script>
I then added a file installscript.qs to my package meta directory with the following content
function Component()
{
}
Component.prototype.createOperationsForArchive = function(archive)
{
// don't use the default operation
// component.createOperationsForArchive(archive);
// add an extract operation with a modified path
component.addOperation("Extract", archive, "#TargetDir#/SubDirectoryName");
}
The files in the package data folder were then installed in the subfolder SubDirectoryName
You need this based on the documentation:
Extract "Extract" archive target directory Extracts archive to target directory.
In my case, the component.addOperation("Extract", ... line resulted in extracting to #TargetDir#.
Instead, use one of the 'Operations> options in the Package.xml file.

Grunt concat specific file first, then all remaining files

I'm relatively new to grunt and I'm working to concat my files. I've been digging and haven't been able to come up with a good answer for this:
concat({
src : ['file1.js', ...all other files... ],
dest : 'dist/build.js'
});
Where file1.js is always added first, then it pulls in all remaining files. I could do it all by hand, but in the spirit of automation I was hoping to find a more dynamic method.
src is just a simple array which you can of course fill dynamically. e.g. you can read the files manually, sort them by whatever you want, and add that array to your config!

What is the purpose of files[] in .info?

I've just started learning discovering the changes to Drupal 7, and I just found the files[] array now required in the mymodule.info. From what I've found, it is required to add the mymodule.module file to the list, but what other uses does it have?
From what I've read I figured I should be able to separate my code into several files, for example I wanted to make a mymodule.blocks.inc to contain all the code for my blocks, but it seems like the mymodule_block_info() function never runs.
Am I doing something wrong, or is this not how it is supposed to be used?
As the documentation says:
files (Optional) Drupal now supports a dynamic-loading code registry.
To support it, all modules must now declare any code files containing class or interface declarations in the .info file.
This is only used if the file you specify in files[] contains a class or an interface. If so, the file will be auto-loaded only when needed.
No other files should be declared using files[].
At the beginning it was to make a files registry for each module, but it's not longer used as Drupal do it by himself.
If you want separate your module in multiple files, you should include them in the top of your .module file.
The way I see it, files specified as files[] are meant to be supporting files and called upon when needed. Implemented default Drupal hooks should be specified in the .module file or in the $module.$group.inc file in order for Drupal to recognize them. See hook_hook_info().
Also, see the note in the documentation under files at http://drupal.org/node/542202.

Resources