Last change
on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
883 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | const debug = require("debug")("streamroller:fileNameFormatter");
|
---|
| 2 | const path = require("path");
|
---|
| 3 | const FILENAME_SEP = ".";
|
---|
| 4 | const ZIP_EXT = ".gz";
|
---|
| 5 |
|
---|
| 6 | module.exports = ({
|
---|
| 7 | file,
|
---|
| 8 | keepFileExt,
|
---|
| 9 | needsIndex,
|
---|
| 10 | alwaysIncludeDate,
|
---|
| 11 | compress
|
---|
| 12 | }) => {
|
---|
| 13 | const dirAndName = path.join(file.dir, file.name);
|
---|
| 14 |
|
---|
| 15 | const ext = f => f + file.ext;
|
---|
| 16 |
|
---|
| 17 | const index = (f, i, d) =>
|
---|
| 18 | (needsIndex || !d) && i ? f + FILENAME_SEP + i : f;
|
---|
| 19 |
|
---|
| 20 | const date = (f, i, d) => {
|
---|
| 21 | return (i > 0 || alwaysIncludeDate) && d ? f + FILENAME_SEP + d : f;
|
---|
| 22 | };
|
---|
| 23 |
|
---|
| 24 | const gzip = (f, i) => (i && compress ? f + ZIP_EXT : f);
|
---|
| 25 |
|
---|
| 26 | const parts = keepFileExt
|
---|
| 27 | ? [date, index, ext, gzip]
|
---|
| 28 | : [ext, date, index, gzip];
|
---|
| 29 |
|
---|
| 30 | return ({ date, index }) => {
|
---|
| 31 | debug(`_formatFileName: date=${date}, index=${index}`);
|
---|
| 32 | return parts.reduce(
|
---|
| 33 | (filename, part) => part(filename, index, date),
|
---|
| 34 | dirAndName
|
---|
| 35 | );
|
---|
| 36 | };
|
---|
| 37 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.