/** * @license * Copyright 2018 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * @fileoverview Gulp script to build Blockly for Node & NPM. */ const gulp = require('gulp'); gulp.replace = require('gulp-replace'); gulp.rename = require('gulp-rename'); gulp.sourcemaps = require('gulp-sourcemaps'); const path = require('path'); const fs = require('fs'); const fsPromises = require('fs/promises'); const {exec, execSync} = require('child_process'); const {globSync} = require('glob'); const closureCompiler = require('google-closure-compiler').gulp(); const argv = require('yargs').argv; const {rimraf} = require('rimraf'); const {BUILD_DIR, LANG_BUILD_DIR, RELEASE_DIR, TSC_OUTPUT_DIR, TYPINGS_BUILD_DIR} = require('./config'); const {getPackageJson} = require('./helper_tasks'); const {posixPath, quote} = require('../helpers'); //////////////////////////////////////////////////////////// // Build // //////////////////////////////////////////////////////////// /** * Path to the python runtime. * This will normalize the command across platforms (e.g. python3 on Linux and * Mac, python on Windows). */ const PYTHON = process.platform === 'win32' ? 'python' : 'python3'; /** * Posix version of TSC_OUTPUT_DIR */ const TSC_OUTPUT_DIR_POSIX = posixPath(TSC_OUTPUT_DIR); /** * Suffix to add to compiled output files. */ const COMPILED_SUFFIX = '_compressed'; /** * Name of an object to be used as a shared "global" namespace by * chunks generated by the Closure Compiler with the * --rename_prefix_namespace option (see * https://github.com/google/closure-compiler/wiki/Chunk-output-for-dynamic-loading#using-global_namespace-as-the-chunk-output-type * for more information.) The wrapper for the first chunk will create * an object with this name and save it; wrappers for other chunks * will ensure that the same object is available with this same name. * The --rename_prefix_namespace option will then cause the compiled * chunks to create properties on this object instead of creating * "global" (really chunk-local) variables. This allows later chunks * to depend upon modules from earlier chunks. * * It can be any value that doesn't clash with a global variable or * wrapper argument, but as it will appear many times in the compiled * output it is preferable that it be short. */ const NAMESPACE_VARIABLE = '$'; /** * Property that will be used to store the value of the namespace * object on each chunk's exported object. This is so that dependent * chunks can retrieve the namespace object and thereby access modules * defined in the parent chunk (or it's parent, etc.). This should be * chosen so as to not collide with any exported name. */ const NAMESPACE_PROPERTY = '__namespace__'; /** * A list of chunks. Order matters: later chunks can depend on * earlier ones, but not vice-versa. All chunks are assumed to depend * on the first chunk. Properties are as follows: * * - .name: the name of the chunk. Used to label it when describing * it to Closure Compiler and forms the prefix of filename the chunk * will be written to. * - .files: A glob or array of globs, relative to TSC_OUTPUT_DIR, * matching the files to include in the chunk. * - .entry: the source .js file which is the entrypoint for the * chunk, relative to TSC_OUTPUT_DIR. * - .scriptExport: When the chunk is loaded as a script (e.g., via a *