This project has moved to https://github.com/carafe-fm/carafe-bundler
This is a utility for working with Carafe Bundles outside of FileMaker. Carafe Bundler is an NPM package which is used for a number of different purposes.
- It is packaged in an NPM Initializer to bootstrap a new Carafe Bundle project.
- It is transpiled into a Browser Tool for rendering and validating Carafe Bundles in browser applications.
- It can be packaged into any NPM project and used directly.
You will need to have Node.js and NPM installed to use this utility.
Carafe Bundler has an initializer which you can use to bootstrap a new Carafe Bundle project. The initializer will bootstrap a new bundle project using a starter template and include Carafe Bundler as a devDependency.
This is for two important use cases:
- Starting a brand new Bundle project in your preferred editor or IDE
- Customizing or configuring any existing Bundle in your preferred editor or IDE
npm init @carafe-fm/bundle
To work on an existing Bundle, you can initialize a new project with the appropriate project name, and then import the Bundle.
npm init @carafe-fm/bundle existing-bundle
cd existing-bundle
npm run import path/to/existing-bundle.json
The initializer includes a README in the new project which provides a npm run command reference.
The dist/carafe-bundler.js
tool is for validating and rendering bundles in web browser implementations. See test/browser-bundler.html
for a working example.
The validator.validateBundle
method takes a json bundle argument, and returns a JavaScript Promise. Example usage:
var validator = new carafeBundler.default.CarafeValidator();
validator.validateBundle(theJson)
.then(function () {
console.log('Bundle is valid.');
})
.catch(function (errors) {
console.error('Bundle is not valid:');
console.error(errors);
});
The renderer.render
method takes the html, bookend, config, and data bundle properties as arguments, and returns an HTML document. You can push it into an iframe with JavaScript like this:
var renderer = new carafeBundler.default.CarafeRenderer();
var iframeDocument = document.querySelector('#theiframe').contentWindow.document;
var content = renderer.render(theJson.html, theJson.bookend, theJson.config, theJson.data);
iframeDocument.open('text/html', 'replace');
iframeDocument.write(content);
iframeDocument.close();
You can install Carafe Bundler as a devDependency in your Node project and manipulate a bundle with any of the commandline tools.
npm install @carafe-fm/bundler --save-dev
validate-carafe-bundle -h
usage: validate-carafe-bundle -b <path/to/existing/bundle.json>
purpose: Validates a JSON Bundle.
options:
-b <argument> Required path to existing valid JSON Bundle
-h Shows this help text
render-carafe-bundle -h
usage: render-carafe-bundle -b <path/to/existing/bundle.json> -o <path/to/output/rendered.html>
purpose: Renders a validated JSON Bundle to a specified HTML output path.
options:
-b <argument> Required path to existing valid JSON Bundle
-o <argument> Required path to output the rendered HTML
-h Shows this help text
extract-carafe-bundle -h
usage: extract-carafe-bundle -b <path/to/existing/bundle.json>
purpose: Extracts source files from a given valid JSON Bundle.
CAUTION: overwrites any existing files without warning.
configuration: Source files are loaded from the current directory by default.
Source file paths may be customized in your package.json.
options:
-b <argument> Required path to existing valid JSON Bundle
-h Shows this help text
Starts watching four files in the current directory for changes and hot reloads the browser preview
render-carafe-source -h
usage: render-carafe-source [-p <port>]
purpose: Starts a dev server on localhost:8080 by default.
Server hot reloads on changes to source files.
configuration: Source files are loaded from the current directory by default.
Source file paths may be customized in your package.json.
options:
-p <argument> Overrides the default localhost port (default is 8080)
-s Send the compiled Bundle to Carafe.fmp12 if it is open on the host system (default is false)
-u <argument> URL for send (default is fmp://$/Carafe%20Kitchen?script=Send%20Carafe%20Bundle¶m={sendConfig})
Note: {sendConfig} will be expanded into a JSON object with path string and forceSend bool properties at runtime
-f Force the send to overwrite without prompting the user (default is false)
-h Shows this help text
Server defaults to localhost:8080
Compiles source files and outputs a Bundle to the specified path
compile-carafe-bundle -h
usage: compile-carafe-bundle [-b <output/path/to/new/bundle.json>] [-s [-f] [-u <fmpurl>]]
purpose: Compiles source files to a validated JSON Bundle.
Optionally sends Bundle to Carafe.fmp12 if it is open on the host system.
configuration: Source files are loaded from the current directory by default.
Source file paths and send URL may be customized in your package.json.
options:
-b <argument> Bundle path (default is dist/{name}-{version}-{creator}.carafe-draft-02.json)
-s Send the compiled Bundle to Carafe.fmp12 if it is open on the host system (default is false)
-u <argument> URL for send (default is fmp://$/Carafe%20Kitchen?script=Send%20Carafe%20Bundle¶m={sendConfig})
Note: {sendConfig} will be expanded into a JSON object with path string and forceSend bool properties at runtime
-f Force the send to overwrite without prompting the user (default is false)
-h Shows this help text