-
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.
feat: added command to create new localization file from master file
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
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,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 | ||
]; |
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,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 }); | ||
} |
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,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}`); | ||
}); | ||
} |