Skip to content

Instantly share code, notes, and snippets.

@ssovit
Last active December 19, 2018 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssovit/82a21867e0c4be2aee49eb032767cbf2 to your computer and use it in GitHub Desktop.
Save ssovit/82a21867e0c4be2aee49eb032767cbf2 to your computer and use it in GitHub Desktop.
var svgPHPArray = function (dest) {
var File = gutil.File;
var files = [];
var prepareFiles = function (f, enc, cb) {
if (f.isNull()) {
cb();
return;
}
if (f.isStream()) {
cb();
return;
}
var filename = f.relative.split(".").slice(0, -1).toString();
files.push("\n\t\t\t\"" + filename + '" => "' + filename.replace(/\W+/g, " ").ucwords() + '"');
cb(null, f);
};
var endStream = function (cb) {
var content = "<?php\n\treturn array(";
content += files.join(",");
content += "\n\t\t); \n?>";
var phpFile = new File(dest);
phpFile.path = dest;
phpFile.contents = new Buffer(content);
this.push(phpFile);
cb();
}
return through.obj(prepareFiles, endStream);
}
gulp.task('svgarray', function () {
return gulp.src('*.svg', {
cwd: 'src/svg'
})
.pipe(svgPHPArray("svg.php"))
.pipe(gulp.dest("config"));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment