Skip to content

Commit f26b334

Browse files
committed
added and adapted scraper from readable-stream
1 parent 0211f3a commit f26b334

File tree

6 files changed

+144
-0
lines changed

6 files changed

+144
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

build/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

build/build.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env node
2+
3+
const hyperquest = require('hyperzip')(require('hyperdirect'))
4+
, bl = require('bl')
5+
, fs = require('fs')
6+
, path = require('path')
7+
, cheerio = require('cheerio')
8+
9+
, files = require('./files')
10+
, testReplace = require('./test-replacements')
11+
12+
, srcurlpfx = 'https://raw.github.com/joyent/node/v' + process.argv[2] + '-release/'
13+
, libsrcurl = srcurlpfx + 'lib/'
14+
, testsrcurl = srcurlpfx + 'test/simple/'
15+
, testlisturl = 'https://github.com/joyent/node/tree/v' + process.argv[2] + '-release/test/simple'
16+
, libourroot = path.join(__dirname, '../')
17+
, testourroot = path.join(__dirname, '../test/simple/')
18+
19+
20+
function processFile (url, out, replacements) {
21+
hyperquest(url).pipe(bl(function (err, data) {
22+
if (err)
23+
throw err
24+
25+
data = data.toString()
26+
replacements.forEach(function (replacement) {
27+
data = data.replace.apply(data, replacement)
28+
})
29+
30+
fs.writeFile(out, data, 'utf8', function (err) {
31+
if (err)
32+
throw err
33+
34+
console.log('Wrote', out)
35+
})
36+
}))
37+
}
38+
39+
function processLibFile (file) {
40+
var replacements = files[file]
41+
, url = libsrcurl + file
42+
, out = path.join(libourroot, replacements.out || file)
43+
44+
processFile(url, out, replacements)
45+
}
46+
47+
48+
function processTestFile (file) {
49+
var replacements = testReplace.all
50+
, url = testsrcurl + file
51+
, out = path.join(testourroot, file)
52+
53+
if (testReplace[file])
54+
replacements = replacements.concat(testReplace[file])
55+
56+
processFile(url, out, replacements)
57+
}
58+
59+
60+
if (!/0\.1\d\.\d+/.test(process.argv[2])) {
61+
console.log('Usage: build.js <node version>')
62+
return process.exit(-1)
63+
}
64+
65+
66+
//--------------------------------------------------------------------
67+
// Grab & process files in ../lib/
68+
69+
Object.keys(files).forEach(processLibFile)
70+
71+
//--------------------------------------------------------------------
72+
// Discover, grab and process all test-string-decoder* files on joyent/node
73+
74+
hyperquest(testlisturl).pipe(bl(function (err, data) {
75+
if (err)
76+
throw err
77+
78+
var $ = cheerio.load(data.toString())
79+
80+
$('table.files .js-directory-link').each(function () {
81+
var file = $(this).text()
82+
if (/^test-string-decoder/.test(file) || file == 'common.js')
83+
processTestFile(file)
84+
})
85+
}))
86+
87+
//--------------------------------------------------------------------
88+
// Grab the joyent/node test/common.js
89+
90+
processFile(
91+
testsrcurl + '../common.js'
92+
, path.join(testourroot, '../common.js')
93+
, testReplace['common.js']
94+
)

build/files.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* This file lists the files to be fetched from the node repo
2+
* in the /lib/ directory which will be placed in the ../lib/
3+
* directory after having each of the "replacements" in the
4+
* array for that file applied to it. The replacements are
5+
* simply the arguments to String#replace, so they can be
6+
* strings, regexes, functions.
7+
*/
8+
9+
module.exports['string_decoder.js'] = [
10+
]
11+
12+
module.exports['string_decoder.js'].out = 'index.js'

build/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "string_decoder-build",
3+
"version": "0.0.0",
4+
"description": "",
5+
"main": "build.js",
6+
"dependencies": {
7+
"bl": "~0.6.0",
8+
"hyperzip": "0.0.0",
9+
"hyperdirect": "0.0.0",
10+
"cheerio": "~0.13.1"
11+
}
12+
}

build/test-replacements.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports.all = [
2+
[
3+
/require\(['"]string_decoder['"]\)/g
4+
, 'require(\'../../\')'
5+
]
6+
7+
]
8+
9+
module.exports['common.js'] = [
10+
[
11+
/^ setImmediate,$/m
12+
, ' typeof setImmediate == \'undefined\' ? null : setImmediate,'
13+
]
14+
15+
, [
16+
/^ clearImmediate,$/m
17+
, ' typeof clearImmediate == \'undefined\' ? null : clearImmediate,'
18+
]
19+
20+
, [
21+
/^ global];$/m
22+
, ' global].filter(Boolean);'
23+
]
24+
]

0 commit comments

Comments
 (0)