npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@metrists/cli

v0.0.83

Published

metrists - publish markdown files as a book

Downloads

12

Readme


Downloads Per Month Top Language License: MIT <metrists>

Description

The Metrists CLI is a command-line interface tool that gives you the freedom to store your localization files outside of your source-code.

Metrists cli is intended to be used with a internationalization library. We highly recommend that you use i18next with Metrists.

Table of Contents

Installation

npm install -g @metrists/cli

Sync using a GitHub Repository

Setup a locals GitHub Repository

Create a repository with the following structure; or alternatively, clone our example repository.

en/
├─ default/
│  ├─ footer/
│  │  ├─ copyright.json/
│  ├─ welcome.json
fr/
├─ default/
│  ├─ footer/
│  │  ├─ copyright.json/
│  ├─ welcome.json

Metrists uses ISO 639-1 language codes standard for your top level folder names. Your second level of files/directories specify the localization namespaces. Inside each namespace, you can nested create directories and json files.

🌕 The file structure always follows the pattern: {language}/{namespace}/{file_key}.json.

The file /en/default/welcome.json contains the following content:

{
  "TITLE": "Metrists is great"
}

You can access the phrase TITLE using the key welcome.TITLE inside the default localization namespace.

You could also nest your files and directories as deep as you want. See the following examples:

| Language | namespace | key | Value | | -------- | --------- | --------------------- | ------------------- | | EN | default | welcome.TITLE | Local Repository | | FR | default | welcome.TITLE | Référentiel local | | EN | default | footer.copyright.TEXT | © 2023 Metrists CLI |

Connect Your Project to the Repository

Create a file called .metristssrc in the root of your repository:

{
  "resolvePath": "src/locals",
  "fetcher": "github",
  "fetcherParams": {
    "org": "organization-name",
    "repo": "repository-name"
  }
}
  1. fetcher specifies the mechanisms that grab your localization files. In this case, we will be using github.
  2. resolvePath is the path where your localization files will be store.
  3. Specify your github repository and organization in fetcherParams. If you are using a personal account, your GitHub organization is your GitHub username.
  4. In the root of your project, run:
metrists sync

✅ Your localization files are now synced with your GitHub repository.


Private Repositories

If you are using a private repository, you will need to create a GitHub Personal Access Token. You can create a token by following the instructions here.

Once created, you can provide it to the fetcher with the token parameter. You can also use Environment Variables to provide the token.

{
  "resolvePath": "src/locals",
  "fetcher": "github",
  "fetcherParams": {
    "org": "organization-name",
    "repo": "repository-name",
    "token": "github-token-here"
  }
}

GitHub Enterprise

Metrists by default will assume https://api.github.com as the API endpoint. If you are using GitHub Enterprise, you can specify the API endpoint with the baseUrl parameter:

{
  "resolvePath": "src/locals",
  "fetcher": "github",
  "fetcherParams": {
    "org": "organization-name",
    "repo": "repository-name",
    "baseUrl": "https://api.yourcompanygithub.com"
  }
}

Or as an Environment Variable:

{
  "resolvePath": "src/locals",
  "fetcher": "github",
  "fetcherParams": {
    "org": "organization-name",
    "repo": "repository-name",
    "baseUrl": "env.GITHUB_API_URL"
  }
}

Using Environment Variables as Fetcher Parameters

You can also use Environment Variables to provide fetcher params. Simply add env.[variable name] as the value of a fetcher parameter:

{
  "resolvePath": "src/locals",
  "fetcher": "github",
  "fetcherParams": {
    "org": "organization-name",
    "repo": "repository-name",
    "token": "env.environment-variable-name"
  }
}

Metrists will by default assume that your environment file exists in the root of your project, as .env. If you wish to change the path to your environment file, you can use the envPath parameter inside your .metristsrc file:

{
  "resolvePath": "src/locals",
  "fetcher": "github",
  "fetcherParams": {
    "org": "organization-name",
    "repo": "repository-name",
    "token": "env.environment-variable-name"
  },
  "envPath": "path/to/your/env/file"
}

Fetchers

Fetchers are mechanisms that grab your localization files. Fetchers are responsible for fetching the localization information from a source and outputting it in a JSON format.

The output of all fetchers should look like this:

{
  "[language]": {
    "[namespace]": {
      "[key]": "[phrase]"
    },
    "[another-namespace]": {
      "[key]": {
        "[key]": {
          "[key]": "[value]"
        }
      }
    }
  }
}

🌕 Phrase can be nested as deep as you want.

Custom Fetchers

If you wish to create your custom solution for storing your localization files, you can create your own fetcher. All your fetcher needs to do is to log a JSON version of your localization output:

console.log(
  JSON.stringify({
    en: {
      default: {
        title: 'Metrists is great',
      },
    },
  }),
);

Then you can call upon your fetcher file in your .metristssrc file:

{
  "resolvePath": "src/locals",
  "fetcher": "custom-fetcher.js"
}

Then run:

metrists sync

✅ Your localization files are now synced with your custom fetcher.

Contributing

This package is a beginner-friendly package. If you don't know where to start, visit Make a Pull Request to learn how to make pull requests.

Please visit Contributing for more info.

Code of Conduct

Please visit Code of Conduct.


License

MIT