Gulp doesn't create link to a folder - gulp

Can not create a symbolic link to the /var/www/project/bower_components/bootstrap/less/mixins folder via Gulp JS. I tried to specify the desired path via the nodeJS.
VARIANT 1
CODE:
var gulp = require('gulp');
var path = require('path');
var debug = require('gulp-debug');
var symlink = require('gulp-sym');
gulp.task('symlink-deploy', function () {
var mixins = gulp
.src('' + path.resolve() + 'bower_components/bootstrap/less/mixins/')
.pipe(symlink('' + path.resolve() + 'assets/less/'))
.pipe(debug({title: 'unicorn:'}));
return Promise.all([mixins]);
});
gulp.task('default', ['symlink-deploy']);
RESULT:
user#user-ThinkPad-Edge-E545:/var/www/project$ gulp symlink-deploy
[17:18:44] Using gulpfile /var/www/project/gulpfile.js
[17:18:44] Starting 'symlink-deploy'...
[17:18:44] Finished 'symlink-deploy' after 28 ms
events.js:141
throw er; // Unhandled 'error' event
^
Error: EISDIR: illegal operation on a directory, read
at Error (native)
user#user-ThinkPad-Edge-E545:/var/www/project$
I have also was tried set path manually:
VARIANT 2
CODE:
var gulp = require('gulp');
var path = require('path');
var debug = require('gulp-debug');
var symlink = require('gulp-sym');
gulp.task('symlink-deploy', function () {
var mixins = gulp
.src('/home/user/www/project/bower_components/bootstrap/less/mixins')
.pipe(symlink('/home/user/www/project/assets/less'))
.pipe(debug({title: 'unicorn:'}));
return Promise.all([mixins]);
});
gulp.task('default', ['symlink-deploy']);
RESULT:
user#user-ThinkPad-Edge-E545:/var/www/project$ gulp symlink-deploy
[17:57:55] Using gulpfile /var/www/project/gulpfile.js
[17:57:55] Starting 'symlink-deploy'...
[17:57:55] Finished 'symlink-deploy' after 27 ms
events.js:141
throw er; // Unhandled 'error' event
^
Error: Destination file exists (/home/user/www/project/assets/less) - use force option to replace
at Transform._transform (/var/www/project/node_modules/gulp-sym/index.js:55:26)
at Transform._read (/var/www/project/node_modules/gulp-sym/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at Transform._write (/var/www/project/node_modules/gulp-sym/node_modules/readable-stream/lib/_stream_transform.js:172:12)
at doWrite (/var/www/project/node_modules/gulp-sym/node_modules/readable-stream/lib/_stream_writable.js:237:10)
at writeOrBuffer (/var/www/project/node_modules/gulp-sym/node_modules/readable-stream/lib/_stream_writable.js:227:5)
at Transform.Writable.write (/var/www/project/node_modules/gulp-sym/node_modules/readable-stream/lib/_stream_writable.js:194:11)
at write (/var/www/project/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:623:24)
at flow (/var/www/project/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:632:7)
at DestroyableTransform.pipeOnReadable (/var/www/project/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:664:5)
at emitNone (events.js:67:13)
user#user-ThinkPad-Edge-E545:/var/www/project$
Can't understand why it is't working.

Related

gulp: PostCSS failing - postcss version higher than version of postcss-import

Im trying to transform my css with PostCss using Gulp.
When I add the cssnext plugin to PostCss I get the following error:
Unknown error from PostCSS plugin. Your current PostCSS version is 6.0.19, but postcss-import uses 4.1.16. Perhaps this is the source of the error below.
This is my gulpfile.js:
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const concat = require('gulp-concat');
gulp.task('styles', function() {
const postCssPlugins = [
require('cssnext')()
];
gulp.src('src/css/*.css')
.pipe(postcss(postCssPlugins))
.pipe(concat('style.css'))
.pipe(gulp.dest('.'));
});
Full stack trace:
events.js:183
throw er; // Unhandled 'error' event
^
TypeError: styles.eachAtRule is not a function
at parseStyles (C:\gulp-test\node_modules\cssnext\node_modules\postcss-import\index.js:134:10)
at C:\gulp-test\node_modules\cssnext\node_modules\postcss-import\index.js:84:30
at LazyResult.run (C:\gulp-test\node_modules\postcss\lib\lazy-result.js:277:20)
at LazyResult.asyncTick (C:\gulp-test\node_modules\postcss\lib\lazy-result.js:192:32)
at processing.Promise.then._this2.processed (C:\gulp-test\node_modules\postcss\lib\lazy-result.js:231:20)
at new Promise (<anonymous>)
at LazyResult.async (C:\gulp-test\node_modules\postcss\lib\lazy-result.js:228:27)
at LazyResult.then (C:\gulp-test\node_modules\postcss\lib\lazy-result.js:134:21)
at process._tickCallback (internal/process/next_tick.js:188:7)
As far as I know, the postcss-import package is a dependency of cssnext. So what should I do?
I found the answer:
According to the website of cssnext, the package cssnext (which I used) is dead. The new package to use with PostCSS is postcss-cssnext:
const postCssPlugins = [
require('postcss-cssnext')()
];

Gulp: "Event.js:85" during gulp-clean

I try to delete all folders and files from my directory using gulp-clean.
My directory:
app
---subfolder1
---subfolder2
------subfolder
------file1
etc
My code:
gulp.task('clean',function(){
var PATH_TO_CLEAN = '../app/**';
if(argv.path != null)
PATH_TO_CLEAN = '../app/'+argv.path+'/**';
return gulp.src(PATH_TO_CLEAN, {read: false})
.pipe(clean({force: true}))
.on("error", handleError);
});
// Error handler
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
default path is '../app' but you can delete only subfolder using parametes --path=subfolder_dir
During the execution of gulp clean this error apears:
[14:43:08] Starting 'clean'...
events.js:85
throw er; // Unhandled 'error' event
^
Error: ENOENT, lstat 'C:\some_path\file.type'
at Error (native)
Gulp stops but file mentioned in error is deleted.
Repeating "gulp clean" I can finally reach succes:
[14:53:54] Starting 'clean'...
[14:53:54] Finished 'clean' after 11 ms
Do you have any idea how I can avoid this error?
I tried allso del with no success.
Found solution:
gulp.task('clean',function(){
var PATH_TO_CLEAN = '../app/**';
if(argv.path != null)
PATH_TO_CLEAN = '../app/'+argv.path+'/**';
del([PATH_TO_CLEAN], {force: true});
});
this is not the way I would like to manage this (by pipes) but it works well.
gulp-clean has been deprecated and should not be used anymore.
In my project skeletonSPA, I use the following task to clean my environment:
gulp.task('clean', function() {
var del = require('del');
var vinylPaths = require('vinyl-paths');
return gulp.src([PATH_TO_CLEAN])
.pipe(vinylPaths(del));
});
This task does not break the gulp pipe.
For this to work, you'll need to install the following modules:
npm install del vinyl-paths

Unable to run gulp task

I'm trying to run a simple gulp-sass task, but I'm getting this error:
[22:42:14] Starting 'sass'...
[22:42:14] Finished 'sass' after 10 ms
events.js:72
throw er; // Unhandled 'error' event
^
Error: File not found with singular glob
at Glob.<anonymous> (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\index.js:34:30)
at Glob.EventEmitter.emit (events.js:95:17)
at Glob._finish (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:171:8)
at done (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:158:12)
at Glob._processSimple2 (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:640:12)
at D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:628:10
at Glob._stat2 (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:724:12)
at lstatcb_ (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\glob.js:716:12)
at RES (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\node_modules\inflight\inflight.js:23:14)
at f (D:\Development\WebStorm\calliope\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-stream\node_modules\glob\node_modules\once\once.js:17:25)
I Installed gulp both globally and locally as dev depency.
Here's my task:
var gulp = require("gulp"),
sass = require("gulp-sass");
gulp.task("sass", function(){
gulp.src('assets/sass/*.scss')
.pipe(sass())
.pipe(gulp.dest('assets/css'))
});
The error is not so clear, by the way the Exception is throwed by a wrong link ( resource not found )
Yes, that is correct. The error is thrown whenever the resource is not found. I wrote a function to prevent such an occurrence in my files.
run "npm install fs --save".
then add this to your gulpfile
var fs = require('fs');
var validateResources = function (resources) {
resources.forEach(function (resource) {
if (!fs.existsSync(resource)) {
throw resource + " not found!";
}
});
};
With this, you will be safe to some extent.

getting gulp-sass to work with clean-css

I'm trying to minify a scss file using clean-css and get a useful sourceMap file.
My current gulp-task is:
var gulp = require('gulp'),
sourcemaps = require('gulp-sourcemaps'),
sass = require('gulp-sass'),
through = require('through2');
CleanCSS = require('clean-css'),
applySourceMap = require('vinyl-sourcemaps-apply');
var minify = through.obj(
function minify(file,encoding,callback) {
// do normal plugin logic
var result = new CleanCSS({sourceMap:file.sourceMap
,target: "./src"}).minify(file.contents.toString());
console.log(file.sourceMap)
file.contents = new Buffer(result.styles);
// apply source map to the chain
if (file.sourceMap) {
applySourceMap(file, result.sourceMap.toString());
}
this.push(file);
callback();
}
);
gulp.task('style', [],function () {
return gulp.src('./myfile.scss',{cwd: 'src'})
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(minify)
.pipe(sourcemaps.write('../maps/style',{sourceRoot:'/source/src'}))
.pipe(gulp.dest('./build/style/'))
});
when I run this setup I get the following error:
Error: Source map to be applied is missing the "file" property
at assertProperty (node_modules/vinyl-sourcemaps-apply/index.js:32:13)
at applySourceMap (node_modules/vinyl-sourcemaps-apply/index.js:11:3)
at DestroyableTransform.minify [as _transform] (/gulp/tasks/style.js:21:4)
at DestroyableTransform.Transform._read (/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
at doWrite (/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)
at writeOrBuffer (/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:227:5)
at DestroyableTransform.Writable.write (/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:194:11)
at Stream.ondata (stream.js:51:26)
at Stream.emit (events.js:95:17)
at queueData (/node_modules/gulp-sass/node_modules/map-stream/index.js:43:21)
at next (/node_modules/gulp-sass/node_modules/map-stream/index.js:71:7)
at /node_modules/gulp-sass/node_modules/map-stream/index.js:85:7
at handleOutput (/node_modules/gulp-sass/index.js:100:3)
at opts.success (/node_modules/gulp-sass/index.js:63:7)
at options.success (/node_modules/gulp-sass/node_modules/node-sass/lib/index.js:164:7)
If I add a dummy file path (or remove the assertions at node_modules/vinyl-sourcemaps-apply/index.js:32:13)) the source maps are generated however it does not recognize the original files (I.E. the scss files that gulp-sass compiled) and instead all my sources are mapped to `stdin' virtual file.
How can I get clean-css to recognize the location of the mapped sources processed by gulp-sass?

How to extract zip file with gulp

Here is my gulpfile.js
var gulp = require('gulp');
var download = require('gulp-download');
var unzip = require('unzip');
gulp.task('download-selenium', function(){
download('https://selenium.googlecode.com/files/selenium-server-2.39.0.zip')
.pipe(unzip.Extract({ path: 'selenium' }))
.pipe(gulp.dest("selenium"));
});
When I launch it I have the following issue:
$ gulp download-selenium
[gulp] Using file /Users/toutpt/makina/nmd/carteeco/mockup/gulpfile.js
[gulp] Working directory changed to /Users/toutpt/makina/nmd/carteeco/mockup
[gulp] Running 'download-selenium'...
[gulp] Errored 'download-selenium' in 9.08 ms Cannot pipe. Not readable.
/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/node_modules/orchestrator/index.js:153
throw err;
^
Error: Cannot pipe. Not readable.
at Extract.Writable.pipe (_stream_writable.js:125:22)
at Gulp.gulp.task.server (/Users/toutpt/makina/nmd/carteeco/mockup/gulpfile.js:99:6)
at module.exports (/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:31:7)
at Gulp.Orchestrator._runTask (/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at Gulp.Orchestrator.start (/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
at Gulp.run (/Users/toutpt/makina/nmd/carteeco/mockup/node_modules/gulp/index.js:20:14)
at /usr/local/lib/node_modules/gulp/bin/gulp.js:132:19
at process._tickCallback (node.js:415:13)
at Function.Module.runMain (module.js:499:11)
So How could I extract my downloaded file ?
Remember, gulp uses Streams for the file. npm unzip does not send a pipe-able stream as an output.
For this case you would be best off to not use the gulp.dest, but instead use the unzip extract path.
Try this:
var gulp = require('gulp');
var download = require('gulp-download');
var unzip = require('unzip');
gulp.task('download-selenium', function(){
download('https://selenium.googlecode.com/files/selenium-server-2.39.0.zip')
.pipe(unzip.Extract({ path: './selenium' }));
});
gulp-download doesn't seem to be maintained anymore, and gulp-gunzip has a more up-to-date example:
var gulp = require('gulp')
var request = require('request')
var source = require('vinyl-source-stream')
var gunzip = require('gulp-gunzip')
var untar = require('gulp-untar')
gulp.task('default', function () {
return request('http://example.org/some-file.tar.gz')
.pipe(source('some-file.tar.gz'))
.pipe(gunzip())
.pipe(untar())
.pipe(gulp.dest('output'))
})