File tree Expand file tree Collapse file tree 5 files changed +93
-14
lines changed
Expand file tree Collapse file tree 5 files changed +93
-14
lines changed Original file line number Diff line number Diff line change 33
44const CMD = process . argv [ 2 ] ;
55const path = require ( 'path' ) ;
6- const { execSync } = require ( 'child_process ' ) ;
6+ const { run } = require ( '../../lib/run ' ) ;
77const fs = require ( 'fs' ) ;
88
99if ( ! CMD ) {
@@ -13,10 +13,8 @@ if (!CMD) {
1313
1414const script = path . join ( __dirname , `git-node-${ CMD } ` ) ;
1515if ( ! fs . existsSync ( script ) ) {
16- console . log ( `No such command: git node ${ CMD } ` ) ;
16+ console . error ( `No such command: git node ${ CMD } ` ) ;
1717 process . exit ( 1 ) ;
1818}
1919
20- execSync ( script , process . argv . slice ( 2 ) , {
21- stdio : 'inherit'
22- } ) ;
20+ run ( script , process . argv . slice ( 3 ) ) ;
Original file line number Diff line number Diff line change 1- #! /usr/bin/env bash
1+ #!/usr/bin/env node
2+ 'use strict' ;
23
3- set -x;
4+ const PRID = parseInt ( process . argv [ 2 ] ) ;
5+ const Request = require ( './../../lib/request' ) ;
6+ const paths = require ( './../../lib/paths' ) ;
7+ const { run, runAsync } = require ( '../../lib/run' ) ;
8+ const fs = require ( 'fs' ) ;
9+ const CLI = require ( '../../lib/CLI' ) ;
10+ const cli = new CLI ( process . stderr ) ;
411
5- if [[ $1 -eq 0 ]] ; then
6- echo ' no patch number specified!'
7- exit 1
8- fi
12+ if ( ! PRID ) {
13+ cli . error ( 'No patch number specified!') ;
14+ process . exit ( 1 ) ;
15+ }
916
10- curl -L " https://github.com/nodejs/node/pull/$1 .patch" | git am --whitespace=fix
17+ async function main ( ) {
18+ cli . startSpinner ( `Downloading patch for ${ PRID } ` ) ;
19+ // TODO: support other repos/owners later?
20+ const patch = await new Request ( ) . promise ( {
21+ url : `https://github.com/nodejs/node/pull/${ PRID } .patch`
22+ } ) ;
23+ const patchName = paths . patch ( PRID ) ;
24+ fs . writeFileSync ( patchName , patch , 'utf8' ) ;
25+ cli . stopSpinner ( `Downloaded patch to ${ patchName } ` ) ;
26+ return run ( 'git' , [ 'am' , '--whitespace=fix' , patchName ] ) ;
27+ }
28+
29+ runAsync ( main ( ) ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const path = require ( 'path' ) ;
4+ const fs = require ( 'fs' ) ;
5+
6+ Object . defineProperty ( module . exports , 'ncuDir' , {
7+ get ( ) {
8+ const ncu = path . join ( process . cwd ( ) , '.ncu' ) ;
9+ if ( ! fs . existsSync ( ncu ) ) {
10+ fs . mkdirSync ( ncu ) ;
11+ }
12+ return ncu ;
13+ }
14+ } ) ;
15+
16+ exports . metadata = function ( prid ) {
17+ return path . join ( exports . ncuDir , `meta-${ prid } .txt` ) ;
18+ } ;
19+
20+ exports . message = function ( sha ) {
21+ return path . join ( exports . ncuDir , `msg-${ sha } .txt` ) ;
22+ } ;
23+
24+ exports . patch = function ( prid ) {
25+ return path . join ( exports . ncuDir , `patch-${ prid } .patch` ) ;
26+ } ;
Original file line number Diff line number Diff line change @@ -14,8 +14,10 @@ class Request {
1414 return fs . readFileSync ( filePath , 'utf8' ) ;
1515 }
1616
17- async promise ( ) {
18- return rp ( ...arguments ) ;
17+ async promise ( options ) {
18+ return rp ( Object . assign ( {
19+ gzip : true
20+ } , options ) ) ;
1921 }
2022
2123 async gql ( name , variables , path ) {
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const { spawn } = require ( 'child_process' ) ;
4+
5+ const IGNORE = '__ignore__' ;
6+
7+ function runAsync ( promise ) {
8+ return promise . catch ( ( error ) => {
9+ if ( error . message !== IGNORE ) {
10+ console . error ( error ) ;
11+ }
12+ process . exit ( 1 ) ;
13+ } ) ;
14+ } ;
15+
16+ exports . run = function ( cmd , args , options ) {
17+ const promise = new Promise ( ( resolve , reject ) => {
18+ const child = spawn ( cmd , args , Object . assign ( {
19+ cwd : process . cwd ( ) ,
20+ stdio : 'inherit'
21+ } , options ) ) ;
22+ // console.log(child.pid);
23+ child . on ( 'close' , ( code ) => {
24+ if ( code !== 0 ) {
25+ return reject ( new Error ( IGNORE ) ) ;
26+ }
27+ return resolve ( ) ;
28+ } ) ;
29+ } ) ;
30+
31+ return runAsync ( promise ) ;
32+ } ;
33+
34+ exports . runAsync = runAsync ;
You can’t perform that action at this time.
0 commit comments