vue-i18n-customized-extractor
Version:
A CLI tool to extract text and i18n keys from Vue.js files.
41 lines (35 loc) • 1.77 kB
JavaScript
// NOTES: The above line should be at the top of /bin/cli.js. It means: This is a Node.js script — please run it with Node.
const extractor = require('../index.js');
// Read targetDir from CLI args
const args = process.argv.slice(2);
const targetDir = args.findIndex(arg => arg.startsWith('--path='))
const includeT = args.includes('--include-t');
const pageKeys = args.findIndex(arg => arg.startsWith('--keys='))
const configFilePath = args.findIndex(arg => arg.startsWith('--config='));
const templateOnly = args.includes('--template-only');
if (args.includes('--help')) {
console.log(`
Usage: vue-i18n-customized-extractor [options]
Options:
--path=<directory> Specify the target directory to extract translations from (default: ./src)
--include-t Include $t() function calls in the extraction
--keys=<keys> Specify page keys used for customized components mapping to extract, separated by commas
--config=<file> Specify the configuration file path (default: vue-i18n-customized-extractor.config.cjs)
--template-only Extract translations only from templates
--help Show this help message
`);
process.exit(0);
}
console.log(`Extracting from: ${targetDir}`);
console.log(`Include $t()? ${includeT}`);
console.log(`Extracting from: ${process.cwd()}`);
extractor.run(
targetDir !== -1 ? args[targetDir].split('=')[1] : './src',
{
includeT,
pageKeys: pageKeys !== -1 ? args[pageKeys].split('=')[1].split(',') : [],
configFilePath: configFilePath !== -1 ? args[configFilePath].split('=')[1] : 'vue-i18n-customized-extractor.config.cjs',
templateOnly,
}
);