diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/components/microformats/update | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/microformats/update')
-rw-r--r-- | toolkit/components/microformats/update/package.json | 21 | ||||
-rw-r--r-- | toolkit/components/microformats/update/readme.txt | 33 | ||||
-rw-r--r-- | toolkit/components/microformats/update/update.js | 266 |
3 files changed, 320 insertions, 0 deletions
diff --git a/toolkit/components/microformats/update/package.json b/toolkit/components/microformats/update/package.json new file mode 100644 index 000000000..8f829439f --- /dev/null +++ b/toolkit/components/microformats/update/package.json @@ -0,0 +1,21 @@ +{ + "author": "Glenn Jones", + "name": "microformat-shiv-updater", + "description": "A script for updating microformat-shiv in mozilla-central from source repo", + "version": "1.0.0", + "license": "MIT", + "homepage": "http://microformat-shiv.com", + "repository": { + "type": "git", + "url": "git://github.com/glennjones/microformat-shiv-updater.git" + }, + "main": "update.js", + "scripts": { + "start": "update" + }, + "dependencies": { + "download-github-repo": "0.1.x", + "fs-extra": "0.19.x", + "request": "2.58.x" + } +}
\ No newline at end of file diff --git a/toolkit/components/microformats/update/readme.txt b/toolkit/components/microformats/update/readme.txt new file mode 100644 index 000000000..0e41447a8 --- /dev/null +++ b/toolkit/components/microformats/update/readme.txt @@ -0,0 +1,33 @@ +/*! + update.js + + This node.js script downloads latest version of microformat-shiv and it tests form the authors github repo. + + Make sure your have an uptodate copy of node.js on your machine then using a command line navigate the + directory containing the update.js and run the following commands: + + $ npm install + $ node unpdate.js + + The script will + + 1. Checks the current build status of the project. + 2. Checks the date of the last commit + 3. Downloads and updates the following directories and files: + * microformat-shiv.js + * test/lib + * test/interface-tests + * test/module-tests + * test/standards-tests + * test/static + 4. Adds the EXPORTED_SYMBOLS to the bottom of microformat-shiv.js + 5. Repath the links in test/module-tests/index.html file + + + This will update the microformats parser and all the related tests. + + + + Copyright (C) 2015 Glenn Jones. All Rights Reserved. + MIT License: https://raw.github.com/glennjones/microformat-shiv/master/license.txt + */
\ No newline at end of file diff --git a/toolkit/components/microformats/update/update.js b/toolkit/components/microformats/update/update.js new file mode 100644 index 000000000..80795d523 --- /dev/null +++ b/toolkit/components/microformats/update/update.js @@ -0,0 +1,266 @@ +/* ! + update.js + + run $ npm install + run $ node unpdate.js + + Downloads latest version of microformat-shiv and it tests form github repo + Files downloaded: + * microformat-shiv.js (note: modern version) + * lib + * test/interface-tests + * test/module-tests + * test/standards-tests + * test/static + + Copyright (C) 2015 Glenn Jones. All Rights Reserved. + MIT License: https://raw.github.com/glennjones/microformat-shiv/master/license.txt + */ + +// configuration +var deployDir = '../' + exportedSymbol = 'try {\n // mozilla jsm support\n Components.utils.importGlobalProperties(["URL"]);\n} catch(e) {}\nthis.EXPORTED_SYMBOLS = [\'Microformats\'];'; + + + +var path = require('path'), + request = require('request'), + fs = require('fs-extra'), + download = require('download-github-repo'); + + +var repo = 'glennjones/microformat-shiv', + tempDir = path.resolve(__dirname, 'temp-repo'), + deployDirResolved = path.resolve(__dirname, deployDir), + pathList = [ + ['/modern/microformat-shiv-modern.js', '/microformat-shiv.js'], + ['/lib', '/test/lib'], + ['/test/interface-tests', '/test/interface-tests'], + ['/test/module-tests', '/test/module-tests'], + ['/test/standards-tests', '/test/standards-tests'], + ['/test/static', '/test/static'] + ]; + + + +getLastBuildState( repo, function( err, buildState) { + if (buildState) { + console.log('last build state:', buildState); + + if (buildState === 'passed') { + + console.log('downloading git repo', repo); + getLastCommitDate( repo, function( err, date) { + if (date) { + console.log( 'last commit:', new Date(date).toString() ); + } + }); + updateFromRepo(); + + } else { + console.log('not updating because of build state is failing please contact Glenn Jones glennjones@gmail.com'); + } + + } else { + console.log('could not get build state from travis-ci:', err); + } +}); + + +/** + * updates from directories and files from repo + * + */ +function updateFromRepo() { + download(repo, tempDir, function(err, data) { + + // the err and data from download-github-repo give false negatives + if ( fs.existsSync( tempDir ) ) { + + var version = getRepoVersion(); + removeCurrentFiles( pathList, deployDirResolved ); + addNewFiles( pathList, deployDirResolved ); + fs.removeSync(tempDir); + + // changes files for firefox + replaceInFile('/test/module-tests/index.html', /..\/..\/lib\//g, '../lib/' ); + addExportedSymbol( '/microformat-shiv.js' ); + + console.log('microformat-shiv is now uptodate to v' + version); + + } else { + console.log('error getting repo', err); + } + + }); +} + + +/** + * removes old version of delpoyed directories and files + * + * @param {Array} pathList + * @param {String} deployDirResolved + */ +function removeCurrentFiles( pathList, deployDirResolved ) { + pathList.forEach( function( path ) { + console.log('removed:', deployDirResolved + path[1]); + fs.removeSync(deployDirResolved + path[1]); + }); +} + + +/** + * copies over required directories and files into deployed path + * + * @param {Array} pathList + * @param {String} deployDirResolved + */ +function addNewFiles( pathList, deployDirResolved ) { + pathList.forEach( function( path ) { + console.log('added:', deployDirResolved + path[1]); + fs.copySync(tempDir + path[0], deployDirResolved + path[1]); + }); + +} + + +/** + * gets the repo version number + * + * @return {String} + */ +function getRepoVersion() { + var pack = fs.readFileSync(path.resolve(tempDir, 'package.json'), {encoding: 'utf8'}); + if (pack) { + pack = JSON.parse(pack) + if (pack && pack.version) { + return pack.version; + } + } + return ''; +} + + +/** + * get the last commit date from github repo + * + * @param {String} repo + * @param {Function} callback + */ +function getLastCommitDate( repo, callback ) { + + var options = { + url: 'https://api.github.com/repos/' + repo + '/commits?per_page=1', + headers: { + 'User-Agent': 'request' + } + }; + + request(options, function (error, response, body) { + if (!error && response.statusCode == 200) { + var date = null, + json = JSON.parse(body); + if (json && json.length && json[0].commit && json[0].commit.author ) { + date = json[0].commit.author.date; + } + callback(null, date); + } else { + console.log(error, response, body); + callback('fail to get last commit date', null); + } + }); +} + + +/** + * get the last build state from travis-ci + * + * @param {String} repo + * @param {Function} callback + */ +function getLastBuildState( repo, callback ) { + + var options = { + url: 'https://api.travis-ci.org/repos/' + repo, + headers: { + 'User-Agent': 'request', + 'Accept': 'application/vnd.travis-ci.2+json' + } + }; + + request(options, function (error, response, body) { + if (!error && response.statusCode == 200) { + var buildState = null, + json = JSON.parse(body); + if (json && json.repo && json.repo.last_build_state ) { + buildState = json.repo.last_build_state; + } + callback(null, buildState); + } else { + console.log(error, response, body); + callback('fail to get last build state', null); + } + }); +} + + +/** + * adds exported symbol to microformat-shiv.js file + * + * @param {String} path + * @param {String} content + */ +function addExportedSymbol( path ) { + if (path === '/microformat-shiv.js') { + fs.appendFileSync(deployDirResolved + '/microformat-shiv.js', '\r\n' + exportedSymbol + '\r\n'); + console.log('appended exported symbol to microformat-shiv.js'); + } +} + + +/** + * adds exported symbol to microformat-shiv.js file + * + * @param {String} path + * @param {String} content + */ +function replaceInFile( path, findStr, replaceStr ) { + readFile(deployDirResolved + path, function(err, fileStr) { + if (fileStr) { + fileStr = fileStr.replace(findStr, replaceStr) + writeFile(deployDirResolved + path, fileStr); + console.log('replaced ' + findStr + ' with ' + replaceStr + ' in ' + path); + } else { + console.log('error replaced strings in ' + path); + } + }) +} + + +/** + * write a file + * + * @param {String} path + * @param {String} content + */ +function writeFile(path, content) { + fs.writeFile(path, content, 'utf8', function(err) { + if (err) { + console.log(err); + } else { + console.log('The file: ' + path + ' was saved'); + } + }); +} + + +/** + * read a file + * + * @param {String} path + * @param {Function} callback + */ +function readFile(path, callback) { + fs.readFile(path, 'utf8', callback); +} |