-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving to a build process, big change
- Loading branch information
1 parent
2663db7
commit 393beb5
Showing
18 changed files
with
2,307 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<html><head><script src="https://unpkg.com/dropbox/dist/Dropbox-sdk.min.js"></script><script>function parseQueryString(e){var a=Object.create(null);return"string"!=typeof e?a:(e=e.trim().replace(/^(\?|#|&)/,""))?(e.split("&").forEach(function(e){var t=e.replace(/\+/g," ").split("="),n=t.shift(),o=t.length>0?t.join("="):void 0;n=decodeURIComponent(n),o=void 0===o?null:decodeURIComponent(o),void 0===a[n]?a[n]=o:Array.isArray(a[n])?a[n].push(o):a[n]=[a[n],o]}),a):a}window.addEventListener("message",function(e){if("setClientID"==e.data[0]){var a=new Dropbox({clientId:e.data[1]});window.location.href=a.getAuthenticationUrl(window.location.href)}});var hashData=parseQueryString(window.location.hash);(hashData.access_token||hashData.error)&&window.opener.postMessage(JSON.stringify(["dialogLogin",hashData]),"*")</script></head><body></body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
|
||
/* | ||
* This file is the build process for this repository. | ||
* | ||
* It begins by importing all the gulp modules needed to do the tasks below. | ||
*/ | ||
var gulp = require( 'gulp' ); | ||
var htmlmin = require( 'gulp-htmlmin' ); | ||
var embed = require( 'gulp-embed' ); | ||
var uglify = require( 'gulp-uglify' ); | ||
var each = require( 'gulp-each' ); | ||
var rename = require( 'gulp-rename' ); | ||
var concat = require( 'gulp-concat' ); | ||
var addsrc = require( 'gulp-add-src' ); | ||
|
||
/* | ||
* Any client will need to import our scripts. The main one is the | ||
* cloud-storage.js file itself, which we compile here, from the source | ||
* folder to the release folder. | ||
* | ||
* This is a simple minification of the source file, with one additional | ||
* step. We embed the entire dialog.{html,css,js} content as a single, | ||
* base64-encoded string at the top of the compiled file, so that it can be | ||
* used programmatically to fill an iframe, without the need for those three | ||
* files to be present in the same folder. | ||
*/ | ||
gulp.task( 'build-main-script', function () { | ||
return gulp.src( 'source/dialog.html' ) | ||
// embed dialog.{js,css} into dialog.html, then minify | ||
.pipe( embed() ) | ||
.pipe( htmlmin( { collapseWhitespace : true, | ||
removeComments : true, | ||
minifyJS : true, | ||
minifyCSS : true } ) ) | ||
// manually base64 encode the result as a JS string variable | ||
.pipe( each( function ( content, file, callback ) { | ||
callback( null, | ||
'var dialogHTML = "data:text/html;base64,' + | ||
( new Buffer( content ).toString( 'base64' ) ) + | ||
'";' ); | ||
} ) ) | ||
// prepend this onto cloud-storage.js and make it use the var | ||
.pipe( addsrc.append( 'source/cloud-storage.js' ) ) | ||
.pipe( concat( 'cloud-storage.js' ) ) | ||
.pipe( each( function ( content, file, callback ) { | ||
callback( null, | ||
content.replace( "'./dialog.html'", "dialogHTML" ) ); | ||
} ) ) | ||
// minify and output | ||
.pipe( uglify() ) | ||
.pipe( gulp.dest( 'release/' ) ); | ||
} ); | ||
|
||
/* | ||
* Any client will need to import our scripts. In addition to the | ||
* cloud-storage.js file built by the process above, there are also a | ||
* handful of "backends" that reside in their own .js files, so that clients | ||
* can import exactly the subset they need, and no more. We compile those | ||
* here, also from the source folder to the release folder. | ||
*/ | ||
gulp.task( 'minify-backends', function () { | ||
return gulp.src( 'source/*-backend.js' ) | ||
.pipe( uglify() ) | ||
.pipe( gulp.dest( 'release/' ) ); | ||
} ); | ||
|
||
/* | ||
* A client who chooses to use the Dropbox backend will need a page in their | ||
* own web space to which to direct the Dropbox login procedure. We provide | ||
* the file dropbox-login.html that receives that redirection from Dropbox | ||
* and emits the messages that the scripts in dropbox-backend.js need to | ||
* access the user's Dropbox. The user will need a copy of thta file in | ||
* the same folder as the page importing cloud-storage.js. | ||
* | ||
* This build task just copies the dropbox-login.html page to the release | ||
* folder, from which clients who need it can download it. But while we're | ||
* at it, we might as well minify its contents. | ||
*/ | ||
gulp.task( 'minify-login-page', function () { | ||
return gulp.src( 'source/dropbox-login.html' ) | ||
.pipe( htmlmin( { collapseWhitespace : true, | ||
removeComments : true, | ||
minifyJS : true } ) ) | ||
.pipe( gulp.dest( 'release/' ) ); | ||
} ); | ||
|
||
/* | ||
* This repository contains an example/ folder to show how to use the tools | ||
* provided. This task just copies the minified login page from the release | ||
* folder to the example folder. | ||
*/ | ||
gulp.task( 'build-example', [ 'minify-login-page' ], function () { | ||
return gulp.src( 'release/dropbox-login.html' ) | ||
.pipe( gulp.dest( 'example/' ) ); | ||
} ); | ||
|
||
/* | ||
* The default build task is to do everything. | ||
*/ | ||
gulp.task( 'default', [ 'build-main-script', | ||
'minify-backends', | ||
'minify-login-page', | ||
'build-example' ] ); |
Oops, something went wrong.