mirror of
https://github.com/google/blockly.git
synced 2026-01-05 08:00:09 +01:00
Load dependency graph from tests/deps.js in uncompiled mode
* New gulp task buildDeps (npm run build:deps) to create tests/deps.js. * Old gulp task buildUncompressed is deleted. * blockly_uncompressed.js is now handwritten. * And simplified; in particular, BLOCKLY_BOOT is gone. * And linted! * For consistency with the Closure documentation and base.js, consistently refer to what blockly_uncompressed.js is used for as "uncompiled mode" rather than "uncompressed mode" (but don't yet rename it to blockly_uncompiled.js)
This commit is contained in:
@@ -330,84 +330,21 @@ const buildGenerators = gulp.parallel(
|
||||
);
|
||||
|
||||
/**
|
||||
* This task builds Blockly's uncompressed file.
|
||||
* blockly_uncompressed.js
|
||||
* This task updates tests/deps.js, used by blockly_uncompressed.js
|
||||
* when loading Blockly in uncompiled mode.
|
||||
*/
|
||||
function buildUncompressed() {
|
||||
function buildDeps(done) {
|
||||
const closurePath = argv.closureLibrary ?
|
||||
'node_modules/google-closure-library/closure/goog' :
|
||||
'closure/goog';
|
||||
const header = `// Do not edit this file; automatically generated by gulp.
|
||||
'use strict';
|
||||
|
||||
this.IS_NODE_JS = !!(typeof module !== 'undefined' && module.exports);
|
||||
|
||||
this.BLOCKLY_DIR = (function(root) {
|
||||
if (!root.IS_NODE_JS) {
|
||||
// Find name of current directory.
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
var re = new RegExp('(.+)[\\\/]blockly_(.*)uncompressed\\\.js$');
|
||||
for (var i = 0, script; script = scripts[i]; i++) {
|
||||
var match = re.exec(script.src);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
alert('Could not detect Blockly\\'s directory name.');
|
||||
}
|
||||
return '';
|
||||
})(this);
|
||||
|
||||
this.BLOCKLY_BOOT = function(root) {
|
||||
// Execute after Closure has loaded.
|
||||
`;
|
||||
const footer = `
|
||||
delete root.BLOCKLY_DIR;
|
||||
delete root.BLOCKLY_BOOT;
|
||||
delete root.IS_NODE_JS;
|
||||
};
|
||||
|
||||
if (this.IS_NODE_JS) {
|
||||
this.BLOCKLY_BOOT(this);
|
||||
module.exports = Blockly;
|
||||
} else {
|
||||
document.write('<script src="' + this.BLOCKLY_DIR +
|
||||
'/${closurePath}/base.js"></script>');
|
||||
document.write('<script>this.BLOCKLY_BOOT(this);</script>');
|
||||
}
|
||||
`;
|
||||
|
||||
let deps = [];
|
||||
return gulp.src(maybeAddClosureLibrary(['core/**/**/*.js']))
|
||||
.pipe(through2.obj((file, _enc, cb) => {
|
||||
const result = closureDeps.parser.parseFile(file.path);
|
||||
for (const dep of result.dependencies) {
|
||||
deps.push(dep);
|
||||
}
|
||||
cb(null);
|
||||
}))
|
||||
.on('end', () => {
|
||||
// Update the path to closure for any files that we don't know the full path
|
||||
// of (parsed from a goog.addDependency call).
|
||||
for (const dep of deps) {
|
||||
dep.setClosurePath(closurePath);
|
||||
}
|
||||
|
||||
const addDependency = closureDeps.depFile
|
||||
.getDepFileText(closurePath, deps)
|
||||
.replace(/\\/g, '\/');
|
||||
|
||||
const requires = `goog.addDependency("base.js", [], []);
|
||||
|
||||
// Load Blockly.
|
||||
goog.require('Blockly.requires');
|
||||
`;
|
||||
fs.writeFileSync('blockly_uncompressed.js',
|
||||
header +
|
||||
addDependency +
|
||||
requires +
|
||||
footer);
|
||||
});
|
||||
'node_modules/google-closure-library/closure/goog' :
|
||||
'closure/goog';
|
||||
const roots = [
|
||||
closurePath,
|
||||
'core',
|
||||
'blocks',
|
||||
];
|
||||
const args = roots.map(root => `--root '${root}' `).join('');
|
||||
execSync(`closure-make-deps ${args} > tests/deps.js`, {stdio: 'inherit'});
|
||||
done();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -517,10 +454,10 @@ function buildAdvancedCompilationTest() {
|
||||
* blockly_uncompressed.js
|
||||
*/
|
||||
const buildCore = gulp.parallel(
|
||||
buildCompressed,
|
||||
buildBlocks,
|
||||
buildUncompressed
|
||||
);
|
||||
buildDeps,
|
||||
buildCompressed,
|
||||
buildBlocks,
|
||||
);
|
||||
|
||||
/**
|
||||
* This task builds all of Blockly:
|
||||
@@ -535,10 +472,10 @@ const buildCore = gulp.parallel(
|
||||
* msg/json/*.js
|
||||
*/
|
||||
const build = gulp.parallel(
|
||||
buildCore,
|
||||
buildGenerators,
|
||||
buildLangfiles
|
||||
);
|
||||
buildCore,
|
||||
buildGenerators,
|
||||
buildLangfiles,
|
||||
);
|
||||
|
||||
/**
|
||||
* This task copies built files from BUILD_DIR back to the repository
|
||||
@@ -566,11 +503,11 @@ function cleanBuildDir(done) {
|
||||
|
||||
module.exports = {
|
||||
build: build,
|
||||
deps: buildDeps,
|
||||
core: buildCore,
|
||||
blocks: buildBlocks,
|
||||
generateLangfiles: generateLangfiles,
|
||||
langfiles: buildLangfiles,
|
||||
uncompressed: buildUncompressed,
|
||||
compressed: buildCompressed,
|
||||
generators: buildGenerators,
|
||||
checkinBuilt: checkinBuilt,
|
||||
|
||||
Reference in New Issue
Block a user