Skip to content

Commit

Permalink
⏪️ use sync code
Browse files Browse the repository at this point in the history
Signed-off-by: Vinicius Reis <vinicius.reis@nextcloud.com>
  • Loading branch information
Vinicius Reis committed Sep 21, 2022
1 parent 4effc6f commit d96361e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
14 changes: 6 additions & 8 deletions resources/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
*
*/
const { join, basename } = require('path')
const fs = require('fs/promises')
const fs = require('fs')
const gettextParser = require('gettext-parser')

// https://github.com/alexanderwallin/node-gettext#usage
// https://github.com/alexanderwallin/node-gettext#load-and-add-translations-from-mo-or-po-files
const parseFile = async (fileName) => {
const parseFile = (fileName) => {
const locale = basename(fileName).slice(0, -'.pot'.length)
const po = await fs.readFile(fileName)
const po = fs.readFileSync(fileName)

const json = gettextParser.po.parse(po)

Expand Down Expand Up @@ -55,15 +55,13 @@ const parseFile = async (fileName) => {
}
}

const loadTranslations = async (baseDir) => {
const files = await fs.readdir(baseDir)
const loadTranslations = (baseDir) => {
const files = fs.readdirSync(baseDir)

const promises = files
return files
.filter(name => name !== 'messages.pot' && name.endsWith('.pot'))
.map(file => join(baseDir, file))
.map(parseFile)

return Promise.all(promises)
}

module.exports = {
Expand Down
5 changes: 2 additions & 3 deletions styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ const { merge } = require('webpack-merge')
const webpackConfig = require('./webpack.config.js')

module.exports = async () => {
const base = await webpackConfig()
const newConfig = Object.assign({}, base, {
const newConfig = Object.assign({}, webpackConfig, {
externals: {},
module: {
// Ignore eslint
rules: base.module.rules.filter(
rules: webpackConfig.module.rules.filter(
rule => rule.use !== 'eslint-loader'
),
},
Expand Down
36 changes: 17 additions & 19 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,27 @@ const config = {
},
}

module.exports = async () => {
const translations = await loadTranslations(path.resolve(__dirname, './l10n'))
const translations = loadTranslations(path.resolve(__dirname, './l10n'))

config.plugins.push(new DefinePlugin({
SCOPE_VERSION,
TRANSLATIONS: JSON.stringify(translations),
}))
config.plugins.push(new DefinePlugin({
SCOPE_VERSION,
TRANSLATIONS: JSON.stringify(translations),
}))

if (libraryTarget !== 'umd') {
config.experiments = {
outputModule: true,
}
if (libraryTarget !== 'umd') {
config.experiments = {
outputModule: true,
}

config.entry = {
index: path.join(__dirname, 'src', 'index.js'),
}
config.entry = {
index: path.join(__dirname, 'src', 'index.js'),
}

config.output.filename = `[name].${libraryTarget}.js`
config.output.filename = `[name].${libraryTarget}.js`

config.externals = [...config.externals, ...Object.keys(dependencies)]
config.externals = [...config.externals, ...Object.keys(dependencies)]

delete config.output.library.name
}

return config
delete config.output.library.name
}

module.exports = config

0 comments on commit d96361e

Please sign in to comment.