N
N
Nurlan2016-08-03 01:31:24
gulp.js
Nurlan, 2016-08-03 01:31:24

How to properly extract text using GULP?

You need to extract the text from the files and glue the extracted text into one file. Further, I want to use this file in casper.js, but this is not relevant yet.
I watched a few videos about gulp and I really liked it. I started to cut, but it turns out somehow scary:

gulp.task('urlfind:find', function () {
    return gulp.src('modules/*.class.php')
        .pipe(find(/@url.(.+)+/g))
        .pipe(gulp.dest('urlfind'));
})

gulp.task('urlfind:concat',['urlfind:find'], function () {
    return gulp.src('urlfind/*.class.php')
        .pipe(concat('urls.txt',{newLine: '\r\n'}))
        .pipe(gulp.dest(''));
})

gulp.task('urlfind:clean',['urlfind:concat'], function () {
    return gulp.src('urlfind/*.class.php', {read: false})
        .pipe(clean());
})

gulp.task('urlstart', function () {
    gulp.start('urlfind:find', 'urlfind:concat', 'urlfind:clean');
})

The output file is full of empty lines, and it didn't come out exactly what I wanted. In addition to the link, there is also secondary data. How to properly cook gulp?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kravchenko, 2016-08-03
@daager

no need to save files to disk after each pipe, they can be chained

gulp.task('urlfind', function () {
    return gulp.src('modules/*.class.php')
        .pipe(find(/@url.(.+)+/g))
        .pipe(concat('urls.txt',{newLine: '\r\n'}))
        .pipe(gulp.dest(''));
})

M
Maxim Budin, 2016-08-03
@Kees

Don't forget to install the package.
And a variable. "find" is not taken from anywhere.
Sources can be specified in an array

gulp.src(['modules/*.class.php', 'urlfind/*.class.php', 'urlfind/*.class.php'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question