-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an interactive update system (#84)
* Document update system. * Add a postinstall script which calls ./bin/update.js. * Remove dependency on request and async and rewrite the updater script Also, bundle punycode as a dependency * Test update command during Continuous Integration tests.
- Loading branch information
Thomas Parisot
committed
Sep 13, 2016
1 parent
6d8eeb3
commit a34f354
Showing
7 changed files
with
69 additions
and
44 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
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,19 @@ | ||
#!/usr/bin/env node | ||
|
||
var updater = require('./update.js'); | ||
var SHOULD_UPDATE = process.env.npm_config_tldjs_update_rules === 'true'; | ||
|
||
|
||
if (SHOULD_UPDATE) { | ||
console.log('tldjs: updating rules from %s.', updater.providerUrl); | ||
|
||
updater.run(function(err){ | ||
if (err) { | ||
console.error(err.message); | ||
process.exit(err.code); | ||
} | ||
|
||
console.log('tldjs: rules list updated.'); | ||
process.exit(0); | ||
}); | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,40 +1,48 @@ | ||
"use strict"; | ||
|
||
var join = require('path').join; | ||
var request = require('request'); | ||
var async = require('async'); | ||
var http = require('https'); | ||
var fs = require('fs'); | ||
|
||
var pkg = require('../package.json'); | ||
|
||
var providerUrl = pkg.tldjs.providers['publicsuffix-org']; | ||
var parser = require('./parsers/publicsuffix-org.js'); | ||
var exportTask = require('./exports/standard-json.js'); | ||
|
||
module.exports = { | ||
providerUrl: providerUrl, | ||
run: function runUpdater(done){ | ||
done = typeof done === 'function' ? done : function(){}; | ||
|
||
request.get(providerUrl, function (err, response, body) { | ||
var queue, tlds; | ||
var req = http.request(providerUrl, function (res) { | ||
var body = ''; | ||
|
||
if (err) { | ||
throw new Error(err); | ||
if (res.statusCode !== 200) { | ||
res.destroy(); | ||
return done(new Error('tldjs: remote server responded with HTTP status ' + res.statusCode)); | ||
} | ||
|
||
tlds = parser.parse(body); | ||
queue = async.queue(function(exportTask, callback){ | ||
res.setEncoding('utf8'); | ||
|
||
res.on('data', function(d) { | ||
body += d; | ||
}); | ||
|
||
res.on('end', function() { | ||
var tlds = parser.parse(body); | ||
var task_result = exportTask(tlds); | ||
var filename = task_result[0]; | ||
var data = task_result[1]; | ||
|
||
data = JSON.stringify(data); | ||
|
||
fs.writeFile(join(__dirname, '..', filename), data, 'utf-8', callback); | ||
}, 5); | ||
|
||
queue.drain = done; | ||
|
||
queue.push(require(join(__dirname, 'exports', 'index.js'))); | ||
fs.writeFile(join(__dirname, '..', filename), data, 'utf-8', done); | ||
}); | ||
}); | ||
|
||
req.setTimeout(5000); | ||
req.on('error', done); | ||
req.end(); | ||
} | ||
}; |
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