Skip to content

Commit

Permalink
add eslint prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronlamz committed May 19, 2022
1 parent eb06aa9 commit 153679f
Show file tree
Hide file tree
Showing 11 changed files with 1,076 additions and 171 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
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
6 changes: 6 additions & 0 deletions .eslintignore
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
8 changes: 8 additions & 0 deletions .eslintrc
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"]
}
9 changes: 9 additions & 0 deletions .prettierignore
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
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semi: false
singleQuote: true
trailingComma: "none"
endOfLine: "auto"
arrowParens: "avoid"
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ Working in progress.

```javascript
{
"i18n": {
"zhCHT": {
"zh_CN": {
"KEY_1": "简体中文",
},
"zhCHS": {
"KEY_1": "英文",
},
"en": {
"KEY_1": "繁体中文",
}
"zh_HK": {
"KEY_1": "繁体中文",
},
"en": {
"KEY_1": "英文",
}
}
```
Expand Down
136 changes: 68 additions & 68 deletions bin/index.js
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()
}
154 changes: 77 additions & 77 deletions index.js
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
Loading

0 comments on commit 153679f

Please sign in to comment.