Rename cli script filename. Rename option 'dir' to 'input'

This commit is contained in:
Kim Biesbjerg 2017-03-20 15:51:38 +01:00
parent 72739f2e9a
commit f61cdc4064
4 changed files with 23 additions and 18 deletions

3
bin/cli.js Executable file
View File

@ -0,0 +1,3 @@
#! /usr/bin/env node
require('../dist/cli/cli');

View File

@ -1,3 +0,0 @@
#! /usr/bin/env node
require('../dist/cli/extract');

View File

@ -1,5 +1,5 @@
export interface CliOptionsInterface { export interface CliOptionsInterface {
dir: string[]; input: string[];
output: string[]; output: string[];
format: 'json' | 'namespaced-json' | 'pot'; format: 'json' | 'namespaced-json' | 'pot';
replace: boolean; replace: boolean;

View File

@ -18,18 +18,28 @@ import * as yargs from 'yargs';
const options: CliOptionsInterface = yargs const options: CliOptionsInterface = yargs
.usage('Extract strings from files for translation.\nUsage: $0 [options]') .usage('Extract strings from files for translation.\nUsage: $0 [options]')
.help('help') .help('h')
.option('dir', { .alias('h', 'help')
alias: 'd', .option('input', {
describe: 'Paths you would like to extract strings from. Multiple paths can be specified', alias: ['i', 'dir', 'd'],
describe: 'Paths you would like to extract strings from. You can use path expansion, glob patterns and multiple paths',
default: process.env.PWD, default: process.env.PWD,
type: 'array' type: 'array',
})
.check((options: CliOptionsInterface) => {
options.input.forEach(dir => {
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
throw new Error(`The path you supplied was not found: '${dir}'`)
}
});
return true;
}) })
.option('output', { .option('output', {
alias: 'o', alias: 'o',
describe: 'Path you would like to save extracted strings to. Multiple paths can be specified', describe: 'Paths where you would like to save extracted strings. You can use path expansion, glob patterns and multiple paths',
default: process.env.PWD, type: 'array',
type: 'array' required: true
}) })
.option('format', { .option('format', {
alias: 'f', alias: 'f',
@ -91,13 +101,8 @@ let extractedStrings: TranslationCollection = new TranslationCollection();
// Extract strings from paths // Extract strings from paths
console.log(chalk.bold('Extracting strings from...')); console.log(chalk.bold('Extracting strings from...'));
options.dir.forEach(dir => { options.input.forEach(dir => {
const normalizedDir: string = path.resolve(dir); const normalizedDir: string = path.resolve(dir);
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
console.log(`The path you supplied was not found: '${dir}'`);
process.exit(1);
}
console.log(chalk.gray('- %s'), normalizedDir); console.log(chalk.gray('- %s'), normalizedDir);
extractedStrings = extractedStrings.union(extractor.process(normalizedDir)); extractedStrings = extractedStrings.union(extractor.process(normalizedDir));
}); });