A simple library for adding koji-specific features to a node project.
npm install --save koji-tools
of course!- Add a watcher to your development setup
In your
package.json
file, add a prestart script to your scripts section. You may also optionally add PWA support with koji-tools through a postbuild script shown below:
"scripts": {
"prestart": "koji-tools watch &",
"start": "...",
"build": "...",
"postbuild": "koji-tools pwa"
}
- Add a
Koji.pageLoad()
, function to your app's main js file. App.js
import Koji from 'koji-tools';
...
Koji.pageLoad();
...
- Use
koji-tools
in your application to get Koji Customization options and other features:
import Koji from 'koji-tools';
// If I had a 'backgroundColor' property in a 'colors' customization file.
console.log(Koji.config.colors.backgroundColor);
// If I had a route TestRoute
Koji.request(Koji.routes.TestRoute).then((response) => {
console.log(response);
})
vccTest
is a function to auto test koji VCC's by automatically changing all VCC's, or printing un-handled VCC's to the console.
To run vccTest
Open the browser console and run:
vccTest();
- Just like in frontend, install koji tools:
npm install --save koji-tools
- Add a watcher to your development setup
In your
package.json
file, add a prestart script to your scripts section.
"scripts": {
"prestart": "koji-tools watch &",
"start": "..."
}
- Import koji-tools in your routes to get access to Koji.config. Example:
import Koji from 'koji-tools';
export default async (req, res) => {
console.log('request running...');
const content = Koji.config.strings.content;
res.status(200).json({ content });
}
*NOTE: As of 0.4.3, only Koji.config
is supported for backend node.js usage. Other koji-tools functionality is not available.
-
Koji.watch()
Server Side function that sets file watchers on all .koji customization files and allows for hot reloading of these properties. -
Koji.pageLoad()
Sets upKoji.config
parameters for each client and handles communication between the Koji live preview iframe and your app. -
Koji.request()
Wrapper for fetch that takes objects fromKoji.routes
.
*Note: as of 0.4.2, acache
option can be added to a routes koji.json file, default isno-cache
in order to avoid stale caching. -
Koji.pwaPrompt()
After the'pwaPromptReady'
event has fired, this function will make a popup installation prompt appear.
*Note: this function must be run from some user input. (like onClick) -
Koji.config
An autogenerated list of all of the Koji Customization Controls (CVV's) your application has setup. whenKoji.watch()
is being used this list updates automatically. -
Koji.routes
A autogenerated list of routes based on koji.json files in your project that are used inKoji.request()
to request the backend of you app. -
Koji.on(event, callback)
Register a callback on a koji event. events - change
Koji.on('change', (scope, key, value) => { ... });
Where scope
is the file that has been changed and key
and value
are the json item with its new value.
Koji.on('pwaPromptReady', () => { ... });
On a deployed project that has koji-tools pwa
in the "postbuild"
section of the package.json file, this event will fire when the PWA Install Prompt is ready to be called.
See Koji.pwaPrompt()
.
Get Started at GoKoji.com
- Starting to move away from strict dependance on metadata.json, allow for plugin PWA manifest support.
- VCC testing tools added
- Support for backend to use
Koji.config
- added caching options to Koji.request that are customizable in a routes koji.json
- changed default caching stategy to
no-cache
to keep request freshness
- minor bug fixes
- Added pwa prompt support
- the function
Koji.pwaPrompt()
- the callback handler
Koji.on('pwaPromptReady', () => { ... })
- Added easy to setup pwa support for projects with koji tools
- Added callback handlers
- minor usability fixes
- Initial commit.
- Barely working but technically working