@@ -24,48 +24,35 @@ const fs = require('fs')
2424const path = require ( 'path' )
2525const Handlebars = require ( 'handlebars' )
2626const request = require ( 'request' )
27- const changelogUrl = require ( 'changelog-url' )
28- const semver = require ( 'semver' )
2927
3028const downloads = require ( './helpers/downloads' )
3129
32- function sendRequest ( uri , method ) {
30+ function sendRequest ( opts ) {
3331 return new Promise ( ( resolve , reject ) => {
34- request ( {
35- headers : { 'User-Agent' : 'nodejs.org release blog post script' } ,
36- method : method ,
37- uri : uri
38- } , ( err , res , body ) => {
32+ const options = Object . assign ( {
33+ headers : { 'User-Agent' : 'nodejs.org release blog post script' }
34+ } , opts )
35+
36+ request ( options , ( err , res , body ) => {
3937 if ( err ) {
40- return reject ( new Error ( `Error requesting URL ${ uri } : ${ err . message } ` ) )
38+ return reject ( new Error ( `Error requesting URL ${ options . url } : ${ err . message } ` ) )
4139 }
4240 if ( res . statusCode !== 200 ) {
43- return reject ( new Error ( `Invalid status code (!= 200) while retrieving ${ uri } : ${ res . statusCode } ` ) )
41+ return reject ( new Error ( `Invalid status code (!= 200) while retrieving ${ options . url } : ${ res . statusCode } ` ) )
4442 }
4543
4644 resolve ( body )
4745 } )
4846 } )
4947}
5048
51- function download ( url ) {
52- return sendRequest ( url , 'GET' )
53- }
54-
5549function explicitVersion ( version ) {
5650 return version ? Promise . resolve ( version ) : Promise . reject ( )
5751}
5852
59- function isLegacyVersion ( version ) {
60- return semver . satisfies ( version , '< 1.0.0' )
61- }
62-
6353function findLatestVersion ( ) {
64- return download ( 'https://nodejs.org/dist/index.json' )
65- . then ( JSON . parse )
66- . then ( ( versions ) => {
67- return versions [ 0 ] . version . substr ( 1 )
68- } )
54+ return sendRequest ( { url : 'https://nodejs.org/dist/index.json' , json : true } )
55+ . then ( ( versions ) => versions [ 0 ] . version . substr ( 1 ) )
6956}
7057
7158function fetchDocs ( version ) {
@@ -88,68 +75,64 @@ function fetchDocs (version) {
8875 author,
8976 versionPolicy,
9077 shasums,
91- files}
78+ files
79+ }
9280 } )
9381}
9482
9583function fetchAuthor ( version ) {
9684 return fetchChangelog ( version )
9785 . then ( ( section ) => findAuthorLogin ( version , section ) )
98- . then ( ( author ) => download ( `https://api.github.com/users/${ author } ` ) )
99- . then ( JSON . parse )
86+ . then ( ( author ) => sendRequest ( {
87+ url : `https://api.github.com/users/${ author } ` ,
88+ json : true
89+ } ) )
10090 . then ( ( githubRes ) => githubRes . name )
10191}
10292
10393function fetchChangelog ( version ) {
104- // matches a complete release section,
105- // support release sections with headers like:
106- // ## 2015-09-22, Version 4.1.1 (Stable), @rvagg
107- // ## 2015-10-07, Version 4.2.0 'Argon' (LTS), @jasnell
108- // 2015-12-04, Version 0.12.9 (LTS), @rvagg
109- const rxSection = isLegacyVersion ( version )
110- ? new RegExp ( `\\d{4}-\\d{2}-\\d{2}, Version ${ version } \\([^\\)]+\\)[\\s\\S]*?(?=\\d{4}.\\d{2}.\\d{2})` )
111- : new RegExp ( `## \\d{4}-\\d{2}-\\d{2}, Version ${ version } ('\\w+' )?\\([^\\)]+\\)[\\s\\S]*?(?=## \\d{4})` )
112-
113- return download ( changelogUrl . rawUrl ( version ) )
114- . then ( ( data ) => {
115- const matches = rxSection . exec ( data )
116- return matches ? matches [ 0 ] : Promise . reject ( new Error ( `Couldn't find matching changelog for ${ version } ` ) )
117- } )
94+ const parts = version . split ( '.' )
95+ const releaseLine = parts [ 0 ] === '0'
96+ ? parts . slice ( 0 , 2 ) . join ( '' )
97+ : parts [ 0 ]
98+
99+ return sendRequest ( {
100+ url : `https://raw.githubusercontent.com/nodejs/node/master/doc/changelogs/CHANGELOG_V${ releaseLine } .md`
101+ } ) . then ( ( data ) => {
102+ // matches a complete release section
103+ const rxSection = new RegExp ( `<a id="${ version } "></a>\\n([\\s\\S]+?)(?:\\n<a id="|$)` )
104+ const matches = rxSection . exec ( data )
105+ return matches
106+ ? matches [ 1 ]
107+ : Promise . reject ( new Error ( `Couldn't find matching changelog for ${ version } ` ) )
108+ } )
118109}
119110
120111function fetchChangelogBody ( version ) {
121- const rxSectionBody = / ( # # # ) ? ( N o t a b l e [ \s \S ] * ) / g
122-
123- return fetchChangelog ( version )
124- . then ( ( section ) => {
125- const bodyMatch = rxSectionBody . exec ( section )
126- // ensure ### prefixed "Notable changes" header
127- // https://github.com/nodejs/nodejs.org/pull/551#issue-138257829
128- const body = bodyMatch ? `### ${ bodyMatch [ 2 ] } ` : ''
129-
130- return bodyMatch
131- ? body
132- : Promise . reject ( new Error ( `Could not find changelog body of ${ version } release` ) )
133- } )
112+ return fetchChangelog ( version ) . then ( ( section ) => {
113+ const rxSectionBody = / ( # # # N o t a b l e [ \s \S ] * ) /
114+ const matches = rxSectionBody . exec ( section )
115+ return matches
116+ ? matches [ 1 ]
117+ : Promise . reject ( new Error ( `Could not find changelog body of ${ version } release` ) )
118+ } )
134119}
135120
136121function fetchVersionPolicy ( version ) {
137- // matches the policy for a given version (Stable, LTS etc) in the changelog
138- // ## 2015-10-07, Version 4.2.0 'Argon' (LTS), @jasnell
139- // 2015-12-04, Version 0.12.9 (LTS), @rvagg
140- const rxPolicy = new RegExp ( '^(## )?\\d{4}-\\d{2}-\\d{2}, Version [^(].*\\(([^\\)]+)\\)' )
141-
142- return fetchChangelog ( version )
143- . then ( ( section ) => {
144- const matches = rxPolicy . exec ( section )
145- return matches
146- ? matches [ 2 ]
147- : Promise . reject ( new Error ( `Could not find version policy of ${ version } in its changelog` ) )
148- } )
122+ return fetchChangelog ( version ) . then ( ( section ) => {
123+ // matches the policy for a given version (Stable, LTS etc) in the changelog
124+ // ## 2015-10-07, Version 4.2.0 'Argon' (LTS), @jasnell
125+ // ## 2015-12-04, Version 0.12.9 (LTS), @rvagg
126+ const rxPolicy = / ^ # # ? \d { 4 } - \d { 2 } - \d { 2 } , V e r s i o n [ ^ ( ] .* \( ( [ ^ \) ] + ) \) /
127+ const matches = rxPolicy . exec ( section )
128+ return matches
129+ ? matches [ 1 ]
130+ : Promise . reject ( new Error ( `Could not find version policy of ${ version } in its changelog` ) )
131+ } )
149132}
150133
151134function fetchShasums ( version ) {
152- return download ( `https://nodejs.org/dist/v${ version } /SHASUMS256.txt.asc` )
135+ return sendRequest ( { url : `https://nodejs.org/dist/v${ version } /SHASUMS256.txt.asc` } )
153136 . then ( null , ( ) => '[INSERT SHASUMS HERE]' )
154137}
155138
@@ -164,15 +147,18 @@ function findAuthorLogin (version, section) {
164147 // ## 2016-03-08, Version 5.8.0 (Stable). @Fishrock123
165148 // ## 2015-10-13, Version 4.2.1 'Argon' (LTS), @jasnell
166149 // ## 2015-09-08, Version 4.0.0 (Stable), @rvagg
167- const rxReleaseAuthor = / ^ ( # # ) ? .* ? \( [ ^ \ )] + \) [ , . ] @ ( \S + ) / g
150+ const rxReleaseAuthor = / ^ # # .* ? \( [ ^ ) ] + \) [ , . ] @ ( \S + ) /
168151 const matches = rxReleaseAuthor . exec ( section )
169- return matches ? matches [ 2 ] : Promise . reject ( new Error ( `Couldn't find @author of ${ version } release :(` ) )
152+ return matches
153+ ? matches [ 1 ]
154+ : Promise . reject ( new Error ( `Couldn't find @author of ${ version } release :(` ) )
170155}
171156
172157function urlOrComingSoon ( binary ) {
173- return sendRequest ( binary . url , 'HEAD' ) . then (
158+ return sendRequest ( { url : binary . url , method : 'HEAD' } ) . then (
174159 ( ) => `${ binary . title } : ${ binary . url } ` ,
175- ( ) => `${ binary . title } : *Coming soon*` )
160+ ( ) => `${ binary . title } : *Coming soon*`
161+ )
176162}
177163
178164function renderPost ( results ) {
0 commit comments