Skip to content

Commit

Permalink
chore(global): use two-space indenting and single quotes (closes #45)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcrea committed Mar 31, 2015
1 parent 62c15b5 commit 194b219
Show file tree
Hide file tree
Showing 9 changed files with 433 additions and 427 deletions.
17 changes: 10 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# http://editorconfig.org
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
indent_style = tab
indent_size = 4

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand All @@ -12,10 +19,6 @@ insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

[*.{json,yml}]
indent_style = space
indent_size = 2

[test/fixtures/*]
insert_final_newline = false
trim_trailing_whitespace = false
4 changes: 2 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "double",
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ var rename = require("gulp-rename");

// rename via string
gulp.src("./src/main/text/hello.txt")
.pipe(rename("main/text/ciao/goodbye.md"))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/goodbye.md
.pipe(rename("main/text/ciao/goodbye.md"))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/goodbye.md

// rename via function
gulp.src("./src/**/hello.txt")
.pipe(rename(function (path) {
path.dirname += "/ciao";
path.basename += "-goodbye";
path.extname = ".md"
}))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md
.pipe(rename(function (path) {
path.dirname += "/ciao";
path.basename += "-goodbye";
path.extname = ".md"
}))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md

// rename via hash
gulp.src("./src/main/text/hello.txt", { base: process.cwd() })
.pipe(rename({
dirname: "main/text/ciao",
basename: "aloha",
prefix: "bonjour-",
suffix: "-hola",
extname: ".md"
}))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/bonjour-aloha-hola.md
.pipe(rename({
dirname: "main/text/ciao",
basename: "aloha",
prefix: "bonjour-",
suffix: "-hola",
extname: ".md"
}))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/bonjour-aloha-hola.md
```

**See test/rename.spec.js for more examples and test/path-parsing.spec.js for hairy details.**
Expand Down
83 changes: 43 additions & 40 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,65 @@
var Stream = require("stream"),
Path = require("path");
'use strict';

var Stream = require('stream');
var Path = require('path');

function gulpRename(obj) {
"use strict";

var stream = new Stream.Transform({objectMode: true});
var stream = new Stream.Transform({objectMode: true});

function parsePath(path) {
var extname = Path.extname(path);
return {
dirname: Path.dirname(path),
basename: Path.basename(path, extname),
extname: extname
};
}

stream._transform = function(file, unused, callback) {

function parsePath(path) {
var extname = Path.extname(path);
return {
dirname: Path.dirname(path),
basename: Path.basename(path, extname),
extname: extname
};
}
var parsedPath = parsePath(file.relative);
var path;

stream._transform = function(file, unused, callback) {
var type = typeof obj;

var parsedPath = parsePath(file.relative);
var path;
if (type === 'string' && obj !== '') {

var type = typeof obj;
path = obj;

if (type === "string" && obj !== "") {
} else if (type === 'function') {

path = obj;
obj(parsedPath);
path = Path.join(parsedPath.dirname, parsedPath.basename + parsedPath.extname);

} else if (type === "function") {
} else if (type === 'object' && obj !== undefined && obj !== null) {

obj(parsedPath);
path = Path.join(parsedPath.dirname, parsedPath.basename + parsedPath.extname);
var dirname = 'dirname' in obj ? obj.dirname : parsedPath.dirname,
prefix = obj.prefix || '',
suffix = obj.suffix || '',
basename = 'basename' in obj ? obj.basename : parsedPath.basename,
extname = 'extname' in obj ? obj.extname : parsedPath.extname;

} else if (type === "object" && obj !== undefined && obj !== null) {
path = Path.join(dirname, prefix + basename + suffix + extname);

var dirname = "dirname" in obj ? obj.dirname : parsedPath.dirname,
prefix = obj.prefix || "",
suffix = obj.suffix || "",
basename = "basename" in obj ? obj.basename : parsedPath.basename,
extname = "extname" in obj ? obj.extname : parsedPath.extname;
} else {

path = Path.join(dirname, prefix + basename + suffix + extname);
callback(new Error('Unsupported renaming parameter type supplied'), undefined);
return;

} else {
callback(new Error("Unsupported renaming parameter type supplied"), undefined);
return;
}
}

file.path = Path.join(file.base, path);
file.path = Path.join(file.base, path);

// Rename sourcemap if present
if (file.sourceMap) {
file.sourceMap.file = file.relative;
}
// Rename sourcemap if present
if (file.sourceMap) {
file.sourceMap.file = file.relative;
}

callback(null, file);
};
callback(null, file);
};

return stream;
return stream;
}

module.exports = gulpRename;
4 changes: 2 additions & 2 deletions test/.jshintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../.jshintrc",
"mocha": true
"extends": "../.jshintrc",
"mocha": true
}
Loading

0 comments on commit 194b219

Please sign in to comment.