shaka-player 4.0.3 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/CONTRIBUTORS +2 -0
  3. package/README.md +20 -6
  4. package/demo/index.html +0 -2
  5. package/dist/controls.css +1 -1
  6. package/dist/deps.js +3 -3
  7. package/dist/locales.js +33 -33
  8. package/dist/shaka-player.compiled.d.ts +11 -0
  9. package/dist/shaka-player.compiled.debug.d.ts +11 -0
  10. package/dist/shaka-player.compiled.debug.externs.js +48 -37
  11. package/dist/shaka-player.compiled.debug.js +141 -137
  12. package/dist/shaka-player.compiled.debug.map +4 -4
  13. package/dist/shaka-player.compiled.externs.js +48 -37
  14. package/dist/shaka-player.compiled.js +774 -772
  15. package/dist/shaka-player.compiled.map +4 -4
  16. package/dist/shaka-player.ui.d.ts +11 -0
  17. package/dist/shaka-player.ui.debug.d.ts +11 -0
  18. package/dist/shaka-player.ui.debug.externs.js +48 -37
  19. package/dist/shaka-player.ui.debug.js +153 -149
  20. package/dist/shaka-player.ui.debug.map +4 -4
  21. package/dist/shaka-player.ui.externs.js +48 -37
  22. package/dist/shaka-player.ui.js +892 -890
  23. package/dist/shaka-player.ui.map +4 -4
  24. package/docs/tutorials/upgrade.md +1 -0
  25. package/docs/tutorials/welcome.md +6 -3
  26. package/lib/dash/dash_parser.js +5 -0
  27. package/lib/hls/hls_parser.js +6 -2
  28. package/lib/media/media_source_engine.js +57 -24
  29. package/lib/media/presentation_timeline.js +24 -1
  30. package/lib/media/streaming_engine.js +3 -4
  31. package/lib/media/time_ranges_utils.js +46 -0
  32. package/lib/player.js +1 -1
  33. package/lib/polyfill/media_capabilities.js +3 -0
  34. package/lib/polyfill/videoplaybackquality.js +3 -1
  35. package/lib/util/platform.js +19 -1
  36. package/lib/util/string_utils.js +56 -14
  37. package/maintained-branches.md +15 -0
  38. package/package.json +2 -4
  39. package/test/media/drm_engine_integration.js +24 -8
  40. package/test/media/media_source_engine_integration.js +24 -10
  41. package/test/media/media_source_engine_unit.js +53 -38
  42. package/test/media/streaming_engine_unit.js +28 -27
  43. package/test/test/util/fake_media_source_engine.js +10 -9
  44. package/app-engine/README.md +0 -9
  45. package/app-engine/demo-version-index/README.md +0 -14
  46. package/app-engine/demo-version-index/app.yaml +0 -28
  47. package/app-engine/demo-version-index/generate.py +0 -164
  48. package/app-engine/demo-version-index/main.py +0 -11
  49. package/app-engine/demo-version-index/requirements.txt +0 -5
  50. package/app-engine/demo-version-index/templates/index.html +0 -114
  51. package/app-engine/shaka-player-demo/README.md +0 -18
  52. package/app-engine/shaka-player-demo/app.yaml +0 -61
  53. package/app-engine/shaka-player-demo/main.py +0 -95
  54. package/app-engine/shaka-player-demo/posters/10yo.png +0 -0
  55. package/app-engine/shaka-player-demo/posters/10yo.xcf +0 -0
  56. package/app-engine/shaka-player-demo/posters/1yo.jpg +0 -0
  57. package/app-engine/shaka-player-demo/posters/2yo.png +0 -0
  58. package/app-engine/shaka-player-demo/posters/2yo.xcf +0 -0
  59. package/app-engine/shaka-player-demo/posters/3yo.png +0 -0
  60. package/app-engine/shaka-player-demo/posters/3yo.xcf +0 -0
  61. package/app-engine/shaka-player-demo/posters/4yo.png +0 -0
  62. package/app-engine/shaka-player-demo/posters/4yo.xcf +0 -0
  63. package/app-engine/shaka-player-demo/posters/5yo.png +0 -0
  64. package/app-engine/shaka-player-demo/posters/5yo.xcf +0 -0
  65. package/app-engine/shaka-player-demo/posters/6yo.png +0 -0
  66. package/app-engine/shaka-player-demo/posters/6yo.xcf +0 -0
  67. package/app-engine/shaka-player-demo/posters/7yo.png +0 -0
  68. package/app-engine/shaka-player-demo/posters/7yo.xcf +0 -0
  69. package/app-engine/shaka-player-demo/posters/8yo.png +0 -0
  70. package/app-engine/shaka-player-demo/posters/8yo.xcf +0 -0
  71. package/app-engine/shaka-player-demo/posters/9yo.png +0 -0
  72. package/app-engine/shaka-player-demo/posters/9yo.xcf +0 -0
  73. package/app-engine/shaka-player-demo/posters/audioOnly.gif +0 -0
  74. package/app-engine/shaka-player-demo/posters/audioRickRoll.gif +0 -0
  75. package/app-engine/shaka-player-demo/posters/colorbars.gif +0 -0
  76. package/app-engine/shaka-player-demo/posters/fireworks.jpg +0 -0
  77. package/app-engine/shaka-player-demo/posters/party-hat.png +0 -0
  78. package/app-engine/shaka-player-demo/posters/sources.txt +0 -46
  79. package/app-engine/shaka-player-demo/posters/standard.png +0 -0
  80. package/app-engine/shaka-player-demo/posters/trek.jpg +0 -0
  81. package/app-engine/shaka-player-demo/posters/valentines.png +0 -0
  82. package/app-engine/shaka-player-demo/posters/zombie.jpg +0 -0
  83. package/app-engine/shaka-player-demo/posters.py +0 -110
  84. package/app-engine/shaka-player-demo/requirements.txt +0 -5
  85. package/app-engine/shaka-player-demo/time.txt +0 -1
  86. package/build/README.md +0 -127
  87. package/build/__init__.py +0 -0
  88. package/build/all.py +0 -150
  89. package/build/apps.py +0 -186
  90. package/build/build.py +0 -392
  91. package/build/check.py +0 -354
  92. package/build/checkversion.py +0 -84
  93. package/build/compiler.py +0 -513
  94. package/build/conformance.textproto +0 -335
  95. package/build/docker/Dockerfile +0 -20
  96. package/build/docker/docker-compose.yml +0 -10
  97. package/build/docs.py +0 -54
  98. package/build/eslint-plugin-shaka-rules/arg-comment-spacing.js +0 -72
  99. package/build/eslint-plugin-shaka-rules/index.js +0 -24
  100. package/build/eslint-plugin-shaka-rules/package.json +0 -7
  101. package/build/eslint-plugin-shaka-rules/private.js +0 -109
  102. package/build/gendeps.py +0 -71
  103. package/build/generateExterns.js +0 -867
  104. package/build/generateLocalizations.py +0 -262
  105. package/build/generateTsDefs.py +0 -137
  106. package/build/install-linux-prereqs.sh +0 -136
  107. package/build/license-header +0 -5
  108. package/build/misspellings.txt +0 -39
  109. package/build/pixelsChanged.js +0 -35
  110. package/build/shaka-lab.yaml +0 -161
  111. package/build/shakaBuildHelpers.py +0 -356
  112. package/build/stats.py +0 -816
  113. package/build/subprocessWindowsPatch.py +0 -103
  114. package/build/test.py +0 -541
  115. package/build/types/ads +0 -8
  116. package/build/types/cast +0 -6
  117. package/build/types/cea +0 -13
  118. package/build/types/complete +0 -9
  119. package/build/types/core +0 -108
  120. package/build/types/dash +0 -8
  121. package/build/types/hls +0 -9
  122. package/build/types/manifests +0 -5
  123. package/build/types/networking +0 -6
  124. package/build/types/offline +0 -22
  125. package/build/types/polyfill +0 -18
  126. package/build/types/text +0 -11
  127. package/build/types/ui +0 -39
  128. package/build/updateScreenshots.py +0 -85
  129. package/build/wrapper.template.js +0 -52
