Skip to content

adding support to multiple sources#6

Open
sabios wants to merge 4 commits into
kennyki:masterfrom
sabios:master
Open

adding support to multiple sources#6
sabios wants to merge 4 commits into
kennyki:masterfrom
sabios:master

Conversation

@sabios

@sabios sabios commented Jul 17, 2018

Copy link
Copy Markdown

hello,
in the structure of my project using nuxt I need to pass multiple srcs.
the extract.js file is not validating srcs array.
So I made this code to help

@sabios sabios mentioned this pull request Jul 17, 2018

@kennyki kennyki left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey thanks for the PR. However I have few things to clarify, please see the comments

Comment thread extract.js Outdated
})

const vueFiles = glob.sync(`${srcFolder}/**/*.vue`)
const getFileArrays = (fileExtension = 'vue') => srcFolder.map(src => glob.sync(`${src}/**/*.${fileExtension}`))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Would srcFolder.map fail if only one src is provided?
  2. Perhaps getFiles is a better name :-)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i forgot it.
thanks for feedback. I'm renaming the function. I'll update PR soon

Comment thread extract.js Outdated

const vueFiles = glob.sync(`${srcFolder}/**/*.vue`)
const getFileArrays = (fileExtension = 'vue') => srcFolder.map(src => glob.sync(`${src}/**/*.${fileExtension}`))
const flattenFiles = (fileExtension = 'vue') => [].concat.apply([], getFileArrays())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function necessary?

Because it doesn't make use of fileExtension and is creating an additional array from the results of getFileArrays

Perhaps we can just call:

const vueFiles = getFiles()
const jsFiles = getFiles('js').concat(vueFiles)

@sabios sabios Jul 18, 2018

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glob.sync generates an array... so i'll have a multiple array... that's will be generate an erro.
but i fix that using a reduce function to help that

const syncFiles = (src, fileExtension = 'vue') => glob.sync(`${src}/**/*.${fileExtension}`)

const getFiles = (fileExtension = 'vue') => srcFolder.reduce((files, src) => [...files, ...syncFiles(src, fileExtension)], [])

const vueFiles = Array.isArray(srcFolder) ? getFiles() : syncFiles(srcFolder)
// note: vue files contain js code too
  const jsFiles = Array.isArray(srcFolder) ? getFiles('js') : syncFiles(srcFolder, 'js')
  const files = [...jsFiles, ...vueFiles]

what do you think about that?

@mcibique

mcibique commented Dec 3, 2019

Copy link
Copy Markdown

I was going to comment on this if somebody could review this/resolve conflicts because I encountered the same problem but after checking the source code I found that this package already supports multiple sources because it uses glob.sync() function to get all files for processing. Everything you have to do is node extract.js --output template.pot --src ./{folder1,folder2}/src. This PR might not be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants