Continue migrating to TS

This commit is contained in:
Roman Hotsiy 2016-06-06 19:32:20 +03:00
parent 65bc8ef4e5
commit 3629e34a5a
19 changed files with 156 additions and 72 deletions

View File

@ -21,8 +21,9 @@ gulp.task('build', function (callback) {
return callback();
}
return runSequence(
//'clean',
'concatPrism',
'clean',
'tsc',
'inlineTemplates',
'bundle',
'concatDeps',
'copyDebug',
@ -39,19 +40,32 @@ gulp.task('copyDebug', () => {
gulp.task('rebuild', function(done) {
return runSequence(
'tsc',
'inlineTemplates',
'bundle',
'concatDeps',
'copyDebug',
done
);
});
gulp.task('tsc', function() {
exec('tsc -p ./tsconfig.json');
});
gulp.task('inlineTemplates', ['sass'], function() {
return gulp.src(paths.source, { base: './' })
return gulp.src('.tmp/lib/**/*.js', { base: './tmp' })
.pipe(replace(/'(.*?)\.css'/g, '\'$1.scss\''))
.pipe(inlineNg2Template({
base: '/',
base: './',
useRelativePaths: true,
styleProcessor: compileSass
styleProcessor: compileSass,
customFilePath: function(ext, file) {
var cwd = process.cwd();
var relative = path.relative(cwd, file);
relative = relative.substring('5');
return path.join(cwd, relative);
}
}))
.pipe(gulp.dest(paths.tmp));
});
@ -97,7 +111,8 @@ gulp.task('concatDeps', ['concatPrism'], function() {
});
gulp.task('bundle', function bundle(done) {
fs.existsSync('dist') || fs.mkdirSync('dist');
mkdir('-p', 'dist');
cp('lib/index.js', path.join(paths.tmp, paths.sourceEntryPoint));
var builder = new Builder('./', 'system.config.js');
builder
@ -141,7 +156,7 @@ gulp.task('concatPrism', function() {
return gulp.src(prismFiles)
.pipe(concat(path.join(paths.tmp, 'prismjs-bundle.js')))
.pipe(gulp.dest('.'))
.pipe(gulp.dest('.'));
});
// needs inlineTemplates run before to create .tmp/lib folder

View File

@ -8,7 +8,7 @@ module.exports = function (config) {
regexPreprocessor: {
rules: [
[ /'\.(.*?)\.css'/g, '\'.tmp$1.css\'']
[ /'\.(.*?)\.scss'/g, '\'.tmp$1.css\'']
]
},
babelPreprocessor: {
@ -58,13 +58,13 @@ module.exports = function (config) {
config: 'system.config.js',
loadFiles: ['tests/setup.js', 'tests/helpers.js', 'tests/unit/*.spec.js', 'lib/**/*.js'],
serveFiles: ['tests/schemas/**/*.json','tests/schemas/**/*.yml', 'lib/**/*.html',
'.tmp/lib/**/*.json', '.tmp/*js', '.tmp/lib/**/*.css'],
'.tmp/lib/**/*.json', '.tmp/*js', '.tmp/lib/**/*.scss'],
nocache: true
},
proxies: {
'/tests/': '/base/tests/',
'/lib/components/Redoc/redoc-initial-styles.css': '/base/.tmp/lib/components/Redoc/redoc-initial-styles.css',
'/lib/components/Redoc/redoc-initial-styles.scss': '/base/.tmp/lib/components/Redoc/redoc-initial-styles.scss',
'/lib/version.json': '/base/.tmp/lib/version.json',
'/lib/': '/base/lib/',
'/jspm_packages/': '/base/jspm_packages/',

View File

@ -17,9 +17,6 @@ import {SchemaManager} from '../../utils/SchemaManager';
import { OptionsService, RedocEventsService } from '../../services/index';
//import redocVersion from '../../version.js';
//import './redoc-initial-styles.css!css';
var dom = new BrowserDomAdapter();
var _modeLocked = false;

View File

@ -27,9 +27,7 @@ export class RequestSamples extends BaseComponent {
@ViewChildren(Tabs) childQuery:QueryList<Tabs>;
constructor(schemaMgr:SchemaManager, public events:RedocEventsService) {
super(schemaMgr);
this.childQuery.changes.subscribe(() => {
this.childTabs = this.childQuery.first;
});
this.selectedLang = this.events.samplesLanguageChanged;
}

View File

@ -0,0 +1,70 @@
'use strict';
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = require('@angular/core');
var OpenAPISampler = require('openapi-sampler');
var base_1 = require('../base');
var JsonFormatterPipe_1 = require('../../utils/JsonFormatterPipe');
var SchemaSample = (function (_super) {
__extends(SchemaSample, _super);
function SchemaSample(schemaMgr, elementRef) {
_super.call(this, schemaMgr);
this.element = elementRef.nativeElement;
}
SchemaSample.prototype.init = function () {
this.data = {};
var base = {};
var sample;
if (this.componentSchema.schema) {
base = this.componentSchema;
this.componentSchema = this.componentSchema.schema;
}
if (base.examples && base.examples['application/json']) {
sample = base.examples['application/json'];
}
else {
this.dereference(this.componentSchema);
try {
sample = OpenAPISampler.sample(this.componentSchema);
}
catch (e) {
}
}
this.data.sample = sample;
this.element.addEventListener('click', function (event) {
var collapsed, target = event.target;
if (event.target.className === 'collapser') {
collapsed = target.parentNode.getElementsByClassName('collapsible')[0];
if (collapsed.parentNode.classList.contains('collapsed')) {
collapsed.parentNode.classList.remove('collapsed');
}
else {
collapsed.parentNode.classList.add('collapsed');
}
}
});
};
SchemaSample = __decorate([
base_1.RedocComponent({
selector: 'schema-sample',
templateUrl: './schema-sample.html',
pipes: [JsonFormatterPipe_1.JsonFormatter],
styleUrls: ['./schema-sample.css']
}),
__metadata('design:paramtypes', [base_1.SchemaManager, core_1.ElementRef])
], SchemaSample);
return SchemaSample;
}(base_1.BaseComponent));
exports.SchemaSample = SchemaSample;

View File

@ -2,7 +2,7 @@
import { ElementRef } from '@angular/core';
import SchemaSampler from 'json-schema-instantiator';
import * as OpenAPISampler from 'openapi-sampler';
import { RedocComponent, BaseComponent, SchemaManager } from '../base';
import { JsonFormatter } from '../../utils/JsonFormatterPipe';
@ -37,7 +37,11 @@ export class SchemaSample extends BaseComponent {
sample = base.examples['application/json'];
} else {
this.dereference(this.componentSchema);
sample = SchemaSampler.instantiate(this.componentSchema);
try {
sample = OpenAPISampler.sample(this.componentSchema);
} catch(e) {
// no sample available
}
}
this.data.sample = sample;

12
lib/index.js Normal file
View File

@ -0,0 +1,12 @@
'use strict';
import 'dropkickjs/build/css/dropkick.css!css';
import 'prismjs/themes/prism-dark.css!css';
import 'hint.css/hint.base.css!css';
import './components/redoc/redoc-initial-styles.css!css';
import { Redoc } from './components/index';
export var init = Redoc.init;
window['Redoc'] = Redoc;
Redoc.autoInit();

View File

@ -1,7 +0,0 @@
'use strict';
import {Redoc} from './components/index';
export var init = Redoc.init;
window['Redoc'] = Redoc;
Redoc.autoInit();

View File

@ -3,7 +3,6 @@
import {Component, EventEmitter, ElementRef, Output} from '@angular/core';
import {CORE_DIRECTIVES} from '@angular/common';
import DropKick from 'dropkickjs';
//import 'Robdel12/DropKick/build/css/dropkick.css!css';
@Component({
selector: 'dropdown',
@ -24,7 +23,7 @@ export class DropDown {
}
ngAfterContentInit() {
//this.inst = new DropKick(this.elem.firstElementChild, {autoWidth: true});
this.inst = new DropKick(this.elem.firstElementChild, {autoWidth: true});
}
onChange(value) {

View File

@ -5,12 +5,8 @@ import {isString, stringify, isBlank} from '@angular/core/src/facade/lang';
import {BaseException} from '@angular/core/src/facade/exceptions';
import JsonPointer from './JsonPointer';
//import '../../prismjs-bundle';
declare var Prism: any;
//import 'prismjs/themes/prism-dark.css!css';
//import 'hint.css/hint.base.css!css';
import marked from 'marked';
// in gfm mode marked doesn't parse #Heading (without space after #) as heading

View File

@ -38,14 +38,15 @@
"@angular/platform-browser": "npm:@angular/platform-browser@^2.0.0-rc.1",
"@angular/platform-browser-dynamic": "npm:@angular/platform-browser-dynamic@^2.0.0-rc.1",
"Robdel12/DropKick": "github:Robdel12/DropKick@^2.1.7",
"dropkickjs": "npm:dropkickjs@^2.1.8",
"es6-shim": "github:es-shims/es6-shim@^0.33.6",
"hint.css": "npm:hint.css@^2.2.1",
"json": "github:systemjs/plugin-json@^0.1.0",
"json-formatter-js": "npm:json-formatter-js@^0.2.0",
"json-pointer": "npm:json-pointer@^0.3.0",
"json-schema-instantiator": "npm:json-schema-instantiator@^0.3.0",
"json-schema-ref-parser": "npm:json-schema-ref-parser@^3.1.2",
"marked": "npm:marked@^0.3.5",
"openapi-sampler": "npm:openapi-sampler@^0.1.2",
"prismjs": "npm:prismjs@^1.3.0",
"rxjs": "npm:rxjs@5.0.0-beta.6",
"scrollparent": "npm:scrollparent@^0.1.0",
@ -55,15 +56,12 @@
"devDependencies": {
"babel": "npm:babel-core@^5.8.34",
"babel-runtime": "npm:babel-runtime@^5.8.24",
"clean-css": "npm:clean-css@^3.4.6",
"clean-css": "npm:clean-css@^3.4.17",
"core-js": "npm:core-js@^1.2.6",
"css": "github:systemjs/plugin-css@^0.1.18",
"systemjs/plugin-json": "github:systemjs/plugin-json@^0.1.0"
},
"overrides": {
"github:Robdel12/DropKick@2.1.7": {
"format": "global"
},
"npm:@angular/core@2.0.0-rc.1": {
"main": "esm/index.js",
"format": "esm"
@ -83,6 +81,13 @@
"npm:@angular/platform-browser@2.0.0-rc.1": {
"main": "esm/index.js",
"format": "esm"
},
"npm:openapi-sampler@0.1.2": {
"main": "src/openapi-sampler",
"format": "esm"
},
"npm:dropkickjs@2.1.8": {
"format": "global"
}
}
},
@ -100,7 +105,7 @@
"gulp-concat": "^2.6.0",
"gulp-eslint": "^1.1.1",
"gulp-if": "^2.0.1",
"gulp-inline-ng2-template": "^1.1.2",
"gulp-inline-ng2-template": "^1.1.5",
"gulp-protractor": "^2.1.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
@ -111,7 +116,7 @@
"jasmine-core": "^2.4.1",
"jasmine-spec-reporter": "^2.4.0",
"json-schema-instantiator": "^0.3.0",
"jspm": "^0.16.34",
"jspm": "^0.16.36",
"karma": "^0.13.15",
"karma-babel-preprocessor": "^5.2.2",
"karma-chrome-launcher": "^0.2.2",
@ -126,6 +131,7 @@
"karma-should": "^1.0.0",
"karma-sinon": "^1.0.4",
"node-sass": "^3.7.0",
"openapi-sampler": "^0.1.2",
"phantomjs-prebuilt": "^2.1.7",
"protractor": "^3.0.0",
"reflect-metadata": "^0.1.2",

View File

@ -42,20 +42,20 @@ System.config({
"@angular/core": "npm:@angular/core@2.0.0-rc.1",
"@angular/platform-browser": "npm:@angular/platform-browser@2.0.0-rc.1",
"@angular/platform-browser-dynamic": "npm:@angular/platform-browser-dynamic@2.0.0-rc.1",
"Robdel12/DropKick": "github:Robdel12/DropKick@2.1.7",
"babel": "npm:babel-core@5.8.34",
"babel-runtime": "npm:babel-runtime@5.8.34",
"clean-css": "npm:clean-css@3.4.6",
"clean-css": "npm:clean-css@3.4.17",
"core-js": "npm:core-js@1.2.6",
"css": "github:systemjs/plugin-css@0.1.18",
"dropkickjs": "npm:dropkickjs@2.1.8",
"es6-shim": "github:es-shims/es6-shim@0.33.6",
"hint.css": "npm:hint.css@2.2.1",
"json": "github:systemjs/plugin-json@0.1.2",
"json-formatter-js": "npm:json-formatter-js@0.2.0",
"json-pointer": "npm:json-pointer@0.3.0",
"json-schema-instantiator": "npm:json-schema-instantiator@0.3.0",
"json-schema-ref-parser": "npm:json-schema-ref-parser@3.1.2",
"marked": "npm:marked@0.3.5",
"openapi-sampler": "npm:openapi-sampler@0.1.2",
"prismjs": "npm:prismjs@1.3.0",
"rxjs": "npm:rxjs@5.0.0-beta.6",
"scrollparent": "npm:scrollparent@0.1.0",
@ -63,7 +63,7 @@ System.config({
"systemjs/plugin-json": "github:systemjs/plugin-json@0.1.2",
"zone.js": "npm:zone.js@0.6.12",
"github:jspm/nodelibs-assert@0.1.0": {
"assert": "npm:assert@1.4.0"
"assert": "npm:assert@1.4.1"
},
"github:jspm/nodelibs-buffer@0.1.0": {
"buffer": "npm:buffer@3.6.0"
@ -201,10 +201,9 @@ System.config({
"stream": "github:jspm/nodelibs-stream@0.1.0",
"util": "github:jspm/nodelibs-util@0.1.0"
},
"npm:assert@1.4.0": {
"npm:assert@1.4.1": {
"assert": "github:jspm/nodelibs-assert@0.1.0",
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"buffer-shims": "npm:buffer-shims@1.0.0",
"process": "github:jspm/nodelibs-process@0.1.2",
"util": "npm:util@0.10.3"
},
@ -292,9 +291,6 @@ System.config({
"readable-stream": "npm:readable-stream@2.0.6",
"util": "github:jspm/nodelibs-util@0.1.0"
},
"npm:buffer-shims@1.0.0": {
"buffer": "github:jspm/nodelibs-buffer@0.1.0"
},
"npm:buffer-xor@1.0.3": {
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"systemjs-json": "github:systemjs/plugin-json@0.1.2"
@ -333,7 +329,7 @@ System.config({
"string_decoder": "github:jspm/nodelibs-string_decoder@0.1.0",
"systemjs-json": "github:systemjs/plugin-json@0.1.2"
},
"npm:clean-css@3.4.6": {
"npm:clean-css@3.4.17": {
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"commander": "npm:commander@2.8.1",
"fs": "github:jspm/nodelibs-fs@0.1.2",
@ -451,6 +447,9 @@ System.config({
"randombytes": "npm:randombytes@2.0.3",
"systemjs-json": "github:systemjs/plugin-json@0.1.2"
},
"npm:dropkickjs@2.1.8": {
"process": "github:jspm/nodelibs-process@0.1.2"
},
"npm:ecc-jsbn@0.1.1": {
"buffer": "github:jspm/nodelibs-buffer@0.1.0",
"crypto": "github:jspm/nodelibs-crypto@0.1.0",
@ -667,6 +666,9 @@ System.config({
"process": "github:jspm/nodelibs-process@0.1.2",
"util": "github:jspm/nodelibs-util@0.1.0"
},
"npm:openapi-sampler@0.1.2": {
"process": "github:jspm/nodelibs-process@0.1.2"
},
"npm:os-browserify@0.1.2": {
"os": "github:jspm/nodelibs-os@0.1.0"
},

View File

@ -6,15 +6,16 @@
"target": "es6",
"noImplicitAny": false,
"sourceMap": false,
"outDir": ".tmp-es/",
"outDir": ".tmp/lib",
"moduleResolution": "node"
},
"exclude": [
"node_modules",
"lib",
"jspm_packages",
".tmp",
"build",
"docs",
"*.spec.js"
"*.spec.js",
"lib/index.js"
]
}

View File

@ -1,7 +0,0 @@
// Generated by typings
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/json-pointer/json-pointer.d.ts
declare module "dropkickjs" {
var x: any;
export default x;
}

4
typings/dropkickjs.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
declare module "dropkickjs" {
var x: any;
export default x;
}

1
typings/index.d.ts vendored
View File

@ -1,4 +1,3 @@
/// <reference path="globals/jasmine/index.d.ts" />
/// <reference path="globals/json-pointer/index.d.ts" />
/// <reference path="modules/chai/index.d.ts" />

View File

@ -1,6 +0,0 @@
// Generated by typings
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/json-pointer/json-pointer.d.ts
declare module "json-schema-instantiator" {
var x: any;
export default x;
}

View File

@ -1,5 +1,3 @@
// Generated by typings
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/json-pointer/json-pointer.d.ts
declare module "json-schema-ref-parser/dist/ref-parser" {
var x: any;
export default x;

3
typings/openapi-sampler.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
declare module "openapi-sampler" {
export function sample(schema:any):any;
}