0

I created a small test program for web applications that uses jasmine, and I'm preparing it for easy downloads. Before installing my package, the user's project should look something like this:

myProject/
  app/
  lib/
  ...

I want to be able to have the user cd to myProject in the terminal, issue a single command that points to the app and lib folders, and then end up with this:

myProject/
  app/
  lib/
    requirejs
  test/
    lib/
    node_modules/
    specs/
    SpecRunner.html
    server.js
  ...

app/ should contain the js project files, lib/ should contain all the external js dependencies for the project, and test/lib/ should contain all the external dependencies for the tests. server.js runs with nodejs and depends on apps installed in node_modules/.

What's the best way to go about doing this? I could make a bash script, but I'd rather use a package manager. I'm not sure how I'd do this in bower or npm. And am I right in thinking it's better to have two libs, one for the project and one for testing, rather than one? I know I can declare certain packages as test packages in bower, but it seems like they should live in a separate libraries.

Loktopus
  • 462
  • 2
  • 12
  • you can use devDependencies. take a look here https://www.npmjs.org/doc/json.html#devDependencies – Irakli May 31 '14 at 21:05
  • @Irakli Doesn't that just dump my library in the top level node_modules? How would I assign the app/ and lib/ references to my library in package.json? – Loktopus May 31 '14 at 21:22

1 Answers1

1

And am I right in thinking it's better to have two libs, one for the project and one for testing, rather than one?

No. The idiomatic way in the npm-verse is to have tests in the same package in the test folder. Since bower is based on npm I'd say the same applies there too. If you don't want bower users to have to download test-stuff you should be able to ignore the test folder in the bower.json file (according to this answer). You should also specify node modules that are only used for tests as devDependencies.

Developers who want to run your test should IMO install it directly from source using e.g. git clone git@github.com/your/repo.git (and then just run npm install). Or simply npm install x if it's available on npm. Even if you really want the tests in their own package, I'd still suggest not using a package manager but ask the developer to clone it from the repo into the test folder.

Anyway to answer the question, the following one-liner should work (assuming npm, I'm not too familiar with bower):

npm install x-test && mv node_modules/x-test test
Community
  • 1
  • 1
Andreas Hultgren
  • 14,763
  • 4
  • 44
  • 48
  • Hmm, ok. Still a bit of a longer a process than I'd hoped for, but I guess that's unavoidable. Thanks. – Loktopus May 31 '14 at 23:56