gulp-file-contents-to-keys
Advanced tools
Comparing version 1.0.2 to 2.0.0
@@ -12,4 +12,3 @@ var gulp = require('gulp'); | ||
minify : true, | ||
removeFileTypes : true, | ||
folderDelimiter : '|', | ||
removeFileTypes : true | ||
} | ||
@@ -16,0 +15,0 @@ )) |
24
index.js
@@ -11,3 +11,3 @@ // by Yair-Even-Or | ||
var PLUGIN_NAME = 'gulp-file-contents-to-keys', | ||
files = { }, | ||
files = {}, | ||
outputFile = null, | ||
@@ -22,4 +22,3 @@ options = { | ||
function parseFileName( file ){ | ||
var name = file.path.replace(file.base, '');//.replace(/\\/g,'__').replace(/-/g,'_'); // 'foo/bar/baz-meh.txt' => 'foo__bar__baz_meh' | ||
name = name.replace(/\\/g, options.folderDelimiter); // folders delimeter "|" | ||
var name = file.path.replace(file.base, ''); | ||
@@ -47,4 +46,17 @@ if( options.removeFileTypes ) | ||
outputFile = outputFile || file; | ||
var filePath = parseFileName(file); // path.relative(file.base, file.path); | ||
files[filePath] = parseFileContent(file); | ||
var fileName = parseFileName(file), | ||
path = files; // path.relative(file.base, file.path); | ||
filePathArr = fileName.split('\\'); | ||
filePathArr.forEach((v, i) => { | ||
// last part is the file name itself and not a path | ||
if( i == filePathArr.length - 1 ) | ||
path[v] = parseFileContent(file); | ||
else if( v in path ) | ||
path = path[v]; | ||
else | ||
path = path[v] = {}; | ||
}) | ||
callback(); | ||
@@ -64,3 +76,3 @@ } | ||
outputFile.contents = new Buffer( | ||
options.name + ' = ' + JSON.stringify(files, null, 2) + ';' | ||
options.name + ' = ' + JSON.stringify(files, null, 4) + ';' | ||
); | ||
@@ -67,0 +79,0 @@ |
{ | ||
"version" : "1.0.2", | ||
"version" : "2.0.0", | ||
"name" : "gulp-file-contents-to-keys", | ||
@@ -18,10 +18,9 @@ "description" : "convert files into key/value objects where key is filename, value is the content", | ||
"dependencies": { | ||
"gulp-util" : "~3.0.1", | ||
"nconf" : "~0.6.9", | ||
"through2" : "~0.6.1", | ||
"path" : "~0.12.7", | ||
"vinyl" : "~0.6.1" | ||
"gulp-util" : "~3.0.8", | ||
"through2" : "~2.0.3", | ||
"path" : "~0.12.7", | ||
"vinyl" : "~2.0.2" | ||
}, | ||
"devDependencies": { | ||
"gulp" : "~3.8.7", | ||
"gulp" : "~3.9.1", | ||
"gulp-concat" : "~2.6.1", | ||
@@ -28,0 +27,0 @@ "mocha" : "*" |
@@ -33,3 +33,6 @@ | ||
└── some folder-c | ||
└── c.html | ||
├── c.html | ||
└── deep | ||
└── d.html | ||
``` | ||
@@ -40,15 +43,5 @@ | ||
## Output example: | ||
## How to Use (with GULP) | ||
```javascript | ||
var templates = { | ||
"a": "<div>file a</div>", | ||
"b": "<p style=\"color:red\">file b</p>", | ||
"some folder-c|c": "<ul><li>item 1</li><li>item 2</li><li>item 3</li></ul>" | ||
}; | ||
``` | ||
## How to Use | ||
```javascript | ||
var gulp = require('gulp'); | ||
@@ -72,2 +65,17 @@ var filesTokeys = require('gulp-file-contents-to-keys'); | ||
## Output example: | ||
```javascript | ||
export default templates = { | ||
"a": "<div>file a</div>", | ||
"b": "<p style=\"color:red\">file b</p>", | ||
"some folder-c": { | ||
"c": "<ul><li>item 1</li><li>item 2</li><li>item 3</li></ul>", | ||
"deep": { | ||
"d": "<p>deepest</p>" | ||
} | ||
} | ||
}; | ||
``` | ||
## Settings | ||
@@ -78,3 +86,2 @@ | ||
name | String | `var temlpates` | the name which points to the created Object. For example: `export default templates` if you want to import it using ES6 modules | ||
folderDelimiter | String | \| | delimiter in Object key, for deep files within folders | ||
fileName | String | | example: 'output.js' will output that file to the stream. it is an optional and the output of the plugin can also be used (within the gulp task) with `gulp-concat` to output to anywhere | ||
@@ -81,0 +88,0 @@ minify | Boolean | true | minify the files' content (removes new lines & whitespaces between HTML tags) |
4
88
87
12871
6
+ Addedclone-buffer@1.0.0(transitive)
+ Addedclone-stats@1.0.0(transitive)
+ Addedcloneable-readable@1.1.3(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedreplace-ext@1.0.1(transitive)
+ Addedvinyl@2.0.2(transitive)
- Removednconf@~0.6.9
- Removedasync@0.2.9(transitive)
- Removedini@1.3.8(transitive)
- Removedminimist@0.0.10(transitive)
- Removednconf@0.6.9(transitive)
- Removedoptimist@0.6.0(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedthrough2@0.6.5(transitive)
- Removedwordwrap@0.0.3(transitive)
Updatedgulp-util@~3.0.8
Updatedthrough2@~2.0.3
Updatedvinyl@~2.0.2