Skip to main content

Module: cli-api

Finsemble CLI API reference

Use this API to customize your seed project build process. See the build process tutorial for complete documentation.

Usage:

In Node.js scripts, use require:

const { ruleCSS, launchFEA } = require("@finsemble/finsemble-core/cli-api");

In ts-node scripts, you can use import:

import { ruleCSS, launchFEA } from "@finsemble/finsemble-core/cli-api";
note

The CLI API is built in commonJS format so that it can be used in Node.js.

Type Aliases

StartInstance

Ƭ StartInstance: Object

Type declaration

NameType
serverTupleServerTuple
onClose(handler: (exitCode: null | number) => void) => void

Functions

autoGenerateHtmlFiles

autoGenerateHtmlFiles(webpackConfig): void

Adds plugins to the provided webpack configuration to generate index.html and menu.html files for each of the entries. The index.html file is needed for most apps and components. The menu.html file is needed for any app that uses drop down menus (such as the Toolbar). menu.html is ignored if the app does not require it.

Parameters

NameTypeDescription
webpackConfigConfigurationA valid Webpack configuration

Returns

void


build

build(__namedParameters?): Promise<null | string>

Runs the CLI's build process and optionally starts Finsemble. This is the same as running yarn build or yarn build --start

Parameters

NameTypeDescription
__namedParametersObject-
__namedParameters.args?string[]Command line arguments. This includes pass-through arguments that are accepted by getWebpackConfig() and start(). Plus --prepare and --start.
__namedParameters.environment?string-
__namedParameters.prepare?booleanSet to true to prepare for deployment.
__namedParameters.region?string-
__namedParameters.resolveDependencyMagic?boolean-
__namedParameters.start?booleanSet to true to launch Finsemble when done building.
__namedParameters.webpackConfig?string | ConfigurationOptionally provide a webpack config or the location of a file that contains a webpack config, otherwise one will be generated using getWebpackConfig().

Returns

Promise<null | string>

  • Resolves to an error if one occurs, otherwise resolves to null. If run in watch mode then the process will continue in the background. If run with the --start option, the webpack watch process terminates when Finsemble is closed.

clean

clean(): void

Cleans the seed project, deleting all artifacts from prior builds. This function is synchronous and returns when all files have been removed.

Returns

void


createApp

createApp(__namedParameters): Promise<null | string>

Creates an app. This behaves just like installTemplate except that it uses the "Blank" template and renames it to the name that was provided.

Parameters

NameTypeDescription
__namedParametersObject-
__namedParameters.namenull | stringThe name of the app to create
__namedParameters.output?booleanSet to false to suppress console.log output
__namedParameters.projectFolder?stringThe project folder where to install. If not provided then the cwd will be assumed.

Returns

Promise<null | string>

Resolves to an error string if an error occurs, otherwise to null


createPreload

createPreload(__namedParameters): Promise<null | string>

Creates a preload. This behaves just like createApp except that it uses the "Preload" template instead of the "Blank" template.

Parameters

NameTypeDescription
__namedParametersObject-
__namedParameters.namenull | stringthe name of the preload to create.
__namedParameters.output?booleanset to false to suppress console.log output.
__namedParameters.projectFolder?stringthe project folder where to install. If you don't provide it, Finsemble assumes the cwd.

Returns

Promise<null | string>

  • resolves to an error string if an error occurs, otherwise to null.

displayBuildEnvironmentDetails

displayBuildEnvironmentDetails(): Promise<null | string>

Displays advanced build environment details such as software versions, drive space, OS, etc.

Returns

Promise<null | string>

a Promise which resolves to null


entriesToWebpackEntry

entriesToWebpackEntry(entries): Object

Converts an array of Finsemble's simplified entry points (such as found in a seed project's webpack/entries.json file) into a format usable by Webpack. The output file is specified to be put in the correct place (no ./src) and with the correct extension (.js - generated automatically).

This returns a map of webpack entries and a map of CopyWebpackPlugin configs.

