Using widcards in gulp base path - gulp

Is it possible to use wildcards in the gulp.src() base path. For instance:
gulp.src('./src/**/*.dll'. {base:'./src/**/bin/'})
Say I have these two files:
/src/someMiddleFolder/bin/my.dll
/src/someMiddleFolder/bin/someBinFolder/second.dll
The result I'm after is (with the dist folder set to /dist/bin)
/dist/bin/my.dll
/dist/bin/someBinFolder/second.dll
Can I achieve this with base option?

Related

Gulp, css is saving to dist/css/less, should be dist/css

trying to setup my gulp file for a project, I want to compile the less, and then minify it and have it save this to a new folder.
My less file is saved in app/less/styles.less, the compiled css file should save to dist/css/styles.css but it's saving to dist/css/less/styles.css.
What am I doing wrong here?
var app = 'app/',
dist = 'dist/',
appStyles = app + '**/*.less';
gulp.task('compilecssremote', function(){
return gulp.src(appStyles)
.pipe(plumber({
errorHandler: onError
}))
.pipe(changed(dist)) //must be dist
.pipe(urladjuster({
prepend: '/' + project + '/dist/' //based on location of CSS files
}))
.pipe(less())
.pipe(minifycss({keepBreaks: false}))
.pipe(gulp.dest(dist + 'css'))
});
This is the expected behavior when you use a gulp.src like 'app/**/*.less (aka your appStyles) to match source files with paths like app/less/styles.less. There are two pieces to understand here:
By default everything before the first glob in your gulp.src path will be omitted from the output path. In this case that's everything before the **, which is to say the app/. That's why the your output css file isn't going to 'dest/app/…. (For a more detailed discussion of this, see this answer)
The path matched by the first glob and on is preserved in the output path. In this case, that's the less/ in the matched file 'app/less/styles.less' (that is, the part of 'app/**/*.less' represented by **). (It's beside the point in the case of your problem, but this feature is very useful for preserving relative file structures.)
Using #1 & #2, one quick fix would be to trim less/ from the output path by putting it before the first glob in the gulp.src. For example, change appStyles = app + 'less/**/*.less'.

Match a partial folder name in Gulp

Why does this work:
gulp.src('./tmp/downloads/bootstrap*')
.pipe(unzip())
.pipe(gulp.dest('./tmp/'))
gulp.src('./tmp/bootstrap-3.3.2-dist/**/*')
.pipe(gulp.dest('./dist/bootstrap'))
but this does not:
gulp.src('./tmp/downloads/bootstrap*')
.pipe(unzip())
.pipe(gulp.dest('./tmp/'))
gulp.src('./tmp/bootstrap*/**/*')
.pipe(gulp.dest('./dist/bootstrap'))
I would like to get all the folders and files under ./tmp/downloads/bootstrap<version> and move them to ./dist/bootstrap. I have tried many configurations, and either the folder get there but the files don't, the files get flattened into one folder, or the whole folder bootstrap<version> gets copied into ./dist/bootstrap/bootstrap<version>.
I think you need to use bootstrap** to match directories starting with bootstrap:
gulp.src('./tmp/downloads/bootstrap*')
.pipe(unzip())
.pipe(gulp.dest('./tmp/'))
gulp.src('./tmp/bootstrap**/**/*')
.pipe(gulp.dest('./dist/bootstrap'))

Ignoring the same filename in root and subdirectories

In a Mac project, there are .DS_Store files at multiple levels, like so:
project/.DS_Store
project/subdir/.DS_Store
project/subdir/other_file.txt
project/.hgignore
When I use the following for a .hgignore file, the top-level .DS_Store doesn't get ignored. Is there any way to ignore both .DS_Store files with a single glob line in the .hgignore file? It seems like this should be easy, and adding another .DS_Store line feels clumsy.
syntax: glob
**/.DS_Store
The following works, but I prefer the readability of the glob syntax for ignore files:
syntax: regexp
.*\.DS_Store
Use the glob expression, but don't limit it to being inside a folder, like this:
syntax:glob
.DS_Store
That will match any file with the exact name of .DS_Store anywhere in the repo.

Rename file based on regex in Gulp

Say I have a LESS CSS directory structure like this:
less/
core/
_main.less
header.less
body.less
footer.less
contact/
_main.less
form.less
details.less
I want to write a Gulp task that will look for the _main.less files in each subdirectory of the less/ dir, pass this to gulp-less and write the output to the css/ dir like this:
css/
core.css
contact.css
Because _main.less includes the other files in it's directory, only the _main.less files will have to be parsed, but I want the output file to have the name of the directory it's in.
So far I have this:
gulp.src('less/*/*/_main.less')
.pipe(less())
.pipe(gulp.dest('css'));
But this will create a directory structure like this:
css/
core/
_main.css
contact/
_main.css
But that's not what I want. I was thinking to use a regex to match the directory name, get this back in a matches var, and rename the file accordingly. Something like this:
gulp.src(/less\/[^\/]+\/([^\/]+)\/_main.less/)
.pipe(less())
.pipe(rename(function(context) {
context.src.matches[1] + '.css'
}))
.pipe(gulp.dest('css'));
This code is just an example. I can't figure out how to do something like this, or if it's even possible.
Is this possible? If so, how?
You look like you already have this, but maybe didn't see the gulp-rename plugin?
I don't even think you'll need to use a RegExp, something like this should work:
var rename = require('gulp-rename'),
path = require('path'); // node Path
//...
gulp.src('less/**/_main.less')
.pipe(less())
.pipe(rename(function(filepath) {
// replace file name to that of the parent directory
filepath.basename = path.basename(filepath.dirname);
// remove parent directory from relative path
filepath.dirname = path.dirname(filepath.dirname);
// leave extension as-is
}))
.pipe(gulp.dest('css'));

Using mxmlc to compile as files with more than one src paths

I am using mxmlc.exe to compile my Flash project but I have two separated source files.
I noticed that I can specify more than one -compiler.library-path but it seems not OK to specify more than one -compiler.source-path parameters.
For some reasons I have to keep the src files in different folders. Is there any way I can still compile?
Thanks!
The desired command-line parameters:
mxmlc.exe src/Editor.as
-output=Editor.swf
-compiler.source-path=src1 -compiler.source-path=../src2
-compiler.library-path=libs -compiler.library-path=../libs
The += operator will append the second path to compiler.library-path, whereas the = operator will replace the value with a new one.
try this instead:
mxmlc.exe src/Editor.as
-output=Editor.swf
-compiler.source-path=src1 -compiler.source-path=../src2
-compiler.library-path+=libs -compiler.library-path=../libs
You might have to play a bit with the spacing before and after the += to get it working exactly right.