Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create strcuture folder with gulp

Tags:

gulp

I'd like to create my initial structure folders in web project using gulp, Are there is any package that help me to make this task ?

Example:

-css
-img
--content
--icons
-fonts
-js

with one command in bash create that strcuture

like image 587
Alexander Avatar asked Aug 06 '16 00:08

Alexander


2 Answers

Gulp can create structure folders without any package with this trick:

gulp.task('directories', function () {
    return gulp.src('*.*', {read: false})
        .pipe(gulp.dest('./css'))
        .pipe(gulp.dest('./img'))
        .pipe(gulp.dest('./img/content'))
        .pipe(gulp.dest('./img/icons'))
        .pipe(gulp.dest('./fonts'))
        .pipe(gulp.dest('./js'));
});
like image 165
Ariel Łowczynski Avatar answered Oct 09 '22 08:10

Ariel Łowczynski


You can use fs (Node.js - File System)

const gulp = require('gulp');
const fs   = require('fs');


gulp.task('default', () => {

    const folders = [
        'css',
        'img',
        'img/content',
        'img/icons',
        'fonts',
        'js'
    ];

    folders.forEach(dir => {
        if(!fs.existsSync(dir)) {
            fs.mkdirSync(dir);
            console.log('📁  folder created:', dir);    
        }   
    });
});
like image 27
Jakob E Avatar answered Oct 09 '22 07:10

Jakob E