Angular 2 + i18n + AOT not working - node.js

I'm developing the language change utility using buttons (<a/> tags) so that the user can change the language if they click the link that contain the label of the corresponding language.
To develop it, I have taken as a reference the QuickStart project of Angular 2, I added AOT and JIT compilation, then I added the ng-xi18n module (JIT version) and finally, I added GULP module for generate files of other languages.
When I compile my project with JIT (using npm run start) and run it, my language change utility works fine.
The problem comes when I compile my project with AOT (using npm run start: aot) and I run it, my language change utility does not work.
Where is the problem?
My project (GitHub Link) has two main.ts and index.html - one for JIT and other for AOT.

Related

How to build native nodejs modules for launchui?

I'm building an app using proton-native.
it uses native modules written in C++, for example, keytar.
Proton-native uses a tool named launchui to package nodejs app as an executable. It's basically simple wrapper for nodejs with the following structure on windows:
- myapp.exe
- node.dll
- app/
- - main.js
- - node_modules/
- - - - keytar/
Native modules (node addons) does not work by default for such constructions because node-gyp tool links them against node.exe.
The usual approach is to run something like electron-rebuild, which would compile native modules to a version of node incorporated by electronjs.
However, In case of launchui there are no tools for that yet.
Could someone skilled in node-gyp or C++ linking explain what whould be the best approach to properly re-build native modules for launchui? I keep getting The specified procedure could not be found after running electron-rebuild and trying to run the app.
I have used dependencywalker to analyze current dependencies of the keytar.node and it shows that it depends on node.exe, however it should depend on node.dll.

How to build node js applciation?

it is generic question.
I know that if I have java project I can run mvn clean install and it will build the project and the artifacts will be jar or war in target folder
if U have node.js application How I can build it ? I know that I have package.json that could run with npm install and the artifices are node modules but I guess there is a way to build the result of the node application . what is the type of the result ?
How to build node js application?
You don't really "build" a regular node.js application. There is no compile step. There is no separate executable. Whatever your main entry Javascript file is, you would just run it with node main.js and everything else will be loaded from there as your Javascript files load other modules. The Javascript interpreter will compile your JS files on the fly as they are encountered. If there is a syntax error when the file is loaded, it will throw an exception at that time.
For the simplest possible hello world application, you'd just put this into a text file named main.js:
console.log("Hello World");
And, then type this at the command line:
node main.js
And, you would see your output in the console. No compile step. No build step.
There are transpilers and there are packagers that can do special things, but none of that is needed for a regular node.js app.
but if I write something wrong in the code.How i can check it for example like mvn
Javascript is an interpreted language (like PHP, Python, Perl, etc...), not like Java. You will likely get a run-time error when you run your app if you write something wrong in the code. Of course, there are all sorts of tools that will check things for you before you run your code (such as linters), but Javascript does not work like Java in that regard.
If you want a "typed" and "checked" language, then you can use TypeScript which is "compiled" into Javascript that node.js can run and the compile step for TypeScript will check your syntax for you, enforce data typing, etc...

Testing a module

I just implemented a Jhipster module to provide Maven site generation as well as maven release process within Jhipster.
I implemented mocha tests to verify that files are generated (which pass), but it looks like they aren't generated in a real scaffolded context (if you have any clue on the error, I would be really thankful).
The only way I found to test that module with a scaffolded sample is to publish it in the npm registry in order to be able to select it in module choices radio, but it's not really a good option, as it exposes a non working module on the Jhipster marketplace (I'm really sorry about it).
To test a module locally, do the following:
run npm link in your module directory
generate a project
run npm link generator-jhipster-enterprise-pom in your project
Now when you run yo jhipster-enterprise-pom it will use your local code instead of requiring installation from npmjs.
Looking at your module's code, it looks like you renamed the app folder to server. A yeoman generator runs the code found in the app folder which is why your local test is failing. According to the Writing Your Own Yeoman Generator docs:
The default generator used when you call yo name is the app generator. This must be contained within the app/ directory.
It's currently accessible by running yo jhipster-enterprise-pom:server but I imagine you don't want the :server included in the default command.

Clientside Javascript in Typescript Express projects

I always wondered how I can properly add the clientsided javascript in my express project. I use Typescript and I would also like to take advantage of the Typescript typings (for jquery for instance) when writing my clientside javascripts.
My project structure looks like this:
root
dist
src
helpers
models
registration
router.ts
form.pug
profile
router.ts
profile.pug
wwwroot
css
js
images
What I have done until today:
I created all clientsided javascript files in wwwroot/js (e.g. jquery.min.js, registration-form.js) and I loaded them into the header of the appropriate pages.
Disadvantages:
I had to write ES5 javascript which is compatible with the browsers we would like to support
I couldn't put the javascript files where they logically belong to (e. g. I'd rather put my registration-form.js into src/registration/ instead of the wwwroot)
No Typescript possible :(. No typescript typings, no transpiling to ES5 etc.
In some tutorials I saw they would simply run npm install --save jquery and import it in their clientsided files. So I feel like I must have missing some pretty important stuff, but I couldn't find any tutorials about it.
My question:
What is the "right way / best practice" to write clientsided javascript in Typescript / Express applications (which should also elliminate also the mentioned disadvantages)?
Using TypeScript on the client side is not much different from the server side.
Here is what you can do:
Create client folder for client-side typescript sources
Put tsconfig.json into client folder and configure it to produce "es5" code (target: es5)
Install jquery types (npm install --save-dev #types/jquery)
That's it, now you can write your client side code in TypeScript.
You can compile server-side code with tsc -p ./src (having server-side tsconfig.json under src) and compile client-side code with tsc -p ./client.
I made a simple example of such app, check it here. I put the simple script to build everything into package.json, so you can run npm run-script complie to get both server and client code complied into /dist folder. Then run it with npm start.
Further steps:
Automate your flow: you should be able to start your app locally and then just edit source TypeScript files and the app should be reloaded automatically. This can be done with webpack / gulp / grunt or custom shell script that can be triggered once any of your source file has been changed and saved.
If you find yourself writing good amount of client-side code, check also angular (https://angular.io/docs). It uses TypeScript as preferred language for client-side development and you'll be able to build much more powerful client-side app using it. You may choose another library as well (react, vue.js, etc), see the examples on the TypeScript site.

Building Electron with my own module

I am learning building Node modules and packaging it with Electron. I've successfully built an module out of a CPP file and can run it with node. However, to run it with Electron I need to rebuild Electron. There are instructions out there, for example:
https://github.com/electron/electron/blob/v0.37.2/docs/tutorial/using-native-node-modules.md#using-native-node-modules
https://github.com/electron/electron/issues/2330
Here I have an addon.node file after running node-gyp build. I can reference it in the node application from anywhere: var addon = require('.Release\addon'); and it works fine. However, when I build Electron with it I don't understand where to put the .node file so that it is used in the build. Before I run node_modules\.bin\electron-rebuild (see bullet point 1 link above) where should I put the addon.node file? Is it right to say that before I even test it withing Electron (with console.log or something) I need to run electron-rebuild. Is there a step that I missing that I need to take from having the addon.node file to starting to build it into Electron?
Thank you.

Resources