package/build/compiler.py DELETED
@@ -1,513 +0,0 @@
1
- # Copyright 2016 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- """Classes representing the various compiler and linter tools that are used to
16
- build Shaka Player."""
17
-
18
- import json
19
- import logging
20
- import os
21
- import re
22
- import shutil
23
- import subprocess
24
- import sys
25
-
26
- import generateLocalizations
27
- import shakaBuildHelpers
28
-
29
-
30
- def _canonicalize_source_files(source_files):
31
- """Canonicalize a set or list of source files.
32
-
33
- This makes all path names cygwin-safe and sorted."""
34
-
35
- files = [shakaBuildHelpers.cygwin_safe_path(f) for f in source_files]
36
- files.sort()
37
- return files
38
-
39
- def _get_source_path(path):
40
- """Take path components of a source file as arguments and return an absolute,
41
- cygwin-safe path."""
42
- return shakaBuildHelpers.cygwin_safe_path(os.path.join(
43
- shakaBuildHelpers.get_source_base(), path))
44
-
45
- def _must_build(output, source_files):
46
- """Returns True if any of the |source_files| have changed since |output| was
47
- built, or if |output| does not exist yet."""
48
- if not os.path.isfile(output):
49
- # Nothing built, so we should build the output.
50
- return True
51
-
52
- # Detect changes to the set of files that we intend to build.
53
- build_time = os.path.getmtime(output)
54
- # See if any files were modified since the output was created.
55
- if any(os.path.getmtime(f) > build_time for f in source_files):
56
- # Some input files have changed, so we should build again.
57
- return True
58
-
59
- # Look at all the Python modules that are loaded. If any of them have
60
- # changed, it may affect the build.
61
- this_path = os.path.dirname(os.path.abspath(__file__))
62
- for module in sys.modules.values():
63
- path = getattr(module, '__file__', None)
64
- if path and os.path.exists(path) and os.path.getmtime(path) > build_time:
65
- return True
66
-
67
- logging.warning('No changes detected, skipping. Use --force to override.')
68
- return False
69
-
70
- def _update_timestamp(path):
71
- # This creates the file if it does not exist, and updates the timestamp if it
72
- # does.
73
- open(path, 'wb').close()
74
-
75
-
76
- class ClosureCompiler(object):
77
- def __init__(self, source_files, build_name):
78
- self.source_files = _canonicalize_source_files(source_files)
79
-
80
- prefix = _get_source_path('dist/' + build_name)
81
- self.compiled_js_path = prefix + '.js'
82
- self.source_map_path = prefix + '.map'
83
-
84
- # These can be overridden for special cases:
85
-
86
- # If True, output the compiled bundle to a file.
87
- self.output_compiled_bundle = True
88
- # If True, generate a source map and attach it to the output bundle.
89
- self.add_source_map = True
90
- # If True, wrap the output in a wrapper that prevents window pollution.
91
- self.add_wrapper = True
92
- # If not None, use a timestamp file for change detection, and touch that
93
- # timestamp file after compilation.
94
- self.timestamp_file = None
95
-
96
- def compile(self, options, force=False):
97
- """Builds the files in |self.source_files| using the given Closure
98
- command-line options.
99
-
100
- Args:
101
- options: An array of options to give to Closure.
102
- force: Generate the output even if the inputs have not changed.
103
-
104
- Returns:
105
- True on success; False on failure.
106
- """
107
- if not force:
108
- if self.timestamp_file:
109
- if not _must_build(self.timestamp_file, self.source_files):
110
- return True
111
- else:
112
- if not _must_build(self.compiled_js_path, self.source_files):
113
- return True
114
-
115
- jar = _get_source_path(
116
- 'node_modules/google-closure-compiler-java/compiler.jar')
117
-
118
- output_options = []
119
- if self.output_compiled_bundle:
120
- output_options += [
121
- '--js_output_file', self.compiled_js_path,
122
- ]
123
-
124
- if self.add_source_map:
125
- source_base = _get_source_path('')
126
-
127
- output_options += [
128
- '--create_source_map', self.source_map_path,
129
- # This uses a simple string replacement to create relative paths.
130
- # "source|replacement".
131
- '--source_map_location_mapping', source_base + '|../',
132
- ]
133
- if shakaBuildHelpers.is_windows() or shakaBuildHelpers.is_cygwin():
134
- output_options += [
135
- # On Windows, the source map needs to use '/' for paths, so we
136
- # need to have this mapping so it creates the correct relative
137
- # paths. For some reason, we still need the mapping above for
138
- # other parts of the source map.
139
- '--source_map_location_mapping',
140
- source_base.replace('\\', '/') + '|../',
141
- ]
142
-
143
- if self.add_wrapper:
144
- output_options += self._prepare_wrapper()
145
-
146
- cmd_line = ['java', '-jar', jar] + output_options + options
147
- cmd_line += self.source_files
148
-
149
- if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
150
- logging.error('Build failed')
151
- return False
152
-
153
- if self.output_compiled_bundle and self.add_source_map:
154
- # Add a special source-mapping comment so that Chrome and Firefox can map
155
- # line and character numbers from the compiled library back to the
156
- # original source locations.
157
- with shakaBuildHelpers.open_file(self.compiled_js_path, 'a') as f:
158
- f.write('//# sourceMappingURL=%s' % os.path.basename(
159
- self.source_map_path))
160
-
161
- if self.timestamp_file:
162
- _update_timestamp(self.timestamp_file)
163
-
164
- return True
165
-
166
- def _prepare_wrapper(self):
167
- """Prepares an output wrapper and returns a list of command line arguments
168
- for Closure Compiler to use it."""
169
-
170
- # Load the wrapper and use Closure to strip whitespace and comments.
171
- # This requires %output% in the template to be protected, so Closure doesn't
172
- # fail to parse it.
173
- wrapper_input_path = _get_source_path('build/wrapper.template.js')
174
- wrapper_output_path = _get_source_path('dist/wrapper.js')
175
-
176
- with shakaBuildHelpers.open_file(wrapper_input_path, 'r') as f:
177
- wrapper_code = f.read().replace('%output%', '"%output%"')
178
-
179
- jar = _get_source_path(
180
- 'node_modules/google-closure-compiler-java/compiler.jar')
181
- cmd_line = ['java', '-jar', jar, '-O', 'WHITESPACE_ONLY']
182
-
183
- proc = shakaBuildHelpers.execute_subprocess(
184
- cmd_line, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
185
- stderr=subprocess.PIPE)
186
- stripped_wrapper_code = proc.communicate(wrapper_code.encode('utf8'))[0]
187
-
188
- if proc.returncode != 0:
189
- raise RuntimeError('Failed to strip whitespace from wrapper!')
190
-
191
- with shakaBuildHelpers.open_file(wrapper_output_path, 'w') as f:
192
- code = stripped_wrapper_code.decode('utf8')
193
- f.write(code.replace('"%output%"', '%output%'))
194
-
195
- return ['--output_wrapper_file=%s' % wrapper_output_path]
196
-
197
-
198
- class ExternGenerator(object):
199
- def __init__(self, source_files, build_name):
200
- self.source_files = _canonicalize_source_files(source_files)
201
- self.output = _get_source_path('dist/' + build_name + '.externs.js')
202
-
203
- def generate(self, force=False):
204
- """Generates externs for the files in |self.source_files|.
205
-
206
- Args:
207
- force: Generate the output even if the inputs have not changed.
208
-
209
- Returns:
210
- True on success; False on failure.
211
- """
212
- if not force and not _must_build(self.output, self.source_files):
213
- return True
214
-
215
- extern_generator = _get_source_path('build/generateExterns.js')
216
-
217
- cmd_line = ['node', extern_generator, '--output', self.output]
218
- cmd_line += self.source_files
219
-
220
- if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
221
- logging.error('Externs generation failed')
222
- return False
223
-
224
- return True
225
-
226
-
227
- class TsDefGenerator(object):
228
- def __init__(self, source_files, build_name):
229
- self.source_files = _canonicalize_source_files(source_files)
230
- self.output = _get_source_path('dist/' + build_name + '.d.ts')
231
-
232
- def generate(self, force=False):
233
- """Generates externs for the files in |self.source_files|.
234
-
235
- Args:
236
- force: Generate the output even if the inputs have not changed.
237
-
238
- Returns:
239
- True on success; False on failure.
240
- """
241
- if not force and not _must_build(self.output, self.source_files):
242
- return True
243
-
244
- def_generator = _get_source_path('build/generateTsDefs.py')
245
-
246
- cmd_line = [sys.executable or 'python', def_generator, '--output',
247
- self.output]
248
- cmd_line += self.source_files
249
-
250
- if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
251
- logging.error('TS defs generation failed')
252
- return False
253
-
254
- return True
255
-
256
-
257
- class Less(object):
258
- def __init__(self, main_source_file, all_source_files, output):
259
- # Less only takes one input file, but that input may import others.
260
- # We use main_source_file for compilation, but all_source_files to detect
261
- # if it needs to be rebuilt.
262
- self.main_source_file = _canonicalize_source_files([main_source_file])[0]
263
- self.all_source_files = _canonicalize_source_files(all_source_files)
264
- self.output = output
265
-
266
- def compile(self, force=False):
267
- """Compiles the main less file in |self.main_source_file| into the
268
- |self.output| css file.
269
-
270
- Args:
271
- force: Generate the output even if the inputs have not changed.
272
-
273
- Returns:
274
- True on success; False on failure.
275
- """
276
- if not force and not _must_build(self.output, self.all_source_files):
277
- return True
278
-
279
- lessc = shakaBuildHelpers.get_node_binary('less', 'lessc')
280
- less_options = [
281
- # Enable the "clean-CSS" plugin to minify the output and strip out comments.
282
- '--clean-css',
283
- # Output a source map of the original CSS/less files.
284
- '--source-map=' + self.output + '.map',
285
- ]
286
-
287
- cmd_line = lessc + less_options + [self.main_source_file, self.output]
288
-
289
- if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
290
- logging.error('CSS compilation failed')
291
- return False
292
-
293
- # We need to prepend the license header to the compiled CSS.
294
- with open(_get_source_path('build/license-header'), 'rb') as f:
295
- license_header = f.read()
296
- with open(self.output, 'rb') as f:
297
- contents = f.read()
298
- with open(self.output, 'wb') as f:
299
- f.write(license_header)
300
- f.write(contents)
301
-
302
- return True
303
-
304
-
305
- class Linter(object):
306
- def __init__(self, source_files, config_path):
307
- self.source_files = _canonicalize_source_files(source_files)
308
- self.config_path = config_path
309
- self.output = _get_source_path('dist/.lintstamp')
310
-
311
- def lint(self, fix=False, force=False):
312
- """Run linter checks on the files in |self.source_files|.
313
-
314
- Args:
315
- fix: If True, ask the linter to fix what errors it can automatically.
316
- force: Run linter checks even if the inputs have not changed.
317
-
318
- Returns:
319
- True on success; False on failure.
320
- """
321
- deps = self.source_files + [self.config_path]
322
- if not force and not _must_build(self.output, deps):
323
- return True
324
-
325
- eslint = shakaBuildHelpers.get_node_binary('eslint')
326
- cmd_line = eslint + ['--config', self.config_path] + self.source_files
327
-
328
- if fix:
329
- cmd_line += ['--fix']
330
-
331
- if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
332
- return False
333
-
334
- # TODO: Add back Closure Compiler Linter
335
-
336
- # Update the timestamp of the file that tracks when we last updated.
337
- _update_timestamp(self.output)
338
- return True
339
-
340
-
341
- class CssLinter(object):
342
- def __init__(self, source_files, config_path):
343
- self.source_files = _canonicalize_source_files(source_files)
344
- self.config_path = config_path
345
- self.output = _get_source_path('dist/.csslintstamp')
346
-
347
- def lint(self, fix=False, force=False):
348
- """Run CSS linter checks on the files in |self.source_files|.
349
-
350
- Args:
351
- fix: If True, ask the linter to fix what errors it can automatically.
352
- force: Run linter checks even if the inputs have not changed.
353
-
354
- Returns:
355
- True on success; False on failure.
356
- """
357
- deps = self.source_files + [self.config_path]
358
- if not force and not _must_build(self.output, deps):
359
- return True
360
- # Windows shows an error when the file location has '\' .
361
- if sys.platform == 'win32':
362
- self.config_path = self.config_path.replace('\\', '/')
363
- self.source_files = [f.replace('\\', '/') for f in self.source_files]
364
-
365
- stylelint = shakaBuildHelpers.get_node_binary('stylelint')
366
- cmd_line = stylelint + [
367
- '--config', self.config_path,
368
- # The "default ignores" is something like **/node_modules/**, which
369
- # means that if we run the build scripts from inside the installed node
370
- # modules of shaka-player, all our sources will be filtered out if we
371
- # don't disable the default ignores in stylelint.
372
- '--disable-default-ignores',
373
- ] + self.source_files
374
-
375
- if fix:
376
- cmd_line += ['--fix']
377
-
378
- if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
379
- return False
380
-
381
- # Update the timestamp of the file that tracks when we last updated.
382
- _update_timestamp(self.output)
383
- return True
384
-
385
-
386
- class HtmlLinter(object):
387
- def __init__(self, source_files, config_path):
388
- self.source_files = _canonicalize_source_files(source_files)
389
- self.config_path = config_path
390
- self.output = _get_source_path('dist/.htmllintstamp')
391
-
392
- def lint(self, force=False):
393
- """Run HTML linter checks on the files in |self.source_files|.
394
-
395
- Args:
396
- force: Run linter checks even if the inputs have not changed.
397
-
398
- Returns:
399
- True on success; False on failure.
400
- """
401
- deps = self.source_files + [self.config_path]
402
- if not force and not _must_build(self.output, deps):
403
- return True
404
-
405
- htmlhint = shakaBuildHelpers.get_node_binary('htmlhint')
406
- cmd_line = htmlhint + ['--config=' + self.config_path] + self.source_files
407
-
408
- if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
409
- return False
410
-
411
- # Update the timestamp of the file that tracks when we last updated.
412
- _update_timestamp(self.output)
413
- return True
414
-
415
-
416
- class Jsdoc(object):
417
- def __init__(self, config_path):
418
- self.config_path = config_path
419
- self.source_files = shakaBuildHelpers.get_all_files(
420
- _get_source_path('docs/tutorials'))
421
- self.source_files += shakaBuildHelpers.get_all_files(
422
- _get_source_path('docs/jsdoc-template'))
423
- self.source_files += [
424
- _get_source_path('docs/jsdoc-plugin.js'),
425
- _get_source_path('docs/api-mainpage.md'),
426
- ]
427
-
428
- # Just one of many output files, used to check the freshness of the docs.
429
- self.output = _get_source_path('docs/api/index.html')
430
-
431
- # To avoid getting out of sync with the source files jsdoc actually reads,
432
- # parse the config file and locate all source files based on that.
433
- with open(self.config_path, 'r') as f:
434
- config = json.load(f)
435
- for path in config['source']['include']:
436
- full_path = _get_source_path(path)
437
- self.source_files += shakaBuildHelpers.get_all_js_files(full_path)
438
-
439
- def build(self, force=False):
440
- """Build the documentation.
441
-
442
- Args:
443
- force: Build the docs even if the inputs have not changed.
444
-
445
- Returns:
446
- True on success; False on failure.
447
- """
448
- deps = self.source_files + [self.config_path]
449
- if not force and not _must_build(self.output, deps):
450
- return True
451
-
452
- base = _get_source_path('')
453
-
454
- # Wipe out any old docs.
455
- shutil.rmtree(os.path.join(base, 'docs', 'api'), ignore_errors=True)
456
-
457
- # Jsdoc expects to run from the base dir.
458
- with shakaBuildHelpers.InDir(base):
459
- jsdoc = shakaBuildHelpers.get_node_binary('jsdoc')
460
- cmd_line = jsdoc + ['-c', self.config_path]
461
- if shakaBuildHelpers.execute_get_code(cmd_line) != 0:
462
- return False
463
-
464
- return True
465
-
466
-
467
- class GenerateLocalizations(object):
468
- def __init__(self, locales):
469
- self.locales = locales
470
- self.source_files = shakaBuildHelpers.get_all_files(
471
- _get_source_path('ui/locales'))
472
- self.output = _get_source_path('dist/locales.js')
473
-
474
- def _locales_changed(self):
475
- # If locales is None, it means we are being called by a caller who doesn't
476
- # care what locales are in use. This is true, for example, when we are
477
- # running a compiler pass over the tests.
478
- if self.locales is None:
479
- return False
480
-
481
- # Find out what locales we used before. If they have changed, we must
482
- # regenerate the output.
483
- last_locales = None
484
- try:
485
- prefix = '// LOCALES: '
486
- with shakaBuildHelpers.open_file(self.output, 'r') as f:
487
- for line in f:
488
- if line.startswith(prefix):
489
- last_locales = line.replace(prefix, '').strip().split(', ')
490
- except IOError:
491
- # The file wasn't found or couldn't be read, so it needs to be redone.
492
- return True
493
-
494
- return set(last_locales) != set(self.locales)
495
-
496
- def generate(self, force=False):
497
- """Generate runtime localizations.
498
-
499
- Args:
500
- force: Generate the localizations even if the inputs and locales have not
501
- changed.
502
-
503
- Returns:
504
- True on success; False on failure.
505
- """
506
-
507
- if (not force and not _must_build(self.output, self.source_files) and
508
- not self._locales_changed()):
509
- return True
510
-
511
- locales = self.locales or ['en']
512
- generateLocalizations.main(['--locales'] + locales)
513
- return True