Skip to content

Commit

Permalink
fixed lint, added missing package which code depends on
Browse files Browse the repository at this point in the history
  • Loading branch information
m1lk1way committed May 15, 2019
1 parent 36fc987 commit 5eed5d6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 65 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"no-console": 0,
"no-use-before-define": ["error", { "variables": false }],
"max-len": ["error", { "code": 160 }],
"import/prefer-default-export": 0
"import/prefer-default-export": 0,
"class-methods-use-this": "off"
}
}
37 changes: 13 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"inquirer": "^6.2.2",
"inquirer-autocomplete-prompt": "^1.0.1",
"js-string-escape": "^1.0.1",
"xml2json": "^0.11.2"
"xml2json": "^0.11.2",
"glob": "^7.1.4"
},
"devDependencies": {
"eslint": "^5.15.3",
Expand Down
87 changes: 48 additions & 39 deletions utils/coreResxProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,38 @@ const parser = require('xml2json');

class CoreResxFile {
/**
* @param {String} fullPath
* @param {String} resxRootPath
* @param {String} fullPath
* @param {String} resxRootPath
*/
constructor(fullPath, resxRootPath) {
this.fullPath = fullPath;
this.lang = this.getLang(fullPath.toLowerCase());

let name = fullPath.substring(resxRootPath.length + 1).toLowerCase();
this.name = name.replace(`.${this.lang}.`, ".");
const name = fullPath.substring(resxRootPath.length + 1).toLowerCase();
this.name = name.replace(`.${this.lang}.`, '.');
}

getContent() {
let resolve, reject;
let promise = new Promise((r, rej) => {
let resolve,
reject;

const promise = new Promise((r, rej) => {
resolve = r;
reject = rej;
});

if(this._content) {
resolve(this._content);
}else {
if (this.content) {
resolve(this.content);
}

else {
fs.readFile(this.fullPath, (err, fileContent) => {
if(err) {
if (err) {
reject(err);
} else {
this._content = JSON.parse(parser.toJson(fileContent));
resolve(this._content);
}
else {
this.content = JSON.parse(parser.toJson(fileContent));
resolve(this.content);
}
});
}
Expand All @@ -39,26 +44,26 @@ class CoreResxFile {
}

async getKeys() {
let content = await this.getContent();
const content = await this.getContent();
return content.root.data.map(x => x.name);
}

async getKeyValue(key) {
let content = await this.getContent();
let node = content.root.data.find(x => x.name === key);
const content = await this.getContent();
const node = content.root.data.find(x => x.name === key);
return node && node.value;
}

/**
* @param {String} path
* @param {String} path
*/
getLang(path) {
let regex = new RegExp(`\\.(\\w\\w)\\.resx$`)
let match = regex.exec(path);
if(match) {
const regex = new RegExp('\\.(\\w\\w)\\.resx$');
const match = regex.exec(path);
if (match) {
return match[1].toLowerCase();
}
return "en";
return 'en';
}

toJSON() {
Expand All @@ -68,33 +73,37 @@ class CoreResxFile {

class CoreResxProvider {
/**
* @param {String} corePath
* @param {String} corePath
*/
constructor(corePath) {
this.corePath = corePath.replace(/\/$/, "");
this.corePath = corePath.replace(/\/$/, '');
this.resxProjectPath = `${this.corePath}/LogicSoftware.EasyProjects.Resources`;
}

/**
* @returns {Promise<CoreResxFile[]>}
*/
readAllFiles() {
let resolve, reject;
let promise = new Promise((r, rej) => {
readAllFiles() {
let resolve,
reject;

const promise = new Promise((r, rej) => {
resolve = r;
reject = rej;
});

if(!this.files) {
if (!this.files) {
glob(`${this.resxProjectPath}/**/*.resx`, null, (err, files) => {
if(err){
if (err) {
reject(err);
}else {
}
else {
this.files = files.map(f => new CoreResxFile(f, this.resxProjectPath));
resolve(this.files);
}
});
} else {
}
else {
resolve(this.files);
}
return promise;
Expand All @@ -105,19 +114,19 @@ class CoreResxProvider {
* @returns {Promise<CoreResxFile[]>}
*/
async getResxFiles() {
let files = await this.readAllFiles();
return files.filter(x => x.lang === "en");
const files = await this.readAllFiles();
return files.filter(x => x.lang === 'en');
}

/**
*
* @param {String} name
* @param {String} lang
*
* @param {String} name
* @param {String} lang
*/
async getFile(name, lang = "en") {
let files = await this.readAllFiles();
async getFile(name, lang = 'en') {
const files = await this.readAllFiles();
return files.find(x => x.name === name && x.lang === lang);
}
}

module.exports = CoreResxProvider;
module.exports = CoreResxProvider;

0 comments on commit 5eed5d6

Please sign in to comment.