From 6170b770274df0823a8df274fc2e06b5cacb1a72 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Thu, 24 Oct 2019 11:11:03 -0400 Subject: [PATCH] Add langfiles build task in gulp (#3331) * Add build-langfiles to gulp, and add uncompressed + langfiles to build when building all --- gulpfile.js | 44 ++++++++++++++++++++++++++++++++++++++------ package.json | 4 ++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 8959fbc42..f57d6a33c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -238,7 +238,7 @@ gulp.task('build-dart', function() { * blockly_uncompressed.js */ gulp.task('build-uncompressed', function() { - const header = `// Do not edit this file; automatically generated by build.py. + const header = `// Do not edit this file; automatically generated by gulp. 'use strict'; this.IS_NODE_JS = !!(typeof module !== 'undefined' && module.exports); @@ -272,9 +272,6 @@ if (this.IS_NODE_JS) { this.BLOCKLY_BOOT(this); module.exports = Blockly; } else { - // Delete any existing Closure (e.g. Soy's nogoog_shim). - document.write(''); - // Load fresh Closure Library. document.write(''); document.write(''); @@ -286,13 +283,15 @@ if (this.IS_NODE_JS) { --root_with_prefix="./core ../core" > ${file}`; execSync(cmd, { stdio: 'inherit' }); - const requires = `\n// Load Blockly.\ngoog.require('Blockly.requires');\n`; + const requires = `goog.addDependency("base.js", [], []);\n\n// Load Blockly.\ngoog.require('Blockly.requires')\n`; return gulp.src(file) // Remove comments so we're compatible with the build.py script .pipe(gulp.replace(/\/\/.*\n/gm, '')) // Replace quotes to be compatible with build.py .pipe(gulp.replace(/\'(.*\.js)\'/gm, '"$1"')) + // Remove last parameter to be compatible with build.py + .pipe(gulp.replace(/, \{\}\);/gm, ');')) // Find the Blockly directory name and replace it with a JS variable. // This allows blockly_uncompressed.js to be compiled on one computer and be // used on another, even if the directory name differs. @@ -301,6 +300,35 @@ if (this.IS_NODE_JS) { .pipe(gulp.dest('./')); }); +/** + * This task builds Blockly's lang files. + * msg/*.js + */ +gulp.task('build-langfiles', function(done) { + // Run js_to_json.py + const jsToJsonCmd = `python ./i18n/js_to_json.py \ +--input_file ${path.join('msg', 'messages.js')} \ +--output_dir ${path.join('msg', 'json')} \ +--quiet`; + execSync(jsToJsonCmd, { stdio: 'inherit' }); + + // Run create_messages.py + let json_files = fs.readdirSync(path.join('msg', 'json')); + json_files = json_files.filter(file => file.endsWith('json') && + !(new RegExp(/(keys|synonyms|qqq|constants)\.json$/).test(file))); + json_files = json_files.map(file => path.join('msg', 'json', file)); + const createMessagesCmd = `python ./i18n/create_messages.py \ + --source_lang_file ${path.join('msg', 'json', 'en.json')} \ + --source_synonym_file ${path.join('msg', 'json', 'synonyms.json')} \ + --source_constants_file ${path.join('msg', 'json', 'constants.json')} \ + --key_file ${path.join('msg', 'json', 'keys.json')} \ + --output_dir ${path.join('msg', 'js')} \ + --quiet ${json_files.join(' ')}`; + execSync(createMessagesCmd, { stdio: 'inherit' }); + + done(); +}); + /** * This task builds all of Blockly: * blockly_compressed.js @@ -310,6 +338,8 @@ if (this.IS_NODE_JS) { * php_compressed.js * lua_compressed.js * dart_compressed.js + * blockly_uncompressed.js + * msg/json/*.js */ gulp.task('build', gulp.parallel( 'build-core', @@ -318,7 +348,9 @@ gulp.task('build', gulp.parallel( 'build-python', 'build-php', 'build-lua', - 'build-dart' + 'build-dart', + 'build-uncompressed', + 'build-langfiles' )); //////////////////////////////////////////////////////////// diff --git a/package.json b/package.json index d03df46a2..da8364912 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,11 @@ }, "scripts": { "build": "gulp build", + "build:blocks": "gulp build-blocks", + "build:core": "gulp build-core", "build:debug": "gulp build-core --verbose > build-debug.log 2>&1 && tail -3 -r build-debug.log", + "build:langfiles": "gulp build-langfiles", + "build:uncompressed": "gulp build-uncompressed", "bump": "npm version 3.$(date +'%Y%m%d').0", "lint": "eslint .", "package": "gulp package",