1
1
/**
2
2
* External dependencies
3
3
*/
4
- import del from 'del' ;
5
- import deleteLines from 'gulp-rm-lines' ;
6
- import fs from 'fs' ;
7
4
import gulp from 'gulp' ;
8
- import i18n_calypso from 'i18n-calypso-cli' ;
9
- import json_transform from 'gulp-json-transform' ;
10
5
import log from 'fancy-log' ;
11
- import po2json from 'gulp-po2json' ;
12
- import rename from 'gulp-rename' ;
13
- import request from 'request' ;
14
- import tap from 'gulp-tap' ;
15
6
import { spawn } from 'child_process' ;
16
7
17
8
/**
18
9
* Internal dependencies
19
10
*/
20
- const meta = require ( './package.json' ) ;
21
11
import frontendcss from './tools/builder/frontend-css' ;
22
12
import admincss from './tools/builder/admin-css' ;
23
13
import { watch as react_watch , build as react_build } from './tools/builder/react' ;
@@ -50,114 +40,6 @@ gulp.task( 'search:watch', function() {
50
40
} ) ;
51
41
} ) ;
52
42
53
- /*
54
- I18n land
55
- */
56
-
57
- // Should not be run independently, run gulp languages instead
58
- gulp . task ( 'languages:get' , function ( callback ) {
59
- const process = spawn ( 'php' , [
60
- 'tools/export-translations.php' ,
61
- '.' ,
62
- 'https://translate.wordpress.org/projects/wp-plugins/jetpack/dev' ,
63
- ] ) ;
64
-
65
- process . stderr . on ( 'data' , function ( data ) {
66
- log ( data . toString ( ) ) ;
67
- } ) ;
68
- process . stdout . on ( 'data' , function ( data ) {
69
- log ( data . toString ( ) ) ;
70
- } ) ;
71
- process . on ( 'exit' , function ( code ) {
72
- if ( 0 !== code ) {
73
- log ( 'Failed getting languages: process exited with code ' , code ) ;
74
- // Make the task fail if there was a problem as this could mean that we were going to ship a Jetpack version
75
- // with the languages not properly built
76
- return callback ( new Error ( ) ) ;
77
- }
78
- callback ( ) ;
79
- } ) ;
80
- } ) ;
81
-
82
- // Should not be run independently, run gulp languages instead
83
- gulp . task ( 'languages:build' , function ( done ) {
84
- const terms = [ ] ;
85
-
86
- // Defining global that will be used from jetpack-strings.js
87
- global . $jetpack_strings = [ ] ;
88
- global . array = function ( ) { } ;
89
-
90
- // Plural gettext call doesn't make a difference for Jed, the singular value is still used as the key.
91
- global . __ = global . _n = function ( term ) {
92
- terms [ term ] = '' ;
93
- } ;
94
-
95
- // Context prefixes the term and is separated with a unicode character U+0004
96
- global . _x = function ( term , context ) {
97
- terms [ context + '\u0004' + term ] = '' ;
98
- } ;
99
-
100
- gulp
101
- . src ( [ '_inc/jetpack-strings.php' ] )
102
- . pipe (
103
- deleteLines ( {
104
- filters : [ / < \? p h p / ] ,
105
- } )
106
- )
107
- . pipe ( rename ( 'jetpack-strings.js' ) )
108
- . pipe ( gulp . dest ( '_inc' ) )
109
- . on ( 'end' , function ( ) {
110
- // Requiring the file that will call __, _x and _n
111
- require ( './_inc/jetpack-strings.js' ) ;
112
-
113
- return (
114
- gulp
115
- . src ( [ 'languages/*.po' ] )
116
- . pipe (
117
- po2json ( {
118
- format : 'jed1.x' ,
119
- domain : 'jetpack' ,
120
- } )
121
- )
122
- . pipe (
123
- json_transform ( function ( data ) {
124
- const localeData = data . locale_data . jetpack ;
125
- const filtered = {
126
- '' : localeData [ '' ] ,
127
- } ;
128
-
129
- Object . keys ( localeData ) . forEach ( function ( term ) {
130
- if ( terms . hasOwnProperty ( term ) ) {
131
- filtered [ term ] = localeData [ term ] ;
132
-
133
- // Having a " in the JSON might cause errors with the JSON later
134
- if ( typeof filtered [ term ] === 'string' ) {
135
- filtered [ term ] = filtered [ term ] . replace ( '"' , '"' ) ;
136
- }
137
- }
138
- } ) ;
139
-
140
- return {
141
- locale_data : {
142
- jetpack : filtered ,
143
- } ,
144
- } ;
145
- } )
146
- )
147
-
148
- // WordPress 5.0 uses md5 hashes of file paths to associate translation
149
- // JSON files with the file they should be included for. This is an md5
150
- // of '_inc/build/admin.js'.
151
- . pipe ( rename ( { suffix : '-1bac79e646a8bf4081a5011ab72d5807' } ) )
152
- . pipe ( gulp . dest ( 'languages/json/' ) )
153
- . on ( 'end' , function ( ) {
154
- fs . unlinkSync ( './_inc/jetpack-strings.js' ) ;
155
- done ( ) ;
156
- } )
157
- ) ;
158
- } ) ;
159
- } ) ;
160
-
161
43
gulp . task ( 'php:module-headings' , function ( callback ) {
162
44
const process = spawn ( 'php' , [ 'tools/build-module-headings-translations.php' ] ) ;
163
45
process . stderr . on ( 'data' , function ( data ) {
@@ -174,64 +56,6 @@ gulp.task( 'php:module-headings', function( callback ) {
174
56
} ) ;
175
57
} ) ;
176
58
177
- // Should not be run independently, run gulp languages instead
178
- gulp . task ( 'languages:cleanup' , function ( done ) {
179
- const language_packs = [ ] ;
180
-
181
- request (
182
- 'https://api.wordpress.org/translations/plugins/1.0/?slug=jetpack&version=' + meta . version ,
183
- function ( error , response , body ) {
184
- if ( error || 200 !== response . statusCode ) {
185
- done ( 'Failed to reach wordpress.org translation API: ' + error ) ;
186
- }
187
-
188
- body = JSON . parse ( body ) ;
189
-
190
- body . translations . forEach ( function ( language ) {
191
- language_packs . push ( './languages/jetpack-' + language . language + '.*' ) ;
192
- } ) ;
193
-
194
- log ( 'Cleaning up languages for which Jetpack has language packs:' ) ;
195
- del ( language_packs ) . then ( function ( paths ) {
196
- paths . forEach ( function ( item ) {
197
- log ( item ) ;
198
- } ) ;
199
- done ( ) ;
200
- } ) ;
201
- }
202
- ) ;
203
- } ) ;
204
-
205
- gulp . task ( 'languages:extract' , function ( done ) {
206
- const paths = [ ] ;
207
-
208
- return gulp
209
- . src ( [
210
- '_inc/client/**/*.js' ,
211
- '_inc/client/**/*.jsx' ,
212
- '_inc/blocks/*.js' ,
213
- '_inc/blocks/**/*.js' ,
214
- ] )
215
- . pipe (
216
- tap ( function ( file ) {
217
- paths . push ( file . path ) ;
218
- } )
219
- )
220
- . on ( 'end' , function ( ) {
221
- i18n_calypso ( {
222
- projectName : 'Jetpack' ,
223
- inputPaths : paths ,
224
- output : '_inc/jetpack-strings.php' ,
225
- phpArrayName : 'jetpack_strings' ,
226
- format : 'PHP' ,
227
- textdomain : 'jetpack' ,
228
- keywords : [ 'translate' , '__' , '_n' , '_x' , '_nx' ] ,
229
- } ) ;
230
-
231
- done ( ) ;
232
- } ) ;
233
- } ) ;
234
-
235
59
gulp . task ( 'old-styles' , gulp . parallel ( frontendcss , admincss , 'sass:old' , 'sass:packages' ) ) ;
236
60
237
61
// Default task
@@ -256,11 +80,3 @@ gulp.task( 'sass:build', sass_build );
256
80
gulp . task ( 'react:build' , react_build ) ;
257
81
gulp . task ( 'sass:watch' , gulp . parallel ( sass_watch , sass_watch_packages ) ) ;
258
82
gulp . task ( 'react:watch' , react_watch ) ;
259
-
260
- gulp . task (
261
- 'languages' ,
262
- gulp . parallel (
263
- gulp . series ( 'languages:extract' ) ,
264
- gulp . series ( 'languages:get' , 'languages:build' , 'languages:cleanup' )
265
- )
266
- ) ;
0 commit comments