I'm trying to write a new library that would work in Scala.js. I have written some of the implementations of the classes and methods in Javascript. How do I set it up so that a user can code in Scala.js (Scala)?
I've looked at some Scala.js libraries on GitHub, but these do not show the Javascript code; they all appear to be .scala files.
So how does one actually create a new library for Scala.js?
Edit: The main code for the library must be written in Javascript since it takes advantage of the Javascript audio api.
Somewhat agreeing with the comment from #sjrd, it should be possible to write your JavaScript-targeted API directly within Scala.js (See Calling JavaScript from Scala.js ).
Alternatively, there may also be the possibility for 'importing' or converting your existing JavaScript code into Scala.js '.scala' files in a strongly-typed-Scala manner, so:
Convert your JavaScript file to TypeScript, start by changing the file extension from '.js' to '.ts'.
Process your TypeScript file(s)
created in #1 into valid Scala[JS] files using #sjrd's (!) TypeScript-to-ScalaJS
importer # Github.
Finally, develop your code against Scala.js, using the '.scala'
files generated in #2
As TypeScript is a strongly-typed superset of JavaScript, changing the extension alone might be enough - otherwise, after running and failing step #2, you might need to refine you TypeScript'd library, this post, 'How to compile plain *.js (JavaScript) files with the TypeScript Compiler', should help with that.
The 'DefinitelyTyped' code repository # Github contains a collection of JavaScript libraries updated to TypeScript, the webaudio API is one of them (so this could be converted and used within Scala.JS using some of the process outlined above).
I haven't [yet] personally tested this myself, in anger, I'd be interested in whether you get any mileage out of this tool set/process.
Here are some extra TypeScript resources:
http://en.wikipedia.org/wiki/TypeScript
http://www.sitepen.com/blog/2013/12/31/definitive-guide-to-typescript
Related
I can't seem to find a basic piece of tooling which is a static analyzer that shows me which pieces of code use methods from which other pieces. I could even do with a very primitive one that only shows me which source files contain references to names found in other files in a NodeJS project (still using CJS require here). So far all I have found is a couple of abandoned projects, but one should think there simply must be something out there.
Edit: Graphical output is not required (but certainly a plus); what I primarily need is a tabulation (text) of which functions in which module call functions from which other modules so I can order dependencies.
Sublime text has this feature where when you hover over a name you get the location where that name was defined; this even works across modules and with CoffeeScript. Does anybody know how that is implemented?
This is an actively maintained proprietary call graph generator that supports multiple languages.
Usage : callGraph <files> <options>
https://github.com/koknat/callGraph
I’ve been looking for a similar tool to help my team track the indirect usage of a deprecated function, so I ended up writing a script based on the ts-morph module: https://gist.github.com/adrienjoly/fc117b187f87cca3417abc4a8433e3a2
It’s a node.js CLI that generates the call tree (a.k.a. call hierarchy, or dependency graph) of a function. You can probably modify it to support JavaScript projects. Or create a tsconfig.Json file that includes your JavaScript files.
Hope this helps!
Im angular developer.
In our front & back exists some magic calculation methods.
Classes same, but when anyone find bug in calculation need to fix it in two different projects.
maybe there is a way to create a generic codebase (maby function) that can be converted to js(or ts) & java and update two libraries based on the two results obtained
You could try to use kotlin.
Kotlin transpiles to JavaScript and also compiles to java bytecode.
However, you can only access kotlin utilities and neither access java or JS/TS types if you want to use the code in both java and ts/js code but you can use the kotlin stdlib.
But if it really is just a calculation, you may not need java/js specific classes/functions.
However, as VLAZ mentioned in the comments, you should consider doing the calculation only once in the backend.
Setting this up in IntelliJ
You can create such a project in IntelliJ by sekecting Kotlin in the New Project Window and using the project template Library.
Make sure you have the targets common, jvm and js. Since you didn't say you would do native stuff, you don't need the native target.
You can then use the kotlin library in both JavaScript (e.g. Angular) and Java projects as a dependency.
From a Java project, you can reference KOTLIN_PROJECT/build/classes/kotlin/jvm/main (this directory contains compiled Java classes).
From a JavaScript (e.g. Angular) project, you can reference KOTLIN_PROJECT/build/js/packages/kotlinToJavaAndJS.
As a proof of concept, I have made this repository on GitHub.
I know that it's possible to transform avdl to series of avsc files using java tools provided by Apache.
But despite the website lists plenty of implementations on different languages too, including JS, it seems to be that there is no support for avdl -> avsc conversion in these.
What would be your recommendation how to perform this conversion in pure JavaScript? Does such library even exists or we're forced to go through pure Java implementation always?
Java seems to be the only language that they implemented the compilation from avdl to avsc. The easiest route is probably just to have the avro-tools.jar somewhere and then have your JS code call out to that in some sub process to compile the schemas.
The other option would be to re-implement the IDL compiler in JS. I wouldn't do that, but the Java implementation is pretty much all contained within https://github.com/apache/avro/blob/master/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj if you wanted to take a look.
Netbeans has the ability to create an HTML5/JavaScript project.
I have written a bunch of javascript code that I would like to document. The javascript functions/classes are documented in the source code using java-style comment blocks and "standard" tags (e.g. #param).
I am looking for some way to generate an html or json document from the javascript files. For example, in Netbeans you can generate a JavaDoc via Ant. Is there something similar for a HTML5/JavaScript project?
BTW, I don't use Node.js and I don't want to install npm/node just to generate docs...
I am writing a web server in Node.js, and I want it (among other things) to deliver a single JavaScript file to the client which contains my client SDK. The SDK is basically an object which provides lots of functionality the client can use.
I need to build the SDK from various sources:
3rd party libs, such as AngularJS
Custom code, which is stored in static .js files on the server
Custom code, which is created dynamically in-memory at runtime
For being able to test my custom code (#2) easily, and for being able to share this code with the server-side as well, it would be great if I could write it according to CommonJS.
I do not have too much experience with bundling things up for the client-side, but I know UglifyJS and Browserify.
If it was only about concatenating some files (and perhaps minifying them), I knew what to do with UglifyJS. If it was only about delivering some stuff that is compatible to CommonJS, I also knew what to do with Browserify. What I don't get is their combination, and this in addition with demand #3 - the dynamically generated code.
This essentially means that I am not able to use Grunt for this, but that everything needs to be done at runtime (please let's not discuss why I want to do it like this).
So … I'm somewhat lost. Can anybody help clarify things for me? How do I have to put all these pieces together so that I finally end up with a single deliverable that can be sent to the client, and that the client can use?
Basically, what the client should end up with is a number of global objects such as $, angular and my very own custom object, but all this by only loading one single file.
How could I do this?
PS: I do not have the need to put the result to disk on the server, if it's a pure in-memory solution that's perfectly fine for me (and is even preferred, as then I do not need write access to the file system).
Imho webpack provides all the features you need. It's a bundler like browserify but I find it more flexible and extensible. webpack is agnostic to different module styles (CommonJS, AMD, ES6 or old-school globals) and is able to apply and chain pre-processors on modules. These are called loaders (according to the CommonJS spec) and can be used to generate code dynamically. Usually they transform LESS to CSS or CSS to JavaScript, but they can be used for any dynamic task.
To provide your global $, angular and your custom object you could use the script-loader, which runs the given module classically in a global context.
What you're looking for is called "asset pipeline".
You can use mincer (I didn't try it, but it looks very promising) or asset-pipeline (certainly will do the job, but is kinda deprecated).