Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you quickly convert all Jade files into Pug files?

Tags:

pug

Jade isn't called "Jade" any more. It is now known as "Pug". In order to convert an old jade project into the new pug format, you need to rename all the old .jade files to .pug files.

Doing it by hand is painful and tedious, surely there is a faster way to do it?

like image 323
Daniel Tonon Avatar asked Jul 07 '16 09:07

Daniel Tonon


People also ask

How do you go from jade to Pug?

Jade isn't called "Jade" any more. It is now known as "Pug". In order to convert an old jade project into the new pug format, you need to rename all the old .

Why did Jade rename the Pug?

Due to a trademark issue, the project name has been changed from “Jade” to “Pug” in conjunction with the release of Pug 2. This also means that we have changed the official supported file extension from . jade to .


2 Answers

On Windows, you can rename extension recursively by this command:

for /R %x in (*.jade) do ren "%x" *.pug

Taken from this answer.

Note that this only works in Windows Command Prompt. You will receive errors if you try to run this command in programs like Git Bash or Windows PowerShell.

If you are a Mac user, use this command in Mac Terminal:

find . -name '*.jade' | xargs rename 's/\.jade$/.pug/'
like image 111
Victor Kaptsov Avatar answered Jan 04 '23 01:01

Victor Kaptsov


I made this Gulp task to convert all the files for me in one hit :)

It requires the gulp-rename and del npm plugins to work.

Use this if all the jade files are within the root gulp folder (ie. the folder that the main gulp file is in)

//Use this if all jade files are inside gulps root folder

var rename = require("gulp-rename");
var del = require('del');

gulp.task('switch-to-pug', function() {
    console.log('\nCreated:\n');
    gulp.src(['**/*.jade'])
        .pipe(rename(function(path){
            path.extname = ".pug";
            console.log(path.dirname+'/'+path.basename + path.extname+'\n');
        }))
        .pipe(gulp.dest('./'))
        .on('end', function(){
            del(['**/*.jade']).then(function(paths){
                console.log('\nDeleted:\n\n', paths.join('\n'));
            });
        });
});

Use this (and edit the paths to suit your needs) if there are files outside the root gulp folder that you also want to rename:

//Use this (and edit accordingly) if jade files are also found outside the root folder

var rename = require("gulp-rename");
var del = require('del');

gulp.task('switch-to-pug', function() {
    console.log('\nCreated:\n');
    gulp.src(['../**/*.jade'])
        .pipe(rename(function(path){
            path.extname = ".pug";
            console.log(path.dirname+'/'+path.basename + path.extname+'\n');
        }))
        .pipe(gulp.dest('../'))
        .on('end', function(){
            del(['../**/*.jade'], { force: true }).then(function(paths){
                console.log('\nDeleted:\n\n', paths.join('\n'));
            });
        });
});

Then just run this and it will change all the files for you :)

gulp switch-to-pug
like image 28
Daniel Tonon Avatar answered Jan 04 '23 01:01

Daniel Tonon