messages-combiner
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

Messages Combiner

Messages Combiner is a library designed to facilitate the combination and organization of localization message files. It provides a CLI tool and programmatic API to watch for changes in message files, combine them based on specified namespaces, and output the combined messages into separate files for each language.

Usage

Example 1: Execute via CLI

npx messages-combiner -p /path/to/your/project -o /path/to/output

For more options, please refer to the Options description below.

Example 2: Execute via Programmatic API

import { combineWatcher,combine } from 'messages-combiner';

startWatcher('/path/to/your/project', {
    basePath:'src',
    output:'/path/to/output',
    namespace:{
        '/locales/**/*':'common',
        '/app/**/*':'page',
        '/components/**/*':'component',
    },
    // you can also use config file to define options, The default is mcombiner.json relative your path argument
    configFile:'pathto/my_mcombiner.json',
});
combine('/path/to/your/project', {
    // same as above
})

Options

Options:

  • -p, --path : Path to watch. This is a required option that specifies the directory where your message files are located.
  • -w, --watch : Watch the file changes. default is true.
  • -o, --output : Output directory. This optional parameter specifies the directory where the combined message files will be saved. Default is i18n/messages.
  • -n, --namespace : Namespace mapping in JSON format. This optional parameter allows you to define custom namespaces to organize your message files.
  • -b, --base-path : Base path for the watcher. This optional parameter specifies the base path for the watcher.
  • -c, --config-file : Configuration file for the watcher. This optional parameter allows you to specify a configuration file that contains the options for the watcher.

You can also use a configuration file to define the options. The configuration file is a JSON file that contains the options for the watcher. The configuration file is located in the root directory of your project. The configuration file is named .mcombiner.json.

Configuration File

The configuration file is a JSON file that contains the options for the watcher. The configuration file is located in the root directory of your project. The configuration file is named .mcombiner.json.

{
    "basePath":"src",
    "output":"i18n/messages",
    "namespace":{
        "/locales/**/*":"common",
        "/app/**/*":"page",
        "/components/**/*":"component"
    }
}

Key Features:

  • Namespace Mapping: Define custom namespaces to organize your message files.
  • File Watching: Automatically watch for changes in your message files and update the combined output accordingly.
  • Configurable Output: Specify the output directory for the combined message files.
  • CLI and Programmatic API: Use the provided CLI tool for quick setup or integrate the library programmatically into your project.

How It Works:

  1. Watch for Changes: The library uses chokidar to watch for changes in the specified directory.
  2. Combine Messages: When a change is detected, the library reads the message files, applies namespace mappings, and combines the messages.
  3. Output Combined Messages: The combined messages are written to separate files for each language in the specified output directory.

Readme

Keywords

none

Package Sidebar

Install

npm i messages-combiner

Weekly Downloads

8

Version

0.0.6

License

MIT

Unpacked Size

41.6 kB

Total Files

21

Last publish

Collaborators

  • qq651088004