wuchale
Version:
Protobuf-like i18n from normal code
73 lines (71 loc) • 2.35 kB
JavaScript
import { configName, getConfig } from "../config.js";
import { parseArgs } from 'node:util';
import { color, Logger } from "../log.js";
import { extract } from "./extract.js";
import { init } from "./init.js";
import { status } from "./status.js";
const { positionals, values } = parseArgs({
options: {
config: {
type: 'string',
},
clean: {
type: 'boolean',
short: 'c',
},
watch: {
type: 'boolean',
short: 'w',
},
force: {
type: 'boolean',
short: 'f',
},
help: {
type: 'boolean',
short: 'h',
}
},
allowPositionals: true,
});
const cmd = positionals[0];
const help = `
Usage:
${color.cyan('wuchale [command] {options}')}
Commands:
${color.grey('[none]')} Extract/compile messages from the codebase into catalogs
deleting unused messages if ${color.cyan('--clean')} is specified
${color.cyan('init')} Initialize on a codebase
${color.cyan('status')} Show current status
Options:
${color.cyan('--config')} use another config file instead of ${color.cyan(configName)}
${color.cyan('--clean')}, ${color.cyan('-c')} (only when no commands) remove unused messages from catalogs
${color.cyan('--watch')}, ${color.cyan('-w')} (only when no commands) continuously watch for file changes
${color.cyan('--force')}, ${color.cyan('-f')} (only on ${color.cyan('init')}) overwrite loader file even if not empty
${color.cyan('--help')}, ${color.cyan('-h')} Show this help
`;
const logger = new Logger(true);
async function getConfigNLocales() {
const config = await getConfig(values.config);
const locales = [config.sourceLocale, ...config.otherLocales];
return [config, locales];
}
if (values.help) {
logger.log('wuchale cli');
logger.log(help.trimEnd());
}
else if (cmd == null) {
await extract(...await getConfigNLocales(), logger, values.clean, values.watch);
}
else if (cmd === 'init') {
await init(...await getConfigNLocales(), values.force, logger);
}
else if (cmd === 'status') {
await status(...await getConfigNLocales(), logger);
}
else {
logger.warn(`Unknown command: ${cmd}`);
logger.log(help);
}
//# sourceMappingURL=index.js.map