I'm new to using CoffeeScript and this is my first time trying it out. I have two questions.
Compile to particular file
I want to compile a particular coffee file to javascript on the fly.
To do this, I've done the following:
coffee -w -o controllers/loginCtrl.js -c coffeescripts/loginCtrl.coffee
This gives me
ENOENT, open 'c:\path\to\public\testassets\js\controllers\loginCtrl.js\loginCtrl.js'
I believe this is happening because the js file already exists. If I remove the js file, the same command creates a folder called loginCtrl.js and then adds a file inside it.
How do I get coffeeScript to compile to a particular existing file or to a proper path?
Remove unneeded code from compiled file
Assuming that the file gets compiled, the new js file gets compiled as
(function() {
....
}).call(this);
Is it possible for me to remove the first and last lines of this compiled code?
The -o option specifies the output directory. You sholud get the expected output if you remove the file name from this argument.
To compile without the top-level function safety wrapper, use the -b option.
Please read about the coffee command options here: http://coffeescript.org/#usage
With param -o you can set output directory but the name of your js file will be the same as name of coffee file
If you want to prevent coffeescript from wrapping the code into immediately invoked function, you need to add param -b or --bare ("Compile the JavaScript without the top-level function safety wrapper." from official docs)
Related
I am familiar with adding individual environment variables through the CLI by entering:
./node_modules/.bin/cypress run -- --env itemToOverride="val"
But let's say I have an entire JSON that can be a valid cypress.env, how do I pass that in via CLI without having to add each item from the JSON individually?
For example, let's say I have env1.json and env2.json which both have valid structure for my test, but I want to be able to run all my tests with env1 then env2? Similar to:
./node_modules/.bin/cypress run -- --env env1.json
For others that stumble here and want a working answer: The easiest solution to this would be to create a config folder in your project directory containing all the environment JSONs you want. I wrote a script to take an environment file's name as an argument when running it. I decided on a bash script, but you could also use an npm script to achieve this. Basically, to run the tests in "env1" you would type on your command line:
./cypress --env=env1
The way I achieved this was by copying the selected JSON from the config folder to the main directory, then renaming it 'cypress.env.json'. This is a setup function in my bash script to get you started:
function doSetup {
echo "Selecting environment variables from $ENV.env.json"
cp ./cypress/config/"$ENV.env.json" ./
mv "$ENV.env.json" "cypress.env.json"
}
It's an obscure problem that does not have very many answers online, but I hope this helps!
With the following folder structure:
mypackage/
index.js
package.json
mypackage.json
When I run node mypackage, node quits without running the program, because of mypackage.json. If I rename it to mypackage.jsonx, then the program executes as expected.
I really want this file to be named mypackage.json, and I want to run program with a package name without specifying path to index.js, because I want to use an advantage of exports and different entrypoints.
I've tried to specify node ./mypackage and node ./mypackage/ and node mypackage/ - it still "runs" the json.
This might be your answer: https://zellwk.com/blog/ignoring-files-from-npm-package/
If you want to ignore specific files, there's a couple ways to do it (.gitignore/.npmignore). You can also whitelist files that you want to include by adding a files property to your package.json file.
I am working with angular 8, I have finished my project and I have used lazy loading, after having my project ready I have done an ng build --prod (therefore I generated several javascript files).
We use Django as a server, and because of our way of working we separate the JS and CSS files in a folder and the index.html in the root, what is the problem?
What the files to be called within the runtime file have an undefined path, I see that it has a src function that returns the location of the file, but I don't know how to modify this function.
Inside to runtime.js we have this
After performing a console.log in the variable "u.p" I can see EMPTY,
How can I modify a U.P. variable/function? I want to place u.p. = "js /" (I have manually replaced u.p with what I need and it works, but I want it to be automatic) I understand that it must be an Angular.json configuration or an extra command when doing the ng build --prod
Here is the task:
I want to run .js file which was created by Emscripten from .cpp file, from another .js file.
i.e.: I have ping.cpp file, which simply displays text "ping". I use Emscripten to create ping.js To do it, I type em++ ping.cpp and here it is - ping.js.
Now I can run it using node ping.js, but I want it to run from my second .js file which is called init.js and I can't understand how should I do it. Because ping.js doesn't have main functions which display "ping" and which I can call from another .js file or for example .html file, instead of this it has 68500 lines of code.
So, is there any chance for me to run ping.js from init.js?
You should probably load your ping.js file with a script tag in your HTML file, just like any other script. The trick is to make sure that you make any functions you want to use accessible to OTHER scripts that you load. To do so, you need to set an EXPORTED_FUNCTIONS compilation flag to indicate which function names you want to preserve. Specifically
em++ -s EXPORTED_FUNCTIONS="['_ping']" ping.cpp -o ping.js
Note the underscore ('_') that needed to be added in front of the function name to compensate for name mangling.
In the other JS file where you want to use ping, you need to set it up. Make sure the compiled script loads first, and then do:
ping = Module.cwrap('ping', 'null', ['string']);
This will then allow you to use ping, assuming it has a void return type (hence the null) and a single c-style string argument (hence the ['string']).
If you really do want to load it from another JavaScript file, see this answer:
How do I include a JavaScript file in another JavaScript file?
I have just installed ctags and am trying to use it in Vim in web-development.
First I have set set tags=tags;/. This will help the tag to find the source from the project directory to root.
I have run ctags -R in the project directory and a tags file has been generated. While generating the tags file it throws a warning :
ctags: Warning: ignoring null tag in filename.js
However, when I use the shortcuts(like ctrl+]) they do not open the source(jump to definition) files. Instead an error shows tag not found filename.js
What am I missing or doing wrong?
I think you should use the ./ prefix, so that the search starts with the current file's path, not the current working directory. And you don't need the / stop directory; the following should work:
set tags=./tags;
For troubleshooting, the tagfiles() function prints all found tags files. Check that your is found via
:echo tagfiles()
Adding to what Ingo Karkat said, you could also test manually by changing your current working directory to where your tags files are.
:pwd
Use pwd to check if your are not already there. If not you change directory to your tag file directory.
:cd /your/tag/file/directory
Then try again Ctrl].