Skip to content

Commit d3cf4ef

Browse files
committed
Build process now includes a min.js file. Our license is prepended to each output js
1 parent a521078 commit d3cf4ef

File tree

5 files changed

+90
-42
lines changed

5 files changed

+90
-42
lines changed

LICENSE

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
22-
21+
SOFTWARE.

gulpfile.js

+36-37
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ var require;
55
var browserify = require("browserify");
66
var del = require("del");
77
var forever = require("forever");
8+
var fs = require("file-system");
89
var globby = require("globby");
910
var gulp = require("gulp");
11+
var header = require("gulp-header");
1012
var merge = require("merge-stream");
1113
var plumber = require("gulp-plumber");
1214
var qunit = require("node-qunit-phantomjs");
15+
var rename = require("gulp-rename");
1316
var runSequence = require("run-sequence");
1417
var source = require("vinyl-source-stream");
1518
var ts = require("gulp-typescript");
1619
var tslint = require("gulp-tslint");
1720
var tsd = require("gulp-tsd");
21+
var uglify = require("gulp-uglify");
1822

1923
var PATHS = {
2024
SRCROOT: "src/",
@@ -92,10 +96,19 @@ gulp.task("tslint", function () {
9296
////////////////////////////////////////
9397
// BUNDLE
9498
////////////////////////////////////////
99+
function getLicense() {
100+
return [
101+
"/*",
102+
fs.readFileSync("LICENSE", "utf8"),
103+
"*/"
104+
].join("\n");
105+
}
106+
95107
gulp.task("bundleApi", function () {
96108
return browserify(PATHS.BUILDROOT + "scripts/oneNoteApi.js", { standalone: "OneNoteApi" })
97109
.bundle()
98110
.pipe(source("oneNoteApi.js"))
111+
.pipe(header(getLicense()))
99112
.pipe(gulp.dest(PATHS.BUNDLEROOT));
100113
});
101114

@@ -115,6 +128,21 @@ gulp.task("bundle", function (callback) {
115128
callback);
116129
});
117130

131+
////////////////////////////////////////
132+
// MINIFY BUNDLED
133+
////////////////////////////////////////
134+
gulp.task("minifyBundled", function (callback) {
135+
var targetDir = PATHS.BUNDLEROOT;
136+
137+
var minifyTask = gulp.src(PATHS.BUNDLEROOT + "oneNoteApi.js")
138+
.pipe(uglify({
139+
preserveComments: "license"
140+
}))
141+
.pipe(rename({ suffix: ".min" }))
142+
.pipe(gulp.dest(targetDir));
143+
144+
return merge(minifyTask);
145+
});
118146

119147
////////////////////////////////////////
120148
// EXPORT
@@ -124,10 +152,10 @@ gulp.task("exportApi", function () {
124152
.pipe(gulp.dest(PATHS.TARGETROOT + "modules/"));
125153

126154
var copyTask = gulp.src([
127-
PATHS.BUNDLEROOT + "oneNoteApi.js",
128-
PATHS.SRCROOT + "oneNoteApi.d.ts"
129-
])
130-
.pipe(gulp.dest(PATHS.TARGETROOT));
155+
PATHS.BUNDLEROOT + "oneNoteApi.js",
156+
PATHS.BUNDLEROOT + "oneNoteApi.min.js",
157+
PATHS.SRCROOT + "oneNoteApi.d.ts"
158+
]).pipe(gulp.dest(PATHS.TARGETROOT));
131159

132160
return merge(modulesTask, copyTask);
133161
});
@@ -136,10 +164,9 @@ gulp.task("exportTests", function () {
136164
var targetDir = PATHS.TARGETROOT + "tests/";
137165

138166
var libsTask = gulp.src([
139-
"node_modules/qunitjs/qunit/qunit.+(css|js)",
140-
PATHS.SRCROOT + "tests/bind_polyfill.js"
141-
])
142-
.pipe(gulp.dest(targetDir + "libs"));
167+
"node_modules/qunitjs/qunit/qunit.+(css|js)",
168+
PATHS.SRCROOT + "tests/bind_polyfill.js"
169+
]).pipe(gulp.dest(targetDir + "libs"));
143170

