Skip to content

Instantly share code, notes, and snippets.

View kbshl's full-sized avatar

Konstantin Büschel kbshl

  • Marburg, Hessen, Deutschland
  • 01:47 (UTC +02:00)
  • X @iskostja
View GitHub Profile
@kbshl
kbshl / npmRights.sh
Created September 16, 2014 14:41
NPM cannot install dependencies - Falls auf einem Mac Rechte Probleme beim Installieren von globalen oder lokalen NPM Packages auftreten
# Run these commands in a terminal window (note - DON'T replace the whoami part...thats a linux command to get your user!
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
# ...and...if you're on a mac (like I am), and still see errors after running these commands, then run this last one and you should be good. (Recommend you try testing before you do this one. I don't like changing the permissions on the ENTIRE /usr/local directory unless it really seems necessary!)
sudo chown -R `whoami` /usr/local
@kbshl
kbshl / deleteFilesFoldersGulp.js
Last active October 30, 2017 18:36
Gulp Receipe: Delete files and folders
/*
* Delete files and folders
* You might want delete some files before running your build. Since deleting files doesn't work on the file contents there's no reason to use a gulp plugin. An excellent opportunity to use a vanilla node module.
*
* Let's use the del module for this example as it supports multiple files and globbing:
*/
// $ npm install --save-dev gulp del
// Imagine this file structure:
@kbshl
kbshl / combineStreamGulp.js
Created September 16, 2014 15:03
Gulp Receipe: Combining streams to handle errors
// Combining streams to handle errors
// By default, emitting an error on a stream will cause it to be thrown unless it already has a listener attached to the error event. This gets a bit tricky when you're working with longer pipelines of streams.
// By using multistream you can turn a series of streams into a single stream, meaning you only need to listen to the error event in one place in your code.
// Here's an example of using it in a gulpfile:
var Multistream = require('multistream');
var uglify = require('gulp-uglify');
var gulp = require('gulp');
@kbshl
kbshl / changedFilesGulp.js
Created September 16, 2014 15:04
Gulp Receipe: Only pass through changed files
// Files are passed through the whole pipe chain on every run by default. By using gulp-changed only changed files will be passed through. This can speed up consecutive runs considerably.
// npm install --save-dev gulp gulp-changed gulp-jscs gulp-uglify
var gulp = require('gulp');
var changed = require('gulp-changed');
var jscs = require('gulp-jscs');
var uglify = require('gulp-uglify');
// we define some constants here so they can be reused
@kbshl
kbshl / cliArgsGulp.js
Created September 16, 2014 15:04
Gulp Receipe: Pass arguments from the command line
// npm install --save-dev gulp gulp-if gulp-uglify minimist
var gulp = require('gulp');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var minimist = require('minimist');
var knownOptions = {
string: 'env',
@kbshl
kbshl / onlyChangedFilesGulp.js
Created September 16, 2014 15:05
Gulp Receipe: Rebuild only files that change
// With gulp-watch:
var gulp = require('gulp');
var sass = require('gulp-sass');
var watch = require('gulp-watch');
gulp.task('default', function() {
return gulp.src('sass/*.scss')
.pipe(watch())
.pipe(sass())
@kbshl
kbshl / filePerFolderGulp.js
Created September 16, 2014 15:06
Gulp Receipe: Generating a file per folder
/*
If you have a set of folders, and wish to perform a set of tasks on each, for instance...
/scripts
/scripts/jquery/*.js
/scripts/angularjs/*.js
...and want to end up with...
/scripts
/scripts/jquery.min.js
@kbshl
kbshl / taskDependencyGulp.js
Created September 16, 2014 15:07
Gulp Receipe: Running tasks in series, i.e. Task Dependency
/*
By default, tasks run with maximum concurrency -- e.g. it launches all the tasks at once and waits for nothing. If you want to create a series where tasks run in a particular order, you need to do two things:
give it a hint to tell it when the task is done,
and give it a hint that a task depends on completion of another.
For these examples, let's presume you have two tasks, "one" and "two" that you specifically want to run in this order:
In task "one" you add a hint to tell it when the task is done. Either take in a callback and call it when you're done or return a promise or stream that the engine should wait to resolve or end respectively.
In task "two" you add a hint telling the engine that it depends on completion of the first task.
@kbshl
kbshl / config.json
Created September 16, 2014 15:08
Gulp Receipe: Using external config file
{
"desktop" : {
"src" : [
"dev/desktop/js/**/*.js",
"!dev/desktop/js/vendor/**"
],
"dest" : "build/desktop/js"
},
"mobile" : {
"src" : [
@kbshl
kbshl / multipleSourcesOneTaskGulp.js
Created September 16, 2014 15:09
Gulp Receipe: Using multiple sources in one task
// npm install --save-dev gulp merge-stream
var gulp = require('gulp');
var merge = require('merge-stream');
gulp.task('test', function() {
var bootstrap = gulp.src('bootstrap/js/*.js')
.pipe(gulp.dest('public/bootstrap'));
var jquery = gulp.src('jquery.cookie/jquery.cookie.js')