You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
7 years ago
|
/*
|
||
7 years ago
|
* This is a Webpack loader that loads the language data by running
|
||
|
* dump_selected.php.
|
||
7 years ago
|
*/
|
||
|
|
||
7 years ago
|
const { spawnSync } = require('child_process')
|
||
|
const path = require('path')
|
||
7 years ago
|
const selectedKeys = require('./js-keys')
|
||
7 years ago
|
|
||
|
module.exports = function (source) {
|
||
7 years ago
|
let child = spawnSync(path.resolve(__dirname, '_js-dump.php'), selectedKeys, {
|
||
|
timeout: 1000
|
||
7 years ago
|
})
|
||
7 years ago
|
|
||
7 years ago
|
let data
|
||
|
try {
|
||
|
data = JSON.parse(child.stdout.toString().trim())
|
||
|
} catch (err) {
|
||
|
console.error(`\x1b[31;1m[lang-loader] Failed to parse JSON:`)
|
||
|
console.error(child.stdout.toString().trim())
|
||
|
console.error(`\x1b[m`)
|
||
7 years ago
|
|
||
7 years ago
|
if (err) throw err
|
||
7 years ago
|
}
|
||
|
|
||
|
// adapted from webpack/loader-utils
|
||
|
let remainingRequest = this.remainingRequest
|
||
|
if (!remainingRequest) {
|
||
|
remainingRequest = this.loaders.slice(this.loaderIndex + 1)
|
||
|
.map(obj => obj.request)
|
||
|
.concat([this.resource]).join('!')
|
||
|
}
|
||
|
|
||
|
let currentRequest = this.currentRequest
|
||
|
if (!currentRequest) {
|
||
|
remainingRequest = this.loaders.slice(this.loaderIndex)
|
||
|
.map(obj => obj.request)
|
||
|
.concat([this.resource]).join('!')
|
||
|
}
|
||
|
|
||
|
let map = {
|
||
|
version: 3,
|
||
|
file: currentRequest,
|
||
|
sourceRoot: '',
|
||
|
sources: [remainingRequest],
|
||
7 years ago
|
sourcesContent: [source],
|
||
7 years ago
|
names: [],
|
||
|
mappings: 'AAAA;AAAA'
|
||
|
}
|
||
|
|
||
7 years ago
|
this.callback(null,
|
||
|
`/* Generated language file */\n` +
|
||
|
`module.exports=${JSON.stringify(data)}\n`, map)
|
||
7 years ago
|
}
|