Move build and package directory config into new config.js

Make the destination directories for certain build/package/release
steps more easily (and centrally) configurable.

This only deals with building *_compressed* files;
blockly_uncompressed.js and the various msg/js/*.js files are not
affected by this commit.
This commit is contained in:
Christopher Allen
2021-06-18 13:38:58 +01:00
parent b348e18dfb
commit 082fd1fc6f
4 changed files with 89 additions and 61 deletions

View File

@@ -21,8 +21,8 @@ var through2 = require('through2');
var closureCompiler = require('google-closure-compiler').gulp(); var closureCompiler = require('google-closure-compiler').gulp();
var closureDeps = require('google-closure-deps'); var closureDeps = require('google-closure-deps');
var argv = require('yargs').argv; var argv = require('yargs').argv;
var { getPackageJson } = require('./helper_tasks'); var {BUILD_DIR} = require('./config');
var {getPackageJson} = require('./helper_tasks');
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Build // // Build //
@@ -217,7 +217,7 @@ function buildCompressed() {
})) }))
.pipe( .pipe(
gulp.sourcemaps.write('.', {includeContent: false, sourceRoot: './'})) gulp.sourcemaps.write('.', {includeContent: false, sourceRoot: './'}))
.pipe(gulp.dest('./')); .pipe(gulp.dest(BUILD_DIR));
}; };
/** /**
@@ -242,7 +242,7 @@ function buildBlocks() {
includeContent: false, includeContent: false,
sourceRoot: './' sourceRoot: './'
})) }))
.pipe(gulp.dest('./')); .pipe(gulp.dest(BUILD_DIR));
}; };
/** /**
@@ -268,7 +268,7 @@ function buildGenerator(language, namespace) {
includeContent: false, includeContent: false,
sourceRoot: './' sourceRoot: './'
})) }))
.pipe(gulp.dest('./')); .pipe(gulp.dest(BUILD_DIR));
}; };
/** /**

View File

@@ -0,0 +1,22 @@
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Common configuration for Gulp scripts.
*/
var path = require('path');
// Paths are all relative to the repository root. Do not include
// trailing slash.
module.exports = {
// Directory to write compiled output to.
BUILD_DIR: '.',
// Directory in which to assemble (and from which to publish) the
// blockly npm package.
RELEASE_DIR: 'dist',
};

View File

