Origami comics

Generate an exports file for a JavaScript project

Beyond sites, Origami is good for any build process - like generating a main.js file for a JavaScript project.

main.js
/* This file is generated by main.ori.js, do not edit it directly. */
export { default as add } from './src/add.js';
export { default as divide } from './src/divide.js';
export { default as multiply } from './src/multiply.js';
export { default as subtract } from './src/subtract.js';

Builds transform trees: Origami’s speciality!

Suppose your src folder has JavaScript modules that export individual functions.

add.js
export default (a, b) => a + b;
subtract.js
export default (a, b) => a - b;

To generate a top-level file with all the exports, use a template to turn src files into export statements.

main.ori.js
/* This file is generated by main.ori.js, do not edit it directly. */
${
  Tree.map(src, (value, key) => Tree.indent`
    export { default as ${ Origami.basename(key) } } from './src/${key}';
  `)
}

Run this template in your build script to create the export file!

package.json
{
  "name": "my-project",
  "type": "module",
  "scripts": {
    "build": "ori main.ori.js/ > main.js"
  }
}
$ npm run build
$ cat main.js
/* This file is generated by main.ori.js, do not edit it directly. */
export { default as add } from './src/add.js';
export { default as divide } from './src/divide.js';
export { default as multiply } from './src/multiply.js';
export { default as subtract } from './src/subtract.js';
$

Read more: Origami template documents

  Comic index