Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-dynamic-name

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-dynamic-name

Dynamically rename files during a jade build process

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

gulp-dynamic-name

gulp-dynamic-name is a gulp plugin to rename files easily.

Usage

gulp-dynamic-name is heavily based on the gulp-rename package, extending it to allow for dynamic naming of files within a stream using a structured object on the first line of the file. Useful for naming and building files in a build process when combined with the likes of Jade.

It provides all the features and methods of gulp-rename plus an extended feature set

Example

Assuming your using Jade to build out a series of templates

//- { "dest_path": "./dist", "dest_name" : "lazy-dog" }
doctype html
  html
    body
      P The Quick Brown Fox Jumped Over The Lazy Dog
var rename = require("gulp-dynamic-name");
var linereader = require("line-reader");
var intercept = require('gulp-intercept');

// dynamically naming and positioning a jade file
return gulp.src('path/to/jade/files/*.jade')
  .pipe( intercept( function(file){
      //  Read the first line of the Jade file for any local, file level settings
      linereader.eachLine(file.path, function(line, last, cb)
      {
        var ob;
        try {
            ob = JSON.parse( line.substring(4) );
            file.data = {
              'targetpath' : ob.dest_path,
              'filename' : ob.dest_name };
            ps.resume();
        } catch( err ) {
            file.data = {'targetpath' : cpath };
            ps.resume();
        }
      })
      return file;
  }))
  .pipe(jade({
    locals: MERGED,
    pretty: true
  })
  .pipe(rename({
    extname: '.foo',
    useconfig: true
  }))
  .pipe( gulp.dest( function(file, t) {
      return String( file.data.targetpath );
  })) // Builds the Jade files to /dist/lazy-dog.foo

Notes

  • extname is the file extension including the '.' like path.extname(filename).
  • The file bring renamed must contain a structured JSON object on the first line of the file
    • dest_path is the path to where the compiled file should be sent
    • dest_name the base name the file should be called

License

MIT License

Keywords

FAQs

Package last updated on 18 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc