grunt-date-suffix
Advanced tools
Comparing version
{ | ||
"name": "grunt-date-suffix", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Grunt plugin for renaming a file with date suffix.", | ||
@@ -5,0 +5,0 @@ "main": "lib/datesuffix.js", |
@@ -16,5 +16,47 @@ [](https://www.npmjs.com/package/grunt-date-suffix) | ||
### Configure | ||
### Grunt configuration | ||
```javascript | ||
datesuffix: { | ||
rename1: { | ||
/** | ||
* Original filename (with path if not in current directory) | ||
* @required | ||
*/ | ||
file: "test.txt", | ||
/** | ||
* If move file to other directory, define here. | ||
* @optional | ||
*/ | ||
dest: "outputDir" | ||
/** | ||
* Divider between filename and date. | ||
* @optional | ||
* @default "." | ||
*/ | ||
divider: "-" | ||
/** | ||
* Switch behavior from "rename/move" to "copy". | ||
* @optional | ||
* @default false | ||
*/ | ||
copy: true, | ||
/** | ||
* Datetime format. Used node library `date-format`. | ||
* @optional | ||
* @default "yyyyMMddhhmmssSSS" | ||
*/ | ||
date_format: "yyyyMMdd" | ||
}, | ||
} | ||
``` | ||
### Configuration example | ||
```javascript | ||
//Gruntfile.js | ||
@@ -28,3 +70,3 @@ grunt.initConfig({ | ||
file: "test.txt", //required | ||
dest: "output", //default: undefined | ||
dest: "outputDir", //default: undefined | ||
}, | ||
@@ -40,2 +82,6 @@ test3: { | ||
ignore_nonexistent: true //default: false | ||
}, | ||
test5: { | ||
files: "filedoesnotexist.txt", //required | ||
divider: "-" //default: "." | ||
} | ||
@@ -55,2 +101,3 @@ } | ||
grunt datesuffix:test4 | ||
grunt datesuffix:test5 | ||
``` | ||
@@ -72,2 +119,5 @@ | ||
# no error is thrown even if the file does not exist | ||
# test5 | ||
test-20150116201020123.txt | ||
``` |
@@ -12,3 +12,3 @@ 'use strict' | ||
var done = this.async(); | ||
var file = options.file; | ||
@@ -20,2 +20,3 @@ var filename = Path.basename(file); | ||
var dest = options.dest||Path.dirname(file); | ||
var divider = options.divider||"."; | ||
@@ -41,3 +42,3 @@ var dateSuffixFormat = options.date_format||"yyyyMMddhhmmssSSS"; | ||
var newFilename = filename.substring(0, filename.length-extname.length) + "." + df.asString(dateSuffixFormat, new Date()) + extname; | ||
var newFilename = filename.substring(0, filename.length-extname.length) + divider + df.asString(dateSuffixFormat, new Date()) + extname; | ||
var newFile = Path.join(dest, newFilename); | ||
@@ -44,0 +45,0 @@ var handler = copy ? fs.copy : fs.rename; |
10026
10.71%170
0.59%119
72.46%