Gulp task to copy folder into build folder give empty folder - javascript

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.

Related

How to retain folder structure when compiling test in NPM/GULP?

I am using this boilerplate for my workspace. When I compile my workspace into my dist folder, everything from my pages directory is copied except for the folder structure.
This is how the structure of the folder actually looks.
This is how it's supposed to be.
BTDT and I2PTGH is supposed to be inside the 2019-midterm folder but for some reason when it's compiled the directory structure of templates/pages is not retained. How can I make it so it so my folder structure is copied from templates/pages?
My gulpfile.js
What do I have to do to achieve what I want?

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'));
});

How to ignore node_modules directory from gulp:watch?

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.

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