项目作者: chrispcode

项目描述 :
The CLI to empower your ImmutableWebApps projects
高级语言: TypeScript
项目地址: git://github.com/chrispcode/iwa-cli.git
创建时间: 2020-04-13T14:57:53Z
项目社区:https://github.com/chrispcode/iwa-cli

开源协议:MIT License

下载


iwa-cli

IWA

An ImmutableWebApp CLI using oclif and cosmiconfig

oclif
Version
Downloads/week
License

Installation

  1. yarn add --dev iwa-cli
  2. npm install --save-dev iwa-cli

Usage

Generate

  1. Create a .iwarc file in the root of your project.
    The format of this file should look like this.
  1. {
  2. "env": {
  3. "all" : {
  4. "COMMON_ATTRIBUTE": "DEFAULT_VALUE",
  5. },
  6. "production": {
  7. "KEY": "VALUE_PRODUCTION"
  8. },
  9. "development": {
  10. "KEY": "VALUE_DEVELOPMENT",
  11. "COMMON_ATTRIBUTE": "DEVELOPMENT_SPESIFIC_VALUE",
  12. }
  13. }
  14. }
  • The all and production environment cannot be omitted!
  • Specify as many environments as you need! In this case we have 2 (one for production and one for development)
  1. Create a script tag with id="iwa" in your index.html or template.index.html
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head></head>
  4. <body>
  5. <div id="menu"></div>
  6. <main id="root"></main>
  7. <div id="footer"></div>
  8. <script id="iwa"></script> <!-- This line here is the one -->
  9. </body>
  10. </html>
  • Make sure you don’t have anything it, because it will get erased!
  • Make sure it is placed before all you bundles!
  1. Run the generate command
  1. iwa generate --env=production ./example/index.html # or the location where the file is located

The command will inject the configuration in the script tag:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head></head>
  4. <body>
  5. <div id="menu"></div>
  6. <main id="root"></main>
  7. <div id="footer"></div>
  8. <script id="iwa">window.env = {"COMMON_ATTRIBUTE": "DEFAULT_VALUE", "KEY":"VALUE_PRODUCTION"}</script>
  9. </body>
  10. </html>

Override

You can override a variable with process.env variables:

  1. KEY="VALUE_PROCESS" iwa generate ./example/index.html

Remove

You can also erase the configuration from a file, by using the remove command

  1. iwa remove ./example/index.html

Commands

iwa check [INPUT]

Checks HTML file for injected iwa config, useful in a pre-commit hook to prevent commiting injected iwa-config.

  1. USAGE
  2. $ iwa check [INPUT]
  3. OPTIONS
  4. -d, --verbose
  5. -h, --help show CLI help
  6. -s, --isStaged Checks only staged files, and will throw error if config found
  7. -v, --version show CLI version
  8. ALIASES
  9. $ iwa check
  10. $ iwa c

See code: src/commands/check.ts

iwa generate [INPUT] [OUTPUT]

Generates a HTML file, where window.env configuration is injected

  1. USAGE
  2. $ iwa generate [INPUT] [OUTPUT]
  3. OPTIONS
  4. -c, --config=config Location to look for iwa configuration
  5. -d, --verbose
  6. -e, --env=env [default: production]
  7. -h, --help show CLI help
  8. -v, --version show CLI version
  9. ALIASES
  10. $ iwa gen
  11. $ iwa g

See code: src/commands/generate.ts

iwa remove [INPUT]

Removes injected configuration from an HTML file

  1. USAGE
  2. $ iwa remove [INPUT]
  3. OPTIONS
  4. -h, --help show CLI help
  5. -v, --version show CLI version
  6. ALIASES
  7. $ iwa rm

See code: src/commands/remove.ts