GithubHelp home page GithubHelp logo

isabella232 / rollup-plugin-app-utils Goto Github PK

View Code? Open in Web Editor NEW

This project forked from autodesk/rollup-plugin-app-utils

0.0 0.0 0.0 643 KB

Provides common rollup build utils for i18n, prepare & clean directories, copy assets & html injects

License: Apache License 2.0

JavaScript 98.84% HTML 1.16%

rollup-plugin-app-utils's Introduction

rollup-plugin-app-utils

Common rollup build utils for i18n, prepare & clean directories, copy assets & html injects

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.

rollup-plugin-app-utils's People

Contributors

svapreddy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.