npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-lgcjs

v0.0.5

Published

Rollup plugin for transpiling .xlgc files + live editor support

Downloads

11

Readme

rollup-plugin-lgcjs

A rollup plugin for importing .xlgc gamebook files and much more.

Edit files from a live session of Lgcjs web editor, using your favourite browser, import and transpile them on the fly, everything out of the box!

Works by binding rollup to chrome devtools - more below.

Getting started

Install with:

npm install --save-dev rollup-plugin-lgcjs

And add to your rollup.config.js:

import lgcjs from 'rollup-plugin-lgcjs'

export default {
  /* Rollup configs, input, output, ... */
  plugins: [
    lgcjs({
      // Add Lgcjs options here
    })
  ]
}

Now you can import book from 'book.xlgc', rollup-plugin-lgcjs will search for a book.xlgc on your package.json folder and transpile it as pure javascript.

Open Lgcjs web editor on watch

The greatest feature about rollup-plugin-lgcjs is that it lets you connect your code with a live session of lgcjs web editor. Open chrome (or any other compliant browser) with devtools enabled:

google-chrome --remote-debugging-port=9222

And launch rollup -c -w

Done! Now you can edit your gamebook inside Lgcjs and save them on disk (ctrl+S). Every time the file is saved rollup would transpile it again.

Plugin options

Here every avaible option with default values:

lgcjs({
  // Chrome options
  open: true,          // False disable connections
  newPage: false,      // True always open a new tab

  // Urls (browser devtools, lgcjs web editor url and app url)
  browserURL: "http://localhost:9222",
  lgcjsURL: "https://librogamesland.github.io/lgcjs/release/",
  /* If you are watching node, you are probably
  serving a preview of your gamebook app on localhost
  set the url here to embed it on lgcjs as iframe */
  appURL: '',


  // Book parsing options
  bookpath: path.join(process.cwd(), "book.xlgc"),
  encoder: 'vuejs', // see formats below


})

Formats

.xlgc parsing is done with in two steps:

  • the xlgc xml is parsed to a javascript friendly json format called jlgc (the same format used by Lgcjs editor internally)
  • the jlgc file is transpiled and optimized, tags and special sequences (such as {link number:@T}) are resolved and compiled to html tags ahead of time.

Default encoder is the vuejs one, it replace every code with a Vue.js tag, so it's easy to render your gamebook chapters as vue components. An example is provided below. Use json to avoid vuejs encoding and import raw jlgc format.

You can create your own jlgc parser too - just pass a function as encoder param:

lgcjs({
  encoder: book => {
    console.log(book.info)
    return 'export default ' + JSON.stringify(book)
  }
})

jlgc and Vuejs encoded examples

jlgc encode: 'json'

// book structure
export default {
  "info": {
    "title": "Esempio",
    "author": "Luca Fabbian",
    "map": "/path/to/map.jpg"
  },
  "entities": {
    "1": {
      "title": "Paragrafo 1",
      "flags": ["fixed", "death", "final"],
      "data": "<p> {link 2:@T} o {link intro:Introduzione}</p>"
    },
    "2": {
      "map":
      "group": "esempio",
      "data": "<p></p>"
    },
    "intro": {
      "type" : "section",
      "title": "Introduzione",
      "data": "<p>Vai al {link 1:@T}"
    }
  },
}

vuejs encode: 'vuejs'