144171
var testsTask = gulp.src(PATHS.BUNDLEROOT + "tests/**", { base: PATHS.BUNDLEROOT + "tests/" })
145172
.pipe(gulp.dest(targetDir));
@@ -150,39 +177,10 @@ gulp.task("exportTests", function () {
150177
return merge(libsTask, testsTask, indexTask);
151178
});
152179

153-
gulp.task("exportSampleJs", function () {
154-
return gulp.src([
155-
PATHS.BUNDLEROOT + "oneNoteApi.js",
156-
PATHS.SRCROOT + "sample/javascript/index.html",
157-
PATHS.SRCROOT + "sample/javascript/sample.js"
158-
])
159-
.pipe(gulp.dest(PATHS.WEBROOT));
160-
});
161-
162-
gulp.task("exportSampleTs", function () {
163-
return gulp.src([
164-
PATHS.BUNDLEROOT + "oneNoteApi.js",
165-
PATHS.SRCROOT + "sample/typescript/index.html",
166-
PATHS.BUILDROOT + "sample/typescript/sample.js"
167-
])
168-
.pipe(gulp.dest(PATHS.WEBROOT + "typescript/"));
169-
});
170-
171-
gulp.task("exportSampleTsModule", function () {
172-
return gulp.src([
173-
PATHS.SRCROOT + "sample/typescript_module/index.html",
174-
PATHS.BUNDLEROOT + "sample.js"
175-
])
176-
.pipe(gulp.dest(PATHS.WEBROOT + "typescript_module/"));
177-
});
178-
179180
gulp.task("export", function (callback) {
180181
runSequence(
181182
"exportApi",
182183
"exportTests",
183-
"exportSampleJs",
184-
"exportSampleTs",
185-
"exportSampleTsModule",
186184
callback);
187185
});
188186

@@ -211,6 +209,7 @@ gulp.task("build", function (callback) {
211209
runSequence(
212210
"compile",
213211
"bundle",
212+
"minifyBundled",
214213
"export",
215214
"tslint",
216215
"runTests",

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.3",
2+
"version": "1.0.4",
33
"name": "onenoteapi",
44
"description": "JavaScript library to make calling the OneNote API easier.",
55
"main": "target/modules/oneNoteApi.js",
@@ -14,14 +14,18 @@
1414
"babel-preset-es2015": "^6.3.13",
1515
"browserify": "^13.0.0",
1616
"del": "^2.0.2",
17+
"file-system": "^2.2.1",
1718
"forever": "^0.15.1",
1819
"globby": "^4.0.0",
1920
"gulp": "^3.9.0",
21+
"gulp-header": "^1.8.8",
2022
"gulp-nodemon": "^2.0.4",
2123
"gulp-plumber": "^1.0.1",
24+
"gulp-rename": "^1.2.2",
2225
"gulp-tsd": "^0.0.4",
2326
"gulp-tslint": "^5.0.0",
2427
"gulp-typescript": "^2.9.2",
28+
"gulp-uglify": "^1.5.3",
2529
"jquery": "^2.1.4",
2630
"merge-stream": "^1.0.0",
2731
"node-qunit-phantomjs": "^1.4.0",
@@ -34,5 +38,5 @@
3438
"typescript": "^1.7.3",
3539
"vinyl-source-stream": "^1.1.0"
3640
},
37-
"files": ["README.*", "target/oneNoteApi.d.ts", "target/oneNoteApi.js"]
41+
"files": ["README.*", "target/oneNoteApi.d.ts", "target/oneNoteApi.js", "target/oneNoteApi.min.js"]
3842
}

target/oneNoteApi.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
1-
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.OneNoteApi = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2015 OneNoteDev
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.OneNoteApi = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
224
/*--------------------------------------------------------------------------
325
Definitions of the supported ContentTypes.
426
-------------------------------------------------------------------------*/

target/oneNoteApi.min.js

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)