Skip to content

Commit

Permalink
feat: added command to create new localization file from master file
Browse files Browse the repository at this point in the history
  • Loading branch information
Pisyukaev committed Nov 15, 2023
1 parent 6b30b3f commit c864592
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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 sort from './sort.js';

export const commands = [
addString,
delString,
sort,
change
change,
newLocale
];
41 changes: 41 additions & 0 deletions src/commands/newLocale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { ArgumentsCamelCase, Argv } from 'yargs';

import { newLocale } from '../modifiers/newLocale';

export const command = 'new';
export const description = 'Create new localization file from master file';

export function builder(yargs: Argv) {
return yargs
.option('name', {
alias: 'n',
desc: 'Name of new localization file',
demandOption: true,
type: 'string'
})
.option('master', {
alias: 'm',
desc: 'Master localization file',
demandOption: true,
type: 'string'
})
.option('directory', {
alias: 'dir',
desc: 'Directory of localization files',
type: 'string',
default: 'mock'
})
.usage(`\nExample:\n $0 ${command} -n strings-kz.xml -m strings.xml`);
}

export async function handler({
name,
master,
directory
}: ArgumentsCamelCase<{
name: string;
master: string;
directory: string;
}>) {
newLocale({ name, master, directory });
}
18 changes: 18 additions & 0 deletions src/modifiers/newLocale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as fs from 'fs';

export function newLocale(options: {
name: string;
master: string;
directory: string;
}) {
const { name, master, directory } = options;

fs.copyFile(`${directory}/${master}`, `${directory}/${name}`, (err) => {
if (err) {
console.error(err);

return;
}
console.log(`${master} was copied to ${directory}/${name}`);
});
}

0 comments on commit c864592

Please sign in to comment.