diff --git a/_demo/api/bootstrap.ts b/_demo/api/bootstrap.ts deleted file mode 100644 index a52e374..0000000 --- a/_demo/api/bootstrap.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { server, logger } from './main'; - -server.start().then(() => { - logger.info('Server running at:', server.getEngine().info.uri); -}); diff --git a/_demo/api/controllers/index.ts b/_demo/api/controllers/index.ts deleted file mode 100644 index 1a25276..0000000 --- a/_demo/api/controllers/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export {TestController} from './test.controller'; -export {SimpleController} from './simple.controller'; diff --git a/_demo/api/controllers/simple.controller.ts b/_demo/api/controllers/simple.controller.ts deleted file mode 100644 index 7d572cf..0000000 --- a/_demo/api/controllers/simple.controller.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Server } from '../../../api/servers/abstract.server'; -import { - AbstractController, Request, - RouteParam -} from '../../../api/controllers/abstract.controller'; -import { RouteBase } from '../../../api/controllers/routeBase.decorator'; -import { Action } from '../../../api/controllers/action.decorator'; -import { LoggerService } from '../../../api/services/logger.service'; -import { AbstractModel } from '../../../common/models/abstract.model'; -import { Cat } from '../../common/models/cat.model'; - -@Injectable() -@RouteBase('simple') -export class SimpleController extends AbstractController { - - constructor(server: Server, logger: LoggerService) { - super(server, logger); - } - - @Action('GET', '/test-route') - public test() { - return 'hello world'; - } - - protected getOneById(request: Request, routeParams: RouteParam[]): AbstractModel { - return new Cat(); - } - -} diff --git a/_demo/api/controllers/test.controller.spec.ts b/_demo/api/controllers/test.controller.spec.ts deleted file mode 100644 index 86f5135..0000000 --- a/_demo/api/controllers/test.controller.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { - it, - describe, - expect -} from '@angular/core/testing'; - -describe('Test api', () => { - - it('should pass', () => { - - expect(true).toBe(true); - }); - - it('should fail', () => { - expect(true).toBe(true); - }); - -}); diff --git a/_demo/api/controllers/test.controller.ts b/_demo/api/controllers/test.controller.ts deleted file mode 100644 index fe0bd05..0000000 --- a/_demo/api/controllers/test.controller.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Server } from '../../../api/servers/abstract.server'; -import { - AbstractController, RouteParam, - Request -} from '../../../api/controllers/abstract.controller'; -import { RouteBase } from '../../../api/controllers/routeBase.decorator'; -import { LoggerService } from '../../../api/services/logger.service'; -import { AbstractModel } from '../../../common/models/abstract.model'; -import { Cat } from '../../common/models/cat.model'; - -@Injectable() -@RouteBase('test') -export class TestController extends AbstractController { - - - constructor(server: Server, logger: LoggerService) { - super(server, logger); - - logger.info('route base is %s', this.routeBase); - - } - - protected getOneById(request: Request, routeParams: RouteParam[]): AbstractModel { - return new Cat(); - } - -} diff --git a/_demo/api/main.ts b/_demo/api/main.ts deleted file mode 100644 index e79d4dd..0000000 --- a/_demo/api/main.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { coreInjector } from '../../api/main'; -import { ReflectiveInjector, ResolvedReflectiveProvider, provide } from '@angular/core'; -import { Server } from '../../api/servers/abstract.server'; -import * as Controllers from './controllers'; -import * as _ from 'lodash'; -import { ConsoleLoggerService } from '../../api/services/consoleLogger.service'; -import { LoggerService } from '../../api/services/logger.service'; -import * as dotenv from 'dotenv'; - -/** - * Load .env variables into process.env.* - */ -dotenv.config(); - -// resolve all controllers -let resolvedControllerProviders = ReflectiveInjector.resolve(_.values(Controllers)); - -// resolve all other user classes -let resolvedProviders = ReflectiveInjector.resolve([ - provide(LoggerService, {useClass: ConsoleLoggerService}), -]).concat(resolvedControllerProviders); - -// get an injector from the resolutions, using the core injector as parent -let injector = ReflectiveInjector.fromResolvedProviders(resolvedProviders, coreInjector); - -// export vars for the bootstrapper -export const server: Server = injector.get(Server); -export const logger: LoggerService = injector.get(LoggerService); - -// iterate over the controller providers, instantiating them to register their routes -resolvedControllerProviders.forEach((resolvedControllerProvider: ResolvedReflectiveProvider) => { - logger.info('initializing %s', resolvedControllerProvider.key.displayName); - injector.instantiateResolved(resolvedControllerProvider); -}); diff --git a/_demo/common/models/cat.model.ts b/_demo/common/models/cat.model.ts deleted file mode 100644 index a24ef4e..0000000 --- a/_demo/common/models/cat.model.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { AbstractModel } from '../../../common/models/abstract.model'; -export class Cat extends AbstractModel { - - public greet(): string { - return 'meow'; - } - -} diff --git a/index.d.ts b/index.d.ts index e0608c4..66adad0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,2 +1,2 @@ -export * from './build/node/api/index'; -export * from './build/node/common/index'; +export * from './build/server/server/index'; +export * from './build/server/common/index'; diff --git a/index.js b/index.js new file mode 100644 index 0000000..b62fdca --- /dev/null +++ b/index.js @@ -0,0 +1,6 @@ +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +__export(require('./build/server/server/index')); +__export(require('./build/server/common/index')); diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..66adad0 --- /dev/null +++ b/index.ts @@ -0,0 +1,2 @@ +export * from './build/server/server/index'; +export * from './build/server/common/index'; diff --git a/browser/app/app.component.css b/src/browser/app/app.component.css similarity index 100% rename from browser/app/app.component.css rename to src/browser/app/app.component.css diff --git a/browser/app/app.component.html b/src/browser/app/app.component.html similarity index 100% rename from browser/app/app.component.html rename to src/browser/app/app.component.html diff --git a/browser/app/app.component.spec.ts b/src/browser/app/app.component.spec.ts similarity index 100% rename from browser/app/app.component.spec.ts rename to src/browser/app/app.component.spec.ts diff --git a/browser/app/app.component.ts b/src/browser/app/app.component.ts similarity index 83% rename from browser/app/app.component.ts rename to src/browser/app/app.component.ts index 0c9cc1e..e7716a4 100644 --- a/browser/app/app.component.ts +++ b/src/browser/app/app.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import '../public/css/styles.css'; -import { Cat } from '../../_demo/common/models/cat.model'; +import { Cat } from '../../../_demo/common/models/cat.model'; @Component({ selector: 'my-app', template: require('./app.component.html'), diff --git a/browser/index.html b/src/browser/index.html similarity index 100% rename from browser/index.html rename to src/browser/index.html diff --git a/browser/main.ts b/src/browser/main.ts similarity index 100% rename from browser/main.ts rename to src/browser/main.ts diff --git a/browser/polyfills.ts b/src/browser/polyfills.ts similarity index 100% rename from browser/polyfills.ts rename to src/browser/polyfills.ts diff --git a/browser/public/css/styles.css b/src/browser/public/css/styles.css similarity index 100% rename from browser/public/css/styles.css rename to src/browser/public/css/styles.css diff --git a/browser/public/images/angular.png b/src/browser/public/images/angular.png similarity index 100% rename from browser/public/images/angular.png rename to src/browser/public/images/angular.png diff --git a/browser/vendor.ts b/src/browser/vendor.ts similarity index 100% rename from browser/vendor.ts rename to src/browser/vendor.ts diff --git a/common/index.ts b/src/common/index.ts similarity index 100% rename from common/index.ts rename to src/common/index.ts diff --git a/common/models/abstract.model.ts b/src/common/models/abstract.model.ts similarity index 100% rename from common/models/abstract.model.ts rename to src/common/models/abstract.model.ts diff --git a/common/models/base.collection.ts b/src/common/models/base.collection.ts similarity index 100% rename from common/models/base.collection.ts rename to src/common/models/base.collection.ts diff --git a/common/models/index.ts b/src/common/models/index.ts similarity index 100% rename from common/models/index.ts rename to src/common/models/index.ts diff --git a/api/controllers/abstract.controller.spec.ts b/src/server/controllers/abstract.controller.spec.ts similarity index 100% rename from api/controllers/abstract.controller.spec.ts rename to src/server/controllers/abstract.controller.spec.ts diff --git a/api/controllers/abstract.controller.ts b/src/server/controllers/abstract.controller.ts similarity index 100% rename from api/controllers/abstract.controller.ts rename to src/server/controllers/abstract.controller.ts diff --git a/api/controllers/action.decorator.ts b/src/server/controllers/action.decorator.ts similarity index 100% rename from api/controllers/action.decorator.ts rename to src/server/controllers/action.decorator.ts diff --git a/api/controllers/index.ts b/src/server/controllers/index.ts similarity index 100% rename from api/controllers/index.ts rename to src/server/controllers/index.ts diff --git a/api/controllers/routeBase.decorator.ts b/src/server/controllers/routeBase.decorator.ts similarity index 100% rename from api/controllers/routeBase.decorator.ts rename to src/server/controllers/routeBase.decorator.ts diff --git a/api/index.ts b/src/server/index.ts similarity index 100% rename from api/index.ts rename to src/server/index.ts diff --git a/api/main.ts b/src/server/main.ts similarity index 100% rename from api/main.ts rename to src/server/main.ts diff --git a/api/servers/abstract.server.ts b/src/server/servers/abstract.server.ts similarity index 100% rename from api/servers/abstract.server.ts rename to src/server/servers/abstract.server.ts diff --git a/api/servers/hapi.server.ts b/src/server/servers/hapi.server.ts similarity index 100% rename from api/servers/hapi.server.ts rename to src/server/servers/hapi.server.ts diff --git a/api/servers/index.ts b/src/server/servers/index.ts similarity index 100% rename from api/servers/index.ts rename to src/server/servers/index.ts diff --git a/api/services/consoleLogger.service.ts b/src/server/services/consoleLogger.service.ts similarity index 100% rename from api/services/consoleLogger.service.ts rename to src/server/services/consoleLogger.service.ts diff --git a/api/services/index.ts b/src/server/services/index.ts similarity index 100% rename from api/services/index.ts rename to src/server/services/index.ts diff --git a/api/services/logger.service.ts b/src/server/services/logger.service.ts similarity index 100% rename from api/services/logger.service.ts rename to src/server/services/logger.service.ts diff --git a/tasks/index.js b/tasks/index.js deleted file mode 100644 index 7c4f5e2..0000000 --- a/tasks/index.js +++ /dev/null @@ -1,276 +0,0 @@ -'use strict'; - -let gulp = require('gulp'); -var path = require('path'); -const _ = require('lodash'); - -class UbiquitsProject { - - constructor(basePath, paths) { - this.basePath = basePath; - - this.paths = _.merge({ - source: { - api: { - tsConfig: this.basePath + '/tsconfig.api.json', - ts: [ - './api/**/*.ts', - './common/**/*.ts', - './_demo/api/**/*.ts', - './_demo/common/**/*.ts', - ], - definitions: [ - './typings/**/*.d.ts', - '!./typings/index.d.ts', - '!./typings/**/core-js/*.d.ts', - ] - }, - }, - destination: { - build: './build', - coverage: './coverage', - api: 'build/node', - browser: 'build/browser', - } - }, paths); - - } - - registerTask(name, help, task, dependencies) { - return this.gulp.task(name, help, dependencies || [], task); - } - - clean(paths) { - const rimraf = require('gulp-rimraf'); - - return () => this.gulp.src(paths, {read: false, cwd: this.basePath}) - .pipe(rimraf()) - } - - tslint(paths) { - const tslint = require('gulp-tslint'); - - return () => this.gulp.src(paths, {cwd: this.basePath}) - .pipe(tslint()) - .pipe(tslint.report('verbose')) - } - - compileApi(paths) { - - const sourcemaps = require('gulp-sourcemaps'); - const typescript = require('gulp-typescript'); - const merge = require('merge2'); - - return () => { - const tsProject = typescript.createProject(paths.tsConfig); - let tsResult = this.gulp.src(paths.source, {cwd: this.basePath, base: './'}) - .pipe(sourcemaps.init()) - .pipe(typescript(tsProject)); - - return merge([ // Merge the two output streams, so this task is finished when the IO of both operations are done. - tsResult.dts - .pipe(this.gulp.dest(paths.destination)), - tsResult.js - .pipe(sourcemaps.write('.', {sourceRoot: this.basePath})) - .pipe(this.gulp.dest(paths.destination)) - ]); - } - } - - instrument(paths) { - - const istanbul = require('gulp-istanbul'); - - return () => this.gulp.src(paths, {cwd: this.basePath}) - // Covering files - .pipe(istanbul()) - // Force `require` to return covered files - .pipe(istanbul.hookRequire()); - } - - jasmine(paths) { - - return () => { - Error.stackTraceLimit = Infinity; - - require('core-js'); - require('reflect-metadata'); - require('zone.js/dist/zone-node'); - - const istanbul = require('gulp-istanbul'); - const jasmine = require('gulp-jasmine'); - const SpecReporter = require('jasmine-spec-reporter'); - - return gulp.src(paths.source, {cwd: this.basePath}) - .pipe(jasmine({ - reporter: new SpecReporter({ - displayFailuresSummary: false - }) - }) - ) - // Creating the reports after tests ran - .pipe(istanbul.writeReports({ - dir: paths.coverage, - reporters: ['json'] - })); - - } - - } - - remapCoverage(paths) { - - return () => { - let remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul'); - let fs = require('fs'); - let merge = require('gulp-merge-json'); - - return gulp.src(paths.source, {cwd: this.basePath}) - .pipe(merge('summary.json')) - .pipe(remapIstanbul({ - reports: { - 'json': this.resolvePath('./coverage/summary/coverage.json'), - 'html': this.resolvePath('./coverage/summary/html-report'), - 'text': this.resolvePath('./coverage/summary/text-summary', true), - 'lcovonly': this.resolvePath('./coverage/summary/lcov.info') - } - })).on('end', () => { - console.log(fs.readFileSync(this.resolvePath('./coverage/summary/text-summary')).toString()); - }); - } - - } - - nodemon(config) { - - return () => { - - const nodemon = require('gulp-nodemon'); - - nodemon({ - script: config.entryPoint, - 'ext': 'js json ts', - watch: [ - this.resolvePath('api'), - this.resolvePath('_demo'), - this.resolvePath('common') - ], - nodeArgs: [ - // ad-hoc debugging (doesn't allow debugging of bootstrap, but app will run with debugger off) - '--debug=5858' - // explicit debugging (app won't start until remote debugger connects) - // '--debug-brk=5858' - ], - env: {'NODE_ENV': 'development'}, - tasks: config.tasks - }).on('restart', function () { - console.log('restarted nodemon!') - }) - } - - } - - resolvePath(pathString, relative) { - const normalized = path.normalize(this.basePath + '/' + pathString); - if (!relative) { - return normalized; - } - return path.relative(this.basePath, normalized); - } - - webpack(config) { - - return () => { - - const gulpWebpack = require('webpack-stream'); - const gutil = require('gulp-util'); - const webpackConfig = require(config.webpackPath); - - webpackConfig.progress = true; - - return gulp.src('.') - .pipe(gulpWebpack(webpackConfig, null, (err, stats) => { - if(err) { - throw new gutil.PluginError("webpack", err); - } - gutil.log("[webpack]", stats.toString({ - chunkModules: false, - colors: gutil.colors.supportsColor, - })); - })) - .pipe(gulp.dest(config.destination)); - } - - } - - - registerDefaultTasks(gulp) { - this.gulp = require('gulp-help')(gulp); - - const runSequence = require('run-sequence'); - - this.registerTask('clean:build', 'removes the build directory', this.clean(this.paths.destination.build)); - - this.registerTask('clean:coverage', 'removes the coverage directory', this.clean(this.paths.destination.coverage)); - - this.registerTask('clean', 'build & coverage directories', null, ['clean:build', 'clean:coverage']); - - this.registerTask('tslint', 'lint files', this.tslint(this.paths.source.api.ts)); - - this.registerTask('compile:api', 'compile API files', this.compileApi({ - source: [].concat(this.paths.source.api.ts, this.paths.source.api.definitions), - destination: this.paths.destination.api, - tsConfig: this.paths.source.api.tsConfig - }), ['clean:build']); - - this.registerTask('instrument:api', 'instrument api files', this.instrument(this.paths.destination.api + '/**/*.js')); - - this.registerTask('test:api', 'run api tests', (callback) => { - runSequence('compile:api', 'instrument:api', 'jasmine:api', callback); - }); - - this.registerTask('test', 'run all tests', (callback) => { - runSequence('test:api', 'test:browser', 'coverage:remap', callback); - }, ['clean']); - - this.registerTask('jasmine:api', 'run api spec files', this.jasmine({ - source: [this.paths.destination.api + '/**/*.js', '!build/api/_demo/api/bootstrap.js'], - coverage: this.paths.destination.coverage + '/api/js' - })); - - this.registerTask('coverage:remap', 'remap coverage files to typescript sources', this.remapCoverage({ - source: [ - this.resolvePath('./coverage/browser/js/coverage-final.json'), - this.resolvePath('./coverage/api/js/coverage-final.json'), - ], - coverage: this.paths.destination.coverage - })); - - this.registerTask('watch', 'watch all files with nodemon', this.nodemon({ - entryPoint: this.resolvePath('./localhost.js'), - tasks: ['compile:api'] - }), ['compile:api']); - - this.registerTask('test:browser', 'test browser', (done) => { - - const KarmaServer = require('karma').Server; - - new KarmaServer({ - configFile: this.resolvePath('./karma.conf.js'), - singleRun: true - }, done).start(); - }, ['compile:api']); - - this.registerTask('compile:browser', 'compile browser', this.webpack({ - webpackPath: this.resolvePath('./browser/config/webpack.prod.js'), - destination: this.paths.destination.browser - })); - - this.registerTask('compile', 'compile all files', null, ['compile:browser', 'compile:api']); - - } - -} - - -module.exports = {gulp, UbiquitsProject}; diff --git a/tsconfig.browser.json b/tsconfig.browser.json index 9ac41cd..e511a3e 100644 --- a/tsconfig.browser.json +++ b/tsconfig.browser.json @@ -13,8 +13,8 @@ "exclude": [ "node_modules", "build", - "api", - "_demo/api", + "server", + "_demo/server", "index.d.ts" ] } diff --git a/tsconfig.api.json b/tsconfig.server.json similarity index 100% rename from tsconfig.api.json rename to tsconfig.server.json