JHipster generator: addMavenDependency is not defined - jhipster

I'm trying to create a JHipster generator to setup Axon2 for the generated project.
In order to add a java library to the project I'using the function
addMavenDependency in the index.js,
try {
addMavenDependency('org.axonframework', 'axon-integration', '2.4.6','');
}catch (e) {
but I receive the following error:
ERROR!
Problem when adding the new libraries in your pom.xml
You need to add manually:
"org.axonframework:axon-integration": "2.4.6",
ReferenceError: addMavenDependency is not defined
Any help will be really appreciated.

You need to extend the BaseGenerator and call this.addMavenDependency().
Unless you are composing with another generator, then you can pass an object to be populated with the variables and functions being used by the generator like so:
const jhipsterVar = { moduleName: 'your-module' };
const jhipsterFunc = {};
module.exports = generator.extend({
initializing: {
compose() {
this.composeWith('other-module',
{ jhipsterVar, jhipsterFunc },
this.options.testmode ? { local: require.resolve('generator-jhipster/generators/modules') } : null
);
}
},
writing: {
jhipsterFunc.addMavenDependency('com.test', 'test', '1.0.0');
}
});

Related

Are Decorators allowed in NodeJS?

I'm trying to run the following code in NodeJS using terminal
function addStringToName(target, name, descriptor) {
const fn = descriptor.value;
descriptor.value = wrestler => {
fn.call(target, wrestler + ' is a wrestler');
};
}
class Wrestler {
#addStringToName
setName(name) {
this.name = name;
}
sayName() {
console.log(this.name);
}
}
const w = new Wrestler();
w.setName('Macho Man');
w.sayName();
Getting the following error
Can Decorators be used in NodeJS if yes what is wrong with the written code ?
Unfortunately, no. You have to use TypeScript in order to have decorators enabled. Moreover, even TypeScript doesn't support it natively. You will have to have target: "ES5" at least and "experimentalDecorators": true.
You can find more about decorators and TypeScript here: https://www.typescriptlang.org/docs/handbook/decorators.html

Mock $root with vue-test-utils and JEST

My component has the following computed code:
textButton() {
const key = this.$root.feature.name === //...
// ...
},
Right now I'm trying desperately to mock "root" in my test, but I just don't know how. Any tips?
Vue test utils provides you with the ability to inject mocks when you mount (or shallow mount) your component.
const $root = 'some test value or jasmine spy'
let wrapper = shallow(ComponentToTest, {
mocks: { $root }
})
That should then be easily testable. Hope that helps
There are two ways to accomplish this with vue-test-utils.
One way, as mentioned above, is using the mocks mounting option.
const wrapper = shallowMount(Foo, {
mocks: {
$root: {
feature: {
name: "Some Val"
}
}
}
})
But in your case, you probably want to use the computed mouting option, which is a bit cleaner than a deep object in mocks.
const wrapper = shallowMount(Foo, {
computed: {
textButton: () => "Some Value"
}
})
Hopefully this helps!
If you are interested I am compiling a collection of simple guides on how to test Vue components here. It's under development, but feel free to ask make an issue if you need help with other related things to testing Vue components.
Solution from https://github.com/vuejs/vue-test-utils/issues/481#issuecomment-423716430:
You can set $root on the vm directly:
wrapper.vm.$root = { loading: true }
wrapper.vm.$forceUpdate()
Or you can pass in a parent component with the parentComponent mounting option. In VTU, the paren will be the $root:
const Parent = {
data() {
return {
loading: "asdas"
}
}
}
const wrapper = shallowMount(TestComponent, {
parentComponent: Parent
})
You may use a Vue Plugin inside the test to inject the mock data into localVue so that your components can access it.
import {createLocalVue, shallow} from '#vue/test-utils';
const localVue = createLocalVue();
localVue.use((Vue) => {
Vue.prototype.feature = {
name: 'Fake news!'
};
});
let wrapper = shallow(Component, {
localVue
});
I had the same issues a while ago and I came to the conclusion that accessing this.$root may be a sign that you have to further improve the way you communicate with components. Consider using the plugin structure to define globally available properties and methods not only inside the test for example. Mixins might be helpful as well.
https://v2.vuejs.org/v2/guide/plugins.html
https://v2.vuejs.org/v2/api/#mixins

How to load google maps javascript api in Aurelia javascript application?

I found npm module google-maps-api and installed it (npm install google-maps-api) but I can't figure out how to import it with systemjs/jspm (jspm cannot find this module). Here's the configuration from my config.js:
"paths": {
"*": "app/dist/*.js",
"github:*": "app/jspm_packages/github/*.js",
"npm:*": "app/jspm_packages/npm/*.js" }
So, when I try do something like this:
import {mapsapi} from 'google-maps-api';
I get the following error in browser console:
GET https://localhost:44308/app/dist/google-maps-api.js 404 (Not Found)
Looking at the filesystem I see that npm installed the module under app/node_modules/google-maps-api so how do I reference it in the import clause from Aurelia module?
I found a solution and answering my own question here:
I finally figured how to install it with jspm, so you just need to give a hint to jspm to install it from npm like so:
jspm install npm:google-maps-api
After jspm completes installation, import (no {} syntax) works fine:
import mapsapi from 'google-maps-api';
then I inject it in constructor and instantiate geocoder api:
#inject(mapsapi('InsertYourGMAPIKeyHere'))
export class MyClass {
constructor(mapsapi) {
let that = this;
let maps = mapsapi.then( function(maps) {
that.maps = maps;
that.geocoder = new google.maps.Geocoder();
});
...
}
In order to create map on a div I use EventAggregator to subscribe for router:navigation:complete event and use setTimeout to schedule map creation:
this.eventAggregator.subscribe('router:navigation:complete', function (e) {
if (e.instruction.fragment === "/yourRouteHere") {
setTimeout(function() {
that.map = new google.maps.Map(document.getElementById('map-div'),
{
center: new google.maps.LatLng(38.8977, -77.0366),
zoom: 15
});
}, 200);
}
});
Here's a complete view-model example that uses attached() to link to your view.
import {inject} from 'aurelia-framework';
import mapsapi from 'google-maps-api';
#inject(mapsapi('your map key here'))
export class MapClass {
constructor(mapsAPI) {
this.mapLoadingPromise = mapsAPI.then(maps => {
this.maps = maps;
});
}
attached() {
this.mapLoadingPromise.then(() => {
var startCoords = {
lat: 0,
long: 0
};
new this.maps.Map(document.getElementById('map-div'), {
center: new this.maps.LatLng(startCoords.lat, startCoords.long),
zoom: 15
});
});
}
}
For everyone using Typescript and getting "Cannot find module 'google-maps-api'" error,
you need to add typings to the solution. Something like this works
declare module 'google-maps-api' {
function mapsapi(apikey: string, libraries?, onComplete?);
namespace mapsapi {
}
export = mapsapi;
}
and then import it like this
import * as mapsapi from 'google-maps-api';

Defining modules in UI5

I am trying to keep my code separated in modules. When I defined my first module I extended sap.ui.base.Object and it worked. My question is: Is it a must to extend sap.ui.base.Object when defining my own module? According to the API documentation I tried following example:
sap.ui.define([], function() {
// create a new class
var SomeClass = function();
// add methods to its prototype
SomeClass.prototype.foo = function() {
return "Foo";
}
// return the class as module value
return SomeClass;
});
I required this module inside my Component.js as dependency like this:
sap.ui.define([
"path/to/SomeClass"
], function (SomeClass) {
"use strict";
//var test = new SomeClass();
I always receive a syntax error:
failed to load '[...]/Component.js' from ./Component.js: Error: failed to load '[...]/module/SomeClass.js' from ./module/Service.js: SyntaxError: Unexpected token ;
Does anyone have an idea why this happens? Thanks!
We group code in modules like this for example:
jQuery.sap.declare("our.namespace.iscool.util.Navigation");
our.namespace.iscool.util.Navigation = {
to: function (pageId, context) {
// code here
}
// etc.
}
and call the function of the module like this in a controller
jQuery.sap.require("our.namespace.iscool.util.Navigation");
sap.ui.controller("our.namespace.iscool.Detail", {
// somewhere in this file comes this
handleNavButtonPress: function (evt) {
our.namespace.iscool.util.Navigation.navBackToMaster(
evt.getSource().getBindingContext()
);
},
}
Stupid mistake - missing curly brackets in the docs.
var someclass = function() {} ;

Uncaught Error: [$injector:unpr] Unknown provider: sessionInjectorProvider

I am new to angular js, loopback and nodejs,
While implementing the authentication in the angular app, I am getting the below mentioned error
Uncaught Error: [$injector:unpr] Unknown provider: sessionInjectorProvider <- sessionInjector <- $http <- $compile
I was going through this document, but no help.
http://www.webdeveasy.com/interceptors-in-angularjs-and-useful-examples/
This error came when I added the below lines for sessionInjector
angular.module('myApp', []).factory('sessionInjectorProvider', ['SessionService', function(SessionService) {
var sessionInjector = {
request: function(config) {
if (!SessionService.isAnonymus) {
config.headers['x-session-token'] = SessionService.token;
}
return config;
}
};
return sessionInjector;
}]);
angular.module('myApp', []).config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('sessionInjector');
}]);
There are for sure at least two errors in your code:
angular.module('myApp', []) creates a module, whereas angular.module('myApp') calls the module. This means that at the end of your code you're creating again the module and hence losing what you had written before.
There are different ways to format this code, one that would solve the problem would be:
angular.module('myApp', [])
.factory('sessionInjectorProvider', ['SessionService', function(SessionService) {
var sessionInjector = {
request: function(config) {
if (!SessionService.isAnonymus) {
config.headers['x-session-token'] = SessionService.token;
}
return config;
}
};
return sessionInjector;
}])
.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('sessionInjectorProvider');
}]);
Also, as mentioned already, you're mixing 'sessionInjectorProvider' and 'sessionInjector' - your interceptor should use 'sessionInjectorProvider' as shown in the code I posted above.

Resources