Compiling CoffeeScript - javascript

I am trying to compile CoffeeScript but it fails. I have Node.JS installed, set $NODE_PATH to /home//bin (with my username, of course). That directory contains these files:
browserify coffee#1.1.3 uglifyjs
browserify#1.10.8 coffee#1.3.1 uglifyjs#1.0.6
cake sharejs uglifyjs#1.0.7
cake#1.1.3 sharejs#0.5.0-pre uglifyjs#1.2.6
cake#1.3.1 sharejs-exampleserver
coffee sharejs-exampleserver#0.5.0-pre
But I get this error:
Error: Command failed: /bin/sh: node_modules/.bin/browserify: not found
How to solve it? Not sure why it checks that directory.
I used "cake webclient" to compile it using the Cakefile.
I am using Ubuntu 11.10 x64, compiled ndm from source.
EDITED as requested:
I have got a project downloaded from github, which is written in CoffeeScript. I want to run to so I need to compile (build or whatever it is called) it to JavaScript. There is a Cakefile in trunk directory of the project. I got there and executed cake. It said there are 3 options available to build, one of them was cake webclient, so I executed this command. It started converting CoffeeScript files to JavaScript files but then I got that error on one of the files. That is all I know about the situation :D
EDITED (PATH and NODE_PATH values):
pius#pius-laptop:~$ echo $PATH
/home/pius/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/node/bin:/usr/local/share/npm/bin
pius#pius-laptop:~$ echo $NODE_PATH
/home/pius/bin
pius#pius-laptop:~$

I would guess you haven't set $NODE_PATH correctly because it's looking in the default directory. It should be done like this:
export NODE_PATH="/home/$USER/bin"
And check it with
echo $NODE_PATH
EDIT:
Perhaps something needs access to npm. You can try adding that to your path.
export PATH="$PATH:/usr/local/share/npm/bin"
Also, add these things to your .bashrc file and then they'll be available for every terminal. You will need to restart the terminal or execute
source ~/.bashrc
for the changes to take effect.

Try to download a pre-made package for ndm & CoffeeScript in Ubuntu 11.10 x64. If those work, then the issue is with the way you compile. If it does not work, then the issue is with your OS install (missing libs, different folders, etc).

Related

How to run a node script by CLI custom command?

