@zauberware/weblate-create-components
Version:
You need `curl` to be installed. It is installed per default on each unix-like machine.
39 lines (36 loc) • 1.29 kB
JavaScript
const path = require('path')
const glob = require('glob')
const createComponent = require('./create-component.js')
const { getLanguageCodeIdentifiers } = require('./helpers.js')
const createComponents = async (options, createComponentOptions) => {
glob(options.fileMask, options, (err, matches) => {
if (err) {
throw err
}
matches
.filter(filepath => {
const found = getLanguageCodeIdentifiers(createComponentOptions.sourceLanguageCode).filter(lang => {
return filepath.includes(lang, lang.replace(createComponentOptions.sourceLanguageCode))
})
return found.length > 0
})
.forEach(async (file) => {
file = path.relative(options.cwd, file)
console.log(`[+] Creating component for file ${file}`)
let fileName = '';
if (createComponentOptions.isLanguageCodeInFilename === 'Yes') {
fileName = file.split('/').slice(0, file.split('/').length - 1).join('/')
} else {
fileName = file.split('/').pop()
fileName = fileName.split('.')[0]
}
const newOptions = {
...createComponentOptions,
fileName,
file,
}
await createComponent(newOptions)
})
})
}
module.exports = createComponents