-
Notifications
You must be signed in to change notification settings - Fork 55
/
gulpfile.mjs
121 lines (99 loc) · 2.93 KB
/
gulpfile.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import gulp from 'gulp'
import child from 'child_process'
import fs from 'fs'
import rimraf from 'rmfr'
import { mkdirp } from 'mkdirp'
import replace from 'replace'
const libphonenumberVersion =
fs.readFileSync( 'libphonenumber.version', 'utf8' ).toString( ).trim( );
const rootDir = '.';
const buildRoot = `${rootDir}/build`;
const libphonenumberUrl = 'https://github.com/google/libphonenumber/';
const closureLinterUrl = 'https://github.com/google/closure-linter';
const pythonGflagsUrl = 'https://github.com/google/python-gflags.git';
const antName = 'apache-ant-1.10.15';
const antTar = `${antName}.tar.gz`;
const antUrl = `https://downloads.apache.org/ant/binaries/${antName}-bin.tar.gz`;
const isDebug = process.env.DEBUG && process.env.DEBUG !== '0';
gulp.task( 'clean', ( ) =>
rimraf( buildRoot )
);
gulp.task( 'make-build-dir', async ( ) =>
await mkdirp( buildRoot )
);
gulp.task( 'clone-libphonenumber', gulp.series( 'make-build-dir', ( ) =>
gitClone( libphonenumberUrl, 'libphonenumber', libphonenumberVersion )
) );
gulp.task( 'checkout-closure-linter', gulp.series( 'make-build-dir', ( ) =>
gitClone( closureLinterUrl, 'closure-linter' )
) );
gulp.task( 'checkout-python-gflags', gulp.series( 'make-build-dir', ( ) =>
gitClone( pythonGflagsUrl, 'python-gflags' )
) );
gulp.task( 'download-ant', gulp.series(
'make-build-dir',
( ) =>
runCommand(
'curl',
[ '-L', '-o', antTar, antUrl ],
{ cwd: buildRoot }
),
( ) =>
runCommand(
'tar',
[ 'zxf', antTar ],
{ cwd: buildRoot }
)
) );
gulp.task( 'download-deps', gulp.parallel(
'clone-libphonenumber',
'checkout-closure-linter',
'checkout-python-gflags',
'download-ant'
) );
gulp.task( 'build-deps', gulp.series( 'download-deps' ) );
gulp.task( 'build-libphonenumber', ( ) =>
runCommand( `${rootDir}/build.sh`, [ ], { cwd: rootDir } )
);
gulp.task( 'build', gulp.series( 'build-deps', 'build-libphonenumber' ) );
gulp.task( 'update-readme', ( ) =>
updateReadme( )
);
gulp.task( 'default', gulp.series( 'clean', 'build', 'update-readme' ) );
async function updateReadme( )
{
replace( {
regex: 'Uses libphonenumber ([A-Za-z.0-9]+)',
replacement: `Uses libphonenumber ${libphonenumberVersion}`,
paths: [ 'README.md' ],
silent: true,
} );
}
function gitClone( url, name, branch )
{
const args = [ '--depth=1' ];
if ( branch )
args.push( '--branch=' + branch );
return runCommand( 'git', [ 'clone', ...args, url, name ] );
}
function runCommand( cmd, args, opts )
{
opts = opts || {
cwd : './build',
stdio : [ null, null, isDebug ? process.stderr : null ]
};
return new Promise( function( resolve, reject ) {
var cp = child.spawn( cmd, args, opts );
cp.stdout.on( 'data', data => {
if ( isDebug )
console.log( data.toString( ) );
} );
cp.on( 'close', code => {
if ( code === 0 )
return resolve( );
reject( new Error(
`${cmd} exited with exitcode ${code}. Args: ${args}` ) );
} );
cp.on( 'error', err => reject( err ) );
} );
}