-
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 #22 from yoloforks/xml-locales-new-api
- Loading branch information
Showing
27 changed files
with
495 additions
and
549 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
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,47 @@ | ||
import type { ArgumentsCamelCase, Argv } from 'yargs'; | ||
|
||
import { readFiles, writeFile } from '../utils/files.js'; | ||
|
||
export const command = 'add'; | ||
export const description = 'Add one localization string in files'; | ||
|
||
export function builder(yargs: Argv) { | ||
return yargs | ||
.option('path', { | ||
alias: 'p', | ||
desc: 'Path of file or directory to adding string', | ||
demandOption: true, | ||
type: 'string', | ||
default: process.cwd() | ||
}) | ||
.option('key', { | ||
alias: 'k', | ||
desc: 'Key of adding string', | ||
demandOption: true, | ||
type: 'string' | ||
}) | ||
.option('value', { | ||
alias: 'v', | ||
desc: 'Value of adding string', | ||
demandOption: true, | ||
type: 'string' | ||
}) | ||
.usage( | ||
`\nExample:\n $0 ${command} --path "path/to/file/or/directory" --key "some_key" --value "some_value"` | ||
); | ||
} | ||
|
||
export async function handler({ | ||
key, | ||
value, | ||
path | ||
}: ArgumentsCamelCase<{ | ||
key: string; | ||
value: string; | ||
path: string; | ||
}>) { | ||
const files = await readFiles(path); | ||
for (const [path, file] of files) { | ||
await writeFile(path, file.add({ key, value }).toXML()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,13 +1,11 @@ | ||
import * as addString from './addString.js'; | ||
import * as change from './change.js'; | ||
import * as delString from './delString.js'; | ||
import * as newLocale from './newLocale.js'; | ||
import * as add from './add.js'; | ||
import * as remove from './remove.js'; | ||
import * as sort from './sort.js'; | ||
import * as update from './update.js'; | ||
|
||
export const commands = [ | ||
addString, | ||
delString, | ||
sort, | ||
change, | ||
newLocale | ||
add, | ||
update, | ||
remove, | ||
sort | ||
]; |
This file was deleted.
Oops, something went wrong.
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,53 @@ | ||
import type { ArgumentsCamelCase, Argv } from 'yargs'; | ||
|
||
import { readFiles, writeFile } from '../utils/files.js'; | ||
|
||
export const command = 'remove'; | ||
export const description = 'Remove one localization string in files'; | ||
|
||
export function builder(yargs: Argv) { | ||
return yargs | ||
.option('path', { | ||
alias: 'p', | ||
desc: 'Path of file or directory to adding string', | ||
demandOption: true, | ||
type: 'string', | ||
default: process.cwd() | ||
}) | ||
.option('key', { | ||
alias: 'k', | ||
desc: 'Key of remove string', | ||
type: 'string' | ||
}) | ||
.option('value', { | ||
alias: 'v', | ||
desc: 'Value of remove string', | ||
type: 'string' | ||
}) | ||
.usage( | ||
`\nExample:\n ${command} --path "path/to/file/or/directory" --key "some_key" --value "or_some_value"` | ||
); | ||
} | ||
|
||
export async function handler({ | ||
key, | ||
value, | ||
path | ||
}: ArgumentsCamelCase<{ | ||
key: string; | ||
value: string; | ||
path: string; | ||
}>) { | ||
const files = await readFiles(path); | ||
for (let [path, file] of files) { | ||
if (key) { | ||
file = file.deleteByKey(key); | ||
} | ||
|
||
if (value) { | ||
file = file.deleteByValue(value); | ||
} | ||
|
||
await writeFile(path, file.toXML()); | ||
} | ||
} |
Oops, something went wrong.