dndGenerator
dndGenerator copied to clipboard
Publish generate npc library to npm
Love this app. Would love to be able to make api calls and get a response back with the NPC. I mess with it a bit but couldn't seem to get it to work. I don't know much about react though. I tried to make a file called "test.ts" with the following code:
` import { generate } from "./npcData/generate"; import { NpcGenerateOptions } from "./npcData/index";
const npc = generate(NpcGenerateOptions);
console.log(npc); `
I tried a few different things but none of them seem to work. If would be great to get this a feature or if someone could point me in the right direction to get started I could just make my own. I love all the logic that this has and I thought I could make an api out of it in a few hours. 6 hours later I understand how all the tables work but not much closer to an api.
NpcGenerateOptions is a typescript interface, it cannot be used as an argument.
You should be able to do
import { generate } from "./npcData/generate";
import { NpcGenerateOptions } from "./npcData/index";
const options: NpcGenerateOptions = {}
const npc = generate(options);
console.log(npc);
I think what you're asking is a library allowing generate NPCs
Technically what's needed to do that would be to publish the src/npcData folder to something like npm then you could npm install the project and use it in your own.
I'll think about it, would need @etiens approval too since he created pretty much all of the data in this project.
That makes sense. I am pretty sure I tried that same syntax and still got some errors but I will try when I get back home and let you know.
I wasn't thinking about a library but now that you mention that a library would be pretty great. I was going to set this up as an API backend that gets called from the frontend.
The one issue I dislike about a library is that means the data is static. As it is now if I set it up as an API I can add/edit the tables. As a library, I'd be locked in.
If you want to setup a backend that you manage suit yourself hahaha. This project is serverless to minimize cost so there is no backend to make api calls
Fair. For now, I'll keep working on it, and when/if you make an npm library I'll just switch it.
I still get an error. I've added "type": "module" to package.json and running ts-node but I get
"Cannot use import statement outside a module"
any idea? I've used very little type script.
I figured that out just had to update the tsconfig. Now I'm trying to figure out this webpack issue, I think.
const r = require.context("./tables/", false, /.json$/); ^ TypeError: require.context is not a function
Fixed it. Just need to set my environment to test and forget about the webpack stuff.
I've finally got around to publish the library to npm https://github.com/Cellule/npc-generator https://www.npmjs.com/package/npc-generator