Skip to content

Commit 270bdce

Browse files
author
Jonathan Casarrubias
committed
Release 2.0.6 🚀
- Hot Fix: #107
1 parent e33da85 commit 270bdce

57 files changed

Lines changed: 585 additions & 408 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This file is created to keep history of the LoopBack SDK Builder, it does not consider or keeps any history of its parent module `loopback-sdk-angular`.
44

5+
## Release 2.0.6
6+
7+
- Hot Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/107
8+
59
## Release 2.0.5
610

711
- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/100

bin/lb-sdk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var argv = optimist
3636
*/
3737
console.log('================================================================================================================================');
3838
console.log('* __ ____ __ _____ ____ __ __ ____ _ __ __ _ _____ *');
39-
console.log('* / / ___ ___ ____ / __ )____ ______/ /__ / ___/ / __ \\/ //_/ / __ )__ __(_) /___/ /__ _____ | | / /__ \\ *');
39+
console.log('* / / ___ ___ ____ / __ )____ ______/ /__ / ___/ / __ \\/ //_/ / __ )__ __(_) /___/ /__ _____ | | / /__ \\ *');
4040
console.log('* / / / __ \\/ __ \\/ __ \\/ __ / __ \'/ ___/ //_/ \\__ \\/ / / / ,< / __ / / / / / / __ / _ \\/ ___/ | | / /__/ / *');
4141
console.log('* / /___/ /_/ / /_/ / /_/ / /_/ / /_/ / /__/ , < ___/ / /_/ / /| | / /_/ / /_/ / / / /_/ / __/ / | |/ // __/ *');
4242
console.log('* /_____/\\____/\\____/ .___/_____/\\__,_/\\___/_/|_| /_____/_____/_/ |_| /_____/\\__,_/_/_/\\__,_/\\___/_/ |___//____/ *');
@@ -75,7 +75,7 @@ function verifyPath() {
7575
output: process.stdout
7676
});
7777

