I have the following file hierarchy:
scripts
someConfigFile.js
anotherConfigFile.js
someModuleDirectory
someModule.js
anotherModuleDirectory
anotherModule.js
subDirectory
thirdModule.js
I want to match all the files in the module directories, but excude the config files contained in the scripts directory itself, using Glob:
var glob = require('glob');
console.log(glob.sync(unknownGlobPattern));
Required output (unordered):
[
'someModuleDirectory/someModule.js',
'anotherModuleDirectory/anotherModule.js',
'anotherModuleDirectory/subDirectory/thirdModule.js'
]
The following glob should work:
['./scripts/**/*', '!./scripts/*']
First part will include all files in all subdirectories. Second part will exclude files in starting directory.
Related
My src folder contains both *.js files and *.min.js files. I just need to delete all files leaving *.min.js files intact using gulp. I tried this
return del.sync([
'js/**/*',
'!js/**/*.min.js']);
But this deletes all files in the src folder how do I proceed. considering that the src folder also contains other formats other than js
I'm trying to use gulp to copy one file to the same directory with a dfferent name - the file with a different name exists already. In Unix this is simply cp ./data/file.json.bak ./data/file.json In gulp it seems much more tricky (I'm on a Windows system).
I've tried:
gulp.task('restore-json',function(){
return gulp.src('./data/file.json.bak')
.pipe(gulp.dest('./data/file.json',{overwrite:true}));
});
If the file exists, I get a EEXIST error. If it doesn't, it creates file.json as a directory.
I'm assuming this problem is because gulp uses globbing and effectively it's treating src and dest as paths. Do you know the most efficient way I can do this? I suppose a workaround would be to copy the file to a tmp directory and then rename and copy using glob wildcards, but is that the right way?
The argument that you pass to gulp.dest() is not a file name. It is the name of the directory that you want all files in your stream to be written to. See the docs.
If you want to rename a file, use the gulp-rename plugin:
var rename = require('gulp-rename');
gulp.task('restore-json',function(){
return gulp.src('./data/file.json.bak')
.pipe(rename({extname:''}))
.pipe(gulp.dest('./data/'));
});
Gulp: see below as an example
How to copy files ending with .html in a directory and its subdirectories?
How to copy files that not ending with .js in a directory and its subdirectories.
--dirA
--dirB
--b.html
--b.js
--dirC
--c.html
--index.html
Like jacmoe answered, if you need to get specific files in gulp, use that kind of syntax:
'/directory/*.fileextension' //Get all files in directory with .extension
'!/directory*.fileextension' //Ignore files with .extension
'/directory/**/*.fileextension' //Get all files in directory AND all subdirectories with .extension
And remember that gulp paths support arrays so you can write something like that:
['!/directory/**/*.js', '/directory/**/*'] //Get all files except .js files
Or if needed only specific files:
['/directory/**/*.html'] //Get all .html files
If I am not totally mistaken:
gulp.task('copyHTML', function() {
return gulp.src('directory/**/*.html')
.pipe(gulp.dest('copied/html'));
});
That code will copy any file ending in .html in any directory beneath the directory directory.
I have a folder structure like this
ProjectX
.......|_____node_modules
.......|_____src
.......|_____build
.......|_____app
.......|_____libraries
I have written a glob pattern in grunt browserify something like this
src:['**/*.js','!node_modules','!build'],
dest:'build/build.js'
What i want from above code is, all .js files in my project should be browserified except the .js files in 'node_modules' and 'build' folder.
But what actually is happening is still the files from node_modules and build folder are browserified in my 'build/build.js' destination.
And i do not want to specify folder names of the .js file i require. I do not want to do something like this
['src/**/*.js' ... etc]
How can i solve this problem?
I am new to gulp.
I have a directory in /src which I want to move to /dist.
My directory looks like this with a depth of more than 1.
folder1
- folder2
-folder4
-folder5
-folder6
-folder7
-folder8
-folder10
-folder9
- folder3
I have declared src path as /src/folder1/* in gulp file and it has moved only folder1,folder2,folder3 to the destination path.folder2 and folder3 are empty folders which is perfectly fine.
I have declared src path as /src/folder/** in gulp file and it has moved all the folders as expected to the destination path.And while I was going through all the folders in destination path after running gulpfile, it crashed with segmentation11.What is the reason for this?
And what is the actual method to move all the folders of above structure in gulp?
This is the behavior of node-glob which gulp uses under the hood. From their readme:
* Matches 0 or more characters in a single path portion
..
** If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does
not crawl symlinked directories.
* will match everything in the same directory.
** will match everything recursively (subdirectories).
The segmentation fault is most likely due to a flaw in your script.