mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
Move package to scripts/package (#4045)
This commit is contained in:
@@ -36,7 +36,7 @@ function packageUMD(namespace, dependencies) {
|
||||
dependencies: function () { return dependencies; },
|
||||
namespace: function () { return namespace; },
|
||||
exports: function () { return namespace; },
|
||||
template: path.join(__dirname, `${blocklyRoot}/package/templates/umd.template`)
|
||||
template: path.join(__dirname, `${blocklyRoot}/scripts/package/templates/umd.template`)
|
||||
});
|
||||
};
|
||||
|
||||
@@ -50,7 +50,7 @@ function packageCommonJS(namespace, dependencies) {
|
||||
dependencies: function () { return dependencies; },
|
||||
namespace: function () { return namespace; },
|
||||
exports: function () { return namespace; },
|
||||
template: path.join(__dirname, `${blocklyRoot}/package/templates/node.template`)
|
||||
template: path.join(__dirname, `${blocklyRoot}/scripts/package/templates/node.template`)
|
||||
});
|
||||
};
|
||||
|
||||
@@ -73,11 +73,11 @@ function packageCompressed() {
|
||||
};
|
||||
|
||||
/**
|
||||
* This task wraps package/blockly.js into a UMD module.
|
||||
* This task wraps scripts/package/blockly.js into a UMD module.
|
||||
* @example import 'blockly/blockly';
|
||||
*/
|
||||
function packageBlockly() {
|
||||
return gulp.src('package/blockly.js')
|
||||
return gulp.src('scripts/package/blockly.js')
|
||||
.pipe(packageUMD('Blockly', [{
|
||||
name: 'Blockly',
|
||||
amd: './blockly_compressed',
|
||||
@@ -88,11 +88,11 @@ function packageBlockly() {
|
||||
};
|
||||
|
||||
/**
|
||||
* This task wraps package/blocks.js into a UMD module.
|
||||
* This task wraps scripts/package/blocks.js into a UMD module.
|
||||
* @example import 'blockly/blocks';
|
||||
*/
|
||||
function packageBlocks() {
|
||||
return gulp.src('package/blocks.js')
|
||||
return gulp.src('scripts/package/blocks.js')
|
||||
.pipe(packageUMD('Blockly.Blocks', [{
|
||||
name: 'Blockly',
|
||||
amd: './blocks_compressed',
|
||||
@@ -103,13 +103,13 @@ function packageBlocks() {
|
||||
};
|
||||
|
||||
/**
|
||||
* This task wraps package/index.js into a UMD module.
|
||||
* This task wraps scripts/package/index.js into a UMD module.
|
||||
* We implicitly require the Node entry point in CommonJS environments,
|
||||
* and the Browser entry point for AMD environments.
|
||||
* @example import * as Blockly from 'blockly';
|
||||
*/
|
||||
function packageIndex() {
|
||||
return gulp.src('package/index.js')
|
||||
return gulp.src('scripts/package/index.js')
|
||||
.pipe(packageUMD('Blockly', [{
|
||||
name: 'Blockly',
|
||||
amd: './browser',
|
||||
@@ -120,7 +120,7 @@ function packageIndex() {
|
||||
};
|
||||
|
||||
/**
|
||||
* This task wraps package/browser/index.js into a UMD module.
|
||||
* This task wraps scripts/package/browser/index.js into a UMD module.
|
||||
* By default, the module includes Blockly core and built-in blocks,
|
||||
* as well as the JavaScript code generator and the English block
|
||||
* localization files.
|
||||
@@ -129,7 +129,7 @@ function packageIndex() {
|
||||
* @example import * as Blockly from 'blockly/browser';
|
||||
*/
|
||||
function packageBrowser() {
|
||||
return gulp.src('package/browser/index.js')
|
||||
return gulp.src('scripts/package/browser/index.js')
|
||||
.pipe(packageUMD('Blockly', [{
|
||||
name: 'Blockly',
|
||||
amd: './core-browser',
|
||||
@@ -152,7 +152,7 @@ function packageBrowser() {
|
||||
};
|
||||
|
||||
/**
|
||||
* This task wraps package/browser/core.js into a UMD module.
|
||||
* This task wraps scripts/package/browser/core.js into a UMD module.
|
||||
* By default, the module includes the Blockly core package and a
|
||||
* helper method to set the locale.
|
||||
* This module is configured (in package.json) to replaces the module
|
||||
@@ -160,7 +160,7 @@ function packageBrowser() {
|
||||
* @example import * as Blockly from 'blockly/core';
|
||||
*/
|
||||
function packageCore() {
|
||||
return gulp.src('package/browser/core.js')
|
||||
return gulp.src('scripts/package/browser/core.js')
|
||||
.pipe(packageUMD('Blockly', [{
|
||||
name: 'Blockly',
|
||||
amd: './blockly',
|
||||
@@ -171,7 +171,7 @@ function packageCore() {
|
||||
};
|
||||
|
||||
/**
|
||||
* This task wraps package/node/index.js into a CommonJS module for Node.js.
|
||||
* This task wraps scripts/package/node/index.js into a CommonJS module for Node.js.
|
||||
* By default, the module includes Blockly core and built-in blocks,
|
||||
* as well as all the code generators and the English block localization files.
|
||||
* This module is configured (in package.json) to be replaced by the module
|
||||
@@ -179,7 +179,7 @@ function packageCore() {
|
||||
* @example import * as Blockly from 'blockly/node';
|
||||
*/
|
||||
function packageNode() {
|
||||
return gulp.src('package/node/index.js')
|
||||
return gulp.src('scripts/package/node/index.js')
|
||||
.pipe(packageCommonJS('Blockly', [{
|
||||
name: 'Blockly',
|
||||
cjs: './core',
|
||||
@@ -210,7 +210,7 @@ function packageNode() {
|
||||
};
|
||||
|
||||
/**
|
||||
* This task wraps package/node/core.js into a CommonJS module for Node.js.
|
||||
* This task wraps scripts/package/node/core.js into a CommonJS module for Node.js.
|
||||
* By default, the module includes the Blockly core package for Node.js
|
||||
* and a helper method to set the locale.
|
||||
* This module is configured (in package.json) to be replaced by the module
|
||||
@@ -218,7 +218,7 @@ function packageNode() {
|
||||
* @example import * as Blockly from 'blockly/core';
|
||||
*/
|
||||
function packageNodeCore() {
|
||||
return gulp.src('package/node/core.js')
|
||||
return gulp.src('scripts/package/node/core.js')
|
||||
.pipe(packageCommonJS('Blockly', [{
|
||||
name: 'Blockly',
|
||||
amd: './blockly',
|
||||
@@ -235,7 +235,7 @@ function packageNodeCore() {
|
||||
* @param {string} namespace Export namespace.
|
||||
*/
|
||||
function packageGenerator(file, rename, namespace) {
|
||||
return gulp.src(`package/${rename}`)
|
||||
return gulp.src(`scripts/package/${rename}`)
|
||||
.pipe(packageUMD(`Blockly${namespace}`, [{
|
||||
name: 'Blockly',
|
||||
amd: './core',
|
||||
@@ -348,11 +348,11 @@ function packageJSON(cb) {
|
||||
};
|
||||
|
||||
/**
|
||||
* This task copies the package/README.md file into the distribution directory.
|
||||
* This task copies the scripts/package/README.md file into the distribution directory.
|
||||
* This file is what developers will see at https://www.npmjs.com/package/blockly.
|
||||
*/
|
||||
function packageReadme() {
|
||||
return gulp.src('./package/README.md')
|
||||
return gulp.src('./scripts/package/README.md')
|
||||
.pipe(gulp.dest(`${packageDistribution}`));
|
||||
};
|
||||
|
||||
|
||||
77
scripts/package/README.md
Normal file
77
scripts/package/README.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# Blockly
|
||||
|
||||
Google's Blockly is a web-based, visual programming editor. Users can drag
|
||||
blocks together to build programs. All code is free and open source.
|
||||
|
||||
The source for this module is in the [Blockly repo](http://github.com/google/blockly).
|
||||
|
||||
## Installation
|
||||
|
||||
You can install this package either via ``npm`` or ``unpkg``.
|
||||
|
||||
### npm
|
||||
```bash
|
||||
npm install blockly
|
||||
```
|
||||
|
||||
### unpkg
|
||||
```html
|
||||
<script src="https://unpkg.com/blockly/blockly.min.js"></script>
|
||||
```
|
||||
|
||||
## Example Usage
|
||||
|
||||
```js
|
||||
import Blockly from 'blockly';
|
||||
Blockly.inject('blocklyDiv', {
|
||||
...
|
||||
})
|
||||
```
|
||||
|
||||
## Samples
|
||||
|
||||
For samples on how to integrate Blockly into your project, view the list of samples at [blockly-samples](https://github.com/google/blockly-samples).
|
||||
|
||||
|
||||
### Importing Blockly
|
||||
|
||||
When you import Blockly with ``import * as Blockly from 'blockly';`` you'll get the default modules:
|
||||
Blockly core, Blockly built-in blocks, the JavaScript generator and the English lang files.
|
||||
|
||||
If you need more flexibility, you'll want to define your imports more carefully:
|
||||
|
||||
#### Blockly Core
|
||||
|
||||
```js
|
||||
import * as Blockly from 'blockly/core';
|
||||
```
|
||||
|
||||
#### Blockly built in blocks
|
||||
|
||||
```js
|
||||
import 'blockly/blocks';
|
||||
```
|
||||
|
||||
#### Blockly Generators
|
||||
If your application needs to generate code from the Blockly blocks, you'll want to include a generator.
|
||||
|
||||
```js
|
||||
import 'blockly/python';
|
||||
```
|
||||
to include the Python generator, you can also import ``blockly/javascript``, ``blockly/php``, ``blockly/dart`` and ``blockly/lua``.
|
||||
|
||||
#### Blockly Languages
|
||||
|
||||
```js
|
||||
import * as Fr from 'blockly/msg/fr';
|
||||
Blockly.setLocale(Fr);
|
||||
```
|
||||
|
||||
To import the French lang files. Once you've imported the specific lang module, you'll also want to set the locale in Blockly.
|
||||
|
||||
For a full list of supported Blockly locales, see: [https://github.com/google/blockly/tree/master/msg/js](https://github.com/google/blockly/tree/master/msg/js)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Apache 2.0
|
||||
12
scripts/package/blockly.js
Normal file
12
scripts/package/blockly.js
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Blockly module.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
14
scripts/package/blocks.js
Normal file
14
scripts/package/blocks.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Blockly Blocks module.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
Blockly.Blocks = {};
|
||||
21
scripts/package/browser/core.js
Normal file
21
scripts/package/browser/core.js
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Blockly core module for the browser. It includes blockly.js
|
||||
* and adds a helper method for setting the locale.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
// Add a helper method to set the Blockly locale.
|
||||
Blockly.setLocale = function (locale) {
|
||||
Blockly.Msg = Blockly.Msg || {};
|
||||
Object.keys(locale).forEach(function (k) {
|
||||
Blockly.Msg[k] = locale[k];
|
||||
});
|
||||
};
|
||||
24
scripts/package/browser/index.js
Normal file
24
scripts/package/browser/index.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Blockly module for the browser. This includes Blockly core
|
||||
* and built in blocks, the JavaScript code generator and the English block
|
||||
* localization files.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
// Include the EN Locale by default.
|
||||
Blockly.setLocale(En);
|
||||
|
||||
Blockly.Blocks = Blockly.Blocks || {};
|
||||
Object.keys(BlocklyBlocks).forEach(function (k) {
|
||||
Blockly.Blocks[k] = BlocklyBlocks[k];
|
||||
});
|
||||
|
||||
Blockly.JavaScript = BlocklyJS;
|
||||
14
scripts/package/dart.js
Normal file
14
scripts/package/dart.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Dart Generator module.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
Blockly.Dart = BlocklyDart;
|
||||
12
scripts/package/index.js
Normal file
12
scripts/package/index.js
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Blockly module.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
14
scripts/package/javascript.js
Normal file
14
scripts/package/javascript.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview JavaScript Generator module.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
Blockly.JavaScript = BlocklyJavaScript;
|
||||
14
scripts/package/lua.js
Normal file
14
scripts/package/lua.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Lua Generator module.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
Blockly.Lua = BlocklyLua;
|
||||
33
scripts/package/node/core.js
Normal file
33
scripts/package/node/core.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Blockly core module for Node. It includes blockly-node.js
|
||||
* and adds a helper method for setting the locale.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
// Add a helper method to set the Blockly locale.
|
||||
Blockly.setLocale = function (locale) {
|
||||
Blockly.Msg = Blockly.Msg || {};
|
||||
Object.keys(locale).forEach(function (k) {
|
||||
Blockly.Msg[k] = locale[k];
|
||||
});
|
||||
};
|
||||
|
||||
// Override textToDomDocument and provide Node.js alternatives to DOMParser and
|
||||
// XMLSerializer.
|
||||
if (typeof Blockly.utils.global.document !== 'object') {
|
||||
Blockly.utils.global.DOMParser = require("jsdom/lib/jsdom/living").DOMParser;
|
||||
Blockly.utils.global.XMLSerializer = require("jsdom/lib/jsdom/living").XMLSerializer;
|
||||
var doc = Blockly.utils.xml.textToDomDocument(
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml"></xml>');
|
||||
Blockly.utils.xml.document = function() {
|
||||
return doc;
|
||||
};
|
||||
}
|
||||
31
scripts/package/node/index.js
Normal file
31
scripts/package/node/index.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Blockly module for Node. It includes Blockly core,
|
||||
* built-in blocks, all the generators and the English locale.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
// Include the EN Locale by default.
|
||||
Blockly.setLocale(En);
|
||||
|
||||
Blockly.Blocks = Blockly.Blocks || {};
|
||||
Object.keys(BlocklyBlocks).forEach(function (k) {
|
||||
Blockly.Blocks[k] = BlocklyBlocks[k];
|
||||
});
|
||||
|
||||
Blockly.JavaScript = BlocklyJS;
|
||||
|
||||
Blockly.Python = BlocklyPython;
|
||||
|
||||
Blockly.Lua = BlocklyLua;
|
||||
|
||||
Blockly.PHP = BlocklyPHP;
|
||||
|
||||
Blockly.Dart = BlocklyDart;
|
||||
14
scripts/package/php.js
Normal file
14
scripts/package/php.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview PHP Generator module.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
Blockly.PHP = BlocklyPHP;
|
||||
14
scripts/package/python.js
Normal file
14
scripts/package/python.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Python Generator module.
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
Blockly.Python = BlocklyPython;
|
||||
5
scripts/package/templates/node.template
Normal file
5
scripts/package/templates/node.template
Normal file
@@ -0,0 +1,5 @@
|
||||
/* eslint-disable */
|
||||
(function (<%= param %>){
|
||||
<%= contents %>
|
||||
module.exports = <%= exports %>;
|
||||
})(<%= cjs %>);
|
||||
13
scripts/package/templates/umd.template
Normal file
13
scripts/package/templates/umd.template
Normal file
@@ -0,0 +1,13 @@
|
||||
/* eslint-disable */
|
||||
;(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) { // AMD
|
||||
define(<%= amd %>, factory);
|
||||
} else if (typeof exports === 'object') { // Node.js
|
||||
module.exports = factory(<%= cjs %>);
|
||||
} else { // Browser
|
||||
root.<%= namespace %> = factory(<%= global %>);
|
||||
}
|
||||
}(this, function(<%= param %>) {
|
||||
<%= contents %>
|
||||
return <%= exports %>;
|
||||
}));
|
||||
Reference in New Issue
Block a user