Adding gulpfile to build Node.js compatible library. (#1847)

The gulp file is derived from work in PR #887, with numerous
refinements and clarifying comments.

Also updating the version number in package.json, including the
'develop' prerelease tag for the develop branch.
This commit is contained in:
Andrew n marshall
2018-05-11 15:19:47 -07:00
committed by GitHub
parent ad16a1fd6f
commit 2e8c29de45
4 changed files with 115 additions and 3 deletions

View File

@@ -1,5 +1,7 @@
*_compressed*.js
*_uncompressed*.js
blockly_node_javascript_en.js
gulpfile.js
/msg/*
/core/css.js
/tests/blocks/*

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
blockly_node_javascript_en.js
node_modules
npm-debug.log
.DS_Store

102
gulpfile.js Normal file
View File

@@ -0,0 +1,102 @@
/**
* @license
* Visual Blocks Editor
*
* Copyright 2018 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Gulp script to build Blockly for Node & NPM.
* Run this script by calling "npm install" in this directory.
*/
var gulp = require('gulp');
gulp.shell = require('gulp-shell');
gulp.concat = require('gulp-concat');
var insert = require('gulp-insert');
// Rebuilds Blockly, including the following:
// - blockly_compressed.js
// - blocks_compressed.js
// - Localization string tables in msg/js/*.js
// - Generators in generators/*.js
// These files are already up-to-date in the master branch.
gulp.task('build', gulp.shell.task([
'python build.py'
]));
// Concatenates the necessary files to load Blockly in a Node.js VM. Blockly's
// inidividual libraries target use in a browser, where globals (via the window
// objects) are used to share state and APIs. By concatenating all the
// necessary components into a single file, Blockly can be loaded as a Node.js
// module.
//
// This task builds Node with the assumption that the app needs English blocks
// and JavaScript code generation. If you need another localization or
// generator language, just copy and edit the srcs. Only one localization
// language can be included.
gulp.task('blockly_javascript_en', ['build'], function() {
var srcs = [
'blockly_compressed.js',
'blocks_compressed.js',
'javascript_compressed.js',
'msg/js/en.js'
];
// Concatenate the sources, appending the module export at the bottom.
return gulp.src(srcs)
.pipe(gulp.concat('blockly_node_javascript_en.js'))
.pipe(insert.append(`
if (typeof module === 'object') { module.exports = Blockly; }
if (typeof window === 'object') { window.Blockly = Blockly; }\n`))
.pipe(gulp.dest(''));
});
/**
* Task-builder for the watch function. Currently any change invokes the whole
* build script. Invoke with "gulp watch".
*
* @param {?string=} concatTask Name of the concatenating task for node usage.
*/
// TODO: Only run the necessary phases of the build script for a given change.
function buildWatchTaskFn(concatTask) {
return function() {
// Tasks to trigger.
var tasks = ['build'];
if (concatTask) {
tasks.push(concatTask);
}
// Currently any changes invokes the whole build script. (To fix.)
var srcs = [
'core/**/*.js', // Blockly core code
'blocks/*.js', // Block definitions
'generators/**/*.js', // Code generation
'msg/messages.js', 'msg/json/*.json' // Localization data
];
var options = {
debounceDelay: 2000 // Milliseconds to delay rebuild.
};
gulp.watch(srcs, options, tasks);
};
}
// Watch Blockly files for changes and trigger automatic rebuilds, including
// the Node-ready blockly_node_javascript_en.js file.
gulp.task('watch', buildWatchTaskFn('blockly_javascript_en'));
// The default task concatenates files for Node.js, using English language
// blocks and the JavaScript generator.
gulp.task('default', ['blockly_javascript_en']);

View File

@@ -1,7 +1,8 @@
{
"name": "blockly",
"version": "1.0.0",
"version": "1.20180420.0-develop",
"description": "Blockly is a library for building visual programming editors.",
"main": "blockly_node_javascript_en.js",
"keywords": [
"blockly"
],
@@ -17,6 +18,7 @@
"name": "Neil Fraser"
},
"scripts": {
"prepare": "gulp default",
"lint": "eslint .",
"pretest": "tests/scripts/test_setup.sh",
"test": "node tests/test_runner.js"
@@ -24,8 +26,12 @@
"license": "Apache-2.0",
"private": true,
"devDependencies": {
"jshint": "latest",
"eslint": "^4.16"
"eslint": "^4.16",
"gulp-concat": "^2.6.1",
"gulp-insert": "^0.5.0",
"gulp-series": "^1.0.2",
"gulp-shell": "^0.6.5",
"jshint": "^2.9.5"
},
"jshintConfig": {
"globalstrict": true,
@@ -43,6 +49,7 @@
},
"dependencies": {
"google-closure-library": "^20180204.0.0",
"gulp": "^3.9.1",
"install": "^0.8.8",
"npm": "^4.4.4",
"webdriverio": "^4.6.2"