Coder Social home page Coder Social logo

gulp-rte's Introduction

gulp-rte NPM version

Better dest handling for Gulp.

Install

Install with npm:

npm i gulp-rte --save-dev

How it works

Substitute prop-strings like :basename, :ext, :dirname or any random string that has a match on the context object.

The generated dest path will be appended to whatever is defined in gulp.dest().

For example:

gulp.src('*.js')
  .pipe(rte(':basename:ext'))
  .pipe(gulp.dest('blog'));

//=> blog/a.js, blog/b.js, blog/c.js...

Context

File paths are parsed to create the default context object, so any of the following will work:

Given the filepath a/b/c/d.js:

  • :dirname returns a/b/c
  • :basename returns d.js
  • :ext|:extname returns .js

Note that, continuing with this example, the path must actually have an extension for :ext to return an extension. If an extension doesn't actually exist on the filepath then ext itself will be returned. An easy way around this is to define ext as a custom property.

Custom properties

Pass custom properties as a second parameter (continuing with a/b/c/d.js):

rte(':alpha/:gamma:ext', {alpha: 'one', gamma: 'three'})
//=> one/three.js

rte(':alpha/:basename/:gamma:ext', {alpha: 'one', gamma: 'three'})
//=> one/d/three.js

Usage examples

Basic example

This is just a basic example of what rte can do:

var gulp = require('gulp');
var rte = require('gulp-rte');

// given you have:
// ['a/b/c/foo.js', 'a/b/c/bar.js', 'a/b/c/baz.js']

gulp.task('default', function() {
 return gulp.src('a/b/c/*.js')
    .pipe(rte(':basename.min:ext'))
    .pipe(gulp.dest('blog'));
});
//=> blog/foo.min.js
//=> blog/bar.min.js
//=> blog/baz.min.js

Random string

Add a randomized string to any point in a file path:

var context = {
  random: Math.random().toString(36).substr(2, 5);
};

gulp.task('default', function() {
 return gulp.src('a/b/c/*.js')
    .pipe(rte(':basename-:random.js', context))
    .pipe(gulp.dest('blog'));
});
//=> blog/foo-qi2os.js
//=> blog/bar-s5s7p.js
//=> blog/baz-bu96e.js

Any pattern can be used. For inspiration or examples, see:

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on June 28, 2014.

gulp-rte's People

Contributors

jonschlinkert avatar txbm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gulp-rte's Issues

review / plugin advice

@stevelacy / @sindresorhus, I wonder if I could ask one of you for feedback on this plugin? no need for anything comprehensive, just quick feedback if you have a moment.

  1. will this plugin get blacklisted? I know sometimes plugins are blacklisted if they are similar to another plugin. The obvious plugin that's similar is gulp-rename. I made this b/c IMHO I think this approach is substantively better than gulp-rename, but I'd rather not spend more time on it if it's going to be blacklisted as similar to another plugin. Your feedback here would be great.
  2. Assuming it's okay as a plugin, do you notice anything wrong with how I'm doing this: https://github.com/jonschlinkert/gulp-rte/blob/master/index.js#L12-L13. I'm still learning streams, feel free to comment/give suggestions on any of it, but I'm pretty sure I'm not doing the highlighted code correctly in particular.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.