@@ -17,13 +17,11 @@ gulp.umd = require('gulp-umd');
var path = require('path'); var path = require('path');
var fs = require('fs'); var fs = require('fs');
var { getPackageJson } = require('./helper_tasks'); var {getPackageJson} = require('./helper_tasks');
var {BUILD_DIR, RELEASE_DIR} = require('./config');
const blocklyRoot = '../../';
// The destination path where all the NPM distribution files will go.
const packageDistribution = 'dist';
// Path to template files for gulp-umd.
const TEMPLATE_DIR = 'scripts/package/templates';
/** /**
* A helper method for wrapping a file into a Universal Module Definition. * A helper method for wrapping a file into a Universal Module Definition.
@@ -35,7 +33,7 @@ function packageUMD(namespace, dependencies) {
dependencies: function () { return dependencies; }, dependencies: function () { return dependencies; },
namespace: function () { return namespace; }, namespace: function () { return namespace; },
exports: function () { return namespace; }, exports: function () { return namespace; },
template: path.join(__dirname, `${blocklyRoot}/scripts/package/templates/umd.template`) template: path.join(TEMPLATE_DIR, 'umd.template')
}); });
}; };
@@ -49,26 +47,26 @@ function packageCommonJS(namespace, dependencies) {
dependencies: function () { return dependencies; }, dependencies: function () { return dependencies; },
namespace: function () { return namespace; }, namespace: function () { return namespace; },
exports: function () { return namespace; }, exports: function () { return namespace; },
template: path.join(__dirname, `${blocklyRoot}/scripts/package/templates/node.template`) template: path.join(TEMPLATE_DIR, 'node.template')
}); });
}; };
/** /**
* This task copies source files into the distribution directory. * This task copies source files into the release directory.
*/ */
function packageSources() { function packageSources() {
return gulp.src(['core/**/**.js', 'blocks/**.js', 'generators/**/**.js'], return gulp.src(['core/**/**.js', 'blocks/**.js', 'generators/**/**.js'],
{base: '.'}) {base: '.'})
.pipe(gulp.dest(packageDistribution)); .pipe(gulp.dest(RELEASE_DIR));
}; };
/** /**
* This task copies the compressed files and their source maps into the * This task copies the compressed files and their source maps into
* distribution directory. * the release directory.
*/ */
function packageCompressed() { function packageCompressed() {
return gulp.src('*_compressed.js?(.map)') return gulp.src('*_compressed.js?(.map)', {cwd: BUILD_DIR})
.pipe(gulp.dest(packageDistribution)); .pipe(gulp.dest(RELEASE_DIR));
}; };
/** /**
@@ -83,7 +81,7 @@ function packageBlockly() {
cjs: './blockly_compressed', cjs: './blockly_compressed',
}])) }]))
.pipe(gulp.rename('blockly.js')) .pipe(gulp.rename('blockly.js'))
.pipe(gulp.dest(packageDistribution)); .pipe(gulp.dest(RELEASE_DIR));
}; };
/** /**
@@ -98,7 +96,7 @@ function packageBlocks() {
cjs: './blocks_compressed', cjs: './blocks_compressed',
}])) }]))
.pipe(gulp.rename('blocks.js')) .pipe(gulp.rename('blocks.js'))
.pipe(gulp.dest(packageDistribution)); .pipe(gulp.dest(RELEASE_DIR));
}; };
/** /**
@@ -115,7 +113,7 @@ function packageIndex() {
cjs: './node', cjs: './node',
}])) }]))
.pipe(gulp.rename('index.js')) .pipe(gulp.rename('index.js'))
.pipe(gulp.dest(packageDistribution)); .pipe(gulp.dest(RELEASE_DIR));
}; };
/** /**
@@ -147,7 +145,7 @@ function packageBrowser() {
cjs: './javascript', cjs: './javascript',
}])) }]))
.pipe(gulp.rename('browser.js')) .pipe(gulp.rename('browser.js'))
.pipe(gulp.dest(packageDistribution)); .pipe(gulp.dest(RELEASE_DIR));
}; };
/** /**
@@ -166,7 +164,7 @@ function packageCore() {
cjs: './blockly', cjs: './blockly',
}])) }]))
.pipe(gulp.rename('core-browser.js')) .pipe(gulp.rename('core-browser.js'))
.pipe(gulp.dest(packageDistribution)); .pipe(gulp.dest(RELEASE_DIR));
}; };
/** /**
@@ -205,7 +203,7 @@ function packageNode() {
cjs: './dart', cjs: './dart',
}])) }]))
.pipe(gulp.rename('node.js')) .pipe(gulp.rename('node.js'))
.pipe(gulp.dest(packageDistribution)); .pipe(gulp.dest(RELEASE_DIR));
}; };
/** /**
@@ -224,7 +222,7 @@ function packageNodeCore() {
cjs: './blockly', cjs: './blockly',
}])) }]))
.pipe(gulp.rename('core.js')) .pipe(gulp.rename('core.js'))
.pipe(gulp.dest(packageDistribution)); .pipe(gulp.dest(RELEASE_DIR));
}; };
/** /**
@@ -245,7 +243,7 @@ function packageGenerator(file, rename, namespace) {
cjs: `./${file}`, cjs: `./${file}`,
}])) }]))
.pipe(gulp.rename(rename)) .pipe(gulp.rename(rename))
.pipe(gulp.dest(packageDistribution)); .pipe(gulp.dest(RELEASE_DIR));
}; };
/** /**
@@ -303,7 +301,7 @@ function packageLocales() {
amd: '../core', amd: '../core',
cjs: '../core', cjs: '../core',
}])) }]))
.pipe(gulp.dest(`${packageDistribution}/msg`)); .pipe(gulp.dest(`${RELEASE_DIR}/msg`));
}; };
/** /**
@@ -314,60 +312,63 @@ function packageLocales() {
*/ */
function packageUMDBundle() { function packageUMDBundle() {
var srcs = [ var srcs = [
'blockly_compressed.js', `${BUILD_DIR}/blockly_compressed.js`,
'msg/js/en.js', 'msg/js/en.js',
'blocks_compressed.js', `${BUILD_DIR}/blocks_compressed.js`,
'javascript_compressed.js' `${BUILD_DIR}/javascript_compressed.js`,
]; ];
return gulp.src(srcs) return gulp.src(srcs)
.pipe(gulp.concat('blockly.min.js')) .pipe(gulp.concat('blockly.min.js'))
.pipe(gulp.dest(`${packageDistribution}`)) .pipe(gulp.dest(`${RELEASE_DIR}`));
}; };
/** /**
* This task copies all the media/* files into the distribution directory. * This task copies all the media/* files into the release directory.
*/ */
function packageMedia() { function packageMedia() {
return gulp.src('./media/*') return gulp.src('media/*')
.pipe(gulp.dest(`${packageDistribution}/media`)); .pipe(gulp.dest(`${RELEASE_DIR}/media`));
}; };
/** /**
* This task copies the package.json file into the distribution directory. * This task copies the package.json file into the release directory.
*/ */
function packageJSON(cb) { function packageJSON(cb) {
const packageJson = getPackageJson(); const packageJson = getPackageJson();
const json = Object.assign({}, packageJson); const json = Object.assign({}, packageJson);
delete json['scripts']; delete json['scripts'];
if (!fs.existsSync(packageDistribution)) { if (!fs.existsSync(RELEASE_DIR)) {
fs.mkdirSync(packageDistribution); fs.mkdirSync(RELEASE_DIR);
} }
fs.writeFileSync(`${packageDistribution}/package.json`, fs.writeFileSync(`${RELEASE_DIR}/package.json`,
JSON.stringify(json, null, 2)); JSON.stringify(json, null, 2));
cb(); cb();
}; };
/** /**
* This task copies the scripts/package/README.md file into the distribution directory. * This task copies the scripts/package/README.md file into the
* This file is what developers will see at https://www.npmjs.com/package/blockly. * release directory. This file is what developers will see at
* https://www.npmjs.com/package/blockly .
*/ */
function packageReadme() { function packageReadme() {
return gulp.src('./scripts/package/README.md') return gulp.src('scripts/package/README.md')
.pipe(gulp.dest(`${packageDistribution}`)); .pipe(gulp.dest(`${RELEASE_DIR}`));
}; };
/** /**
* This task copies the typings/blockly.d.ts TypeScript definition file into the * This task copies the typings/blockly.d.ts TypeScript definition
* distribution directory. * file into the release directory. The bundled declaration file is
* The bundled declaration file is referenced in package.json in the types property. * referenced in package.json in the types property.
*/ */
function packageDTS() { function packageDTS() {
return gulp.src(['./typings/*.d.ts', './typings/msg/*.d.ts'], {base: './typings'}) return gulp.src(['typings/*.d.ts', 'typings/msg/*.d.ts'],
.pipe(gulp.dest(`${packageDistribution}`)); {base: './typings'})
.pipe(gulp.dest(`${RELEASE_DIR}`));
}; };
/** /**
* This task prepares the NPM distribution files under the /dist directory. * This task prepares the files to be included in the NPM by copying
* them into the release directory.
*/ */
const package = gulp.parallel( const package = gulp.parallel(
packageIndex, packageIndex,

View File

@@ -17,9 +17,9 @@ var typings = require('./typings');
var buildTasks = require('./build_tasks'); var buildTasks = require('./build_tasks');
var gitTasks = require('./git_tasks'); var gitTasks = require('./git_tasks');
var packageTasks = require('./package_tasks'); var packageTasks = require('./package_tasks');
var { getPackageJson } = require('./helper_tasks'); var {getPackageJson} = require('./helper_tasks');
var {RELEASE_DIR} = require('./config');
const RELEASE_DIR = 'dist';
// Gets the current major version. // Gets the current major version.
function getMajorVersion() { function getMajorVersion() {
@@ -80,20 +80,25 @@ function checkBranch(done) {
} }
// Sanity check that the dist folder exists, and that certain files are in the dist folder. // Sanity check that the RELASE_DIR directory exists, and that certain
function checkDist(done) { // files are in it.
const sanityFiles = ['blockly_compressed.js', 'blocks_compressed.js', 'core', 'blocks', 'generators']; function checkReleaseDir(done) {
// Check that dist exists. const sanityFiles = ['blockly_compressed.js', 'blocks_compressed.js',
'core', 'blocks', 'generators'];
// Check that directory exists.
if (fs.existsSync(RELEASE_DIR)) { if (fs.existsSync(RELEASE_DIR)) {
// Sanity check that certain files exist in dist. // Sanity check that certain files exist in RELASE_DIR.
sanityFiles.forEach((fileName) => { sanityFiles.forEach((fileName) => {
if (!fs.existsSync(`${RELEASE_DIR}/${fileName}`)) { if (!fs.existsSync(`${RELEASE_DIR}/${fileName}`)) {
done(new Error(`Your dist folder does not contain:${fileName}`)); done(new Error(
`Your ${RELEASE_DIR} directory does not contain ${fileName}`));
return;
} }
}); });
done(); done();
} else { } else {
done(new Error('The dist directory does not exist. Is packageTasks.package being run?')); done(new Error(`The ${RELEASE_DIR} directory does not exist. ` +
'Has packageTasks.package been run?'));
} }
} }
@@ -148,7 +153,7 @@ function updateBetaVersion(done) {
const publish = gulp.series( const publish = gulp.series(
packageTasks.package, packageTasks.package,
checkBranch, checkBranch,
checkDist, checkReleaseDir,
loginAndPublish loginAndPublish
); );
@@ -158,7 +163,7 @@ const publishBeta = gulp.series(
buildTasks.build, buildTasks.build,
packageTasks.package, packageTasks.package,
checkBranch, checkBranch,
checkDist, checkReleaseDir,
loginAndPublishBeta loginAndPublishBeta
); );