If an entry is already an object then it is passed back without any change other than extracting the optionally specified copyConfig.

Parameters

NameTypeDescription
entriesstring[]The entries to convert, from webpack/entries.json format

Returns

Object

NameType
copyConfigsRecord<string, any>
entriesRecord<string, { filename: string ; import: string }>

generateDefaultConfig

generateDefaultConfig(__namedParameters): Configuration

Generates a baseline Finsemble compatible webpack configuration with the following behaviors:

  • Empty webpack entries
  • Caching turned on
  • Source maps turned on unless mode is "production"
  • Minimal output stats
  • All rules enabled
  • Resolving typescript, javascript, and css files
  • CaseSensitivePaths plugin & EnvironmentPlugin that captures "NODE_ENV"

The returned config can be modified as necessary, including adding entries or overriding plugins.

Parameters

NameTypeDescription
__namedParametersObject-
__namedParameters.dirnamestringShould be __dirname of the calling function. This is used to determine location of webpack cache and output
__namedParameters.mode?"none" | "development" | "production"-
__namedParameters.name?string-
__namedParameters.tsxOptions?null | Record<string, any>-

Returns

Configuration

A webpack configuration is returned. This can be passed to a webpack process.


getWebpackConfig

getWebpackConfig(__namedParameters?): Configuration

Returns a complete webpack configuration that can be used to build Finsemble UI components.

Parameters

NameTypeDescription
__namedParametersObject-
__namedParameters.args?string[]Optionally pass command line arguments, supporting each parameter as --parameter
__namedParameters.autoGenerateHtml?booleanindex.html and menu.html files will be generated for each entry unless this is set to false.
__namedParameters.consoleOutput?booleanIf set to false then console output, feedback and warnings, will be prevented.
__namedParameters.copyWebpackPlugin?booleanBy default, any non build related files such as .html, .css, etc will be copied from the source to the output. Set this field to false to prevent that behavior.
__namedParameters.entries?string[]Optional array of entry points to compile.
__namedParameters.entriesFile?stringOptional location of a JSON file containing entry points
__namedParameters.mode?"none" | "development" | "production"Webpack mode is set to "development" by default. Optionally set this to "production" for production builds.
__namedParameters.outputPath?stringOptional output path for compiled entries. Defaults to the project's public/build directory
__namedParameters.resolveDependencyMagic?booleanIf set to false, dependencies will not be automatically resolved from @finsemble/finsemble-core's own dependencies. You will need to then add all dependencies to your package.json.
__namedParameters.watch?booleanWatch mode is enabled by default. Set this to false to disable watch mode.
__namedParameters.webpackConfig?ConfigurationOptionally provide a starting webpack config. Any field in this config will not be modified. CopyWebpackPlugins will not be generated for any entries in this object.

Returns

Configuration


installTemplates

installTemplates(__namedParameters): Promise<null | string>

Installs the requested UI component templates. For each template, a subdirectory will be created in the project's src folder containing the template and a webpack entry will be added to the webpack/entries.json file. Those folders and files will be created if they don't exist. Finally, a component entry will be added to the project's public/configs/application/config.json file to override the default values from core.

Parameters

NameTypeDescription
__namedParametersObject-
__namedParameters.output?booleanSet to false to suppress console.log output
__namedParameters.projectFolder?stringThe project folder location. If not provided then it will assume the current working directory.
__namedParameters.whichTemplatesstring[]A list of templates to install. Run npx finsemble templates for a full list.

Returns

Promise<null | string>

Resolves to an error string if an error occurs, otherwise to null


launch

launch(__namedParameters?): Promise<FEAInstance>

Launches Finsemble on either Electron or io.Connect Desktop depending on the arguments passed.

Parameters

NameType
__namedParametersObject
__namedParameters.args?string[]
__namedParameters.environment?string
__namedParameters.region?string

Returns

Promise<FEAInstance>


launchFEA

