diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 4876b92f..00000000 --- a/.eslintrc +++ /dev/null @@ -1,32 +0,0 @@ -{ - "parser": "babel-eslint", - "extends": "eslint:recommended", - "env": { - "browser": true, - "jasmine": true - }, - // currently eslint doesn't support extension-typed configs - "globals": { - "should": true, - "expect": true, - "sinon": true, - "Reflect": true - }, - "rules": { - "quotes": [2, "single"], - "no-console": 0, - "comma-spacing": 2, - "comma-style": [2, "last"], - "consistent-return": 2, - "strict": [2, "global"], - "eqeqeq": [2, "smart"], - "curly": [2, "multi-line"], - "semi-spacing": [2, {"before": false, "after": true}], - "semi": [2, "always"], - "no-extra-semi": 2, - "comma-dangle": [2, "never"], - "no-sequences": 2, - "comma-spacing": [2, {"before": false, "after": true}], - "comma-style": [2, "last"] - } -} diff --git a/README.md b/README.md index a4c4908a..5db3d241 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ReDoc -[![Build Status](https://travis-ci.org/Rebilly/ReDoc.svg?branch=master)](https://travis-ci.org/Rebilly/ReDoc) [![Coverage Status](https://coveralls.io/repos/Rebilly/ReDoc/badge.svg?branch=master&service=github)](https://coveralls.io/github/Rebilly/ReDoc?branch=master) [![Tested on APIs.guru](http://apis-guru.github.io/api-models/banners/tested_on_banner.svg)](https://github.com/APIs-guru/api-models) [![Code Climate](https://codeclimate.com/github/Rebilly/ReDoc/badges/gpa.svg)](https://codeclimate.com/github/Rebilly/ReDoc) [![David](https://david-dm.org/Rebilly/ReDoc/dev-status.svg)](https://david-dm.org/Rebilly/ReDoc#info=devDependencies) [![Stories in Ready](https://badge.waffle.io/Rebilly/ReDoc.png?label=ready&title=Ready)](https://waffle.io/Rebilly/ReDoc) +[![Build Status](https://travis-ci.org/Rebilly/ReDoc.svg?branch=master)](https://travis-ci.org/Rebilly/ReDoc) [![Coverage Status](https://coveralls.io/repos/Rebilly/ReDoc/badge.svg?branch=master&service=github)](https://coveralls.io/github/Rebilly/ReDoc?branch=master) [![Tested on APIs.guru](http://api.apis.guru/badges/tested_on.svg)](https://APIs.guru) [![Code Climate](https://codeclimate.com/github/Rebilly/ReDoc/badges/gpa.svg)](https://codeclimate.com/github/Rebilly/ReDoc) [![David](https://david-dm.org/Rebilly/ReDoc/dev-status.svg)](https://david-dm.org/Rebilly/ReDoc#info=devDependencies) [![Stories in Ready](https://badge.waffle.io/Rebilly/ReDoc.png?label=ready&title=Ready)](https://waffle.io/Rebilly/ReDoc) [![npm](http://img.shields.io/npm/v/redoc.svg)](https://www.npmjs.com/package/redoc) [![Bower](http://img.shields.io/bower/v/redoc.svg)](http://bower.io/) [![License](https://img.shields.io/npm/l/redoc.svg)](https://github.com/Rebilly/ReDoc/blob/master/LICENSE) diff --git a/build/paths.js b/build/paths.js index 988f2cc8..63a59b59 100644 --- a/build/paths.js +++ b/build/paths.js @@ -1,7 +1,7 @@ var path = require('path'); var paths = { - source: 'lib/**/*.js', + source: 'lib/**/*.ts', html: 'lib/**/*.html', scss: 'lib/**/*.scss', sourceEntryPoint: 'lib/index.js', @@ -9,7 +9,7 @@ var paths = { output: 'dist/', tmp: '.tmp/', demo: 'demo/**/*', - tests: '{lib,tests}/**/*.spec.js', + tests: '{lib,tests}/**/*.spec.ts', releases: 'demo/releases/' } diff --git a/build/tasks/build.js b/build/tasks/build.js index 3ab8725c..b51a3e35 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -13,6 +13,8 @@ var replace = require('gulp-replace'); var rename = require('gulp-rename'); var argv = require('yargs').argv; var gulpIf = require('gulp-if'); +var sassCopm = require('node-sass'); +var ts = require('typescript'); gulp.task('build', function (callback) { if (argv.skipRebuild) { @@ -21,7 +23,8 @@ gulp.task('build', function (callback) { } return runSequence( 'clean', - 'concatPrism', + 'tsc', + 'inlineTemplates', 'bundle', 'concatDeps', 'copyDebug', @@ -38,19 +41,73 @@ gulp.task('copyDebug', () => { gulp.task('rebuild', function(done) { return runSequence( + 'inlineTemplates', 'bundle', 'concatDeps', + 'copyDebug', done ); }); -gulp.task('inlineTemplates', ['sass'], function() { - return gulp.src(paths.source, { base: './' }) - .pipe(replace(/'(.*?\.css)'/g, '\'.tmp/$1\'')) - .pipe(inlineNg2Template({ base: '/' })) +gulp.task('tsc', function() { + exec('tsc -p ./tsconfig.json'); +}); + + +// function compileTs(files, es5) { +// var tsProject = ts.createProject('tsconfig.json'); +// var allFiles = [].concat(files, ['typings/**/*.d.ts']); +// var res = gulp.src(allFiles, { +// base: config.src, +// outDir: config.tmp +// }) +// .pipe(tslint()) +// .pipe(tslint.report('prose', { +// summarizeFailureOutput: true, +// emitError: !watchMode +// })) +// .pipe(sourcemaps.init()) +// .pipe(ts(tsProject)) +// .on('error', function () { +// if (watchMode) { +// return; +// } +// process.exit(1); +// }); +// return res.js +// .pipe(sourcemaps.write('.', { +// includeContent: inline +// })) +// .pipe(gulp.dest(config.tmp)); +// } + +gulp.task('inlineTemplates', ['tsc', 'sass'], function() { + return gulp.src('.tmp/**/*.js', { base: './tmp' }) + .pipe(replace(/'(.*?)\.css'/g, '\'$1.scss\'')) + .pipe(inlineNg2Template({ + base: './', + useRelativePaths: true, + 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)); }); +function compileSass(ext, file) { + file = file.replace('../../shared/styles/variables', 'lib/shared/styles/variables'); + file = file.replace('json-schema-common', 'lib/components/JsonSchema/json-schema-common'); + file = file.replace('../../shared/styles/share-link', 'lib/shared/styles/share-link'); + file = file.replace('../JsonSchema/lib/components/JsonSchema/json-schema-common', 'lib/components/JsonSchema/json-schema-common'); + file = file.replace('../../styles/variables', 'lib/shared/styles/variables'); + + return sassCopm.renderSync({data: file}).css; +} + var JS_DEPS = argv.prod ? [ 'lib/utils/browser-update.js', 'node_modules/zone.js/dist/zone.min.js', @@ -59,7 +116,7 @@ var JS_DEPS = argv.prod ? [ ]: [ 'lib/utils/browser-update.js', 'node_modules/zone.js/dist/zone.js', - 'node_modules/zone.js/dist/long-stack-trace-zone.js', + //'node_modules/zone.js/dist/long-stack-trace-zone.js', 'node_modules/reflect-metadata/Reflect.js', 'node_modules/babel-polyfill/dist/polyfill.js' ]; @@ -73,16 +130,17 @@ gulp.task('sass', function () { }); // concatenate angular2 deps -gulp.task('concatDeps', function() { - return gulp.src(JS_DEPS.concat([outputFileName])) +gulp.task('concatDeps', ['concatPrism'], function() { + return gulp.src(JS_DEPS.concat([path.join(paths.tmp, 'prismjs-bundle.js'), outputFileName])) .pipe(gulpIf(!argv.prod, sourcemaps.init({loadMaps: true}))) .pipe(concat(outputFileName)) .pipe(gulpIf(!argv.prod, sourcemaps.write('.'))) .pipe(gulp.dest('.')) }); -gulp.task('bundle', ['injectVersionFile', 'inlineTemplates'], function bundle(done) { - fs.existsSync('dist') || fs.mkdirSync('dist'); +gulp.task('bundle', function bundle(done) { + mkdir('-p', 'dist'); + cp('lib/index.js', path.join(paths.tmp, paths.sourceEntryPoint)); var builder = new Builder('./', 'system.config.js'); builder @@ -126,7 +184,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 diff --git a/build/tasks/lint.js b/build/tasks/lint.js index 63559646..526dc523 100644 --- a/build/tasks/lint.js +++ b/build/tasks/lint.js @@ -1,10 +1,15 @@ var gulp = require('gulp'); -var eslint = require('gulp-eslint'); +var tslint = require('gulp-tslint'); var paths = require('../paths'); gulp.task('lint', function () { return gulp.src([paths.source, paths.tests]) - .pipe(eslint()) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()); + .pipe(tslint({ + rulesDirectory: 'node_modules/codelyzer' + })) + .pipe(tslint.report(require('tslint-stylish'), { + emitError: true, + sort: true, + bell: true + })); }); diff --git a/build/tasks/test.js b/build/tasks/test.js index 444b2307..58270bb3 100644 --- a/build/tasks/test.js +++ b/build/tasks/test.js @@ -1,6 +1,7 @@ var gulp = require('gulp'); var Server = require('karma').Server; +var remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul'); /** * Run test once and exit @@ -9,5 +10,34 @@ gulp.task('test', ['concatPrism', 'inlineTemplates', 'injectVersionFile'], funct new Server({ configFile: __dirname + '/../../karma.conf.js', singleRun: true - }, done).start(); + }, karmaDone).start(); + + function karmaDone (exitCode) { + remapCoverage(done, exitCode); + } }); + +function remapCoverage(done, statusCode) { + console.log('Remapping coverage to TypeScript format...'); + gulp.src('coverage/**/coverage-final.json') + .pipe(remapIstanbul({ + reports: { + 'lcovonly': 'coverage/lcov.info', + 'text-summary': 'coverage/text-summary.txt', + 'html': 'coverage' + } + })) + .on('finish', function () { + console.log('Remapping done!'); + console.log(cat('coverage/text-summary.txt').stdout); + console.log('Test Done with exit code: ' + statusCode); + if (process.env.TRAVIS) { + console.log('uploading to coveralls') + var out = cat('coverage/lcov.info').exec('coveralls'); + if (out.code !== 0) { + console.warn('Failed upload to coveralls'); + } + } + done(statusCode); + }); +}; diff --git a/demo/index.html b/demo/index.html index cbcd26f1..0b3bf995 100644 --- a/demo/index.html +++ b/demo/index.html @@ -4,6 +4,11 @@