-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,076 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dist | ||
./jest.config.js | ||
./jest.e2e.config.js | ||
./api-extractor.json | ||
./types | ||
./examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"node": true, | ||
"es6": true | ||
}, | ||
"extends": ["plugin:prettier/recommended"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Ignore artifacts: | ||
dist | ||
types | ||
docs | ||
coverage | ||
tsconfig.json | ||
api-extractor.json | ||
README.md | ||
examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
semi: false | ||
singleQuote: true | ||
trailingComma: "none" | ||
endOfLine: "auto" | ||
arrowParens: "avoid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,75 @@ | ||
#!/usr/bin/env node | ||
const path = require("path"); | ||
const XLSX = require("xlsx"); | ||
const fs = require("fs"); | ||
const program = require("commander"); | ||
const inquirer = require("inquirer"); | ||
const run = require("../index.js"); | ||
const path = require('path') | ||
const XLSX = require('xlsx') | ||
const fs = require('fs') | ||
const program = require('commander') | ||
const inquirer = require('inquirer') | ||
const run = require('../index.js') | ||
const config = require('../package.json') | ||
const workbook = XLSX.readFile("./list.xlsx"); | ||
const sheet_name_list = workbook.SheetNames; | ||
const workbook = XLSX.readFile('./list.xlsx') | ||
const sheet_name_list = workbook.SheetNames | ||
|
||
program.version(config.version).usage("<run>"); | ||
program.arguments("<run>").action(function(cmd) { | ||
var questions = [ | ||
{ | ||
type: "list", | ||
name: "mode", | ||
message: "请选择输出的数据格式", | ||
choices: ["i18n", "array"] | ||
}, | ||
{ | ||
type:'list', | ||
name:'column', | ||
message:'请选择哪一个表格', | ||
choices:sheet_name_list | ||
}, | ||
{ | ||
type: "input", | ||
name: "beginRowNum", | ||
message: "请确保当前目录是否有excel文件,请输入开始的行号(默认为1):" | ||
}, | ||
{ | ||
type: "input", | ||
name: "endRowNum", | ||
message: "请输入结束的行号(默认为10):" | ||
}, | ||
{ | ||
type: "input", | ||
name: "columnKeyZhCHT", | ||
message: "请输入Excel表格繁体列序号(默认为A):" | ||
}, | ||
{ | ||
type: "input", | ||
name: "columnKeyEn", | ||
message: "请输入Excel表格英文列的序号(默认为B):" | ||
}, | ||
{ | ||
type: "input", | ||
name: "columnKeyZhCHS", | ||
message: "请输入Excel表格简体列的序号(默认为C):" | ||
}, | ||
{ | ||
type: "input", | ||
name: "columnCustomKey", | ||
message: "请输入Excel表格自定义KEY的序号(默认为D):" | ||
} | ||
]; | ||
if (cmd === "run") { | ||
inquirer.prompt(questions).then(options => { | ||
console.log(sheet_name_list) | ||
options.column = sheet_name_list.findIndex((element)=>{ | ||
return element === options.column | ||
program.version(config.version).usage('<run>') | ||
program.arguments('<run>').action(function (cmd) { | ||
var questions = [ | ||
{ | ||
type: 'list', | ||
name: 'mode', | ||
message: '请选择输出的数据格式', | ||
choices: ['i18n', 'array'] | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'column', | ||
message: '请选择哪一个表格', | ||
choices: sheet_name_list | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'beginRowNum', | ||
message: '请确保当前目录是否有excel文件,请输入开始的行号(默认为1):' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'endRowNum', | ||
message: '请输入结束的行号(默认为10):' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'columnKeyZhCHT', | ||
message: '请输入Excel表格繁体列序号(默认为A):' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'columnKeyEn', | ||
message: '请输入Excel表格英文列的序号(默认为B):' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'columnKeyZhCHS', | ||
message: '请输入Excel表格简体列的序号(默认为C):' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'columnCustomKey', | ||
message: '请输入Excel表格自定义KEY的序号(默认为D):' | ||
} | ||
] | ||
if (cmd === 'run') { | ||
inquirer.prompt(questions).then(options => { | ||
console.log(sheet_name_list) | ||
options.column = sheet_name_list.findIndex(element => { | ||
return element === options.column | ||
}) | ||
run(options) | ||
}) | ||
run(options); | ||
}); | ||
} else { | ||
console.error("请输入正确的参数!"); | ||
program.help(); | ||
} | ||
}); | ||
} else { | ||
console.error('请输入正确的参数!') | ||
program.help() | ||
} | ||
}) | ||
|
||
program.parse(process.argv); | ||
program.parse(process.argv) | ||
if (!program.args.length) { | ||
program.help(); | ||
program.help() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,88 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const http = require("http"); | ||
const utils = require("./utils"); | ||
const XLSX = require("xlsx"); | ||
const fs = require('fs') | ||
const path = require('path') | ||
const http = require('http') | ||
const utils = require('./utils') | ||
const XLSX = require('xlsx') | ||
|
||
function run(options) { | ||
const workbook = XLSX.readFile("./list.xlsx"); | ||
const defaultMode = "i18n"; | ||
const sheet_name_list = workbook.SheetNames; | ||
const workbookH5 = workbook.Sheets[sheet_name_list[options.column]]; | ||
const workbook = XLSX.readFile('./list.xlsx') | ||
const defaultMode = 'i18n' | ||
const sheet_name_list = workbook.SheetNames | ||
const workbookH5 = workbook.Sheets[sheet_name_list[options.column]] | ||
|
||
let mode = options.mode || defaultMode; | ||
const mode_i18n = { | ||
i18n: { | ||
zhCHT: {}, | ||
zhCHS: {}, | ||
en: {}, | ||
}, | ||
}; | ||
const mode_array = []; | ||
console.log(options); | ||
let columnKeyZhCHT = options.columnKeyZhCHT | ||
? options.columnKeyZhCHT.toUpperCase() | ||
: "A"; // 默认繁体列表序号 | ||
let columnKeyEn = options.columnKeyEn | ||
? options.columnKeyEn.toUpperCase() | ||
: "B"; // 默认繁体列表序号 | ||
let columnKeyZhCHS = options.columnKeyZhCHS | ||
? options.columnKeyZhCHS.toUpperCase() | ||
: "C"; // 默认繁体列表序号 | ||
let columnCustomKey = options.columnCustomKey | ||
? options.columnCustomKey.toUpperCase() | ||
: "D"; // 自定义Key列表序号 | ||
|
||
let beginRowNum = +options.beginRowNum || 1; // 默认开始行号 | ||
let endRowNum = +options.endRowNum || 10; // 默认结束行 | ||
|
||
let workbookMap = {}; | ||
Object.keys(workbookH5).forEach((key) => { | ||
if (key.indexOf("!") === -1) { | ||
let rowNum = key.match(/\d+/) ? key.match(/\d+/)[0] : 0; | ||
if (rowNum < beginRowNum || rowNum > endRowNum) return; | ||
if (!workbookMap[rowNum]) { | ||
workbookMap[rowNum] = {}; | ||
workbookMap[rowNum][key] = workbookH5[key].v; | ||
} else { | ||
workbookMap[rowNum][key] = workbookH5[key].v; | ||
} | ||
let mode = options.mode || defaultMode | ||
const mode_i18n = { | ||
i18n: { | ||
zhCHT: {}, | ||
zhCHS: {}, | ||
en: {} | ||
} | ||
} | ||
}); | ||
const mode_array = [] | ||
console.log(options) | ||
let columnKeyZhCHT = options.columnKeyZhCHT | ||
? options.columnKeyZhCHT.toUpperCase() | ||
: 'A' // 默认繁体列表序号 | ||
let columnKeyEn = options.columnKeyEn | ||
? options.columnKeyEn.toUpperCase() | ||
: 'B' // 默认繁体列表序号 | ||
let columnKeyZhCHS = options.columnKeyZhCHS | ||
? options.columnKeyZhCHS.toUpperCase() | ||
: 'C' // 默认繁体列表序号 | ||
let columnCustomKey = options.columnCustomKey | ||
? options.columnCustomKey.toUpperCase() | ||
: 'D' // 自定义Key列表序号 | ||
|
||
Object.keys(workbookMap).forEach((rowNum) => { | ||
let customKey = workbookMap[rowNum][`${columnCustomKey}${rowNum}`] || `KEY_${rowNum}`; | ||
let zhCHSKey = `${columnKeyZhCHS}${rowNum}`; | ||
let zhCHTKey = `${columnKeyZhCHT}${rowNum}`; | ||
let enKey = `${columnKeyEn}${rowNum}`; | ||
let beginRowNum = +options.beginRowNum || 1 // 默认开始行号 | ||
let endRowNum = +options.endRowNum || 10 // 默认结束行 | ||
|
||
mode_i18n.i18n.zhCHS[customKey] = workbookMap[rowNum][zhCHSKey]; | ||
mode_i18n.i18n.zhCHT[customKey] = workbookMap[rowNum][zhCHTKey]; | ||
mode_i18n.i18n.en[customKey] = workbookMap[rowNum][enKey]; | ||
let workbookMap = {} | ||
Object.keys(workbookH5).forEach(key => { | ||
if (key.indexOf('!') === -1) { | ||
let rowNum = key.match(/\d+/) ? key.match(/\d+/)[0] : 0 | ||
if (rowNum < beginRowNum || rowNum > endRowNum) return | ||
if (!workbookMap[rowNum]) { | ||
workbookMap[rowNum] = {} | ||
workbookMap[rowNum][key] = workbookH5[key].v | ||
} else { | ||
workbookMap[rowNum][key] = workbookH5[key].v | ||
} | ||
} | ||
}) | ||
|
||
mode_array.push([ | ||
`${workbookMap[rowNum][zhCHSKey]}`, | ||
`${workbookMap[rowNum][zhCHTKey]}`, | ||
`${workbookMap[rowNum][enKey]}`, | ||
]); | ||
}); | ||
Object.keys(workbookMap).forEach(rowNum => { | ||
let customKey = | ||
workbookMap[rowNum][`${columnCustomKey}${rowNum}`] || | ||
`KEY_${rowNum}` | ||
let zhCHSKey = `${columnKeyZhCHS}${rowNum}` | ||
let zhCHTKey = `${columnKeyZhCHT}${rowNum}` | ||
let enKey = `${columnKeyEn}${rowNum}` | ||
|
||
let result = null; | ||
if (mode === "i18n") { | ||
result = mode_i18n; | ||
} else { | ||
result = mode_array; | ||
} | ||
console.log(result); | ||
mode_i18n.i18n.zhCHS[customKey] = workbookMap[rowNum][zhCHSKey] | ||
mode_i18n.i18n.zhCHT[customKey] = workbookMap[rowNum][zhCHTKey] | ||
mode_i18n.i18n.en[customKey] = workbookMap[rowNum][enKey] | ||
|
||
const port = 8881; | ||
http | ||
.createServer((req, res) => { | ||
res.writeHead(200, { "Content-Type": "text/plain;charset=utf-8" }); | ||
res.end(JSON.stringify(result, null, " ")); | ||
mode_array.push([ | ||
`${workbookMap[rowNum][zhCHSKey]}`, | ||
`${workbookMap[rowNum][zhCHTKey]}`, | ||
`${workbookMap[rowNum][enKey]}` | ||
]) | ||
}) | ||
.listen(port); | ||
console.log(`Server running at http://localhost:${port}/`); | ||
utils.openBrowse(`http://localhost:${port}/`); | ||
|
||
let result = null | ||
if (mode === 'i18n') { | ||
result = mode_i18n | ||
} else { | ||
result = mode_array | ||
} | ||
console.log(result) | ||
|
||
const port = 8881 | ||
http.createServer((req, res) => { | ||
res.writeHead(200, { 'Content-Type': 'text/plain;charset=utf-8' }) | ||
res.end(JSON.stringify(result, null, ' ')) | ||
}).listen(port) | ||
console.log(`Server running at http://localhost:${port}/`) | ||
utils.openBrowse(`http://localhost:${port}/`) | ||
} | ||
module.exports = run; | ||
module.exports = run |
Oops, something went wrong.