How to ignore node_modules directory from gulp:watch? - javascript

I have a gulp script that watches for code changes in all javascript files. It looks like this:
gulp.watch(['./**/*.jsx', './**/*.js'], ['build:react']);
So, it watches for all .js and .jsx files from root directory, but I want to ignore node_modules directory.
How can I do that ?

You ca use gulp unwatch This removes the folder specified from your pipe. However, it's generally a good idea to have a source folder that gulp watches instead of the project root folder (then the .git directory and all sorts will be caught up in your task.

Related

AWS Lambda Layers - git push only .zip file but no nodejs folder

I'm trying to add a layer for my aws lambda function.
The layer folder is structured like this:
layers/
nameOfLayer/
--nameOfLayer.zip
--nodejs/
-- node_modules
-- package-lock.json
-- package.json
And the nameOfLayer.zip file is structured like this:
nameOfLayer.zip
--nodejs/
-- node_modules
-- package-lock.json
-- package.json
If I git push this to my repo, I can see the .zip file but not the nodejs folder.
My .gitignore file looks like this:
*.js
!jest.config.js
*.d.ts
!lambda/*.js
.vscode
!layers/*.json
node_modules
*.json
# CDK asset staging directory
.cdk.staging
cdk.out
Why is this happening and what is the solution?
Thanks in advance
EDIT_1: My repo is at CodeCommit. Are there more options to set up stuff than the .gitignore file?
I think you want to replace !layers/*.json with !layers/**.json
The former would match layers/file.json but not layers/subdir/file.json
You need to use the double asterisk to match multiple subdirectories.
Refer to: https://git-scm.com/docs/gitignore#_pattern_format
I've added !package.json to the .gitignore probably not the best practice but it works

Gulp task to copy folder into build folder give empty folder

So i have built my own module and am trying to make a gulp task to copy the folder into my build folder. When this happens, nothing inside the folder is created in my build folder, it is just an empty folder.
My gulp task:
gulp.task("MyModule", function() {
return gulp.src("MyModule")
.pipe(chmod(777))
.pipe(gulp.dest(paths.build.node_modules));
});
paths.build.node_modules resolves to: build/node_modules
MyModule is in the root of the application folder.
Any reason why it would just be copying the folder and nothing inside of it?
You're not instructing it to copy the contents of the folder.
try gulp.src(["MyModule", "MyModule/**/*"], base:{'.'}) to copy the folder and everything in it instead of just the folder.

Gulp copy folder structure, but only symlink the files

I have a project with a certain folder structure and an other project which should be basically the same only some files are different.
I would like to write a gulp-task (or tasks) which are copying the first projects folder structure, but only create symlinks for the files, and don't overwrite files already in the other project.
I found out that I can create symlinks with gulp and vinyl-fs.
I tried to create a two step task. First, I tried to copy the folder structure, but I don't know how can I tell gulp that I only care about the folder structure.
Then second, I wanted to create a symlink task that is creating the symlinks in the correct directory.
Maybe, I could create it with only vinyl-fs's symlinks using a function parameter, but I can't find out how.
It would seem you can do this to copy only folders (exclude *.*):
gulp
.src(['base/path/**/*', '!base/path/**/*.*'])
.pipe(gulp.dest('target'));
Assuming all your files have some kind of extension (e.g. *.jpg).
For the symlinks, doesn't the following work?:
var vfs = require('vinyl-fs');
...
vfs
.src('base/path/**/*', { followSymlinks: false, nodir: true })
.pipe(vfs.symlink('target'));
...

compiling typescript and keep directory structure correctly

I have a build and a src dir. And in my src dir with my public folder where all my css's, assets and html's and the server folder with all server files. And now for an example in my server.ts I use a view in public/html. And if I transpiling my code in the build folder only the .ts files are and then the server.js tries to find the view in cmpl/public/html...
What is now a good way to transpiling the full src folder to build? Can Gulp this? Or TSC directly?
Greetz
You can just copy your html files to cmpl directory:
gulp.task('copyHtml', function () {
return gulp
.src('public/html/**/*.html')
.pipe(gulp.dest('cmpl'));
});

Launch Gulp Watch for JS and detect current folder has changed

I need to minimize the number of gulp's command from my gulpfile.
This is my JS folders
js/
templates/
t-01/
t-02/
[...]
t-xxx/
My gulp task for JS (with livereload)
gulp.task('da-js', function() {
gulp.src([
'js/templates/**/*.js',
'!js/templates/**/*.min.js'
])
.pipe(concat('app.min.js'))
.pipe(gulp.dest('js/templates'))
.pipe(livereload());
});
This task is global the destination folder is templates but I want to detect the current folder of js files like is :
I'm changing js in /templates/t-01/
gulp.watch is launching
app.min.js is generating only in this folder t-01
I know the gulp.dest is not correct to target current folder but I don't know how to do this.
Thank you for your help :)
You can use gulp's watch method to monitor a folder with JS files for updates and run a series of tasks in response to some change.
gulp.task('watch-files', function() {
gulp.watch('js/templates/**/*.js', ['da-js']);
});
Here we're watching over all the JS files in templates and all it's sub-folders and running your file concatenation task (da-js) for every update. Now that we're executing the same task, your app.min.js folder will be generated in your templates folder even when you change templates/t-01/some.js.
With the watch-files task defined in your gulpfile.js, you can simply run gulp watch-files command which will start monitoring your files.

Categories

Resources