Currently, I'm working on a personal project and I'd like to create an alias for some commands that I have to run... Similar to:
jest ...
node ...
tsc ...
I think that for my project would be so helpful and cool to have something like
foo ...
I'm working with Node, Typescript, and JS.
I took a look on the internet and read saw some people teaching how to create some alias I tried and it works :)
I already have the alias working on my local machine cause I added the alias on the .bashrc file.
alias foo = command...
However, I also tried to put it on my package.json scripts section, like:
"scripts": {
"runFoo": "foo",
But when I run npm run runFoo it says that "foo" is not recognized... Are any way to do that? How the tools like jest do that?
I would be thankful for any direction about what to study for that.
Extra:
There is any way to run all the .js from a folder by using any node command without knowing the name of the files?
Like:
node *.js
It can help while I don't figure out how to do the alias...
Edit:
What I want to do is:
https://developer.okta.com/blog/2019/06/18/command-line-app-with-nodejs
The answer helped me to find this post, and following it, it worked here.
it says that "foo" is not recognized
That is because shell aliases do not work in npm scripts (they are only valid when directly called in said shell), see e.g. How can I pipe to a bash alias from an npm script?
Aliases are meant to reduce typing, and are not automatically shared across environments, on the contrary of npm scripts which are committed with package.json. Hence if you try running that script in another environment, the latter may not know that alias (or worse, use it for something else!).
How the tools like jest do that?
They do not... Their command is not an alias, but an actual executable binary or script.
When installed as dependencies, you will find links to their executable in node_modules/.bin/ folder, see What is the purpose of .bin folder in node_modules?
You can easily create such executable scripts, even written in JavaScript to be executed by a Node.js engine, see e.g. Appropriate hashbang for Node.js scripts

Less (lessc) does not work on a new System. ([TypeError: undefined is not a function])

I have set up my new development environment with Windows 10 and I am facing a problem regarding less.
I have installed less like explained on lesscss.org using
npm install -g less
The installer runs fine and does not throw any errors.
Now I try to compile a .less file in the command line like this:
lessc input.less output.css
and I get following error:
[TypeError: undefined is not a function]
I have tried reinstalling less and npm but nothing has working. Compiling the same file on my old system works fine. It seems like some installed runtime environment on my new machine has an error which results in lessc calling an undefined function somewhere.
What is the best way to find and fix the error?
You can solve it in two ways:
Provide a path of lessc to your Environment Variables
PATH will be something like this
C:\Users\aayus\AppData\Roaming\npm\node_modules\less\bin\lessc
After it run
lessc input.less output.css
Also what you can do is while compiling provide a full path to your lessc compiler
C:\Users\aayus\AppData\Roaming\npm\node_modules\less\bin\lessc styles.less styles.css
If both of these are not working the best way is to use Online compiler
Here is link to one:
http://beautifytools.com/less-compiler.php
Paste your less code and click on Compile less

How to run (or build then run?) this Mozilla Rhino Debugger?

Would like to try this Rhino Debugger however having problems
I downloaded latest from here according to doc it says just simply run:
java org.mozilla.javascript.tools.debugger.Main [options] [filename.js] [script-arguments]
however..it's source code, so I probably need to build it first...(unless there are precompiled download out there?). Assuming I need to build it to get the jar file for debugger, I assume just build the build.gradle file at the root dir. Or run gradle tasks build ? When I do that I get error:
Execution failed for task ':checkstyleMain'.Unable to create a Checker: configLocation {C:\rhino\rhino-1.7.8\checkstyle.xml}, classpath {C:\rhino\rhino-1.7.8\buil
dGradle\classes\java\main;C:\rhino\rhino-1.7.8\buildGradle\resources\main}.
So..I'm a bit lost. Been ten years since I've worked with Java, but hopefully I'm missing something simple.
Any experienced Rhino JavaScript devs out there that can point me in the right direction? Should I just stick with using Eclipse? (Had that working, but I'm still curious about this debugger)
Download the latest rhino from the link you provided, at this time it is "rhino-1.7.8.zip". Unzip that and change directory to "rhino1.7.8/lib"; you need the "rhino-1.7.8.jar" in your CLASSPATH. Assuming you are in "rhino1.7.8/lib" that should be in your current folder, and you can then do
java -cp rhino-1.7.8.jar org.mozilla.javascript.tools.debugger.Main
Which should render like

'cocos' is not recognized as an internal or external command in the my project directory

I am very much beginner in cocos2d-js game development, I am learning it past two days. I tried to run the my project through cocos command BUT its showing cocos command is not recognized as internal or external command. I have followed this link to create and run the project http://cocos2d-x.org/docs/manual/framework/html5/v2/cocos-console/en
My project directory is D:\Mallikarjun_Disk\cocosAndroid\cocos2d-js-v3.0\cocos2d-js-v3.0\tools\cocos2d-console\bin\Projects\MySimpleGame
I moved to this directory to run my MySimpleGame in command prompt BUT its throwing error 'cocos' is not recognized as an internal or external command, operable program or batch file.
Please give suggestions what might be the problem.
Giving me a simple steps for running project would be much appreciated
You've most likely:
A. Not ran setup.py from your installation folder.
B. Already ran it, but haven't rebooted your system yet.
(Note that you need to have previously installed Python v2.x, Ant -and possibly CMake- in order for setup and all other commands to work).
If you've already done this and still get the error, make sure in your System's Environment Variables that the path to [your cocos2d-js install folder]\tools\cocos2d-console\bin has been added to your PATH.
It'd also be best if you let your project and cocos2d installation folders in two separate folders with short names and no spaces, for example:
C:\cocos2d-js
C:\cocos2d-projects\MySimpleGame
In cocos2d-x v3.2 for cpp i got same error.. it turned out
i did not run
source /Users/your_user/.profile (so that environment variables are actually updated)
this line is generated after you run setup.py
All steps:
Run setup.py
Run source /Users/your_user/.profile (so that environment variables are actually updated)
Run cocos new mygame -p com.your_company.mygame -l cpp -d /directory_to_your_game
replace cpp with js in above command

NPM modules in Grunt based projects

Node has a simple module loading system which uses require() method call to load modules from different locations in the root folder.
E.g.
var qr = require('qr-image');
I am trying to do something similar in grunt but i am unsuccessful with that.
I had added this module to package.json file in the following fashion and then ran npm install at root directory of the project.
"devDependencies": {
.
.
.
"qr-image": "^2.0.0"
},
Now whenever I use require I get the following error on console and my code breaks.
ReferenceError: require is not defined
Please suggest as how to use the npm module in Grunt based project, Thanks.
The require function isn't available in web browsers. Instead it's part of nodejs, which is a server-side language (e.g., something you might run directly from your computer terminal, not in a browser) and used to load dependencies in that language.
In a web browser, I usually just include my dependencies as additional scripts on the page, e.g.,:
<script src="path/to/my/dependency.js"></script>
<script src="path/to/my/code.js"></script>
Some other options are RequireJS or what's listed in this question or as more of a general purpose dependency manager for front-end code: Bower.
Looking closer at your question, it's likely that the "qr-image" npm dependency won't work in client-side code for you (since it was built to run via node in server-side code).
A quick search for QR code client-side code brought up this SO post, which points to the QRCode.js project for client-side QR code generation—I haven't used it, but it looks like a step in the right direction for what you're working on.

Categories

Resources