PhpStorm: how to add watcher on 1 JS file only and not on ALL JS files? - phpstorm

1) How to add a watcher on 1 file ONLY ?
The goal is to put a obfuscator on 1 JS file only (the main.js) : I was unable to do that: obfuscation is applied to ANY JS file I do modify.
2) How to avoid infinite recurrent rules ?
I have 2 watchers right now:
minification on JS files
obfuscation on JS files
Problem is: PhpStorm creates infinite .min.obf.min.obf...js : it looks it applies these 2 rules in endless.

Use Scope field to limit the watched files: create custom Scope that will include only desired file(s) and/or folders and use it there in File Watcher.
Scope can accept both "include" and "exclude" patterns at the same time so it's very flexible in filtering the files.
The same approach for your second issue -- use scope to not to process already processed files.
For example: https://stackoverflow.com/a/24938053/783119
The alternative to having 2 separate File Watchers is creating some batch/shell script that will do that minification + obfuscation and use it as a program in File Watcher.
Another option -- use build tools (Grunt/Gulp or alike) and call appropriate task there.

Related

How to use both LessCSS compiler and CSSO in PhpStorm?

I am using PhpStorm. I'm having problem with 2 file watchers.
.min files does not get updated on save in .less file.
I need first to compile Less to CSS and then to minify that same file.
.min files does not get updated on save in .less file
Use Output paths to refresh for that -- the IDE will check such path(s) looking for changes after current File Watcher finished running.
https://www.jetbrains.com/help/phpstorm/using-file-watchers.html#transpilerBehaviour
I need first to compile Less to CSS and then to minify that same file.
Use 2 file watchers: second one will run after the first one (so it needs to be located after/below the first one).
So I have:
First watcher will take main.scss and compile into main.css (using node-sass) and placed next to the source file.
Second will run after that on main.css and will make main.min.css using CSSO CSS Optimizer.
The File Watchers:
(please ignore disabled ones: this is quite old test project; it keeps all the stuff from the past experiments)
SCSS Watcher (using node-sass):
CSSO CSS Optimizer watcher:
Please note that I'm using custom scope: this is to limit these watchers to those specific folders only (it's test project after all; it has tons of experiments).
Here is the recording/proof that it works just fine: all 3 files are opened and get refreshed automatically by IDE: I only hit the Save button that triggers File Watchers.
A folder structure just in case:

Group files with the same name in filelist

All my projects contains alot of files with the same name 'file1.php file1.less file1.css file1.min.js file1.js file1.json'
Is there a plugin or a way to group all those files with same basename under eg. file1.php, just like the filewatchers does it.
The grouping relations can only be established when running watchers, so using watchers is the right way to go. It can indeed be a batch script that does nothing - this is the 'Output paths to refresh' option that matters: it should provide a pattern for files that has to be nested. For example, let you have same-named files with .php, .css and .js extensions in some folder, and like to nest the latter 2 in .php file (doesn't make much sense, but it's just an example).
create a .bat/sh file that does nothing (echos some string, etc.)
create a new custom file watcher, set 'php' as file type, your .bat - as a program
specify $FileName$ and $FileDir$ as 'Arguments' and 'Working directory' respectively
set $FileNameWithoutExtension$.css:$FileNameWithoutExtension$.js as 'Output paths to refresh'
Now when you modify your phpfile watcher will be run and nest .js and .css in .php
Currently it is not possible to perform such nesting/grouping manually (excluding File Watchers).. and I personally know no plugin that can do this.
Watch these tickets (star/vote/comment) to get notified on progress:
https://youtrack.jetbrains.com/issue/IDEA-113347
https://youtrack.jetbrains.com/issue/WEB-7635

using a function which is defined in a scheme file, inside another scheme file

