Skip to content

Commit

Permalink
Change output file name
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix22 committed Feb 24, 2017
1 parent 9ab28c2 commit c855467
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const md5 = require('md5')
const execS = require('child_process').exec

const { replaceSpaceCharacters } = require('./helpers/util')
const { replaceSpaceCharacters, concatFiles } = require('./helpers/util')

const convert = ({ files, outputPath, name }) => {
// eslint-disable-next-line dot-notation
Expand All @@ -12,7 +12,7 @@ const convert = ({ files, outputPath, name }) => {
if (error) reject(error)

const fileString = files.map(replaceSpaceCharacters).join(' ')
const outputName = name || `ALCHEMY-${md5(fileString).substr(0, 6)}.pdf`
const outputName = name || `ALCHEMY-${concatFiles(files)}.pdf`
const command = `convert ${fileString} ${outputPath}${outputName}`
console.log(command)

Expand Down
14 changes: 11 additions & 3 deletions src/helpers/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
function replaceSpaceCharacters(str) {
return str.replace(/\s/g, '\\ ')
}
const replaceSpaceCharacters = str =>
str.replace(/\s/g, '\\ ')

const concatFiles = files =>
files.map(path => path.split('/').pop())
.map(file => file.split('.')[0])
.map(file => file.substr(0, 10))
.join('_')
.replace(/\s/g, '')
.substr(0, 50)

const uniqueFiles = (files, newArray) =>
newArray.reduce((accum, next) => {
Expand All @@ -11,6 +18,7 @@ const uniqueFiles = (files, newArray) =>
}, files)

module.exports = {
concatFiles,
replaceSpaceCharacters,
uniqueFiles
}

0 comments on commit c855467

Please sign in to comment.