Skip to content

Build API

The K-scaffold’s build API is a powerful parsing tool that allows you to build your sheet quickly and easily. When combined with the Roll20 auto code extension and the Roll20 sheet sandbox, it provides the fastest and easiest sheet build experience available. The API can be used via command line with a config file or in your own custom build js file.

k.config

What does a k.config file look like? Regardless of whether you use a .js or .mjs file, a k.config file looks like this:

js
export default {
  source:'./source',
  destination:'./build',
  testDestination:'../__tests',
  pugOptions:{},
  scssOptions:{},
  templates:'./source'
};
export default {
  source:'./source',
  destination:'./build',
  testDestination:'../__tests',
  pugOptions:{},
  scssOptions:{},
  templates:'./source'
};

It exports the details of how you want to build your sheet so that the build API knows where to send files and how to report. The properties of the exported object are the same as described for the k.all function.

Custom Build File

If you would rather use the build API in a custom build file, you simply need to require it in your js file and use the provided all property (See below for more details on k.all):

js
const k = require('@kurohyou/k-scaffold');//Require the K-scaffold that we installed via NPM
const kOpts = {destination:'./build',testDestination:'../__tests__',source:'./source'};
// We've set our output directory as roll20code, located directly in this same directory.

if(process.argv[2] === '--watch'){
  kOpts.watch = true;
}
k.all(kOpts);// Invoke the all method of the K-scaffold npm package to process all pug and scss files that are in the same directory as this file.
const k = require('@kurohyou/k-scaffold');//Require the K-scaffold that we installed via NPM
const kOpts = {destination:'./build',testDestination:'../__tests__',source:'./source'};
// We've set our output directory as roll20code, located directly in this same directory.

if(process.argv[2] === '--watch'){
  kOpts.watch = true;
}
k.all(kOpts);// Invoke the all method of the K-scaffold npm package to process all pug and scss files that are in the same directory as this file.

k.all

function

Renders PUG and SCSS into HTML and CSS text

  • source - string

    The path to the directory containing your PUG and SCSS files

  • destination - string

    The relative path to the directory where you want your HTML and CSS files to be created.

  • dynamicDestination - boolean

    Whether the generator should create dynamically named folders inside the destination based on the master pug/scss file names, (e.g. my_system.pug and my_system.scss with a destination of ./build will create /build/my_system/my_system.html, /build/my_system/my_system.css, and /build/my_system/translation.js). This is useful if building a sheet template that is going to be used for several different projects.

  • pugOptions - object

    Options for how the k-scaffold should parse the pug and options that should be passed to pugjs. Accepts all options specified at pugjs.org. To be explicit as the pugjs docs are obtuse on this point, you may pass any local variables/functions that you want to have access to in your pug via this object. In addition you may pass:

  • pugOptions.suppressStack - boolean

    Whether the K-scaffold should suppress the full error stack from pug and only display the message portion of the error. The stack traces provided by pug do not refer to the actual chain of included pug files, and so are usually useless in troubleshooting an issue.

  • scssOptions - object

    Options for how the k-scaffold should parse the SCSS and options that should be passed to SASS. Accepts all options specified at sass-lang.com.

  • templates - string

    A directory that contains the template files for translation.json, sheet.json, and readme. Template translation file should be named translation.json just like the build version of the translation file.

  • Returns: Promise.<Array.<array>>

    - Array containing all rendered HTML text in an array at index 0, all rendered CSS text at index 1, and rendered sheet.json at index 2.

Released under the MIT License