0.10.1 • Published 6 months ago

@metricinsights/pp-dev v0.10.1

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

pp-dev

The PP Dev Helper is a development framework and build tool for Metric Insights' Portal Pages, designed to make the lives of PP developers easier:

  • Build and test Portal Pages locally
  • Proxy API requests to a Metric Insights server
  • Hot module replacement for faster development
  • Image optimization and asset management
  • Template variable transformation
  • Code synchronization with Metric Insights instances

pp-dev is based on Vite.

Installation

npm install @metricinsights/pp-dev

Configuration

Configuration File

Create a configuration file named pp-dev.config with one of these extensions:

  • .js or .cjs (for CommonJS)
  • .ts (for TypeScript)
  • .json

Alternatively, you can define configuration in your package.json using the pp-dev key.

Configuration Examples

JavaScript (CommonJS)

// pp-dev.config.js

/**
 * @type {import('@metricinsights/pp-dev').PPDevConfig}
 */
module.exports = {
  backendBaseURL: 'https://mi.company.com',
  portalPageId: 1,
};

TypeScript

// pp-dev.config.ts

import { PPDevConfig } from '@metricinsights/pp-dev';

const config: PPDevConfig = {
  backendBaseURL: 'https://mi.company.com',
  appId: 1,
  v7Features: true,
};

export default config;

JSON

// pp-dev.config.json
{
  "backendBaseURL": "https://mi.company.com",
  "appId": 1,
  "v7Features": true
}

package.json

{
  "name": "my-portal-page",
  "version": "1.0.0",
  "pp-dev": {
    "backendBaseURL": "https://mi.company.com",
    "appId": 1,
    "v7Features": true
  }
}

Configuration Options

Required Options

OptionTypeDescription
backendBaseURLstringURL of the Metric Insights instance for API proxying
portalPageIdnumberID of the Portal Page for variable values (deprecated, use appId instead)
appIdnumberID of the Portal Page for variable values (synonym for portalPageId)

Optional Options

OptionTypeDefaultDescription
miHudLessbooleanfalseDisables Metric Insights navigation bar in development
templateLessbooleanfalseDisables template variable transformation
enableProxyCachebooleantrueEnables caching of proxied requests
proxyCacheTTLnumber600000Cache TTL in milliseconds (10 minutes)
disableSSLValidationbooleanfalseDisables SSL certificate validation for proxy requests
imageOptimizerboolean | objecttrueControls image optimization. See vite-plugin-image-optimizer for object options
outDirstringdistOutput directory for builds
distZipboolean | objecttrueControls build output zipping. Object options: { outDir?: string, outFileName?: string }
syncBackupsDirstringbackupsDirectory for asset backups from MI server
v7FeaturesbooleanfalseEnables Metric Insights v7 features
personalAccessTokenstringprocess.env.MI_ACCESS_TOKENPersonal Access Token for the MI instance

v7Features Details

When enabled (true), this option: 1. Changes development path from /pt/<portal-page-name> to /pl/<portal-page-name> 2. Updates Code Sync feature to use v7.1.0+ URLs

Personal Access Token

The personalAccessToken option allows you to authenticate with the Metric Insights instance. You can set it in your configuration or use the MI_ACCESS_TOKEN environment variable.

Example:

// pp-dev.config.js
module.exports = {
  backendBaseURL: 'https://mi.company.com',
  appId: 1,
  personalAccessToken: process.env.MI_ACCESS_TOKEN,
};

CLI Commands

Global Options

OptionDescription
-c, --config <file>Path to configuration file (default: pp-dev.config.js)
--base <path>Public base path (default: /)
-l, --logLevel <level>Log level: trace, debug, info, warn, error, silent (default: info)
--clearScreenClear screen before logging
--mode <mode>Environment mode: development, production, test (default: development)

Development Server

pp-dev [root] [options]
# Aliases: pp-dev dev, pp-dev serve
OptionDefaultDescription
[root].Root directory of the application
--host <host>localhostServer hostname
--port <port>3000Server port
--open [path]-Open browser on server start
--strictPort-Exit if port is already in use

Next.js Development

pp-dev next [options]
# Aliases: pp-dev next-server, pp-dev next-dev
OptionDefaultDescription
[root].Root directory of the application
--port <port>3000Server port
--host <host>localhostServer hostname

Build

pp-dev build [options]
OptionDefaultDescription
[root].Root directory of the application
--target <target>modulesTranspile target
--outDir <dir>distOutput directory
--assetsDir <dir>assetsAssets directory under outDir
--changelog [file]trueCreate changelog file

Changelog Generation

pp-dev changelog [oldAssetPath] [newAssetPath] [options]
OptionDefaultDescription
[oldAssetPath]-Path to previous assets
[newAssetPath]-Path to current assets
--oldAssetsPath <path>-Path to previous assets
--newAssetsPath <path>-Path to current assets
--destination <path>.Changelog output directory
--filename <name>CHANGELOG.htmlChangelog filename

Icon Font Generation

pp-dev generate-icon-font [source] [destination] [options]
OptionDefaultDescription
[source]-Source directory with SVG icons
[destination]-Output directory
--source <path>-Source directory with SVG icons
--destination <path>-Output directory
--fontName <name>icon-fontFont name

Next.js Integration

  1. Add pp-dev configuration to your project root
  2. Update package.json scripts:
    {
      "scripts": {
        "dev": "pp-dev next"
      }
    }
  3. Wrap your Next.js config:
// next.config.js
const { withPPDev } = require('@metricinsights/pp-dev');

module.exports = withPPDev({
     // your Next.js config
});

Vite Configuration

For custom build configuration, create a vite.config file. See Vite Configuration for details.