├── .nvmrc ├── .gitignore ├── .prettierignore ├── index.js ├── .travis.yml ├── sizereport.config.js ├── prettier.config.js ├── tsconfig.json ├── package.json ├── src ├── bin.ts ├── find-renamed.ts └── index.ts ├── README.md └── LICENSE /.nvmrc: -------------------------------------------------------------------------------- 1 | v11.13.0 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('build/index.js').default; 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | cache: npm 3 | script: npm run build 4 | after_success: node build/bin.js --config 5 | -------------------------------------------------------------------------------- /sizereport.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | repo: 'GoogleChromeLabs/travis-size-report', 3 | path: 'build/**/*', 4 | }; 5 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | printWidth: 100, 3 | proseWrap: 'never', 4 | singleQuote: true, 5 | trailingComma: 'all', 6 | }; 7 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "target": "esnext", 5 | "outDir": "build", 6 | "declaration": true, 7 | "module": "commonjs", 8 | "esModuleInterop": true, 9 | "lib": ["esnext"] 10 | }, 11 | "include": ["src/**/*"] 12 | } 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "travis-size-report", 3 | "version": "1.1.0", 4 | "description": "Compare files from one build to another", 5 | "main": "index.js", 6 | "bin": { 7 | "sizereport": "build/bin.js" 8 | }, 9 | "scripts": { 10 | "clean": "rm -rf build", 11 | "build": "npm run clean && tsc", 12 | "watch": "npm run clean && tsc --watch" 13 | }, 14 | "husky": { 15 | "hooks": { 16 | "pre-commit": "pretty-quick --staged" 17 | } 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/GoogleChromeLabs/travis-size-report.git" 22 | }, 23 | "author": "Jake Archibald", 24 | "license": "Apache-2.0", 25 | "bugs": { 26 | "url": "https://github.com/GoogleChromeLabs/travis-size-report/issues" 27 | }, 28 | "homepage": "https://github.com/GoogleChromeLabs/travis-size-report#readme", 29 | "dependencies": { 30 | "chalk": "^2.4.2", 31 | "escape-string-regexp": "^2.0.0", 32 | "glob": "^7.1.3", 33 | "gzip-size": "^5.1.0", 34 | "minimist": "^1.2.0", 35 | "node-fetch": "^2.3.0", 36 | "pretty-bytes": "^5.1.0", 37 | "typescript": "^3.4.4" 38 | }, 39 | "devDependencies": { 40 | "@types/glob": "^7.1.1", 41 | "@types/minimist": "^1.2.0", 42 | "@types/node-fetch": "^2.3.2", 43 | "@types/pretty-bytes": "^5.1.0", 44 | "husky": "^1.3.1", 45 | "prettier": "^1.17.0", 46 | "pretty-quick": "^1.10.0" 47 | }, 48 | "files": [ 49 | "build", 50 | "README.md" 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /src/bin.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import path from 'path'; 3 | import minimist from 'minimist'; 4 | import sizeReport, { SizeReportOptions } from '.'; 5 | 6 | const argv = minimist(process.argv.slice(2), { 7 | string: ['branch'], 8 | alias: { c: 'config' }, 9 | }); 10 | 11 | // Read arguments from command line 12 | const branch = argv.branch as string; 13 | const configFile = argv.config as string | boolean; 14 | const repo = argv._[0] as string | undefined; 15 | const glob = argv._[1] as string | undefined; 16 | 17 | /** 18 | * Configuration file for travis-size-report. 19 | * This is typically `sizereport.config.js`. 20 | */ 21 | export interface Config { 22 | /** 23 | * The username/repo-name 24 | * @example 25 | * repo: "GoogleChromeLabs/travis-size-report" 26 | */ 27 | repo: string; 28 | /** 29 | * The glob (or array of globs) of files to include in the report. 30 | * @example 31 | * path: 'dist/*' 32 | */ 33 | path: string | readonly string[]; 34 | /** 35 | * The branch to check against. 36 | * @default 'master' 37 | * @example 38 | * branch: 'develop' 39 | */ 40 | branch?: string; 41 | /** 42 | * By default, a renamed file will look like one file deleted and another created. 43 | * By writing a findRenamed callback, you can tell travis-size-report that a file was renamed. 44 | */ 45 | findRenamed?: string | import('./find-renamed').FindRenamed; 46 | } 47 | 48 | let config: Partial = {}; 49 | 50 | // Read arguments from config file 51 | if (configFile) { 52 | config = require(path.join( 53 | process.cwd(), 54 | configFile === true ? 'sizereport.config.js' : configFile, 55 | )); 56 | } 57 | 58 | // Override config file with command line arguments 59 | if (repo) config.repo = repo; 60 | if (glob) config.path = glob; 61 | if (branch) config.branch = branch; 62 | 63 | if (!config.repo) throw TypeError('No repo given'); 64 | if (!config.path) throw TypeError('No path given'); 65 | if (!config.repo.includes('/')) throw TypeError("Repo doesn't look like repo value"); 66 | 67 | const [user, repoName] = config.repo.split('/'); 68 | const opts: SizeReportOptions = {}; 69 | if (config.branch) opts.branch = config.branch; 70 | if (config.findRenamed) opts.findRenamed = config.findRenamed; 71 | 72 | sizeReport(user, repoName, config.path, opts); 73 | -------------------------------------------------------------------------------- /src/find-renamed.ts: -------------------------------------------------------------------------------- 1 | import escapeRE from 'escape-string-regexp'; 2 | 3 | export type FindRenamed = ( 4 | /** Path of a file that's missing in the latest build */ 5 | filePath: string, 6 | /** Paths of files that are new in the latest build */ 7 | newFiles: string[], 8 | ) => string | undefined | PromiseLike; 9 | 10 | const PLACEHOLDER_REGEX = /\\\[(\w+)\\\]/g; 11 | const REPLACEMENTS = { 12 | extname: '(\\.\\w+)', 13 | hash: '[a-f0-9]+', 14 | name: '(.+)', 15 | }; 16 | type Placeholder = keyof typeof REPLACEMENTS; 17 | 18 | /** 19 | * Name doesn't start with "./", "/", "../" 20 | */ 21 | function isPlainName(name: string) { 22 | return !( 23 | name[0] === '/' || 24 | (name[1] === '.' && (name[2] === '/' || (name[2] === '.' && name[3] === '/'))) 25 | ); 26 | } 27 | 28 | /** 29 | * Creates a findRenamed function based on the given `pattern`. 30 | * 31 | * Patterns support the following placeholders: 32 | * - `[extname]`: The file extension of the asset including a leading dot, e.g. `.css` 33 | * - `[hash]`: A hash based on the name and content of the asset. 34 | * - `[name]`: The file name of the asset excluding any extension. 35 | */ 36 | export function buildFindRenamedFunc(pattern: string): FindRenamed { 37 | if (!isPlainName(pattern)) { 38 | throw new TypeError( 39 | `Invalid output pattern "${pattern}, cannot be an absolute or relative path.`, 40 | ); 41 | } 42 | 43 | // Keep track of which placeholder each regex group corresponds to. 44 | let i = 1; 45 | const groups: Placeholder[] = []; 46 | 47 | // Create a regex to extract parts of the path. 48 | const parts = escapeRE(pattern).replace(PLACEHOLDER_REGEX, (_match, type) => { 49 | const replacement = REPLACEMENTS[type as Placeholder]; 50 | if (replacement == undefined) { 51 | throw new TypeError(`"${type}" is not a valid substitution name`); 52 | } 53 | groups[i] = type; 54 | i++; 55 | return replacement; 56 | }); 57 | const partsRe = new RegExp(`^${parts}$`); 58 | 59 | return function generatedFindRenamed(path, newPaths) { 60 | const oldParts = partsRe.exec(path); 61 | if (!oldParts) return undefined; 62 | 63 | return newPaths.find(newPath => { 64 | const newParts = partsRe.exec(newPath); 65 | if (!newParts || newParts.length !== oldParts.length) return false; 66 | for (let i = 1; i < oldParts.length; i++) { 67 | if (oldParts[i] !== newParts[i] && groups[i] !== 'hash') return false; 68 | } 69 | return true; 70 | }); 71 | }; 72 | } 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Travis size report 2 | 3 | Let Travis tell you what changed compared to the last successful build on a particular branch. This helps you catch unexpected file renames and size changes. 4 | 5 | Screenshot 2019-04-05 at 15 55 13 6 | 7 | ## Installation 8 | 9 | ```sh 10 | npm install -D travis-size-report 11 | ``` 12 | 13 | Then, in `.travis.yml`: 14 | 15 | ```yml 16 | after_success: sizereport --config 17 | ``` 18 | 19 | ## Config 20 | 21 | ### Config file 22 | 23 | This is typically `sizereport.config.js`. 24 | 25 | ```js 26 | module.exports = { 27 | repo: 'GoogleChromeLabs/travis-size-report', 28 | path: 'dist/**/*', 29 | branch: 'master', 30 | findRenamed: '[name]-[hash][extname]', 31 | }; 32 | ``` 33 | 34 | - `repo` (required) - The username/repo-name. 35 | - `path` (required) - The glob (or array of globs) of files to include in the report. 36 | - `branch` (optional, default: 'master') - The branch to check against. 37 | - `findRenamed` (optional) - See below 38 | 39 | #### `findRenamed` 40 | 41 | By default, a renamed file will look like one file deleted and another created. However, you can help travis-size-report identify this as a renamed file. 42 | 43 | `findRenamed` can be a string, or a callback. The string form can have the following placeholders: 44 | 45 | - `[name]` - Any character (`.+` in Regex). 46 | - `[hash]` - A typical version hash (`[a-f0-9]+` in Regex). 47 | - `[extname]` - The extension of the file (`\.\w+` in Regex). 48 | 49 | If you provide `'[name]-[hash][extname]'` as the value to `findRenamed`, it will consider `foo-a349fb.js` and `foo-cd6ef2.js` to be the same file, renamed. 50 | 51 | The callback form is `(oldPath, newPaths) => matchingNewPath`. 52 | 53 | - `oldPath` - A path that existed in the previous build, but doesn't exist in the new build. 54 | - `newPaths` - Paths that appear in the new build, but didn't appear in the previous build. 55 | 56 | Match up `oldPath` to one of the `newPaths` by returning the matching `newPath`. Or return undefined if `oldPath` was deleted rather than renamed. 57 | 58 | ### Command line 59 | 60 | ```sh 61 | sizereport [flags] repo path 62 | ``` 63 | 64 | Flags: 65 | 66 | - `--config` (or `-c`) - Path to the config file. If no path is provided, `./sizereport.config.js` is the default. 67 | - `--branch` - Same as `branch` in the config file. 68 | 69 | `repo` and `path` are the same as their equivalents in the config file. 70 | 71 | It's recommended to use the config file rather than use args. If both are used, the command line args take priority over values in the config file. 72 | 73 | ## Results 74 | 75 | Results appear at the end of your Travis log. They're folded away by default, so you'll need to click on the sizereport line to expand it. 76 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from 'util'; 2 | import { stat } from 'fs'; 3 | import { URL, URLSearchParams } from 'url'; 4 | 5 | import glob from 'glob'; 6 | import gzipSize from 'gzip-size'; 7 | import escapeRE from 'escape-string-regexp'; 8 | import fetch, { Response } from 'node-fetch'; 9 | import chalk from 'chalk'; 10 | import prettyBytes from 'pretty-bytes'; 11 | import { buildFindRenamedFunc, FindRenamed } from './find-renamed'; 12 | 13 | const globP = promisify(glob); 14 | const statP = promisify(stat); 15 | // Travis reports it doesn't support colour. IT IS WRONG. 16 | const alwaysChalk = new chalk.constructor({ level: 4 }); 17 | 18 | interface FileData { 19 | path: string; 20 | size: number; 21 | gzipSize: number; 22 | } 23 | 24 | const buildSizePrefix = '=== BUILD SIZES: '; 25 | const buildSizePrefixRe = new RegExp(`^${escapeRE(buildSizePrefix)}(.+)$`, 'm'); 26 | 27 | /** 28 | * Recursively-read a directory and turn it into an array of FileDatas 29 | */ 30 | function pathsToInfoArray(paths: string[]): Promise { 31 | return Promise.all( 32 | paths.map(async path => { 33 | const gzipSizePromise = gzipSize.file(path); 34 | const statSizePromise = statP(path).then(s => s.size); 35 | 36 | return { 37 | path, 38 | size: await statSizePromise, 39 | gzipSize: await gzipSizePromise, 40 | }; 41 | }), 42 | ); 43 | } 44 | 45 | function fetchTravis( 46 | path: string, 47 | searchParams: { [propName: string]: string } = {}, 48 | ): Promise { 49 | const url = new URL(path, 'https://api.travis-ci.org'); 50 | url.search = new URLSearchParams(searchParams).toString(); 51 | 52 | return fetch(url.href, { 53 | headers: { 'Travis-API-Version': '3' }, 54 | }); 55 | } 56 | 57 | function fetchTravisBuildInfo(user: string, repo: string, branch: string) { 58 | return fetchTravis(`/repo/${encodeURIComponent(`${user}/${repo}`)}/builds`, { 59 | 'branch.name': branch, 60 | state: 'passed', 61 | limit: '1', 62 | event_type: 'push', 63 | }).then(r => r.json()); 64 | } 65 | 66 | function fetchTravisText(path: string): Promise { 67 | return fetchTravis(path).then(r => r.text()); 68 | } 69 | 70 | /** 71 | * Scrape Travis for the previous build info. 72 | */ 73 | async function getPreviousBuildInfo( 74 | user: string, 75 | repo: string, 76 | branch: string, 77 | ): Promise { 78 | const buildData = await fetchTravisBuildInfo(user, repo, branch); 79 | const jobUrl = buildData.builds[0].jobs[0]['@href']; 80 | const log = await fetchTravisText(jobUrl + '/log.txt'); 81 | const reResult = buildSizePrefixRe.exec(log); 82 | 83 | if (!reResult) return; 84 | return JSON.parse(reResult[1]); 85 | } 86 | 87 | interface BuildChanges { 88 | deletedItems: FileData[]; 89 | newItems: FileData[]; 90 | changedItems: Map; 91 | } 92 | 93 | /** 94 | * Generate an array that represents the difference between builds. 95 | * Returns an array of { beforeName, afterName, beforeSize, afterSize }. 96 | * Sizes are gzipped size. 97 | * Before/after properties are missing if resource isn't in the previous/new build. 98 | */ 99 | async function getChanges( 100 | previousBuildInfo: FileData[], 101 | buildInfo: FileData[], 102 | findRenamed?: FindRenamed, 103 | ): Promise { 104 | const deletedItems: FileData[] = []; 105 | const changedItems = new Map(); 106 | const matchedNewEntries = new Set(); 107 | 108 | for (const oldEntry of previousBuildInfo) { 109 | const newEntry = buildInfo.find(entry => entry.path === oldEntry.path); 110 | if (!newEntry) { 111 | deletedItems.push(oldEntry); 112 | continue; 113 | } 114 | 115 | matchedNewEntries.add(newEntry); 116 | if (oldEntry.gzipSize !== newEntry.gzipSize) { 117 | changedItems.set(oldEntry, newEntry); 118 | } 119 | } 120 | 121 | const newItems: FileData[] = []; 122 | 123 | // Look for entries that are only in the new build. 124 | for (const newEntry of buildInfo) { 125 | if (matchedNewEntries.has(newEntry)) continue; 126 | newItems.push(newEntry); 127 | } 128 | 129 | // Figure out renamed files. 130 | if (findRenamed) { 131 | const originalDeletedItems = deletedItems.slice(); 132 | const newPaths = newItems.map(i => i.path); 133 | 134 | for (const deletedItem of originalDeletedItems) { 135 | const result = await findRenamed(deletedItem.path, newPaths); 136 | if (!result) continue; 137 | if (!newPaths.includes(result)) { 138 | throw Error(`findRenamed: File isn't part of the new build: ${result}`); 139 | } 140 | 141 | // Remove items from newPaths, deletedItems and newItems. 142 | // Add them to mappedItems. 143 | newPaths.splice(newPaths.indexOf(result), 1); 144 | deletedItems.splice(deletedItems.indexOf(deletedItem), 1); 145 | 146 | const newItemIndex = newItems.findIndex(i => i.path === result); 147 | changedItems.set(deletedItem, newItems[newItemIndex]); 148 | newItems.splice(newItemIndex, 1); 149 | } 150 | } 151 | 152 | return { newItems, deletedItems, changedItems }; 153 | } 154 | 155 | function outputChanges(changes: BuildChanges) { 156 | // One letter references, so it's easier to get the spacing right. 157 | const y = alwaysChalk.yellow; 158 | const g = alwaysChalk.green; 159 | const r = alwaysChalk.red; 160 | 161 | if ( 162 | changes.newItems.length === 0 && 163 | changes.deletedItems.length === 0 && 164 | changes.changedItems.size === 0 165 | ) { 166 | console.log(` No changes.`); 167 | } 168 | 169 | for (const file of changes.newItems) { 170 | console.log(` ${g('ADDED')} ${file.path} - ${prettyBytes(file.gzipSize)}`); 171 | } 172 | 173 | for (const file of changes.deletedItems) { 174 | console.log(` ${r('REMOVED')} ${file.path} - was ${prettyBytes(file.gzipSize)}`); 175 | } 176 | 177 | for (const [oldFile, newFile] of changes.changedItems.entries()) { 178 | // Changed file. 179 | let size; 180 | 181 | if (oldFile.gzipSize === newFile.gzipSize) { 182 | // Just renamed. 183 | size = `${prettyBytes(newFile.gzipSize)} -> no change`; 184 | } else { 185 | const color = newFile.gzipSize > oldFile.gzipSize ? r : g; 186 | const sizeDiff = prettyBytes(newFile.gzipSize - oldFile.gzipSize, { signed: true }); 187 | const relativeDiff = Math.round((newFile.gzipSize / oldFile.gzipSize) * 1000) / 1000; 188 | 189 | size = 190 | `${prettyBytes(oldFile.gzipSize)} -> ${prettyBytes(newFile.gzipSize)}` + 191 | ' (' + 192 | color(`${sizeDiff}, ${relativeDiff}x`) + 193 | ')'; 194 | } 195 | 196 | console.log(` ${y('CHANGED')} ${newFile.path} - ${size}`); 197 | 198 | if (oldFile.path !== newFile.path) { 199 | console.log(` Renamed from: ${oldFile.path}`); 200 | } 201 | } 202 | } 203 | 204 | export interface SizeReportOptions { 205 | /** Branch to compare to. Defaults to 'master' */ 206 | branch?: string; 207 | /** 208 | * Join together a missing file and a new file which should be considered the same (as in, 209 | * renamed). 210 | * 211 | * Return nothing to indicate `filePath` has been removed from the new build, or return one of the 212 | * strings in `newFiles` to treat it as a rename. 213 | * 214 | * This can be async, returning a promise for a string or undefined. 215 | */ 216 | findRenamed?: string | FindRenamed; 217 | } 218 | 219 | export default async function sizeReport( 220 | user: string, 221 | repo: string, 222 | files: string | readonly string[], 223 | { branch = 'master', findRenamed }: SizeReportOptions = {}, 224 | ): Promise { 225 | if (typeof files === 'string') files = [files]; 226 | if (typeof findRenamed === 'string') findRenamed = buildFindRenamedFunc(findRenamed); 227 | 228 | // Get target files 229 | const filePaths = []; 230 | 231 | for (const glob of files) { 232 | const matches = await globP(glob, { nodir: true }); 233 | filePaths.push(...matches); 234 | } 235 | 236 | const uniqueFilePaths = [...new Set(filePaths)]; 237 | 238 | // Output the current build sizes for later retrieval. 239 | const buildInfo = await pathsToInfoArray(uniqueFilePaths); 240 | console.log(buildSizePrefix + JSON.stringify(buildInfo)); 241 | 242 | console.log('\nBuild change report:'); 243 | 244 | let previousBuildInfo; 245 | 246 | try { 247 | previousBuildInfo = await getPreviousBuildInfo(user, repo, branch); 248 | } catch (err) { 249 | console.log(` Couldn't parse previous build info`); 250 | return; 251 | } 252 | 253 | if (!previousBuildInfo) { 254 | console.log(` Couldn't find previous build info`); 255 | return; 256 | } 257 | 258 | const buildChanges = await getChanges(previousBuildInfo, buildInfo, findRenamed); 259 | outputChanges(buildChanges); 260 | } 261 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------