kadamwhite / p5-cli

An NPM-based CLI for creating and running P5.js projects.
MIT License
30 stars 3 forks source link

Separate cli from lib / p5? #13

Open cowboy opened 9 years ago

cowboy commented 9 years ago

Right now, the cli includes p5@0.4.5, but what happens when p5@0.5.0 comes out? Sure, you can publish a new version of p5-cli that incorporates the new p5 changes, but what if some of those changes break backwards compatibility?

Users will either have to:

If the cli tool no longer contained p5, it could use the p5 the user has installed locally. Although maybe this is just a command-line flag that allows the user to specify an alternate p5.js file (crisis averted?)

Also, if the code that does all the serving was broken out into a separate lib that this tool references or consumed, someone could use it that lib programmatically in their node app or build process. Maybe the core code could just be an express middleware that the lib consumes!

Anyways, see @tkellen's https://github.com/tkellen/js-liftoff for examples on how separate lib from cli, if you're interested!

kadamwhite commented 9 years ago

@cowboy Thanks for the input! I think it's important to include p5 locally in some fashion, in order to support this flow:

The other flow, p5 serve . e.g., makes no assumptions about what to serve and leaves it to the user to have their own local p5 referenced properly from an HTML page.

That said, I definitely recognize that pinning the version in what I've been calling "sketch mode" is not ideal. I've been looking at the famous CLI auto-updates itself, and I'm interested in looking for a way to keep this a "one install and you're good" tool, at least for the latest version of the library. I recognize that p5 is in a state of evolution and it would be preferable to allow version specificity in sketch mode, but that's a more complex use case than I'd targeted and (for now!) that use case feels satisfied by the "bring your own .html" local server option.

I will check out js-liftoff and see what I can learn, though!

tkellen commented 9 years ago

@kadamwhite

Have you considered a setup step like p5 init? It would ask for a project name and create a package.json with a p5 devDep and a sketch file with some minimal functioning thing in it using the name.

If you ran p5 sketch immediately after, you could detect if p5 was installed and prompt the user to run npm install if no local dep was found (or npm init if no package.json was found).

I think this minimal amount of ceremony would be worthwhile for someone new to programming--especially if they picked up p5 after setting it down for 6 months only to find the thing they built didn't work because of a global versioning difference.

I'd be happy to provide some examples code for how Liftoff might make some of this easier, if you want. No worries if not, though. I think it's great how you're trying to lower the barrier of entry for this project!

kadamwhite commented 9 years ago

@tkellen p5 init (or p5 create) is definitely under consideration! I'd love to talk to you about how Liftoff could be used here.

chiunhau commented 8 years ago

This is exactly what I need!!