78-
rl.question('\n\nIMPORTANT: The targeted SDK Directory is not empty, do you want to erase its content? (Y/n) ', (answer) => {
78+
rl.question('\n\nWARNING: The targeted SDK Directory is not empty, do you want to erase its content? (Y/n) ', (answer) => {
7979
switch (answer) {
8080
case 'No':
8181
case 'no':

lib/angular2/index.js

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ module.exports = function generate(ctx) {
5050
output: '/index.ts',
5151
params: {
5252
isIo: ctx.isIo,
53-
models: ctx.models
53+
models: ctx.models,
54+
buildModuleImports: buildModuleImports
5455
}
5556
},
5657
{
5758
template: './shared/sdk.module.ejs',
5859
output: '/sdk.module.ts',
5960
params: {
6061
isIo: ctx.isIo,
61-
models: ctx.models
62+
models: ctx.models,
63+
buildModuleImports: buildModuleImports
6264
}
6365
},
6466
{
@@ -105,7 +107,10 @@ module.exports = function generate(ctx) {
105107
{
106108
template: './shared/services/core/base.ejs',
107109
output: '/services/core/base.service.ts',
108-
params: { isIo: ctx.isIo }
110+
params: {
111+
isIo: ctx.isIo,
112+
buildBaseServiceImports: buildBaseServiceImports
113+
}
109114
},
110115
{
111116
template: './shared/services/core/error.ejs',
@@ -114,7 +119,7 @@ module.exports = function generate(ctx) {
114119
},
115120
{
116121
template: './shared/services/core/logger.ejs',
117-
output: '/services/core/logger.service.ts',
122+
output: '/services/custom/logger.service.ts',
118123
params: {}
119124
},
120125
{
@@ -279,7 +284,19 @@ module.exports = function generate(ctx) {
279284
*/
280285
function buildServiceImports(model) {
281286
let modelName = capitalize(model.name);
282-
let output = [`import { ${modelName} } from '../../models/${modelName}'`];
287+
let imports = [
288+
{ module: 'Injectable, Inject, Optional', from: '@angular/core'},
289+
{ module: 'Http, Response', from: '@angular/http'},
290+
{ module: 'BaseLoopBackApi', from: '../core/base.service'},
291+
{ module: 'LoopBackConfig', from: '../../lb.config'},
292+
{ module: 'LoopBackAuth', from: '../core/auth.service'},
293+
{ module: 'LoopBackFilter', from: '../../models/BaseModels'},
294+
{ module: 'JSONSearchParams', from: '../core/search.params'},
295+
{ module: 'ErrorHandler', from: '../core/error.service'},
296+
{ module: 'Subject', from: 'rxjs/Subject'},
297+
{ module: 'rxjs/add/operator/map' },
298+
{ module: modelName, from: `../../models/${modelName}`},
299+
];
283300
let loaded = {}; loaded[model.name] = true;
284301
getModelRelations(model).forEach((relationName, i) => {
285302
let targetClass = model.sharedClass.ctor.relations[relationName].targetClass;
@@ -296,18 +313,82 @@ module.exports = function generate(ctx) {
296313
let through = capitalize(model.sharedClass.ctor.relations[relationName].modelThrough.sharedClass.name);
297314
if (!loaded[through]) {
298315
loaded[through] = true;
299-
output.push(`import { ${through} } from '../../models/${through}'`);
316+
imports.push({ module: through, from: `../../models/${through}` });
300317
}
301318
}
302319
// Now and after the through model was included is the right time to verify if the current model
303320
// was loaded by another relationship, this way we don't duplicate the class during imports'
304321
if (!loaded[targetClass]) {
305322
loaded[targetClass] = true;
306-
output.push(`import { ${targetClass} } from '../../models/${targetClass}'`);
323+
imports.push({ module: targetClass, from: `../../models/${targetClass}` });
307324
}
308325
});
309-
output.push(`import { LoopBackFilter } from '../../models/BaseModels'`);
310-
return output.join(';\n');
326+
327+
return buildImports(imports);
328+
}
329+
/**
330+
* @method buildModuleImports
331+
* @description
332+
* Define import statement for the SDK Module
333+
*/
334+
function buildModuleImports(models, isIndex) {
335+
let imports = [
336+
{ module: 'JSONSearchParams', from: './services/core/search.params'},
337+
{ module: 'ErrorHandler', from: './services/core/error.service'},
338+
{ module: 'LoopBackAuth', from: './services/core/auth.service'},
339+
{ module: 'LoggerService', from: './services/custom/logger.service'},
340+
];
341+
342+
if (!isIndex) {
343+
imports = imports.concat([
344+
{ module: 'HttpModule', from: '@angular/http'},
345+
{ module: 'CommonModule', from: '@angular/common'},
346+
{ module: 'NgModule, ModuleWithProviders', from: '@angular/core'}
347+
]);
348+
}
349+
350+
Object.keys(models).forEach(modelName => {
351+
let name = capitalize(modelName);
352+
imports.push({ module: `${name}Api`, from: `./services/custom/${name}` });
353+
});
354+
355+
return buildImports(imports);
356+
}
357+
/**
358+
* @method buildBaseServiceImports
359+
* @description
360+
* Define import statement for the SDK Module
361+
*/
362+
function buildBaseServiceImports(isIo) {
363+
let imports = [
364+
{ module: 'Injectable, Inject, Optional', from: '@angular/core'},
365+
{ module: 'Http, Headers, Request', from: '@angular/http'},
366+
{ module: 'NgModule, ModuleWithProviders', from: '@angular/core'},
367+
{ module: 'JSONSearchParams', from: './search.params'},
368+
{ module: 'ErrorHandler', from: './error.service'},
369+
{ module: 'LoopBackAuth', from: './auth.service'},
370+
{ module: 'LoopBackConfig', from: '../../lb.config'},
371+
{ module: 'rxjs/add/operator/catch' },
372+
{ module: 'rxjs/add/operator/map' },
373+
];
374+
375+
if (isIo) {
376+
imports.push({ module: 'Subject', from: 'rxjs/Subject'});
377+
imports.push({ module: 'SocketConnections', from: '../../sockets/socket.connections'});
378+
}
379+
380+
return buildImports(imports);
381+
}
382+
/**
383+
* @method buildImports
384+
* @description
385+
* Transform an array of objects describing which should be imported into
386+
* the actual template strings
387+
*/
388+
function buildImports(imports) {
389+
return imports.map(item =>
390+
`import ${(item.from ? `{ ${item.module} }` : `'${item.module}'`)} ${(item.from ? ` from '${item.from}'` : '')};`
391+
).join('\n');
311392
}
312393
/**
313394
* @method normalizeMethodName

lib/angular2/shared/index.ejs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,7 @@
1919
*
2020
* READ: https://angular.io/docs/ts/latest/cookbook/rc4-to-rc5.html#!#5-cleanup
2121
**/
22-
23-
import {
24-
LoopBackAuth,
25-
ErrorHandler,
26-
LoggerService,
27-
JSONSearchParams,<%
28-
Object.keys(models).forEach(function(modelName, i, arr) {
29-
modelName = modelName[0].toUpperCase() + modelName.slice(1);
30-
%>
31-
<%- modelName %>Api<%= i < arr.length -1 ? ',' : '' %><%
32-
});%>
33-
} from './services/index';
22+
<%- buildModuleImports(models, true) %>
3423
/**
3524
* IMPORTANT: API_PROVIDERS WILL BE DEPRECATED WHEN ANGULAR 2 IS STABLE
3625
* PLEASE MIGRATE YOUR PROJECT AS SOON AS POSSIBLE.
@@ -51,6 +40,7 @@ Object.keys(models).forEach(function(modelName, i, arr) {
5140
export * from './models/index';
5241
export * from './services/index';
5342
export * from './lb.config';
43+
export * from './sdk.module';
5444
<% if ( isIo === 'enabled' ){ -%>export * from './sockets/index';
5545
<% }
5646
-%>

lib/angular2/shared/sdk.module.ejs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,7 @@
3232
* export class AppModule { }
3333
*
3434
**/
35-
36-
import { HttpModule } from '@angular/http';
37-
import { CommonModule } from '@angular/common';
38-
import {
39-
NgModule,
40-
ModuleWithProviders
41-
} from '@angular/core';
42-
import {
43-
LoopBackAuth,
44-
ErrorHandler,
45-
LoggerService,
46-
JSONSearchParams,<%
47-
Object.keys(models).forEach(function(modelName, i, arr) {
48-
modelName = modelName[0].toUpperCase() + modelName.slice(1);
49-
%>
50-
<%- modelName %>Api<%= i < arr.length -1 ? ',' : '' %><%
51-
});%>
52-
} from './services/index';
35+
<%- buildModuleImports(models, false) %>
5336

5437
@NgModule({
5538
imports: [ CommonModule, HttpModule ],
@@ -70,7 +53,7 @@ export class SDKModule {
7053
Object.keys(models).forEach(function(modelName, i, arr) {
7154
modelName = modelName[0].toUpperCase() + modelName.slice(1);
7255
%>
73-
<%- modelName %>Api<%= i < arr.length -1 ? ',' : '' %><%
56+
<%- modelName %>Api<%= i < arr.length -1 ? ',' : '' %><%
7457
});%>
7558
]
7659
};

lib/angular2/shared/services/core/base.ejs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
/* tslint:disable */
2-
import { Injectable, Inject, Optional } from '@angular/core';
3-
import { Http, Headers, Request } from '@angular/http';
4-
<% if ( isIo === 'enabled' ){ -%>import { Subject } from 'rxjs/Subject';
5-
<% } -%>
6-
import 'rxjs/add/operator/catch';
7-
import 'rxjs/add/operator/map';
8-
import {
9-
LoopBackAuth,
10-
LoopBackConfig,
11-
ErrorHandler,
12-
<% if ( isIo === 'enabled' ){
13-
-%>SocketConnections,<% }
14-
-%>
15-
JSONSearchParams
16-
} from '../../index';
17-
18-
2+
<%- buildBaseServiceImports() %>
3+
/**
4+
* @module BaseLoopBackApi
5+
* @author Nikolay Matiushenkov <https://github.com/mnvx>
6+
* @contributor Jonathan Casarrubias <@johncasarrubias> <github:jonathan-casarrubias>
7+
* @license MTI
8+
* @description
9+
* Abstract class that will be implemented in every custom service automatically built
10+
* by the sdk builder.
11+
* It provides the core functionallity for every API call, either by HTTP Calls or by
12+
* WebSockets.
13+
**/
1914
@Injectable()
2015
export abstract class BaseLoopBackApi {
2116

lib/angular2/shared/services/core/index.ejs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* tslint:disable */
2-
export * from './logger.service';
32
export * from './auth.service';
43
export * from './error.service';
54
export * from './search.params';

lib/angular2/shared/services/custom/index.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
-%>
77
export * from './<%- modelName %>';
88
<% } // for modelName in models -%>
9+
export * from './logger.service';

lib/angular2/shared/services/custom/service.ejs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
/* tslint:disable */
2-
import { Injectable, Inject, Optional } from '@angular/core';
3-
import { Http, Response } from '@angular/http';
4-
import { BaseLoopBackApi } from '../core/base.service';
5-
import { LoopBackConfig } from '../../lb.config';
6-
import { LoopBackAuth } from '../core/auth.service';
7-
import { JSONSearchParams } from '../core/search.params';
8-
import { ErrorHandler } from '../core/error.service';
92
<%- buildServiceImports(model) %>
10-
import { Subject } from 'rxjs/Subject';
11-
import 'rxjs/add/observable/throw';
12-
import 'rxjs/add/operator/map';
13-
import 'rxjs/add/operator/catch';
14-
import 'rxjs/add/operator/share';
153

164
// Making Sure EventSource Type is available to avoid compilation issues.
175
declare var EventSource: any;
@@ -95,14 +83,13 @@ export class <%-: modelName %>Api extends BaseLoopBackApi {
9583
9684
let result = this.request(method, url, routeParams, urlParams, postBody)<%
9785
if (model.isUser && methodName === 'login') { %>
98-
.share();
99-
result.subscribe(
86+
.map(
10087
(response: { id: string, userId: string, user: any }) => {
10188
this.auth.setUser(response.id, response.userId, response.user);
10289
this.auth.setRememberMe(true);
10390
this.auth.save();
104-
},
105-
() => null
91+
return response;
92+
}
10693
);
10794
return result;
10895
<%

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mean-expert/loopback-sdk-builder",
3-
"version": "2.0.5",
3+
"version": "2.0.6",
44
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
55
"bin": {
66
"lb-sdk": "bin/lb-sdk"
@@ -10,7 +10,7 @@
1010
"prepublish": "",
1111
"test": "npm run test:angular2",
1212
"pretest": "cd tests/angular2 && npm install",
13-
"test:angular2": "cd tests/angular2 && npm install ../../ && npm run test"
13+
"test:angular2": "cd tests/angular2 && npm run test"
1414
},
1515
"repository": {
1616
"type": "git",

0 commit comments

Comments
 (0)