forked from grantila/awesome-phonenumber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
129 lines (105 loc) · 3.32 KB
/
gulpfile.js
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
122
123
124
125
126
127
128
129
const gulp = require( 'gulp' );
const child = require( 'child_process' );
const fs = require( 'fs' );
const util = require( 'util' );
const rimraf = require( 'rimraf-promise' );
const mkdirp = util.promisify( require( 'mkdirp' ) );
const replace = require( 'replace' );
const libphonenumberVersion =
fs.readFileSync( 'libphonenumber.version', 'utf8' ).toString( ).trim( );
const buildRoot = './build';
const libphonenumberUrl = 'https://github.com/googlei18n/libphonenumber/';
const closureLibraryUrl = 'https://github.com/google/closure-library/';
const closureLinterUrl = 'https://github.com/google/closure-linter';
const pythonGflagsUrl = 'https://github.com/google/python-gflags.git';
const antName = 'apache-ant-1.10.5';
const antTar = `${antName}.tar.gz`;
const antUrl = `http://apache.mirrors.spacedump.net/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', ( ) =>
mkdirp( buildRoot )
);
gulp.task( 'clone-libphonenumber', gulp.series( 'make-build-dir', ( ) =>
gitClone( libphonenumberUrl, 'libphonenumber', libphonenumberVersion )
) );
gulp.task( 'clone-closure-library', gulp.series( 'make-build-dir', ( ) =>
gitClone( closureLibraryUrl, 'closure-library', 'v20171112' )
) );
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',
'clone-closure-library',
'checkout-closure-linter',
'checkout-python-gflags',
'download-ant'
) );
gulp.task( 'build-deps', gulp.series( 'download-deps' ) );
gulp.task( 'build-libphonenumber', ( ) => {
var args = [ '-f', 'build.xml', 'compile-exports' ];
return runCommand( `${buildRoot}/${antName}/bin/ant`, args, { cwd: '.' } );
} );
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 ) );
} );
}