-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
63 lines (58 loc) · 1.68 KB
/
index.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 path = require('path')
const fs = require('fs')
const Input = require('./lib/input')
const Ouput = require('./lib/output')
const chalk = require('chalk')
const Warn = console.warn
const Error = console.error
module.exports = function (rootPath) {
let projectPath = rootPath ? path.resolve(__dirname, rootPath) : path.join(__dirname, '../..')
;(function () {
while (projectPath.split(path.sep).filter(p => p).length !== 1) {
if (fs.readdirSync(projectPath).includes('package.json')) {
return
}
projectPath = path.resolve(projectPath, '..')
}
Error(chalk.red('Error: Not a node repository (or any of the parent directories): package.json'))
process.exit(1)
})()
// Read config
let config = {}
try {
config = require(path.join(projectPath, 'config/index.js'))
} catch (e) {
Warn(chalk.yellow(
chalk.bgYellow.black(' WARN '),
'No config/index.js. Read webpack.config.js'
))
try {
config = require(path.join(projectPath, 'webpack.config.js'))
} catch (e) {
Error(chalk.red(
chalk.bgRed.black(' ERROR '),
'No any config file'
))
}
}
// Default path config
const indexEntry = {
entry: 'src',
input: 'src/i18n/index.xlsx',
output: 'src/i18n/index.js'
}
const {
i18n = {
index: indexEntry
}
} = config
// Output to excel && Output to js
Object.values(i18n).forEach(({
entry = indexEntry.entry,
input = indexEntry.input,
output = indexEntry.output
}) => {
Input(path.join(projectPath, entry), path.join(projectPath, input), projectPath)
Ouput(path.join(projectPath, input), path.join(projectPath, output), projectPath)
})
}