Merge branch 'develop_2.0' of github.com:swagger-api/swagger-ui into develop_2.0

This commit is contained in:
Tony Tam
2015-01-28 16:58:22 -08:00
5 changed files with 128 additions and 15 deletions

7
.travis.yml Normal file
View File

@@ -0,0 +1,7 @@
language: node_js
node_js:
- '0.10'
install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- npm install

View File

@@ -1,8 +1,8 @@
fs = require 'fs' fs = require 'fs'
path = require 'path'
{exec} = require 'child_process' {exec} = require 'child_process'
less = require 'less' less = require 'less'
handlebars = require 'handlebars' handlebars = require 'handlebars'
ncp = require 'ncp'
sourceFiles = [ sourceFiles = [
'SwaggerUi' 'SwaggerUi'
@@ -23,12 +23,12 @@ sourceFiles = [
task 'clean', 'Removes distribution', -> task 'clean', 'Removes distribution', ->
console.log 'Clearing dist...' console.log 'Clearing dist...'
exec 'rm -rf dist' rmDir('dist') if fs.existsSync('dist')
task 'dist', 'Build a distribution', -> task 'dist', 'Build a distribution', ->
console.log "Build distribution in ./dist" console.log "Build distribution in ./dist"
fs.mkdirSync('dist') if not path.existsSync('dist') fs.mkdirSync('dist') if not fs.existsSync('dist')
fs.mkdirSync('dist/lib') if not path.existsSync('dist/lib') fs.mkdirSync('dist/lib') if not fs.existsSync('dist/lib')
appContents = new Array remaining = sourceFiles.length appContents = new Array remaining = sourceFiles.length
for file, index in sourceFiles then do (file, index) -> for file, index in sourceFiles then do (file, index) ->
@@ -67,7 +67,6 @@ task 'dist', 'Build a distribution', ->
throw err if err throw err if err
fs.unlink 'dist/_swagger-ui.coffee' fs.unlink 'dist/_swagger-ui.coffee'
console.log ' : Combining with javascript...' console.log ' : Combining with javascript...'
fs.readFile 'package.json', 'utf8', (err, fileContents) -> fs.readFile 'package.json', 'utf8', (err, fileContents) ->
obj = JSON.parse(fileContents) obj = JSON.parse(fileContents)
exec 'echo "// swagger-ui.js" > dist/swagger-ui.js' exec 'echo "// swagger-ui.js" > dist/swagger-ui.js'
@@ -93,13 +92,16 @@ task 'dist', 'Build a distribution', ->
pack = -> pack = ->
console.log ' : Packaging...' console.log ' : Packaging...'
exec 'cp -r lib dist' ncp.ncp 'lib', 'dist/lib', (err) ->
console.log ' : Copied swagger-ui libs' reportNcpErrors err
exec 'cp -r node_modules/swagger-client/lib/swagger.js dist/lib' console.log ' : Copied swagger-ui libs'
console.log ' : Copied swagger dependencies' fs.mkdirSync('dist/lib') if not fs.existsSync('dist/lib')
exec 'cp -r src/main/html/* dist' fs.createReadStream('node_modules/swagger-client/lib/swagger.js').pipe(fs.createWriteStream('dist/lib/swagger.js'));
console.log ' : Copied html dependencies' console.log ' : Copied swagger dependencies'
console.log ' !' ncp.ncp 'src/main/html', 'dist', (err) ->
reportNcpErrors err
console.log ' : Copied html dependencies'
console.log ' !'
task 'spec', "Run the test suite", -> task 'spec', "Run the test suite", ->
exec "open spec.html", (err, stdout, stderr) -> exec "open spec.html", (err, stdout, stderr) ->
@@ -138,3 +140,37 @@ notify = (message) ->
# title: 'CoffeeScript' # title: 'CoffeeScript'
# image: 'bin/CoffeeScript.png' # image: 'bin/CoffeeScript.png'
# try require('growl') message, options # try require('growl') message, options
cat = (dest, files) ->
for file in files
body = fs.readFileSync(file);
fs.appendFileSync(dest, body);
fs.appendFileSync(dest, "\n");
rmDir = (dirPath) ->
try
files = fs.readdirSync(dirPath)
catch e
return
if files.length > 0
i = 0
while i < files.length
filePath = dirPath + "/" + files[i]
if fs.statSync(filePath).isFile()
fs.unlinkSync filePath
else
rmDir filePath
i++
fs.rmdirSync dirPath
reportNcpErrors = (err) ->
if Array.isArray(err)
console.error "There were errors during the copy."
err.forEach (err) ->
console.error err.stack or err.message
process.exit 1
else if err
console.error "An error has occurred."
console.error err.stack or err.message
process.exit 1

View File

@@ -1,5 +1,7 @@
# Swagger UI # Swagger UI
[![Build Status](https://travis-ci.org/swagger-api/swagger-ui.svg?branch=develop_2.0)](https://travis-ci.org/swagger-api/swagger-ui)
Swagger UI is part of the Swagger project. The Swagger project allows you to produce, visualize and consume your OWN RESTful services. No proxy or 3rd party services required. Do it your own way. Swagger UI is part of the Swagger project. The Swagger project allows you to produce, visualize and consume your OWN RESTful services. No proxy or 3rd party services required. Do it your own way.
Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically

View File

@@ -4,7 +4,7 @@
"description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API", "description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API",
"scripts": { "scripts": {
"build": "PATH=$PATH:./node_modules/.bin cake dist", "build": "PATH=$PATH:./node_modules/.bin cake dist",
"test": "echo \"Error: no test specified\" && exit 1" "test": "./node_modules/coffee-script/bin/cake dist; ./node_modules/mocha/bin/mocha src/test/e2e/index.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -24,8 +24,13 @@
"less": "~1.4.2" "less": "~1.4.2"
}, },
"devDependencies": { "devDependencies": {
"express": "3.x", "chai": "^1.10.0",
"cors": "2.1.1",
"docco": "0.4.x", "docco": "0.4.x",
"cors": "2.1.1" "express": "3.x",
"http-server": "^0.7.4",
"mocha": "^2.1.0",
"ncp": "^1.0.1",
"selenium-webdriver": "^2.44.0"
} }
} }

63
src/test/e2e/index.js Normal file
View File

@@ -0,0 +1,63 @@
var webdriver = require('selenium-webdriver');
var createServer = require('http-server').createServer;
var expect = require('chai').expect;
var path = require('path')
var dist = path.join(__dirname, '..', '..', '..', 'dist');
var PORT = 8080;
console.log('started static server from', dist, 'at port', PORT);
var server = createServer({
root: dist,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
}
});
server.listen(PORT);
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.firefox()).
build();
describe('basics', function () {
this.timeout(10 * 1000);
beforeEach(function () {
driver.get('http://localhost:' + PORT);
});
it('should have "Swagger UI" in title', function (done) {
driver.wait(function() {
return driver.getTitle().then(function(title) {
var hasTitle = title.indexOf('Swagger UI') > -1;
if (hasTitle) {
expect(title).to.contain('Swagger UI');
done();
}
return hasTitle;
});
}, 1000);
});
});
describe('cleanup', function () {
it('kills the static server', function () {
server.close();
});
it('quit the webdriver', function () {
driver.quit();
});
})