launchFEA(__namedParameters?): Promise<FEAInstance>

note

Use start() to launch the dev server and Finsemble with a single command.

Launches Finsemble (the Finsemble Electron Adapter (FEA)) using e2oLauncher (in the @finsemble/finsemble-electron-adapter module). If an entry exists in project.json for either the requested or default

Parameters

NameType
__namedParametersObject
__namedParameters.args?string[]
__namedParameters.environment?string
__namedParameters.region?string

Returns

Promise<FEAInstance>


makeInstaller

makeInstaller(__namedParameters?): Promise<null | string>

Makes an installer from the seed project. See Deploying your smart desktop.

Parameters

NameTypeDescription
__namedParametersObject-
__namedParameters.args?string[]-
__namedParameters.configPath?stringOptional path to a config file to be used for installer configuration (overrides default of project.json).
__namedParameters.environment?stringSpecify which environment to use.
__namedParameters.output?boolean-
__namedParameters.region?string-
__namedParameters.runIOCD?boolean-

Returns

Promise<null | string>

Resolves to null when the installer has been created, or to an error string if there is an error.


preparePlatform

preparePlatform(): void

This occurs when building the seed project or launching FEA/io.CD

Prepares a project for deployment by copying @finsemble/finsemble-core/platform into the seed project's public/build/finsemble directory. This step makes the platform available when you deploy your project to a server.

It is assumed that the current working directory is the root of the seed project.

Returns

void


ruleCSS

ruleCSS(mode?): RuleSetRule

This returns a rule that will compile all imported CSS files into local <style> tags which are inlined into .js files. When in development, sourceMap may cause style-loader to convert to <link> tags. This seems to vary from version to version of style-loader.

Parameters

NameType
mode?"none" | "development" | "production"

Returns

RuleSetRule


ruleImageAndFont

ruleImageAndFont(): RuleSetRule

Returns a rule that will inline all images, svg and font files into base64 local entries. There is no size limit on these files. Small size limits would prevent custom fonts from being displayed in Toolbar menu drop downs.

Returns

RuleSetRule


ruleLazyCSS

ruleLazyCSS(mode?): RuleSetRule

Returns a rule that lazily loads files with the suffice .lazy.css. WindowTitleBar requires lazy style loading when it is injected because it is preloaded before the DOM exists and so there is no place for style-loader to put the styles.

Parameters

NameType
mode?"none" | "development" | "production"

Returns

RuleSetRule


ruleSVG

ruleSVG(): RuleSetRule

Returns a rule allows React components to import SVG files and inline them into the DOM.

The "issuer" setting restricts this to run only in .j/tsx files, allowing svg @import in .css files to be supported via the default IMAGE_AND_FONT_RULE. Ideally, our code would always use SVG's from CSS rather than inlining them with React but the latter approach is heavily used in SDD and would require significant refactoring.

url-loader is used so that the images are inlined (as opposed to file-loader which requires very tricky dynamic public_path code).

Returns

RuleSetRule


ruleSourceMaps

ruleSourceMaps(): RuleSetRule

Returns a rule allows webpack to transfer source maps from imported libraries, combining them into the source map for the actual file that it is bundling. This gives developers the ability to debug all the way down into imports from node_modules.

Returns

RuleSetRule


ruleTSX

ruleTSX(options?): RuleSetRule

Returns a rule that will compile all .ts and .tsx files. ts-loader uses tsc. Modify the .tsconfig file to change typescript compilation behavior.

Parameters

NameType
options?null | Record<string, any>

Returns

RuleSetRule


runWebpack

runWebpack(config, output?): StandardPromise<Compiler>

Runs webpack for a given configuration. This function will resolve to null after a successful compilation cycle or a string if an error occurs. When run in watch mode, it will resolve once and only once - either to null or an error - but only on the first compilation cycle. Additional compilation cycles will continue running in the background.

Parameters

NameTypeDefault valueDescription
configConfigurationundefinedMust be a valid webpack configuration. Use getWebpackConfig() to obtain a default configuration.
outputbooleantrueSet to false to suppress console.log output

