11#!/usr/bin/env node
22
3- const hyperquest = require ( 'hyperzip' ) ( require ( 'hyperdirect' ) )
3+ const hyperquest = require ( 'hyperquest' )
44 , bl = require ( 'bl' )
55 , fs = require ( 'fs' )
66 , path = require ( 'path' )
7- , cheerio = require ( 'cheerio' )
7+ , tar = require ( 'tar-fs' )
8+ , gunzip = require ( 'gunzip-maybe' )
89 , babel = require ( 'babel-core' )
10+ , glob = require ( 'glob' )
11+ , pump = require ( 'pump' )
12+ , rimraf = require ( 'rimraf' )
913 , encoding = 'utf8'
10- , urlRegex = / ^ h t t p s ? : \/ \/ /
14+ , urlRegex = / ^ h t t p s ? : \/ \/ /
1115 , nodeVersion = process . argv [ 2 ]
1216 , nodeVersionRegexString = '\\d+\\.\\d+\\.\\d+'
1317 , usageVersionRegex = RegExp ( '^' + nodeVersionRegexString + '$' )
@@ -18,10 +22,10 @@ const hyperquest = require('hyperzip')(require('hyperdirect'))
1822 , files = require ( './files' )
1923 , testReplace = require ( './test-replacements' )
2024
21- , srcurlpfx = `https://raw.githubusercontent.com/nodejs/node/ v${ nodeVersion } /`
22- , libsrcurl = srcurlpfx + 'lib/'
23- , testsrcurl = srcurlpfx + 'test/parallel/'
24- , testlisturl = `https://github.com/nodejs/node/tree/v ${ nodeVersion } / test/parallel`
25+ , downloadurl = `https://nodejs.org/dist/ v${ nodeVersion } /node-v ${ nodeVersion } .tar.gz `
26+ , src = path . join ( __dirname , `node-v ${ nodeVersion } ` )
27+ , libsrcurl = path . join ( src , 'lib/' )
28+ , testsrcurl = path . join ( src , ' test/parallel/' )
2529 , libourroot = path . join ( __dirname , '../lib/' )
2630 , testourroot = path . join ( __dirname , '../test/parallel/' )
2731
@@ -33,16 +37,19 @@ if (!usageVersionRegex.test(nodeVersion)) {
3337
3438// `inputLoc`: URL or local path.
3539function processFile ( inputLoc , out , replacements ) {
36- var file = urlRegex . test ( inputLoc ) ?
37- hyperquest ( inputLoc ) :
38- fs . createReadStream ( inputLoc , encoding )
40+ var file = fs . createReadStream ( inputLoc , encoding )
3941
4042 file . pipe ( bl ( function ( err , data ) {
4143 if ( err ) throw err
4244
45+ console . log ( 'Processing' , inputLoc )
4346 data = data . toString ( )
4447 replacements . forEach ( function ( replacement ) {
45- data = data . replace . apply ( data , replacement )
48+ const regexp = replacement [ 0 ]
49+ var arg2 = replacement [ 1 ]
50+ if ( typeof arg2 === 'function' )
51+ arg2 = arg2 . bind ( data )
52+ data = data . replace ( regexp , arg2 )
4653 } )
4754 if ( inputLoc . slice ( - 3 ) === '.js' ) {
4855 const transformed = babel . transform ( data , {
@@ -69,7 +76,7 @@ function deleteOldTests(){
6976 const files = fs . readdirSync ( path . join ( __dirname , '..' , 'test' , 'parallel' ) ) ;
7077 for ( let file of files ) {
7178 let name = path . join ( __dirname , '..' , 'test' , 'parallel' , file ) ;
72- console . log ( 'removing ' , name ) ;
79+ console . log ( 'Removing ' , name ) ;
7380 fs . unlinkSync ( name ) ;
7481 }
7582}
@@ -94,43 +101,73 @@ function processTestFile (file) {
94101}
95102
96103//--------------------------------------------------------------------
97- // Grab & process files in ../lib/
104+ // Download the release from nodejs.org
105+ console . log ( `Downloading ${ downloadurl } ` )
106+ pump (
107+ hyperquest ( downloadurl ) ,
108+ gunzip ( ) ,
109+ tar . extract ( __dirname ) ,
110+ function ( err ) {
111+ if ( err ) {
112+ throw err
113+ }
98114
99- Object . keys ( files ) . forEach ( processLibFile )
100115
101- // delete the current contents of test/parallel so if node removes any tests
102- // they are removed here
103- deleteOldTests ( ) ;
116+ //--------------------------------------------------------------------
117+ // Grab & process files in ../lib/
104118
105- //--------------------------------------------------------------------
106- // Discover, grab and process all test-stream* files on nodejs/node
119+ Object . keys ( files ) . forEach ( processLibFile )
107120
108- hyperquest ( testlisturl ) . pipe ( bl ( function ( err , data ) {
109- if ( err )
110- throw err
111121
112- var $ = cheerio . load ( data . toString ( ) )
122+ //--------------------------------------------------------------------
123+ // Discover, grab and process all test-stream* files on the given release
113124
114- $ ( 'table.files .js-navigation-open' ) . each ( function ( ) {
115- var file = $ ( this ) . text ( )
116- if ( / ^ t e s t - s t r e a m / . test ( file ) && ! / - w r a p (?: - e n c o d i n g ) ? \. j s $ / . test ( file ) && file !== 'test-stream2-httpclient-response-end.js' && file !== 'test-stream-base-no-abort.js' && file !== 'test-stream-preprocess.js' && file !== 'test-stream-inheritance.js' )
117- processTestFile ( file )
118- } )
119- } ) )
125+ glob ( path . join ( testsrcurl , 'test-stream*.js' ) , function ( err , list ) {
126+ if ( err ) {
127+ throw err
128+ }
120129
130+ list . forEach ( function ( file ) {
131+ file = path . basename ( file )
132+ if ( ! / - w r a p (?: - e n c o d i n g ) ? \. j s $ / . test ( file ) &&
133+ file !== 'test-stream2-httpclient-response-end.js' &&
134+ file !== 'test-stream-base-no-abort.js' &&
135+ file !== 'test-stream-preprocess.js' &&
136+ file !== 'test-stream-inheritance.js' ) {
137+ processTestFile ( file )
138+ }
139+ } )
140+ } )
121141
122- //--------------------------------------------------------------------
123- // Grab the nodejs/node test/common.js
124142
125- processFile (
126- testsrcurl . replace ( / p a r a l l e l \/ $ / , 'common.js' )
127- , path . join ( testourroot , '../common.js' )
128- , testReplace [ 'common.js' ]
143+ //--------------------------------------------------------------------
144+ // Grab the nodejs/node test/common.js
145+
146+ processFile (
147+ testsrcurl . replace ( / p a r a l l e l \/ $ / , 'common.js' )
148+ , path . join ( testourroot , '../common.js' )
149+ , testReplace [ 'common.js' ]
150+ )
151+
152+ //--------------------------------------------------------------------
153+ // Update Node version in README
154+
155+ processFile ( readmePath , readmePath , [
156+ [ readmeVersionRegex , "$1" + nodeVersion ]
157+ ] )
158+ }
129159)
130160
131- //--------------------------------------------------------------------
132- // Update Node version in README
161+ // delete the current contents of test/parallel so if node removes any tests
162+ // they are removed here
163+ deleteOldTests ( ) ;
133164
134- processFile ( readmePath , readmePath , [
135- [ readmeVersionRegex , "$1" + nodeVersion ]
136- ] )
165+ process . once ( 'beforeExit' , function ( ) {
166+ rimraf ( src , function ( err ) {
167+ if ( err ) {
168+ throw err
169+ }
170+
171+ console . log ( 'Removed' , src )
172+ } )
173+ } )
0 commit comments