craftyjs/Crafty

Update documentation for using Crafty as a module

0xf0xx0 opened this issue · 10 comments

I'm helping develop a top-down game for desktop, so I need to use crafty as a module in VSCode. How can I do that? I don't see anything in the docs about this.

Have you tried using it via the npm module?

There's an example app you can look at here, though it's from a few versions ago.

Theres not much info in the README, do I have to cd into the crafty-develop folder?
EDIT: im dumb lol, I didn't realize there was a npm module. thanks! Another question: can Crafty be used outside a html file? I was reading the docs, and it seems you need a html page to use Crafty.

Also, installing craftyjs outputs a bunch of errors.

$ npm i craftyjs

> craftyjs@0.9.0 postinstall /Users/gingkathfox/node_modules/craftyjs
> (node -e "process.env.NODE_ENV !== 'production' && process.exit()" && grunt copy:lib) || node -v

A valid Gruntfile could not be found. Please see the getting started guide for
more information on how to configure grunt: http://gruntjs.com/getting-started
Fatal error: Unable to find Gruntfile.
v8.9.4
npm WARN saveError ENOENT: no such file or directory, open '/Users/gingkathfox/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/gingkathfox/package.json'
npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.3.0 requires a peer of bufferutil@^3.0.3 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.3.0 requires a peer of erlpack@discordapp/erlpack but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.3.0 requires a peer of node-opus@^0.2.7 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.3.0 requires a peer of opusscript@^0.0.6 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.3.0 requires a peer of sodium@^2.0.3 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.3.0 requires a peer of libsodium-wrappers@^0.5.4 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.3.0 requires a peer of uws@^9.14.0 but none is installed. You must install peer dependencies yourself.
npm WARN gingkathfox No description
npm WARN gingkathfox No repository field.
npm WARN gingkathfox No README data
npm WARN gingkathfox No license field.

+ craftyjs@0.9.0
added 40 packages from 139 contributors and audited 11369 packages in 12.809s
found 177 vulnerabilities (77 low, 42 moderate, 54 high, 4 critical)
  run `npm audit fix` to fix them, or `npm audit` for details
$ npm audit
npm ERR! code EAUDITNOPJSON
npm ERR! audit No package.json found: Cannot audit a project without a package.json

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/gingkathfox/.npm/_logs/2018-12-02T16_21_49_339Z-debug.log

log:

A valid Gruntfile could not be found. Please see the getting started guide for
more information on how to configure grunt: http://gruntjs.com/getting-started
Fatal error: Unable to find Gruntfile.

This one looks like an issue with the package.config -- it's a step that's necessary when developing with crafty, but not when installing it as a module. It's getting run as a postinstall script, so even with the error it would normally mean that crafty had installed ok. However:

v8.9.4
npm WARN saveError ENOENT: no such file or directory, open '/Users/gingkathfox/package.json'

and

No package.json found: Cannot audit a project without a package.json

These errors look like you're trying to install crafty into a place that isn't set up as a node project. If you're in the folder for your project, you'll want to start by either creating a package.json file, or running npm init to create one automatically.

Another question: can Crafty be used outside a html file?

All of the rendering methods assume assume some sort of DOM/html context. It's possible to build a headless version of crafty that could run in the context of a node server, but that doesn't sound like what you're going for.

I think PR #1199 will fix the errors when you don't have grunt installed in the future. (But not until we release a new version on npm.)

ok!

I think the main issue here is that we need better docs on using Craft as a module, so updating the title to that.

Hmmm, yeah, that's a better title XD

@starwed the example app helped, thanks! i have another, completely different question though. Do you have a discord so we can chat?