Skip to content

Commit

Permalink
Release 2.0.6 🚀
Browse files Browse the repository at this point in the history
- Hot Fix: #107
  • Loading branch information
Jonathan Casarrubias committed Sep 3, 2016
1 parent e33da85 commit 270bdce
Show file tree
Hide file tree
Showing 57 changed files with 585 additions and 408 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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`.

## Release 2.0.6

- Hot Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/107

## Release 2.0.5

- Fix: https://github.com/mean-expert-official/loopback-sdk-builder/issues/100
Expand Down
4 changes: 2 additions & 2 deletions bin/lb-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var argv = optimist
*/
console.log('================================================================================================================================');
console.log('* __ ____ __ _____ ____ __ __ ____ _ __ __ _ _____ *');
console.log('* / / ___ ___ ____ / __ )____ ______/ /__ / ___/ / __ \\/ //_/ / __ )__ __(_) /___/ /__ _____ | | / /__ \\ *');
console.log('* / / ___ ___ ____ / __ )____ ______/ /__ / ___/ / __ \\/ //_/ / __ )__ __(_) /___/ /__ _____ | | / /__ \\ *');
console.log('* / / / __ \\/ __ \\/ __ \\/ __ / __ \'/ ___/ //_/ \\__ \\/ / / / ,< / __ / / / / / / __ / _ \\/ ___/ | | / /__/ / *');
console.log('* / /___/ /_/ / /_/ / /_/ / /_/ / /_/ / /__/ , < ___/ / /_/ / /| | / /_/ / /_/ / / / /_/ / __/ / | |/ // __/ *');
console.log('* /_____/\\____/\\____/ .___/_____/\\__,_/\\___/_/|_| /_____/_____/_/ |_| /_____/\\__,_/_/_/\\__,_/\\___/_/ |___//____/ *');
Expand Down Expand Up @@ -75,7 +75,7 @@ function verifyPath() {
output: process.stdout
});

rl.question('\n\nIMPORTANT: The targeted SDK Directory is not empty, do you want to erase its content? (Y/n) ', (answer) => {
rl.question('\n\nWARNING: The targeted SDK Directory is not empty, do you want to erase its content? (Y/n) ', (answer) => {
switch (answer) {
case 'No':
case 'no':
Expand Down
99 changes: 90 additions & 9 deletions lib/angular2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ module.exports = function generate(ctx) {
output: '/index.ts',
params: {
isIo: ctx.isIo,
models: ctx.models
models: ctx.models,
buildModuleImports: buildModuleImports
}
},
{
template: './shared/sdk.module.ejs',
output: '/sdk.module.ts',
params: {
isIo: ctx.isIo,
models: ctx.models
models: ctx.models,
buildModuleImports: buildModuleImports
}
},
{
Expand Down Expand Up @@ -105,7 +107,10 @@ module.exports = function generate(ctx) {
{
template: './shared/services/core/base.ejs',
output: '/services/core/base.service.ts',
params: { isIo: ctx.isIo }
params: {
isIo: ctx.isIo,
buildBaseServiceImports: buildBaseServiceImports
}
},
{
template: './shared/services/core/error.ejs',
Expand All @@ -114,7 +119,7 @@ module.exports = function generate(ctx) {
},
{
template: './shared/services/core/logger.ejs',
output: '/services/core/logger.service.ts',
output: '/services/custom/logger.service.ts',
params: {}
},
{
Expand Down Expand Up @@ -279,7 +284,19 @@ module.exports = function generate(ctx) {
*/
function buildServiceImports(model) {
let modelName = capitalize(model.name);
let output = [`import { ${modelName} } from '../../models/${modelName}'`];
let imports = [
{ module: 'Injectable, Inject, Optional', from: '@angular/core'},
{ module: 'Http, Response', from: '@angular/http'},
{ module: 'BaseLoopBackApi', from: '../core/base.service'},
{ module: 'LoopBackConfig', from: '../../lb.config'},
{ module: 'LoopBackAuth', from: '../core/auth.service'},
{ module: 'LoopBackFilter', from: '../../models/BaseModels'},
{ module: 'JSONSearchParams', from: '../core/search.params'},
{ module: 'ErrorHandler', from: '../core/error.service'},
{ module: 'Subject', from: 'rxjs/Subject'},
{ module: 'rxjs/add/operator/map' },
{ module: modelName, from: `../../models/${modelName}`},
];
let loaded = {}; loaded[model.name] = true;
getModelRelations(model).forEach((relationName, i) => {
let targetClass = model.sharedClass.ctor.relations[relationName].targetClass;
Expand All @@ -296,18 +313,82 @@ module.exports = function generate(ctx) {
let through = capitalize(model.sharedClass.ctor.relations[relationName].modelThrough.sharedClass.name);
if (!loaded[through]) {
loaded[through] = true;
output.push(`import { ${through} } from '../../models/${through}'`);
imports.push({ module: through, from: `../../models/${through}` });
}
}
// Now and after the through model was included is the right time to verify if the current model
// was loaded by another relationship, this way we don't duplicate the class during imports'
if (!loaded[targetClass]) {
loaded[targetClass] = true;
output.push(`import { ${targetClass} } from '../../models/${targetClass}'`);
imports.push({ module: targetClass, from: `../../models/${targetClass}` });
}
});
output.push(`import { LoopBackFilter } from '../../models/BaseModels'`);
return output.join(';\n');

return buildImports(imports);
}
/**
* @method buildModuleImports
* @description
* Define import statement for the SDK Module
*/
function buildModuleImports(models, isIndex) {
let imports = [
{ module: 'JSONSearchParams', from: './services/core/search.params'},
{ module: 'ErrorHandler', from: './services/core/error.service'},
{ module: 'LoopBackAuth', from: './services/core/auth.service'},
{ module: 'LoggerService', from: './services/custom/logger.service'},
];

if (!isIndex) {
imports = imports.concat([
{ module: 'HttpModule', from: '@angular/http'},
{ module: 'CommonModule', from: '@angular/common'},
{ module: 'NgModule, ModuleWithProviders', from: '@angular/core'}
]);
}

Object.keys(models).forEach(modelName => {
let name = capitalize(modelName);
imports.push({ module: `${name}Api`, from: `./services/custom/${name}` });
});

return buildImports(imports);
}
/**
* @method buildBaseServiceImports
* @description
* Define import statement for the SDK Module
*/
function buildBaseServiceImports(isIo) {
let imports = [
{ module: 'Injectable, Inject, Optional', from: '@angular/core'},
{ module: 'Http, Headers, Request', from: '@angular/http'},
{ module: 'NgModule, ModuleWithProviders', from: '@angular/core'},
{ module: 'JSONSearchParams', from: './search.params'},
{ module: 'ErrorHandler', from: './error.service'},
{ module: 'LoopBackAuth', from: './auth.service'},
{ module: 'LoopBackConfig', from: '../../lb.config'},
{ module: 'rxjs/add/operator/catch' },
{ module: 'rxjs/add/operator/map' },
];

if (isIo) {
imports.push({ module: 'Subject', from: 'rxjs/Subject'});
imports.push({ module: 'SocketConnections', from: '../../sockets/socket.connections'});
}

return buildImports(imports);
}
/**
* @method buildImports
* @description
* Transform an array of objects describing which should be imported into
* the actual template strings
*/
function buildImports(imports) {
return imports.map(item =>
`import ${(item.from ? `{ ${item.module} }` : `'${item.module}'`)} ${(item.from ? ` from '${item.from}'` : '')};`
).join('\n');
}
/**
* @method normalizeMethodName
Expand Down
14 changes: 2 additions & 12 deletions lib/angular2/shared/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,7 @@
*
* READ: https://angular.io/docs/ts/latest/cookbook/rc4-to-rc5.html#!#5-cleanup
**/

import {
LoopBackAuth,
ErrorHandler,
LoggerService,
JSONSearchParams,<%
Object.keys(models).forEach(function(modelName, i, arr) {
modelName = modelName[0].toUpperCase() + modelName.slice(1);
%>
<%- modelName %>Api<%= i < arr.length -1 ? ',' : '' %><%
});%>
} from './services/index';
<%- buildModuleImports(models, true) %>
/**
* IMPORTANT: API_PROVIDERS WILL BE DEPRECATED WHEN ANGULAR 2 IS STABLE
* PLEASE MIGRATE YOUR PROJECT AS SOON AS POSSIBLE.
Expand All @@ -51,6 +40,7 @@ Object.keys(models).forEach(function(modelName, i, arr) {
export * from './models/index';
export * from './services/index';
export * from './lb.config';
export * from './sdk.module';
<% if ( isIo === 'enabled' ){ -%>export * from './sockets/index';
<% }
-%>
21 changes: 2 additions & 19 deletions lib/angular2/shared/sdk.module.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,7 @@
* export class AppModule { }
*
**/

import { HttpModule } from '@angular/http';
import { CommonModule } from '@angular/common';
import {
NgModule,
ModuleWithProviders
} from '@angular/core';
import {
LoopBackAuth,
ErrorHandler,
LoggerService,
JSONSearchParams,<%
Object.keys(models).forEach(function(modelName, i, arr) {
modelName = modelName[0].toUpperCase() + modelName.slice(1);
%>
<%- modelName %>Api<%= i < arr.length -1 ? ',' : '' %><%
});%>
} from './services/index';
<%- buildModuleImports(models, false) %>

@NgModule({
imports: [ CommonModule, HttpModule ],
Expand All @@ -70,7 +53,7 @@ export class SDKModule {
Object.keys(models).forEach(function(modelName, i, arr) {
modelName = modelName[0].toUpperCase() + modelName.slice(1);
%>
<%- modelName %>Api<%= i < arr.length -1 ? ',' : '' %><%
<%- modelName %>Api<%= i < arr.length -1 ? ',' : '' %><%
});%>
]
};
Expand Down
29 changes: 12 additions & 17 deletions lib/angular2/shared/services/core/base.ejs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
/* tslint:disable */
import { Injectable, Inject, Optional } from '@angular/core';
import { Http, Headers, Request } from '@angular/http';
<% if ( isIo === 'enabled' ){ -%>import { Subject } from 'rxjs/Subject';
<% } -%>
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import {
LoopBackAuth,
LoopBackConfig,
ErrorHandler,
<% if ( isIo === 'enabled' ){
-%>SocketConnections,<% }
-%>
JSONSearchParams
} from '../../index';


<%- buildBaseServiceImports() %>
/**
* @module BaseLoopBackApi
* @author Nikolay Matiushenkov <https://github.com/mnvx>
* @contributor Jonathan Casarrubias <@johncasarrubias> <github:jonathan-casarrubias>
* @license MTI
* @description
* Abstract class that will be implemented in every custom service automatically built
* by the sdk builder.
* It provides the core functionallity for every API call, either by HTTP Calls or by
* WebSockets.
**/
@Injectable()
export abstract class BaseLoopBackApi {

Expand Down
1 change: 0 additions & 1 deletion lib/angular2/shared/services/core/index.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* tslint:disable */
export * from './logger.service';
export * from './auth.service';
export * from './error.service';
export * from './search.params';
Expand Down
1 change: 1 addition & 0 deletions lib/angular2/shared/services/custom/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
-%>
export * from './<%- modelName %>';
<% } // for modelName in models -%>
export * from './logger.service';
19 changes: 3 additions & 16 deletions lib/angular2/shared/services/custom/service.ejs
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
/* tslint:disable */
import { Injectable, Inject, Optional } from '@angular/core';
import { Http, Response } from '@angular/http';
import { BaseLoopBackApi } from '../core/base.service';
import { LoopBackConfig } from '../../lb.config';
import { LoopBackAuth } from '../core/auth.service';
import { JSONSearchParams } from '../core/search.params';
import { ErrorHandler } from '../core/error.service';
<%- buildServiceImports(model) %>
import { Subject } from 'rxjs/Subject';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/share';

// Making Sure EventSource Type is available to avoid compilation issues.
declare var EventSource: any;
Expand Down Expand Up @@ -95,14 +83,13 @@ export class <%-: modelName %>Api extends BaseLoopBackApi {
let result = this.request(method, url, routeParams, urlParams, postBody)<%
if (model.isUser && methodName === 'login') { %>
.share();
result.subscribe(
.map(
(response: { id: string, userId: string, user: any }) => {
this.auth.setUser(response.id, response.userId, response.user);
this.auth.setRememberMe(true);
this.auth.save();
},
() => null
return response;
}
);
return result;
<%
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mean-expert/loopback-sdk-builder",
"version": "2.0.5",
"version": "2.0.6",
"description": "Tool for auto-generating Software Development Kits (SDKs) for LoopBack",
"bin": {
"lb-sdk": "bin/lb-sdk"
Expand All @@ -10,7 +10,7 @@
"prepublish": "",
"test": "npm run test:angular2",
"pretest": "cd tests/angular2 && npm install",
"test:angular2": "cd tests/angular2 && npm install ../../ && npm run test"
"test:angular2": "cd tests/angular2 && npm run test"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion tests/angular2/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Angular2

This project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.11-webpack.2.
This project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.11-webpack.8.

## Development server
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
Expand Down
29 changes: 21 additions & 8 deletions tests/angular2/angular-cli.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
{
"project": {
"version": "1.0.0-beta.11-webpack.2",
"version": "1.0.0-beta.11-webpack.8",
"name": "angular2"
},
"apps": [
{
"main": "src/main.ts",
"tsconfig": "src/tsconfig.json",
"mobile": false
"root": "src",
"outDir": "dist",
"assets": "assets",
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
"styles": [
"styles.css"
],
"scripts": [],
"environments": {
"source": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"dev": "environments/environment.dev.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "config/protractor.conf.js"
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "config/karma.conf.js"
"config": "./karma.conf.js"
}
},
"defaults": {
"prefix": "app",
"sourceDir": "src",
"styleExt": "css",
"prefixInterfaces": false,
"lazyRoutePrefix": "+"
Expand Down
Loading

0 comments on commit 270bdce

Please sign in to comment.