gulp task get error: EISDIR, read? - javascript

gulp.task('dev', function () {
watch(['public/**', '!public/index.html'], function () {
del.sync(['web/**', '!web/.gitkeep', '!web/index.html', '!web/js/**']);
del.sync(['cordova/www/**', '!cordova/www/.gitkeep', '!cordova/www/index.html', '!cordova/www/js/**']);
gulp.src(['public/**', '!public/index.html', '!public/js/**'])
.pipe(gulp.dest('web/'))
.pipe(gulp.dest('cordova/www/'));
});
});
I'm using gulp setting up my development workflow. What I want to do is whenever any change happen in the public/, I want to wipe out everything in another two directory: web/ and cordova/www/, and write everything from public/ to web/ and cordova/www/.
I don't know what I'm doing wrong here. The dev gulp task job keeps throwing the error: EISDIR, read!

Related

gulp prevent duplicated dependent task execution

looking for some help in refactoring my gulp config file.
I have the following two tasks that both depend on a 3rd task.
I'm trying to get the 3rd task to only run once and save the results instead of having that task run twice.
gulp.task('lint', function(done) {
gulp.task('lib', function(done) {
they both depend on gulp.task('default_preferences', gulp.series('default_preferences-pre'))
previously default_preferences was being called for lint & lib
gulp.task('lint', gulp.series('default_preferences') function(done) {
gulp.task('lib', gulp.series('build_number', 'default_preferences') function(done) {
I have tried to create a new task calling 'default_preferences' and parallel on lint and
lib but then the preferences aren't being found.
gulp.task('createDefault', gulp.series('default_preferences', gulp.parallel('lib', 'lint')), function () {})
I feel like I am missing something obvious, thanks for any help provided!
Hello instead of using gulp task you could try approaching the problem this way:
function lint (done){}
function lib (done){}
exports.default= series(default_preferences-pre, parallel(lint,lib));
exports.lint= lint;
exports.lib= lib;
i hope it helps you

Trying to combine component scripts into one file with gulp-concat

I'm trying to update my compile TypeScript task (I've also tried it as a separate task as well) to combine the resulting javascript into one file. Here's my code:
gulp.task('compile:ts', function () {
return gulp
.src(tscConfig.filesGlob) //filesGlob is "src/ts/**/*.ts"
.pipe(plumber({
errorHandler: function (err) {
console.error('>>> [tsc] Typescript compilation failed'.bold.green);
this.emit('end');
}}))
.pipe(sourcemaps.init())
.pipe(tsc(tscConfig.compilerOptions))
.pipe(sourcemaps.write('.'))
.pipe(concat('all-components.js'))
.pipe(gulp.dest('public/dist'));
});
I've tried different destination folders, but I never even see the new file created, let alone used. Every example I've found shows that as the correct way and I don't get any errors so I can't tell what's wrong.

Gulp js cssmin issue. Can't overwrite existing minified files

Haven't found any help with my issue with search and google.
I'm having issues with Gulp and cssmin. Can't figure out what's causing an error. The idea is to keep original css files and minified version in the same folder, concatenation isn't needed.
My gulp task code:
gulp.task("min:css", function ()
{
return gulp.src([paths.css, "!" + paths.minCss], { base: "." })
.pipe(cssmin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('.'));
});
And error I'm getting after running the task:
[13:30:47] Starting 'min:css'...
[13:30:49] 'min:css' errored after 1.59 s
[13:30:49] Error: EPERM: operation not permitted, open '%file location%\bootstrap-theme.min.css' at Error (native)
UPD: After removing the bootstrap-theme.min.css, the error is caused by another one. Conclusion: the task can't overwrite the existing min.css files.
UPD:Managed to make it work with deleting all the .min.css files before build and running the task after the build. Not the best solution imo.
Is there any way to run the command without that, so all min.css files are deleted first?
Any chance your CSS files are in nested folders?
EDIT -
return gulp.src([paths.css, "!" + paths.minCss])
.pipe(cssmin())
.pipe(plugins.rename(function (path) {
path.basename += '.min';
path.dirname += '';
}))
.pipe(gulp.dest('{root folders name}'));
What this will do is rename the file with .min and add the file path to the name.
This will ensure the files go to the exact same place the originals are.

I'm using Gulp and failing to produce the final development script for production.

So I'm having a slight problem with producing production ready scripts for my project. I'm using gulp to concatenate and minify my css and js, and while the css is working fine the gulp js function isn't generating my final file. Please refer to my code below:
gulp.task('js', function() {
return gulp.src([source + 'js/app/**/*.js'])
.pipe(concat('development.js'))
.pipe(gulp.dest(source + 'js'))
.pipe(rename({
basename: 'production',
suffix: '-min',
}))
.pipe(uglify())
.pipe(gulp.dest(source + 'js/'))
.pipe(notify({ message: 'Scripts task complete', onLast: true }));
});
If anyone has encountered a similar problem or has any tips it would be much appreciated :)
There is nothing wrong with your gulpfile. I tested it and it works perfectly.
The only thing I can guess is that your source is not set correctly. Did you forget the trailing slash '/' ?
I would suggest 2 things to figure it out. Include node path library to check where source is actually pointing to like this:
var path = require('path');
// in gulp task ...
path.resolve(path.resolve(source + 'js/app'));
Make sure it points where you think it does.
Secondly, you could use gulp-debug to establish that any files are found:
npm install gulp-debug
Then
var debug = require('gulp-debug');
// in gulp task ...
return gulp.src([source + 'js/app/**/*.js'])
.pipe(concat('development.js'))
.pipe(debug())
.pipe(gulp.dest(source + 'js'))
.pipe(debug())
// etc.
Good luck!
Based on additional infomation in the comments I realise you are generating JS files in a separate process ...
gulp is asynchronous by default. What this boils down to is that all functions try to run at the same time - if you want a specific order it must be by design. This is great because it's very fast but can be a headache to work with.
Problem
Here is what's basically happening:
// SOME TASK THAT SHOULD BE RUN FIRST
gulp.task('copy-vendor-files-to-tempfolder', function (done) {
// copy files to vendor folder
done()
})
// SOME TASKS THAT DEPEND ON FIRST TASK
gulp.task('complile-styles', function () { /* independent task */ })
gulp.task('concat-vendor-files', function () { /* concat files in vendor folder. depends on vendor files existing */ })
// GENERAL TASK WHICH STARTS OTHERS
gulp.task('ready', ['copy-vendor-files-to-tempfolder', 'compile-styles', 'concat-vendor-files])
When you try to run:
$ gulp ready
GULP TASK WILL FAIL! Folder is being created at the same time!!
NOWHERE TO COPY FILES!
Solution
There are many solutions but the following module has come in handy for me again and again:
npm install run-sequence
Then in your gulpfile.js:
var runSequence = require('run-sequence')
gulp.task('ready', function (done) {
runSequence(
'create-folders', // do this first,
[
'copy-css-files',
'copy-html-files'
], // do these AFTER but in parallel
done // callback when ready
)
})
This will guarantee the folder exists when you try to run the other functions.
In your specific case, you should make sure the task that concatenates the JS files is run after the task that copies them out of vendor.
Note: I'm leaving other answer because it contains useful help for debugging similar issues.
HTH!

Running existing task with gulp-watch

I've got some tasks already defined in gulpfile.js and I want to use gulp-watch plugin (to run tasks on new files). My question is, because I couldn't find anything, can I run my existing tasks while running watch (from plugin) function?
var gulp = require('gulp'),
watch = require('gulp-watch'),
...;
gulp.task('lint', function () {
return gulp.src(path.scripts)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('watch', function () {
watch({ glob: 'app/**/*.js' }); // Run 'lint' task for those files
});
Because I don't want to include watch() task in every task I have. I would like to have only 1 task - watch, which will combine all "watches".
----- EDIT ----
(as I probably didn't quite get my point):
I need to run task from inside of gulp('watch') task. for example:
like I did it with gulp.watch:
gulp.task('watch', function () {
gulp.watch('files', ['task1', 'task2']);
});
I need to do the same but with gulp-watch plugin, something like (I know it wouldn't work):
var watch = require('gulp-watch');
gulp.task('watch', function () {
watch({ glob: 'files' }, ['task1', 'task2']);
});
I have also run into the problem of wanting to use gulp-watch (not gulp.watch), needing to use the callback form, and having trouble finding a suitable way to run a task in the callback.
My use case was that I wanted to watch all stylus files, but only process the main stylus file that includes all the others. Newer versions of gulp-watch may address this but I'm having problems with 4.3.x so I'm stuck on 4.2.5.
gulp.run is deprecated so I don't want to use that.
gulp.start works well, but is also advised against by the gulp author, contra.
The run-sequence plugin works well and lets you define a run
order, but it is a self-proclaimed hack:
https://www.npmjs.com/package/run-sequence
Contra suggest writing plain old functions and calling
those. This is a new idea to me, but I think the example below captures the idea. https://github.com/gulpjs/gulp/issues/505
Take your pick.
var gulp = require('gulp'),
watch = require('gulp-watch'), // not gulp.watch
runSequence = require('run-sequence');
// plain old js function
var runStylus = function() {
return gulp.src('index.styl')
.pipe(...) // process single file
}
gulp.task('stylus', runStylus);
gulp.task('watch', function() {
// watch many files
watch('*.styl', function() {
runSequence('stylus');
OR
gulp.start('stylus');
OR
runStylus();
});
});
All of these are working for me without warnings, but I'm still unsure about getting the "done" callback from the 4.2.x version of gulp-watch.
You will most likely want to run specific tasks related to the files you are watching -
gulp.task('watch',['lint'], function () {
gulp.watch('app/**/*.js' , ['lint']);
});
You can also use the ['lint'] portion to run any required tasks when watch first gets called, or utilize the tasks to run async with
gulp.task('default', ['lint','watch'])
You can just call one task, that then includes both task
gulp.task('default', ['lint','watch'])
so here you would just call 'gulp'
gulp.task('watch', function() {
watch(files, function() {
gulp.run(['task1', 'task2']);
});
});
work fine, except a warning

Categories

Resources