0.27.85 • Published 4 years ago

@karhoo/web-lib-pc-scripts v0.27.85

Weekly downloads
-
License
-
Repository
github
Last release
4 years ago

@karhoo/web-lib-pc-scripts

Shared scripts and configuration files that should cover all infrastructure tasks for Partner Central Micro apps development (e.g. linting, bundling, testing, running dev server, etc).

Installation

npm install @karhoo/web-lib-pc-scripts

Contributing

The main philosophy of this package is unification and zero-configuration (reasonably close to zero) of Micro app projects. If some functionality is not provided by these scripts (for example you would like to be able to import CoffeScript files) - don't try to hack your own Micro app project somehow. You can instead extend webpack configuration in this package, so that all other projects can benefit from new functionality and use it in a common way.

Adding new option for a script

  • Extend optionsSchema object (all fields should be required, optional fields will pass validation because of default values)
  • Extend Commander's program with a new option
  • Add default value for the new option if necessary

Bumping common libs version

To share common libs (such as React, ReactDOM, etc) between Root App and Micro Apps web-lib-pc-scripts uses webpack externals functionality. To bump versions of these libs:

  • Bump appropriate versions in webpackExternalsCdn object
  • Make sure to commit this as a breaking change so that major version of web-lib-pc-scripts is changed as well
  • Bump web-lib-pc-scripts version in Root and Micro apps

Usage

Running scripts

Usage: web-lib-pc-scripts [options] [command]

Options:
  -V, --version  output the version number
  -h, --help     output usage information

Commands:
  build          bundle app to be used in partner central
  start          start app in dev server
  test           run unit tests
  format         format source code
  lint           lint source code
  help [cmd]     display help for [cmd]

To see more details about particular command's options please see optionsSchema and program definitions in appropriate script source code (e.g. web-lib-pc-scripts-build).

You can also use cli help:

web-lib-pc-scripts help build

Script options

Each option could be provided as cli argument:

web-lib-pc-scripts build --appName="web-app-fleets" --input="./src/App.jsx" --envList="API_URL,PUBLIC_API_URL" --production

or via project's configuration file: web-lib-pc-scripts-config.js (web-lib-pc-scripts-config.local.js for local untracked overrides):

const path = require('path')

const appName = 'web-app-fleets'
const input = path.resolve(__dirname, 'src/App.tsx')

module.exports = {
  build: {
    appName,
    input,
    production: true,
    envList: ['API_URL', 'PUBLIC_API_URL'],
  },
  start: {
    appName,
    input,
    env: {
      API_URL: 'https://rest.stg.karhoo.net',
      PUBLIC_API_URL: 'https://public-api.stg.karhoo.net',
    },
  },
  test: {
    setupFilesAfterEnv: [path.resolve(__dirname, './src/setupTests.ts')],
  },
}

Project examples

You can use web-lib-pc-create-app package as an example for scripts usage and configuration. This template should always be up-to-date with web-lib-pc-scripts as it will be used for bootstrapping new Micro Apps.