dndGenerator icon indicating copy to clipboard operation
dndGenerator copied to clipboard

Publish generate npc library to npm

Open Shubedobedo opened this issue 5 years ago • 6 comments
trafficstars

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.

Shubedobedo avatar Sep 08 '20 19:09 Shubedobedo

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.

Cellule avatar Sep 08 '20 20:09 Cellule

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.

Shubedobedo avatar Sep 08 '20 20:09 Shubedobedo

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

Cellule avatar Sep 08 '20 21:09 Cellule

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.

Shubedobedo avatar Sep 08 '20 23:09 Shubedobedo

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

Shubedobedo avatar Sep 09 '20 13:09 Shubedobedo

Fixed it. Just need to set my environment to test and forget about the webpack stuff.

Shubedobedo avatar Sep 09 '20 14:09 Shubedobedo

I've finally got around to publish the library to npm https://github.com/Cellule/npc-generator https://www.npmjs.com/package/npc-generator

Cellule avatar Oct 22 '22 18:10 Cellule