简体   繁体   中英

How do you check filenames using gulp?

Here is the code I'm working with and the way I'm thinking about the solution.

gulp.task('templates:components', function () {
log('Building components..');
//if (filename === 'app.jade') {
//  return gulp.src().....
// } else 
    return gulp.src(source.templates.components)
        .pipe($.if(!isProduction, $.changed(build.templates.views, {extension: '.html'})))
        .pipe($.jade())
        .on('error', handleError)
        .pipe($.htmlPrettify(prettifyOpts))
        .pipe(flatten({ includeParents: 1} ))
        .pipe(gulp.dest(build.templates.views + 'views'));
});

I'm not sure how to set up my logic to detect the file, I've search but haven't been able to find a clear example or plugin for doing this.

How do I determine the outcome of a destination based on the filename?

I used gulp-flatten to pick out the part of the path I wanted.

var source = {
scripts: [paths.scripts + 'app.module.js',
    // template modules
    paths.scripts + 'modules/**/*.module.js',
    paths.scripts + 'modules/**/**/*.js',
    // custom modules
    paths.scripts + 'components/**/*.module.js',
    paths.scripts + 'components/**/*.js'
],
templates: {
    components: [paths.components + '**/views/**/*.jade', paths.components + '**/**/**/*.jade']
},
styles: {
    app: [paths.styles + '*.*'],
    themes: [paths.styles + 'themes/*'],
    watch: [paths.styles + '**/*', '!' + paths.styles + 'themes/*']
},
images: paths.images
};

// BUILD TARGET CONFIG 
    var build = {
    scripts: paths.app + 'js',
    styles: paths.app + 'css',
    templates: {
    index: '../',
    views: paths.app,
    cache: paths.app + 'js/' + 'templates.js',
},
images: paths.app + 'img'
};

gulp.task('templates:components', function () {
log('Building components..');
    return gulp.src(source.templates.components)
        .pipe($.if(!isProduction, $.changed(build.templates.views,    {extension: '.html'})))
        .pipe($.jade())
        .on('error', handleError)
        .pipe($.htmlPrettify(prettifyOpts))
        .pipe(flatten({ includeParents: 1} ))
        .pipe(gulp.dest(build.templates.views + 'views'));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM