Yii2 AssetBundle convert less file but don't publish - yii2

I have a widget where I wanted to convert a less file to an css file.
The conversion works perfectly. But now I want that the less files aren't published to the web/assets directory.
And here the Pain begins...
This is my code:
class BreadcrumbsAsset extends \yii\web\AssetBundle
{
public $css = [
'css/breadcrumbs.less',
];
public $js = [
'js/breadcrumbs.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
public $publishOptions = [
"only" => [
"css/*",
"js/*",
],
'except' => [
"doc/",
"*.less",
],
];
}
But with the except setting set the css file isn't generated.
Also when I try the other way around and set:
public $publishOptions = [
"only" => [
"css/*.css",
],
The css file isn't generated from the less file any more.
So how does this supose to work?
When the to options only and except are added for this this case:
https://github.com/yiisoft/yii2/issues/2511 (AssetBundle should not publish .less or .coffee files)
https://github.com/yiisoft/yii2/issues/8566 (AssetManager support for choosing file/dir to be publish)
The Publishoptions are descriped like this:
only: array, list of patterns that the file paths should match if they want to be copied.
except: array, list of patterns that the files or directories should match if they want to be excluded from being copied.
And in the Filehelper which is used for the File Publish the except and only are descriped like this (from the Yii2 Filehelper Source):
- `except`: array, list of patterns excluding from the results matching file or directory paths.
Patterns ending with slash ('/') apply to directory paths only, and patterns not ending with '/'
apply to file paths only. For example, '/a/b' matches all file paths ending with '/a/b';
and `.svn/` matches directory paths ending with `.svn`.
If the pattern does not contain a slash (`/`), it is treated as a shell glob pattern
and checked for a match against the pathname relative to `$dir`.
Otherwise, the pattern is treated as a shell glob suitable for consumption by `fnmatch(3)`
`with the `FNM_PATHNAME` flag: wildcards in the pattern will not match a `/` in the pathname.
For example, `views/*.php` matches `views/index.php` but not `views/controller/index.php`.
A leading slash matches the beginning of the pathname. For example, `/*.php` matches `index.php` but not `views/start/index.php`.
An optional prefix `!` which negates the pattern; any matching file excluded by a previous pattern will become included again.
If a negated pattern matches, this will override lower precedence patterns sources. Put a backslash (`\`) in front of the first `!`
for patterns that begin with a literal `!`, for example, `\!important!.txt`.
Note, the '/' characters in a pattern matches both '/' and '\' in the paths.
- `only`: array, list of patterns that the file paths should match if they are to be returned. Directory paths
are not checked against them. Same pattern matching rules as in the `except` option are used.
If a file path matches a pattern in both `only` and `except`, it will NOT be returned.
So how should this only and except settings work?
Or is this a Bug?
Forgot to mention that of course I have the newest yii2 version installed (the only and except settings for publishOptions were introduced with yii 2.0.6)

Related

Excluding a portion of filename with glob expression

I'm having trouble excluding test files from my glob expression as follows :
I have this list of files
./app/tags.ts
./app/tag.ts
./app/status.ts
./app/bar/{foo}/baz.ts
./app/.hidden.ts
./app/_hidden.ts
./app/foo_dir/.hidden.ts
./app/some/testing_should_be_hidden.test.ts
I'm trying to exclude everything that starts with a '.' or starts with a '_' or includes a '.test' in the filename
so far this is what I tried :
Glob file pattern excluding node_modules
with my expression :
./**/[!._]*^(?!*test).{ts,js}
but It didn't work, however using:
./**/[!._]*.{ts,js}
excludes the 'hidden' files but not the test one
FYI : test is available here :
https://www.digitalocean.com/community/tools/glob?comments=false&glob=.%2F%2A%2A%2F%5B%21._%5D%2A%5E%28%3F%21%2Atest%29.%7Bts%2Cjs%7D&matches=false&tests=.%2Fapp%2Ftags.ts&tests=.%2Fapp%2Fgame%2F%7BgameId%7D%2Fclip.ts&tests=.%2Fapp%2F.hidden.ts&tests=.%2Fapp%2F_hidden.ts&tests=.%2Fapp%2Fgame%2F.hidden.ts&tests=.%2Fapp%2Fsome%2Ftesting.test.ts
So far this worked for me :
./**/[!._]!(*.test).{ts,js}
Can anyone explain this to me vs :
./**/[!._]*!(*.test).{ts,js}

JSDoc not working in .MJS file with Rollup

I have the following...
/**
* Represents a base element
* #extends HTMLElement
* #constructor
*/
export class Base extends HTMLElement {
...
}
When I run...
jsdoc src/jrg-base-element.mjs
Then I get...
There are no input files to process.
I tried --debug and got...
{"env":{"conf":{"plugins":[],"recurseDepth":10,"source":{"includePattern":".+\.js(doc|x)?$","excludePattern":"(^|\/|\\)"},"sourceType":"module","tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"templates":{"monospaceLinks":false,"cleverLinks":false,"default":{"outputSourceFiles":true}}},"opts":{"":["src/jrg-base-element.mjs"],"debug":true,"destination":"./out/","encoding":"utf8"}}}
Which seems to be close to (The error message "There are no input files to process" from jsdoc) but I don't know what to do.
Any ideas?
I just tried it myself:
Install JSDoc:
npm install -g jsdoc => OK
Create a dummy file, src/x.js:
/**
* Represents a base element
* #extends HTMLElement
* #constructor
*/
function hello () {
console.log ('Hello world!');
}
Run jsdoc src
Check the results (default directory "out/"):
In other words:
a) You may specify a JS file, but you'll typically specify a JS package directory.
b) By default, JSDoc doesn't recognize ".mjs"
SUGGESTION:
Specify a configuration file, and edit source.includePatter=n:
https://jsdoc.app/about-configuring-jsdoc.html#specifying-input-files
Specifying input files
The source set of options, in combination with paths given to JSDoc on
the command line, determines the set of input files that JSDoc uses to
generate documentation.
{
"source": {
"include": [ /* array of paths to files to generate documentation for */ ],
"exclude": [ /* array of paths to exclude */ ],
"includePattern": ".+\\.js(doc|x)?$",
"excludePattern": "(^|\\/|\\\\)_"
}
}
source.include: An optional array of paths that contain files for which JSDoc should generate documentation. The paths given to JSDoc on
the command line are combined with these paths. You can use the -r
command-line option to recurse into subdirectories.
source.exclude: An optional array of paths that JSDoc should ignore. In JSDoc 3.3.0 and later, this array may include subdirectories of the
paths in source.include.
source.includePattern: An optional string, interpreted as a regular expression. If present, all filenames must match this regular
expression to be processed by JSDoc. By default, this option is set to
".+.js(doc|x)?$", meaning that only files with the extensions .js,
.jsdoc, and .jsx will be processed.
source.excludePattern: An optional string, interpreted as a regular expression. If present, any file matching this regular expression
will be ignored. By default, this option is set so that files
beginning with an underscore (or anything under a directory beginning
with an underscore) is ignored.
Good luck - and please post back what you find!

What are the return values of os.walk() in python?

I have a directory structure like this:
dir/
└── subdir
My code:
import os
for d in os.walk('dir'):
print(d)
I get the output:
('dir', ['subdir'], [])
('dir/subdir', [], [])
My question is what are those trailing [ ]s ?
There is 1 in the first tuple and 2 in the second.. it confuses me.
It's worth checking out the Python docs for questions like this as they tend to have pretty solid documentation: https://docs.python.org/2/library/os.html#os.walk
Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames).
So it will always return a 3-tuple.
For your first directory 'dir', it contains one directory called 'subdir', and it doesn't contain any files so there's an empty list for filenames.
It then has another entry for subdir, which is your 'dir/subdir'. 'subdir' doesn't have any directories or files under it, so you have empty lists for both dirnames and filenames. The key thing is that it always returns a 3-tuple, and the last two elements are always lists, so there are no subdirectories or files, it will return empty lists.

Passing each file of a selected Directory

Is there any way to pass each and every file (with an extention .tcl) of a selected directory one by one in a particular variable in tcl ?
One way to do what I think you want to do is
foreach file [glob -directory $dir *.tcl] {
# do something with the filename $file
}
The glob command returns a list of file names that match the pattern in the last argument (in this case *.tcl, which means "any name that ends in .tcl"). The -directory option specifies which directory to look for files in.
The command will raise an error if there are no files that match the pattern. To avoid this and simply get an empty list, use the option -nocomplain.
The foreach command takes a variable specification, a list (in this case the list of file names), and a script. The script is evaluated once for every item (or batch of items in some cases) with the variable set to the item.
Documentation:
foreach,
glob,
File name conventions supported by Tcl commands
Syntax of Tcl string matching:
* matches a sequence of zero or more characters
? matches a single character
[chars] matches a single character in the set given by chars (^ does not negate; a range can be given as a-z)
\x matches the character x, even if that character is special (one of *?[]\)

What is the ** glob character?

I have this path in my react gulpfile:
var path = {
HTML: 'src/index.html',
ALL: ['src/js/*.js', 'src/js/**/*.js', 'src/index.html'],
JS: ['src/js/*.js', 'src/js/**/*.js'],
MINIFIED_OUT: 'build.min.js',
DEST_SRC: 'dist/src',
DEST_BUILD: 'dist/build',
DEST: 'dist'
};
What is the double glob character?
I know what the single glob is... but what is the double?
single glob
It's almost the same as the single asterisk but may consist of multiple directory levels.
In other words, while /x/*/y will match entries like:
/x/a/y
/x/b/y
and so on (with only one directory level in the wildcard section), the double asterisk /x/**/y will also match things like:
/x/any/number/of/levels/y
with the concept of "any number of levels" also including zero (in other words, /x/**/y will match /x/y as one of its choices).
As an aside, as much as I hate to credit the mainframe with anything, I believe this has been used since the earlist days of MVS to allow selection of datasets at multiple levels :-)
** matches any character including a forward-slash /
* matches any character except a forward-slash (to match just the file or directory name)
It's usually used to indicate any number of subdirectories. So
src/js/**/*.js
Would match
src/js/files/*.js
src/js/more-files/*.js
etc
etc
Like Grunt, the double ** is saying, "Look in all the subfolders
within js and for all of the .js files."
You can actually refer here for the same:
https://www.codefellows.org/blog/quick-intro-to-gulp-js