Skip to content

Commit

Permalink
Merge pull request #22 from yoloforks/xml-locales-new-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Pisyukaev authored Nov 23, 2023
2 parents 22d9fbc + f2b9e6e commit b76c387
Show file tree
Hide file tree
Showing 27 changed files with 495 additions and 549 deletions.
2 changes: 0 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
"dependencies": {
"@inquirer/prompts": "3.3.0",
"@types/yargs": "17.0.32",
"fast-xml-parser": "^4.3.2",
"xml-formatter": "^3.6.0",
"xml-locales": "workspace:0.0.3",
"yargs": "17.7.2"
}
Expand Down
47 changes: 47 additions & 0 deletions packages/cli/src/commands/add.ts
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());
}
}
58 changes: 0 additions & 58 deletions packages/cli/src/commands/addString.ts

This file was deleted.

63 changes: 0 additions & 63 deletions packages/cli/src/commands/change.ts

This file was deleted.

50 changes: 0 additions & 50 deletions packages/cli/src/commands/delString.ts

This file was deleted.

16 changes: 7 additions & 9 deletions packages/cli/src/commands/index.ts
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
];
43 changes: 0 additions & 43 deletions packages/cli/src/commands/newLocale.ts

This file was deleted.

53 changes: 53 additions & 0 deletions packages/cli/src/commands/remove.ts
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());
}
}
Loading

0 comments on commit b76c387

Please sign in to comment.