df-cc
v1.0.1
Published
DataFlex Custom Component CLI — scaffold and generate components for DataFlex webapps
Maintainers
Readme
df-cc — DataFlex Custom Component CLI
A CLI tool for scaffolding and generating custom components for DataFlex webapps. Write modern JavaScript classes, bundle them with Vite, and have them available in your DataFlex application.
Features
- Modern JavaScript — write ES2024 class syntax with full ESLint checking
- Vite bundler — fast builds, watch mode for development
- IIFE output — components are bundled into
AppHtml/Custom/DFCC.jsand loaded as a global namespace object - Multiple components — all components share a single bundle
- Per-component CSS — each component gets its own stylesheet
Prerequisites
Install NodeJS if you haven't already:
winget install OpenJS.NodeJS.LTSUsage
Step 1 — Initialise a DataFlex workspace
Navigate to your DataFlex project folder and run:
npx df-cc initThis creates the build setup in the current directory:
package.json— Vite + ESLint dependencies and build scriptsvite.config.js— Vite IIFE bundle configurationeslint.config.js— ESLint 10 flat configsrc/index.js— entry point that exports all components
Dependencies are installed automatically.
Options:
npx df-cc init --name MyAppUse --name to set the global namespace (default: DFCC). All components will be available as
window.MyApp.<ComponentName> in the browser.
Step 2 — Create a component
npx df-cc create MyCustomComponentThis generates:
src/MyCustomComponent.js— JavaScript class extendingdf.WebBaseControlsrc/MyCustomComponent.css— stylesheet for the componentAppSrc/cMyCustomComponent.pkg— DataFlex class withpsJSClasspre-set
And updates src/index.js to export the new component.
Run create again for each additional component you want in the bundle:
npx df-cc create MyOtherComponentStep 3 — Build
Build for production (runs ESLint first):
npm run buildWatch mode during development (rebuilds on file changes):
npm run watchStep 4 — Add to Index.html
Add the bundled files to your Index.html:
<script src="Custom/DFCC.js"></script>
<link rel="stylesheet" href="Custom/DFCC.css">Step 5 — Use the component in DataFlex
In your DataFlex program, use the generated .pkg file like any other web control:
Use AppSrc\cMyCustomComponent.pkg
Object oMyWidget is a cMyCustomComponent
End_ObjectHow it works
Each JavaScript component class is exported by name from src/index.js.
Vite bundles everything as an IIFE and assigns the exports to a global namespace object (e.g. window.DFCC).
The DataFlex psJSClass property points to the class using dot notation, e.g. "DFCC.MyCustomComponent".
Writing a component
The generated JavaScript class template looks like this:
export class MyCustomComponent extends df.WebBaseControl {
constructor(sName, oParent) {
super(sName, oParent);
this._sControlClass = 'my-custom-component';
}
openHtml(aHtml) {
super.openHtml(aHtml);
aHtml.push(`<div class="my-custom-component-wrapper" id="${this._sControlId}">`);
aHtml.push('<h1>Hello DataFlex!</h1>');
aHtml.push('</div>');
}
afterRender() {
this._eControl = df.dom.query(this._eElem, `#${this._sControlId}`);
super.afterRender();
}
}You can install and use npm packages inside your component files. They will be included in the bundle automatically.
License
MIT
