-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Pisyukaev/refactor-core-package
- Loading branch information
Showing
17 changed files
with
201 additions
and
465 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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
# @xml-locales/cli | ||
|
||
## 0.0.5 | ||
|
||
### Patch Changes | ||
|
||
- Updated dependencies | ||
- [email protected] | ||
|
||
## 0.0.4 | ||
|
||
### Patch Changes | ||
|
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
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,79 +1,30 @@ | ||
import { checkKeyExist, replaceValue } from '../utils/files.js'; | ||
// import { hasConflict } from '../../../cli/src/utils/queries.js'; | ||
import { checkKeyExist, replaceValue } from '../utils/helpers.js'; | ||
import { sort } from './sort.js'; | ||
import type { XmlJson } from '../utils/types.js'; | ||
import type { AddOptions } from '../utils/types.js'; | ||
|
||
export function add(options: { | ||
key: string; | ||
value: string; | ||
directory: string; | ||
sort?: 'asc' | 'desc'; | ||
accept: boolean; | ||
}) { | ||
let REPLACE_ALL = false; | ||
let NEED_REPLACE = false; | ||
export function add({ key, value, sortDirection, jsonXml }: AddOptions) { | ||
const { | ||
resources: { string } | ||
} = jsonXml; | ||
|
||
return async function ({ | ||
filePath, | ||
jsonXml | ||
}: { | ||
filePath: string; | ||
jsonXml: XmlJson; | ||
}) { | ||
const { key, value, sort: sortDirection, accept } = options; | ||
const hasKey = checkKeyExist(key, string); | ||
|
||
if (accept) { | ||
REPLACE_ALL = true; | ||
} | ||
if (hasKey) { | ||
const replacedStrings = replaceValue(string, key, value); | ||
|
||
const { | ||
resources: { string } | ||
} = jsonXml; | ||
jsonXml.resources.string = replacedStrings; | ||
} | ||
|
||
const hasKey = checkKeyExist(key, string); | ||
if (!hasKey) { | ||
jsonXml.resources.string.push({ | ||
key_name: key, | ||
'#text': value | ||
}); | ||
} | ||
|
||
// if (!REPLACE_ALL && hasKey) { | ||
// const answer = await hasConflict(filePath); | ||
if (sortDirection) { | ||
sort({ sortDirection, jsonXml }); | ||
} | ||
|
||
// switch (answer) { | ||
// case 'yes': { | ||
// NEED_REPLACE = true; | ||
// break; | ||
// } | ||
// case 'all': { | ||
// REPLACE_ALL = true; | ||
// break; | ||
// } | ||
// case 'skip': { | ||
// NEED_REPLACE = false; | ||
// break; | ||
// } | ||
|
||
// default: | ||
// console.log('Cancelled'); | ||
// return; | ||
// } | ||
// } | ||
|
||
const needReplace = REPLACE_ALL || NEED_REPLACE; | ||
|
||
if (needReplace) { | ||
const replacedStrings = replaceValue(string, key, value); | ||
|
||
jsonXml.resources.string = replacedStrings; | ||
} | ||
|
||
if (!hasKey) { | ||
jsonXml.resources.string.push({ | ||
key_name: key, | ||
'#text': value | ||
}); | ||
} | ||
|
||
if (sortDirection) { | ||
sort({ direction: sortDirection })({ jsonXml }); | ||
} | ||
|
||
return jsonXml; | ||
}; | ||
return jsonXml; | ||
} |
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,71 +1,28 @@ | ||
import { checkKeyValueExist, replace } from '../utils/files.js'; | ||
// import { hasConflict } from '../../../cli/src/utils/queries.js'; | ||
import { checkKeyValueExist, replace } from '../utils/helpers.js'; | ||
import { sort } from './sort.js'; | ||
import type { XmlJson } from '../utils/types.js'; | ||
import type { ChangeOptions } from '../utils/types.js'; | ||
|
||
export function change(options: { | ||
oldKey: string; | ||
newKey: string; | ||
sort?: 'asc' | 'desc'; | ||
accept: boolean; | ||
}) { | ||
let REPLACE_ALL = false; | ||
let NEED_REPLACE = false; | ||
export function change({ | ||
oldKey, | ||
newKey, | ||
sortDirection, | ||
jsonXml | ||
}: ChangeOptions) { | ||
const { | ||
resources: { string } | ||
} = jsonXml; | ||
|
||
return async function ({ | ||
filePath, | ||
jsonXml | ||
}: { | ||
filePath: string; | ||
jsonXml: XmlJson; | ||
}) { | ||
const { oldKey, newKey, sort: sortDirection, accept } = options; | ||
const hasKey = checkKeyValueExist(oldKey, string); | ||
|
||
if (accept) { | ||
REPLACE_ALL = true; | ||
} | ||
if (hasKey) { | ||
const replacedStrings = replace(string, oldKey, newKey); | ||
|
||
const { | ||
resources: { string } | ||
} = jsonXml; | ||
jsonXml.resources.string = replacedStrings; | ||
} | ||
|
||
const hasKey = checkKeyValueExist(oldKey, string); | ||
if (sortDirection) { | ||
sort({ sortDirection, jsonXml }); | ||
} | ||
|
||
// if (!REPLACE_ALL && hasKey) { | ||
// const answer = await hasConflict(filePath); | ||
|
||
// switch (answer) { | ||
// case 'yes': { | ||
// NEED_REPLACE = true; | ||
// break; | ||
// } | ||
// case 'all': { | ||
// REPLACE_ALL = true; | ||
// break; | ||
// } | ||
// case 'skip': { | ||
// NEED_REPLACE = false; | ||
// break; | ||
// } | ||
|
||
// default: | ||
// console.log('Cancelled'); | ||
// return; | ||
// } | ||
// } | ||
|
||
const needReplace = REPLACE_ALL || NEED_REPLACE; | ||
|
||
if (needReplace) { | ||
const replacedStrings = replace(string, oldKey, newKey); | ||
|
||
jsonXml.resources.string = replacedStrings; | ||
} | ||
|
||
if (sortDirection) { | ||
sort({ direction: sortDirection })({ jsonXml }); | ||
} | ||
|
||
return jsonXml; | ||
}; | ||
return jsonXml; | ||
} |
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,72 +1,26 @@ | ||
// import { checkKeyValueExist } from '../utils/files.js'; | ||
// import { deleteAnswer } from '../../../cli/src/utils/queries.js'; | ||
import { checkKeyValueExist } from '../utils/helpers.js'; | ||
import { sort } from './sort.js'; | ||
import type { XmlJson } from '../utils/types.js'; | ||
import type { DeleteOptions } from '../utils/types.js'; | ||
|
||
export function del(options: { | ||
keyValue: string; | ||
sort?: 'asc' | 'desc'; | ||
accept: boolean; | ||
}) { | ||
let DELETE_ALL = false; | ||
let NEED_DELETE = false; | ||
export function del({ keyValue, sort: sortDirection, jsonXml }: DeleteOptions) { | ||
const { | ||
resources: { string } | ||
} = jsonXml; | ||
|
||
return async function delString({ | ||
filePath, | ||
jsonXml | ||
}: { | ||
filePath: string; | ||
jsonXml: XmlJson; | ||
}) { | ||
const { keyValue, sort: sortDirection, accept } = options; | ||
const hasKeyValue = checkKeyValueExist(keyValue, string); | ||
|
||
if (accept) { | ||
DELETE_ALL = true; | ||
} | ||
if (hasKeyValue) { | ||
const filteredStrings = string.filter( | ||
(element) => | ||
element['#text'] !== keyValue && element.key_name !== keyValue | ||
); | ||
|
||
const { | ||
resources: { string } | ||
} = jsonXml; | ||
jsonXml.resources.string = filteredStrings; | ||
} | ||
|
||
// const hasKeyValue = checkKeyValueExist(keyValue, string); | ||
// if (!accept && !DELETE_ALL && hasKeyValue) { | ||
// const answer = await deleteAnswer(filePath); | ||
if (sortDirection) { | ||
sort({ sortDirection, jsonXml }); | ||
} | ||
|
||
// switch (answer) { | ||
// case 'yes': { | ||
// NEED_DELETE = true; | ||
// break; | ||
// } | ||
// case 'all': { | ||
// DELETE_ALL = true; | ||
// break; | ||
// } | ||
// case 'skip': { | ||
// NEED_DELETE = false; | ||
// break; | ||
// } | ||
|
||
// default: | ||
// console.log('Cancelled'); | ||
// return; | ||
// } | ||
// } | ||
|
||
const needDelete = DELETE_ALL || NEED_DELETE; | ||
|
||
if (needDelete) { | ||
const filteredStrings = string.filter( | ||
(element) => | ||
element['#text'] !== keyValue && element.key_name !== keyValue | ||
); | ||
|
||
jsonXml.resources.string = filteredStrings; | ||
} | ||
|
||
if (sortDirection) { | ||
sort({ direction: sortDirection })({ jsonXml }); | ||
} | ||
|
||
return jsonXml; | ||
}; | ||
return jsonXml; | ||
} |
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
Oops, something went wrong.