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

rollup-plugin-app-utils

v1.0.6

Published

Common application build utils: i18n strings bundler, html injects, prepare and clean directories

Downloads

2,388

Readme

Table of Contents

Usage:

  import Utils from 'rollup-plugin-app-utils'

Output screenshot:

logo

i18nBundler()
  Utils.i18nBundler({
    target: localesDir,
    baseLanguage: 'en',
    skipBackFilling: false, // Please read Back Filling section below.
    // Optional
    transformer: (lang, data) => {
      return data
    }
  })

then in your JS import translations using below line

  import translations from 'i18n.translations'
  console.log(translations.en)
Back Filling

i18n bundler reads json files from the specified directory and prepares a JSON structure. It uses base language directory as reference directory and

  • Adds missing files, adds missing keys to all the other languages
  • Removes keys from other languages JSON files that are removed from base language
  • Creates files or remove unnecessary files. For exeample, home.json exists in en folder but not in te folder, then when you build, the i18nBundler will create file and copy the content from base language folder for you. In a same way, if te folder contains test.json but en folder does not, then test.json will be removed from the te folder

For example, if you have locales folder with this structure and content,

{
  "en": {
    "onlyEng.json": {
      "wasInENonly": "yes"
    },
    "test.json": {
      "willbeAdded": "willbeAdded",
      "willnotOverride": "en text"
    }
  },
  "te": {
    "test.json": {
      "willbeRemoved": "willbeRemoved",
      "willnotOverride": "te text"
    }
  }
}

it will be transformed to below:

{
  "en": {
    "onlyEng": {
      "wasInENonly": "yes"
    },
    "test": {
      "willbeAdded": "willbeAdded",
      "willnotOverride": "en text"
    }
  },
  "te": {
    "onlyEng": {
      "wasInENonly": "yes"
    },
    "test": {
      "willbeAdded": "willbeAdded",
      "willnotOverride": "te text"
    }
  }
}

Please check test-data folder for example structure. Then run npm test and take a look at test-data-copy/output.js and test-data-copy/locales for a better understanding.

copyAssets()

Helps to copy static content from during build, this does the job in a synchronous way.

  Utils.copyAssets({
    // Source -> Target.
    './test-data': './test-data-copy',
    './test': './test-new'
  }, filterFun) // uses fs-extra `copySync`. You can also pass filter function
prepareDirectories()

Helps to prepare directories during build, this does the job in a synchronous way. For example, during thee build if you want to use dynamically named folder name, this method can be used to create directories. We use this to create a folder with unique name and then put static content in it.

  Utils.prepareDirectories(somedir1)
  // or
  Utils.prepareDirectories([somedir2, somedir3])
emptyDirectories()

Helps to cleanup directories during build, this does the job in a synchronous way. We use this to clean the dist folder before rollup write the output to dist folder.

  Utils.emptyDirectories(somedir1)
  // or
  Utils.emptyDirectories([somedir2, somedir3])
htmlInjector()

Helps to generate a html page from template and write to a target html file. This does the job in a synchronous way.

For example you have below html:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>{title}</title>
  </head>
  <body>
    {keyOne}
  </body>
</html>

Then in your rollup config if you do below:

  Utils.htmlInjector({
    template: './test-data-copy/test.template.html',
    target: './test-data-copy/tdir/index.html',
    injects: {
      title: '___title___',
      keyOne: '___keyOne____'
    }
  }),

The output looks like this:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>___title___</title>
  </head>
  <body>
    ___keyOne____
  </body>
</html>

Contributing:

Please check guidelines for more details.