I am new to Scheme.
I wrote a program that defines a function named "run", and I stored it as "Run.scm".
Then I have a "test.scm" file which uses this "run" function which I defined it inside "Run.scm".
I don't know how to include the "Run.scm" inside "test.scm" that I can use "run" function inside test file. Can anyone help me?
Compatible method
If you have a file with source code you can in any Scheme comforming program use load. So in your test you can do this:
% ls
test.scm Run.scm
Contents of test.scm
(load "Run.scm")
(run)
The new and better way (R6RS and later)
If you have a R6RS or a R7RS you have the ability to make a library. It is implementation specific how the library is incorporated into it but not how the source file looks. Read you documentation to how you add the library to your system.
Then, imagine you have made an awesome/utility.scm library. In R6rs/R7RS you would add it to your code like this:
(import (awesome utility))
;; start using the imported code..
(awesome-function '(1 2 3 4)) ; ==> (4 3 2 1)
Alternative by R5RS Schemes
Since R5RS and earlier just had load most implementations made their own way of loading both libraries and source files. eg. Racket has require and Chicken Scheme has import. To use these will lock you in with one supplier, but many libraries do it by building a implementation specific start file that import the other files in the special way to make out the differences between them or make a source file based on parts with gnu make or similar program.

Combining and minifying cross-script variables

I'm looking to combine and minify my JavaScript files. I have a question; on my pages I basically have the same library JS files, and then one 'specific' JS file to run code for that page. I also have variables defined in that specific JS file which are then used elsewhere in the library JS files. For example, I defined var tablename which is then used in a library file to render out a table using what is set as 'tablename'.
My question is, if I combine all of my JavaScript files from all of my pages into one big JS file, and then include that combined/minified file on my pages, then as a result of combining all of the files then that big JS file will have multiple .ready() events and the same variable tablename will be defined multiple times. How is this overcome? Maybe it can't in my situation and I'll need to create a combined/minified file for each of my pages?
Thanks
I think I found the solution; YUI Compressor (that I'm using) doesn't munge global variables, and since my tablename variable will be global (not in a function) then it won't get munged.

customizing `org-publish-project-alist`

I'm trying to publish webpage using org-mode. Two questions:
Is there a way to "sync" the org-mode files in the base-directory and the html files in the publishing-directory? Specifically, if I delete an org file in the base-directory, can I get org-publish-html to delete the corresponding file in the html directory also?
If I have pages within subdirectories, how can I specify a single .css file in the root directory to be used for the style sheet? For instance, my directory structure is as follows:
public_html/
css/
mystyle.css
index.html
subdir/
index.html
With the following specifications in org-publish-project-alist (this is just a subset) --
:publishing-directory "public_html"
:style "<link rel=\"stylesheet\" href=\"css/mystyle.css\" type=\"text/css\"/>"
mystyle.css is used by public_html/index.html but not by public_html/subdir/index.html. Is there a simple remedy to this (I want the style sheet to be used by both/all files in subdirectories)?
Thanks much ~
There is no straightforward way of doing this. Org-mode doesn't know (or care) about the location to which it is publishing - it just sends things there and makes sure the correct directory structure exists. There is a hook in the publishing process that gets called after the files have been pushed to their published location. This is controlled by setting the :completion-function property in your org-publish-project-alist. You could use this hook to write a function that compares the *.org files in your base-dir and subdirectories to the accompanying *.html published files, and remove those *.html files that don't have an accompanying *.org file.
I suspect this will be most easily accomplished by making your Lisp completion-function call a shell script that removes the necessary files. If you are doing something fancy with the :include, :exclude, or :base-extension properties, you'll likely want your completion-function to grab the pertinent information from the plist and then pass them to your shell script. This org-mode page has an example completion-function that shows how to get property values for the org-publish-project-alist. You would then need to pass them to your shell script.
There are several ways to do this. Perhaps the simplest is to just override the default style sheet in each file with a line such as:
#+STYLE: <link rel="stylesheet" type="text/css" href="../stylesheet.css" />
for your first level of subdirectory files, and keep adding ../ as you get deeper in the directory structure.
Another possibility is generate generic template files for each level within the directory tree. This org-mode page gives a nice example of how to set this up.
Lastly, another option is to use the :preparation-function property of org-publish-project-alist to define a function that will automatically change the style file for each file. Again, this is probably best done by having the Lisp preparation-function call a shell script to parse the files. I could imagine doing this with the Unix sed program to find a regular expression denoted something like href="#MYLOC#/stylesheet.css" /> and substitute the stuff between #'s with the appropriate level within the directory tree. This seems like overkill, given the other options.