Returns

StandardPromise<Compiler>

Resolves to a tuple. The first argument contains an error string if an error occurs, otherwise to null. The second argument contains the webpack Compiler instance.


sdd

sdd(__namedParameters?): Promise<undefined | FEAInstance>

Launches Finsemble in Smart Desktop Designer mode.

This will install a copy of Finsemble's platform and then use the current working directory as a project template. Both are installed in @finsemble/finsemble-electron-adapter/deploy.

Parameters

NameTypeDescription
__namedParametersObject-
__namedParameters.args?string[]Optional array of command line arguments to pass to FEA.
__namedParameters.consoleOutput?booleanSet to false to suppress console output.
__namedParameters.environment?stringSpecify which environment to use.
__namedParameters.region?string-

Returns

Promise<undefined | FEAInstance>

Resolves to an FEAInstance which contains an onClose function. Use this function to register a callback for when Finsemble closes.

Example

const feaInstance = await sdd();
feaInstance.onClose((exitCode) => {
console.log(`Electron closed with code ${exitCode}`);
});

server

server(__namedParameters?): Promise<ServerTuple>

Starts the Finsemble server.

Parameters

NameType
__namedParametersObject
__namedParameters.args?string[]
__namedParameters.consoleOutput?boolean
__namedParameters.environment?string
__namedParameters.region?string

Returns

Promise<ServerTuple>


showWebpackConfig

showWebpackConfig(__namedParameters?): void

Outputs a generated webpack config to stdout. This takes the same parameters as build().

Parameters

NameType
__namedParametersObject
__namedParameters.args?string[]

Returns

void


start

start(__namedParameters?): Promise<StartInstance>

Starts Finsemble.

This function follows these steps:

1) Installs the platform. See preparePlatform()

2) Starts FEA's built-in Express dev server. See startFEAServer()

3) Launches FEA. See launchFEA()

This function resolves when the server is started and FEA is launched. When FEA exits, the server will be stopped automatically. The promise resolution contains an object with an onClose handler that can be used to determine when FEA exits.

Example

const instance = await start({ environment: "production" });
instance.onClose((exitCode) => {
console.log(`Electron closed with code ${exitCode}`);
});

Parameters

NameTypeDescription
__namedParametersObject-
__namedParameters.args?string[]Optional array of command line arguments. --smartDesktopMode to launch the SDD. --prepare=false to prevent prepare phase (copying public/build/finsemble). --iocd to launch the io.Connect Desktop container instead of FEA. --verbose to for verbose console output (from io.CD) --serve only start the server, don't launch the desktop
__namedParameters.consoleOutput?booleanSet to false to suppress console output.
__namedParameters.environment?string-
__namedParameters.region?string-
__namedParameters.verbose?boolean-

Returns

Promise<StartInstance>

Resolves to an object that contains a a ServerTuple (see startFEAServer()) and a FEAInstance (see launchFEA)


startFEAServer

startFEAServer(__namedParameters?): Promise<ServerTuple>

note

Use start() to launch the dev server and Finsemble with a single command.

Runs the Finsemble Electron Adapter's built in Express dev server. This function is typically run before running launchFEA().

Resolves with a tuple containing an instance of the Express server and an instance of the underlying Node.js http.server. These can be used to listen to events.

Parameters

NameTypeDescription
__namedParametersObject-
__namedParameters.args?string[]Optional array of command line arguments. --smartDesktopMode to launch the SDD.
__namedParameters.consoleOutput?booleanSet to false to suppress console output.
__namedParameters.environment?stringSpecify which environment to use.
__namedParameters.region?string-
__namedParameters.runIOCD?booleanIf set to true (or if "--iocd" is passed on command line arg) then the io.CD artifacts will be configured and served

Returns

Promise<ServerTuple>

Resolves to a tuple that contains an instance of the Express server and corresponding Node.js http.server.