smontanari / code-forensics

A toolset for code analysis and report visualisation
384 stars 45 forks source link

Problem: Starting Webserver #1

Closed andife closed 6 years ago

andife commented 7 years ago

Hello, I installed code-forensics and tried to visualize the results now. Unfortunatly, I'm not able to start the webserver and I got the following error message.

C:\Users\user1>gulp webserver
[17:32:23] Using gulpfile ~\gulpfile.js
[17:32:23] Starting 'webserver'...
[17:32:23] 'webserver' errored after 40 ms
[17:32:23] Error: spawnSync C:\Users\user1\node_modules\code-forensics\scripts\webserver.js UNKNOWN
    at exports._errnoException (util.js:1022:11)
    at spawnSync (child_process.js:461:20)
    at Object.execFileSync (child_process.js:498:13)
    at C:\Users\user1\node_modules\code-forensics\lib\tasks\misc_tasks.js:44:11
    at run (C:\Users\user1\node_modules\code-forensics\lib\models\task\runners\default_runner.js:13:32)
    at Gulp.<anonymous> (C:\Users\user1\node_modules\code-forensics\lib\models\task\task_definitions.js:35:44)
    at module.exports (C:\Users\user1\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\Users\user1\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\Users\user1\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\Users\user1\node_modules\orchestrator\index.js:134:8)

Maybe it would be possible to give me hint, what I've done wrong and how I can help myself?

smontanari commented 7 years ago

I'm not running code-forensics on windows so I can't actually reproduce this problem, however I think the issue could be that webserver.js is expecting the OS to figure out how to execute itself as a script (through the shebang #!/usr/bin/env node) and this is not much Microsoft friendly.

Have you tried and run the webserver.js script directly with node?, i.e.:

cd C:\Users\user1\node_modules\code-forensics\scripts
node webserver.js

If that works then the issue is likely to be what I mentioned, and for the moment you could make yourself a simple .bat script to run the server in place of using gulp.

smontanari commented 7 years ago

One idea is to try and use the npm package "bin" configuration Have a read at http://stackoverflow.com/questions/10396305/npm-package-bin-script-for-windows

My suggestion is to: a) rename scripts/webserver.js to  scripts/webserver b) create a mapping in package json to link the command, i.e.

"bin": {
  "cf-webserver": "./scripts/webserver"
},

c) don't forget to update the gulp task to refer to the renamed script (the js file is lib/tasks/misc_tasks.js)

I used "cf-webserver" because "webserver" may be a bit too generic and clash with other modules.

In theory, when you install code-forensics in Windows, NPM should create a cmd wrapper around the script which would allow you to execute it properly

jdevoo commented 6 years ago

I am using code-forensics on Windows 10 through Docker. The docker image is built with the required Java, Node and I added git and subversion for convenience of pulling repos for analysis. In the image, gulp is installed globally and code-forensics under the root user. As the install happens on a fresh install, there's no collision between npm packages. Here's the gist to the Dockerfile as well as a small batch file. I use the batch in 2 ways. First to shell into the image and use e.g. git to clone with bash as argument. The other way is to invoke it inside a directory where I find the cloned repo (through shared volume) and the gulpfile.js I can edit with e.g. Sublime. It can be called without arguments to see the list of gulp tasks or like so e.g. cofo webserver

gernotstarke commented 6 years ago

@jdevoo - the link to your gist (Dockerfile) above is broken, it should be:

https://gist.github.com/jdevoo/ebaf48afbd533748301cdcb0cbd34219

jdevoo commented 6 years ago

fixed - thank you @gernotstarke

FlasH-RUS commented 6 years ago

@smontanari, just in case, I can confirm that node webserver.js from node_modules\code-forensics\scripts works in Windows. And thanks for this wonderful tool ^_^

smontanari commented 6 years ago

thank you @FlasH-RUS, I'm closing the issue then.