This repository has been archived by the owner on Apr 22, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
report.js
63 lines (53 loc) · 1.48 KB
/
report.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { chalk } = require(require.resolve('@vue/cli-shared-utils'))
const { resolve } = require('path')
const i18nExtract = require('vue-i18n-extract').default
const EXTRACT_MISSING = 1
const EXTRACT_UNUSED = 2
const EXTRACT_ALL = 3
const options = {
description: 'vue-i18n report',
usage: 'vue-cli-service i18n:report [options]',
options: {
locales: 'target locale files path, required',
src: 'target source codes path, required',
type: 'reporting type, default `missing` and `unused` all, optional',
output: 'create a json file out of report, optional'
}
}
function resolveReportType(args) {
let type = EXTRACT_ALL
if (args.type === 'missing') {
type = EXTRACT_MISSING
} else if (args.type === 'unused') {
type = EXTRACT_UNUSED
}
return type
}
async function service(args = {}, api) {
if (!args.src) {
console.log(chalk.red(`not specified 'src' argument.`))
return
}
if (!args.locales) {
console.log(chalk.red(`not specified 'locales' argument.`))
return
}
const currentDir = process.cwd()
const srcFiles = resolve(currentDir, args.src)
const localeFiles = resolve(currentDir, args.locales)
const extractType = resolveReportType(args)
const i18nReport = i18nExtract.createI18NReport(
srcFiles,
localeFiles,
extractType
)
i18nExtract.logI18NReport(i18nReport)
if (args.output) {
await i18nExtract.writeReportToFile(i18nReport, args.output)
}
return i18nReport
}
module.exports = {
service,
options
}