Merge branch 'mohsen1-gulp' into develop_2.0t push origin develop_2.0
This commit is contained in:
176
Cakefile
176
Cakefile
@@ -1,176 +0,0 @@
|
||||
fs = require 'fs'
|
||||
{exec} = require 'child_process'
|
||||
less = require 'less'
|
||||
handlebars = require 'handlebars'
|
||||
ncp = require 'ncp'
|
||||
|
||||
sourceFiles = [
|
||||
'SwaggerUi'
|
||||
'view/HeaderView'
|
||||
'view/MainView'
|
||||
'view/ResourceView'
|
||||
'view/OperationView'
|
||||
'view/StatusCodeView'
|
||||
'view/ParameterView'
|
||||
'view/SignatureView'
|
||||
'view/ContentTypeView'
|
||||
'view/ResponseContentTypeView'
|
||||
'view/ParameterContentTypeView'
|
||||
'view/ApiKeyButton'
|
||||
'view/BasicAuthButton'
|
||||
]
|
||||
|
||||
|
||||
task 'clean', 'Removes distribution', ->
|
||||
console.log 'Clearing dist...'
|
||||
rmDir('dist') if fs.existsSync('dist')
|
||||
|
||||
task 'dist', 'Build a distribution', ->
|
||||
console.log "Build distribution in ./dist"
|
||||
fs.mkdirSync('dist') if not fs.existsSync('dist')
|
||||
fs.mkdirSync('dist/lib') if not fs.existsSync('dist/lib')
|
||||
|
||||
appContents = new Array remaining = sourceFiles.length
|
||||
for file, index in sourceFiles then do (file, index) ->
|
||||
console.log " : Reading src/main/coffeescript/#{file}.coffee"
|
||||
fs.readFile "src/main/coffeescript/#{file}.coffee", 'utf8', (err, fileContents) ->
|
||||
throw err if err
|
||||
appContents[index] = fileContents
|
||||
precompileTemplates() if --remaining is 0
|
||||
|
||||
precompileTemplates= ->
|
||||
console.log ' : Precompiling templates...'
|
||||
templateFiles = fs.readdirSync('src/main/template')
|
||||
templateContents = new Array remaining = templateFiles.length
|
||||
for file, index in templateFiles then do (file, index) ->
|
||||
console.log " : Compiling src/main/template/#{file}"
|
||||
fs.readFile "src/main/template/#{file}", 'utf8', (err, source) ->
|
||||
throw err if err
|
||||
compiled = handlebars.precompile(source)
|
||||
templateContents[index] = '(function() {\n var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\ntemplates[\'' + file.replace('.handlebars', '') + '\'] = template(' + compiled + ');\n})();'
|
||||
fs.unlink 'dist/_' + file + '.js', (err) ->
|
||||
console.log "#{err.code}: #{err.path}" unless err.code == 'ENOENT'
|
||||
if --remaining is 0
|
||||
templateContents.push '\n\n'
|
||||
fs.writeFile 'dist/_swagger-ui-templates.js', templateContents.join('\n\n'), 'utf8', (err) ->
|
||||
throw err if err
|
||||
build()
|
||||
|
||||
build = ->
|
||||
console.log ' : Collecting Coffeescript source...'
|
||||
|
||||
appContents.push '\n\n'
|
||||
fs.writeFile 'dist/_swagger-ui.coffee', appContents.join('\n\n'), 'utf8', (err) ->
|
||||
throw err if err
|
||||
console.log ' : Compiling...'
|
||||
exec 'coffee --compile dist/_swagger-ui.coffee', (err, stdout, stderr) ->
|
||||
throw err if err
|
||||
fs.unlink 'dist/_swagger-ui.coffee'
|
||||
console.log ' : Combining with javascript...'
|
||||
fs.readFile 'package.json', 'utf8', (err, fileContents) ->
|
||||
obj = JSON.parse(fileContents)
|
||||
exec 'echo "// swagger-ui.js" > dist/swagger-ui.js'
|
||||
exec 'echo "// version ' + obj.version + '" >> dist/swagger-ui.js'
|
||||
exec 'cat src/main/javascript/doc.js dist/_swagger-ui-templates.js dist/_swagger-ui.js >> dist/swagger-ui.js', (err, stdout, stderr) ->
|
||||
throw err if err
|
||||
fs.unlink 'dist/_swagger-ui.js'
|
||||
fs.unlink 'dist/_swagger-ui-templates.js'
|
||||
console.log ' : Minifying all...'
|
||||
exec 'java -jar "./bin/yuicompressor-2.4.7.jar" --type js -o ' + 'dist/swagger-ui.min.js ' + 'dist/swagger-ui.js', (err, stdout, stderr) ->
|
||||
throw err if err
|
||||
lessc()
|
||||
|
||||
lessc = ->
|
||||
# Someone who knows CoffeeScript should make this more Coffee-licious
|
||||
console.log ' : Compiling LESS...'
|
||||
|
||||
less.render fs.readFileSync("src/main/less/screen.less", 'utf8'), (err, css) ->
|
||||
fs.writeFileSync("src/main/html/css/screen.css", css)
|
||||
less.render fs.readFileSync("src/main/less/reset.less", 'utf8'), (err, css) ->
|
||||
fs.writeFileSync("src/main/html/css/reset.css", css)
|
||||
pack()
|
||||
|
||||
pack = ->
|
||||
console.log ' : Packaging...'
|
||||
ncp.ncp 'lib', 'dist/lib', (err) ->
|
||||
reportNcpErrors err
|
||||
console.log ' : Copied swagger-ui libs'
|
||||
fs.mkdirSync('dist/lib') if not fs.existsSync('dist/lib')
|
||||
fs.createReadStream('node_modules/swagger-client/lib/swagger-client.js');
|
||||
console.log ' : Copied swagger dependencies'
|
||||
ncp.ncp 'src/main/html', 'dist', (err) ->
|
||||
reportNcpErrors err
|
||||
console.log ' : Copied html dependencies'
|
||||
console.log ' !'
|
||||
|
||||
task 'spec', "Run the test suite", ->
|
||||
exec "open spec.html", (err, stdout, stderr) ->
|
||||
throw err if err
|
||||
|
||||
task 'watch', 'Watch source files for changes and autocompile', ->
|
||||
# Function which watches all files in the passed directory
|
||||
watchFiles = (dir) ->
|
||||
files = fs.readdirSync(dir)
|
||||
for file, index in files then do (file, index) ->
|
||||
console.log " : " + dir + "/#{file}"
|
||||
fs.watchFile dir + "/#{file}", (curr, prev) ->
|
||||
if +curr.mtime isnt +prev.mtime
|
||||
invoke 'dist'
|
||||
|
||||
notify "Watching source files for changes..."
|
||||
|
||||
# Watch specific source files
|
||||
for file, index in sourceFiles then do (file, index) ->
|
||||
console.log " : " + "src/main/coffeescript/#{file}.coffee"
|
||||
fs.watchFile "src/main/coffeescript/#{file}.coffee", (curr, prev) ->
|
||||
if +curr.mtime isnt +prev.mtime
|
||||
invoke 'dist'
|
||||
|
||||
# watch all files in these folders
|
||||
watchFiles("src/main/template")
|
||||
watchFiles("src/main/javascript")
|
||||
watchFiles("src/main/html")
|
||||
watchFiles("src/main/less")
|
||||
watchFiles("src/test")
|
||||
|
||||
notify = (message) ->
|
||||
return unless message?
|
||||
console.log message
|
||||
# options =
|
||||
# title: 'CoffeeScript'
|
||||
# image: 'bin/CoffeeScript.png'
|
||||
# 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
|
||||
12
README.md
12
README.md
@@ -12,7 +12,7 @@ generate beautiful documentation and sandbox from a Swagger-compliant API. Becau
|
||||
The goal of Swagger™ is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swagger removes the guesswork in calling the service.
|
||||
|
||||
|
||||
Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
|
||||
Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
|
||||
|
||||
|
||||
## Compatibility
|
||||
@@ -21,7 +21,7 @@ The Swagger Specification has undergone 3 revisions since initial creation in 20
|
||||
Swagger UI Version | Release Date | Swagger Spec compatibility | Notes | Status
|
||||
------------------ | ------------ | -------------------------- | ----- | ------
|
||||
2.1.0-alpha.7 (in development) | 2014-10-06 | 1.1, 1.2, 2.0 | [master](https://github.com/swagger-api/swagger-ui/tree/develop_2.0) | [Issues](https://github.com/swagger-api/swagger-ui/milestones/v2.1.0)
|
||||
2.0.24 | 2014-09-12 | 1.1, 1.2 | [tag v2.0.24](https://github.com/swagger-api/swagger-ui/tree/v2.0.24) |
|
||||
2.0.24 | 2014-09-12 | 1.1, 1.2 | [tag v2.0.24](https://github.com/swagger-api/swagger-ui/tree/v2.0.24) |
|
||||
1.0.13 | 2013-03-08 | 1.1, 1.2 | [tag v1.0.13](https://github.com/swagger-api/swagger-ui/tree/v1.0.13) |
|
||||
1.0.1 | 2011-10-11 | 1.0, 1.1 | [tag v1.0.1](https://github.com/swagger-api/swagger-ui/tree/v1.0.1) |
|
||||
|
||||
@@ -33,9 +33,9 @@ You can use the swagger-ui code AS-IS! No need to build or recompile--just clon
|
||||
### Build
|
||||
You can rebuild swagger-ui on your own to tweak it or just so you can say you did. To do so, follow these steps:
|
||||
|
||||
1. npm install
|
||||
2. npm run-script build
|
||||
3. You should see the distribution under the dist folder. Open ./dist/index.html to launch Swagger UI in a browser
|
||||
1. `npm install`
|
||||
2. `npm run build`
|
||||
3. You should see the distribution under the dist folder. Open [`./dist/index.html`](./dist/index.html) to launch Swagger UI in a browser
|
||||
|
||||
### Build using Docker
|
||||
|
||||
@@ -167,7 +167,7 @@ This tells us that the petstore resource listing supports OPTIONS, and the follo
|
||||
- Try swagger-ui from your file system and look at the debug console. If CORS is not enabled, you'll see something like this:
|
||||
|
||||
```
|
||||
XMLHttpRequest cannot load http://sad.server.com/v2/api-docs. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
|
||||
XMLHttpRequest cannot load http://sad.server.com/v2/api-docs. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
|
||||
```
|
||||
|
||||
Swagger-UI cannot easily show this error state.
|
||||
|
||||
Binary file not shown.
2
dist/index.html
vendored
2
dist/index.html
vendored
@@ -12,7 +12,7 @@
|
||||
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
|
||||
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
|
||||
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
|
||||
<script src='lib/handlebars-1.0.0.js' type='text/javascript'></script>
|
||||
<script src='lib/handlebars-2.0.0.js' type='text/javascript'></script>
|
||||
<script src='lib/underscore-min.js' type='text/javascript'></script>
|
||||
<script src='lib/backbone-min.js' type='text/javascript'></script>
|
||||
<script src='lib/swagger-client.js' type='text/javascript'></script>
|
||||
|
||||
2278
dist/lib/handlebars-1.0.0.js
vendored
2278
dist/lib/handlebars-1.0.0.js
vendored
File diff suppressed because it is too large
Load Diff
28
dist/lib/handlebars-2.0.0.js
vendored
Normal file
28
dist/lib/handlebars-2.0.0.js
vendored
Normal file
File diff suppressed because one or more lines are too long
4307
dist/swagger-ui.js
vendored
4307
dist/swagger-ui.js
vendored
File diff suppressed because it is too large
Load Diff
3
dist/swagger-ui.min.js
vendored
3
dist/swagger-ui.min.js
vendored
File diff suppressed because one or more lines are too long
105
gulpfile.js
Normal file
105
gulpfile.js
Normal file
@@ -0,0 +1,105 @@
|
||||
'use strict';
|
||||
|
||||
var gulp = require('gulp');
|
||||
var es = require('event-stream');
|
||||
var gutil = require('gulp-util');
|
||||
var clean = require('gulp-clean');
|
||||
var coffee = require('gulp-coffee');
|
||||
var concat = require('gulp-concat');
|
||||
var uglify = require('gulp-uglify');
|
||||
var rename = require('gulp-rename');
|
||||
var less = require('gulp-less');
|
||||
var handlebars = require('gulp-handlebars');
|
||||
var wrap = require('gulp-wrap');
|
||||
var declare = require('gulp-declare');
|
||||
|
||||
/*
|
||||
* Clean ups ./dist folder
|
||||
*/
|
||||
gulp.task('clean', function() {
|
||||
|
||||
return gulp
|
||||
.src('./dist', {read: false})
|
||||
.pipe(clean({force: true}))
|
||||
.on('error', gutil.log);
|
||||
});
|
||||
|
||||
/*
|
||||
* Processes Handlebars templates
|
||||
*/
|
||||
function templates() {
|
||||
return gulp
|
||||
.src(['./src/main/template/**/*'])
|
||||
.pipe(handlebars())
|
||||
.pipe(wrap('Handlebars.template(/*__DEFINING__*/<%= contents %>)'))
|
||||
.pipe(declare({
|
||||
namespace: 'Handlebars.templates',
|
||||
noRedeclare: true, // Avoid duplicate declarations
|
||||
}))
|
||||
.on('error', gutil.log);
|
||||
}
|
||||
|
||||
/*
|
||||
* Processes CoffeeScript files
|
||||
*/
|
||||
function coffeescript () {
|
||||
return gulp
|
||||
.src(['./src/main/coffeescript/**/*.coffee'])
|
||||
.pipe(coffee({bare: true}))
|
||||
.on('error', gutil.log);
|
||||
}
|
||||
|
||||
/*
|
||||
* Build a distribution
|
||||
*/
|
||||
gulp.task('dist', ['clean'], function() {
|
||||
|
||||
return es.merge(
|
||||
gulp.src('./src/main/javascript/doc.js'),
|
||||
coffeescript(),
|
||||
templates()
|
||||
)
|
||||
.pipe(concat('swagger-ui.js'))
|
||||
.pipe(gulp.dest('./dist'))
|
||||
.pipe(uglify())
|
||||
.pipe(rename({extname: '.min.js'}))
|
||||
.on('error', gutil.log)
|
||||
.pipe(gulp.dest('./dist'));
|
||||
});
|
||||
|
||||
/*
|
||||
* Processes less files into CSS files
|
||||
*/
|
||||
gulp.task('less', ['clean'], function() {
|
||||
|
||||
return gulp
|
||||
.src([
|
||||
'./src/main/less/screen.less',
|
||||
'./src/main/less/reset.less'
|
||||
])
|
||||
.pipe(less())
|
||||
.on('error', gutil.log)
|
||||
.pipe(gulp.dest('./src/main/html/css/'));
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* Copy lib and html folders
|
||||
*/
|
||||
gulp.task('copy', ['clean'], function() {
|
||||
|
||||
// copy JavaScript files inside lib folder
|
||||
gulp
|
||||
.src(['./lib/**/*.js'])
|
||||
.pipe(gulp.dest('./dist/lib'))
|
||||
.on('error', gutil.log)
|
||||
|
||||
// copy all files inside html folder
|
||||
gulp
|
||||
.src(['./src/main/html/**/*'])
|
||||
.pipe(gulp.dest('./dist'))
|
||||
.on('error', gutil.log)
|
||||
});
|
||||
|
||||
|
||||
gulp.task('default', ['dist', 'less', 'copy']);
|
||||
File diff suppressed because it is too large
Load Diff
28
lib/handlebars-2.0.0.js
Normal file
28
lib/handlebars-2.0.0.js
Normal file
File diff suppressed because one or more lines are too long
28
package.json
28
package.json
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"name": "swagger-ui",
|
||||
"version": "2.1.0-alpha.8",
|
||||
"version": "2.1.0-alpha.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",
|
||||
"scripts": {
|
||||
"build": "PATH=$PATH:./node_modules/.bin cake dist",
|
||||
"test": "./node_modules/coffee-script/bin/cake dist; ./node_modules/mocha/bin/mocha src/test/e2e/index.js"
|
||||
"build": "./node_modules/gulp/bin/gulp.js;",
|
||||
"test": "./node_modules/gulp/bin/gulp.js; ./node_modules/mocha/bin/mocha src/test/e2e/index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -17,20 +17,28 @@
|
||||
},
|
||||
"license": "Apache",
|
||||
"readmeFilename": "README.md",
|
||||
"dependencies": {
|
||||
"coffee-script": "~1.6.3",
|
||||
"swagger-client": "2.1.0-alpha.7",
|
||||
"handlebars": "~1.0.10",
|
||||
"less": "~1.4.2"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"swagger-client": "2.1.0-alpha.7",
|
||||
"chai": "^1.10.0",
|
||||
"cors": "2.1.1",
|
||||
"docco": "0.4.x",
|
||||
"event-stream": "^3.2.1",
|
||||
"express": "3.x",
|
||||
"gulp": "^3.8.10",
|
||||
"gulp-clean": "^0.3.1",
|
||||
"gulp-coffee": "^2.2.0",
|
||||
"gulp-concat": "^2.4.3",
|
||||
"gulp-declare": "^0.3.0",
|
||||
"gulp-handlebars": "^3.0.1",
|
||||
"gulp-less": "^2.0.1",
|
||||
"gulp-rename": "^1.2.0",
|
||||
"gulp-uglify": "^1.1.0",
|
||||
"gulp-util": "^3.0.2",
|
||||
"gulp-wrap": "^0.10.1",
|
||||
"http-server": "^0.7.4",
|
||||
"less": "~1.4.2",
|
||||
"mocha": "^2.1.0",
|
||||
"ncp": "^1.0.1",
|
||||
"selenium-webdriver": "^2.44.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
|
||||
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
|
||||
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
|
||||
<script src='lib/handlebars-1.0.0.js' type='text/javascript'></script>
|
||||
<script src='lib/handlebars-2.0.0.js' type='text/javascript'></script>
|
||||
<script src='lib/underscore-min.js' type='text/javascript'></script>
|
||||
<script src='lib/backbone-min.js' type='text/javascript'></script>
|
||||
<script src='lib/swagger-client.js' type='text/javascript'></script>
|
||||
|
||||
Reference in New Issue
Block a user