mirror of
https://github.com/google/blockly.git
synced 2026-01-09 18:10:08 +01:00
- Reconfigure package_tasks.js to use BUILD_DIR from config.js
(i.e., build/) rather than repository root as source of files to
package.
- Add check to packageTasks.package to ensure that certain required
files exist in BUILD_DIR, to verify that buildTasks.build and
typings.typings have been run.
- Fix packageUMDBundle to use generated, rather than checked-in
version of en.js.
- Fix packageDTS to use the generated (rather than checked-in)
versions of blockly.d.ts and msg/*.d.ts.
- Modify run_all_tests.sh to run packageTasks.package before running
node tests, since they depend on it. Previously this was only
working because 'npm install' runs the 'prepare' script, which would
run the 'package' script - so the code being tested by the node tests
was not the current source but whatever precomipled code had
previously been checked in.
- Remove the 'prepare' script from package.json, since it is no longer
needed (and is now broken, since it requires that build and typings
have been done first.) Note that no scripts at all are included in
the version of package.json that is created in dist/ and subsequently
included in the published npms, so this deletion does not affect what
happens when the Blockly npm in installed - it only affects what
happens when 'npm install' is run after the blockly repo is cloned.
- Factor out the actual recompilation steps from releaseTasks.recompile.
- Rename releaseTasks.recomple to recompileDevelop, since it deals
specifically with the develop branch. (The npm script name is
unchanged.)
- Ensure that a full recompile and repackage is done before publishing
(beta and non-beta) npms.
195 lines
6.0 KiB
JavaScript
195 lines
6.0 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2020 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Gulp scripts for releasing Blockly.
|
|
*/
|
|
|
|
var execSync = require('child_process').execSync;
|
|
var fs = require('fs');
|
|
var gulp = require('gulp');
|
|
var readlineSync = require('readline-sync');
|
|
var typings = require('./typings');
|
|
|
|
var buildTasks = require('./build_tasks');
|
|
var gitTasks = require('./git_tasks');
|
|
var packageTasks = require('./package_tasks');
|
|
var {getPackageJson} = require('./helper_tasks');
|
|
var {RELEASE_DIR} = require('./config');
|
|
|
|
|
|
// Gets the current major version.
|
|
function getMajorVersion() {
|
|
var { version } = getPackageJson();
|
|
var re = new RegExp(/^(\d)./);
|
|
var match = re.exec(version);
|
|
if (!match[0]) {
|
|
return null;
|
|
}
|
|
console.log(match[0]);
|
|
return parseInt(match[0]);
|
|
}
|
|
|
|
// Updates the version depending on user input.
|
|
function updateVersion(done, updateType) {
|
|
var majorVersion = getMajorVersion();
|
|
if (!majorVersion) {
|
|
done(new Error('Something went wrong when getting the major version number.'));
|
|
} else if (!updateType) {
|
|
// User selected to cancel.
|
|
done(new Error('Cancelling process.'));
|
|
}
|
|
|
|
switch (updateType.toLowerCase()) {
|
|
case 'major':
|
|
majorVersion++;
|
|
execSync(`npm --no-git-tag-version version ${majorVersion}.$(date +'%Y%m%d').0`, {stdio: 'inherit'});
|
|
done();
|
|
break;
|
|
case 'minor':
|
|
execSync(`npm --no-git-tag-version version ${majorVersion}.$(date +'%Y%m%d').0`, {stdio: 'inherit'});
|
|
done();
|
|
break;
|
|
case 'patch':
|
|
execSync(`npm --no-git-tag-version version patch`, {stdio: 'inherit'});
|
|
done();
|
|
break;
|
|
default:
|
|
done(new Error('Unexpected update type was chosen.'))
|
|
}
|
|
}
|
|
|
|
// Prompt the user to figure out what kind of version update we should do.
|
|
function updateVersionPrompt(done) {
|
|
var releaseTypes = ['Major', 'Minor', 'Patch'];
|
|
var index = readlineSync.keyInSelect(releaseTypes, 'Which version type?');
|
|
updateVersion(done, releaseTypes[index]);
|
|
}
|
|
|
|
// Checks with the user that they are on the correct git branch.
|
|
function checkBranch(done) {
|
|
var gitBranchName = execSync('git rev-parse --abbrev-ref HEAD').toString();
|
|
if (readlineSync.keyInYN(`You are on '${gitBranchName.trim()}'. Is this the correct branch?`)) {
|
|
done();
|
|
} else {
|
|
done(new Error('Not on correct branch'));
|
|
}
|
|
}
|
|
|
|
|
|
// Sanity check that the RELASE_DIR directory exists, and that certain
|
|
// files are in it.
|
|
function checkReleaseDir(done) {
|
|
const sanityFiles = ['blockly_compressed.js', 'blocks_compressed.js',
|
|
'core', 'blocks', 'generators'];
|
|
// Check that directory exists.
|
|
if (fs.existsSync(RELEASE_DIR)) {
|
|
// Sanity check that certain files exist in RELASE_DIR.
|
|
sanityFiles.forEach((fileName) => {
|
|
if (!fs.existsSync(`${RELEASE_DIR}/${fileName}`)) {
|
|
done(new Error(
|
|
`Your ${RELEASE_DIR} directory does not contain ${fileName}`));
|
|
return;
|
|
}
|
|
});
|
|
done();
|
|
} else {
|
|
done(new Error(`The ${RELEASE_DIR} directory does not exist. ` +
|
|
'Has packageTasks.package been run?'));
|
|
}
|
|
}
|
|
|
|
// Check with the user that the version number is correct, then login and publish to npm.
|
|
function loginAndPublish_(done, isBeta) {
|
|
var { version } = getPackageJson();
|
|
if(readlineSync.keyInYN(`You are about to publish blockly with the version number:${version}. Do you want to continue?`)) {
|
|
execSync(`npm login --registry https://wombat-dressing-room.appspot.com`, {stdio: 'inherit'});
|
|
execSync(`npm publish --registry https://wombat-dressing-room.appspot.com ${isBeta ? '--tag beta' : ''}`, {cwd: RELEASE_DIR, stdio: 'inherit'});
|
|
done();
|
|
} else {
|
|
done(new Error('User quit due to the version number not being correct.'));
|
|
}
|
|
}
|
|
|
|
// Login and publish.
|
|
function loginAndPublish(done) {
|
|
return loginAndPublish_(done, false);
|
|
}
|
|
|
|
// Login and publish the beta version.
|
|
function loginAndPublishBeta(done) {
|
|
return loginAndPublish_(done, true);
|
|
}
|
|
|
|
// Repeatedly prompts the user for a beta version number until a valid one is given.
|
|
// A valid version number must have '-beta.x' and can not have already been used to publish to npm.
|
|
function updateBetaVersion(done) {
|
|
var isValid = false;
|
|
var newVersion = null;
|
|
var blocklyVersions = JSON.parse(execSync('npm view blockly versions --json').toString());
|
|
var re = new RegExp(/-beta\.(\d)/);
|
|
var latestBetaVersion = execSync('npm show blockly version --tag beta').toString().trim();
|
|
while(!isValid) {
|
|
newVersion = readlineSync.question(`What is the new beta version? (latest beta version: ${latestBetaVersion})`);
|
|
var existsOnNpm = blocklyVersions.indexOf(newVersion) > -1;
|
|
var isFormatted = newVersion.search(re) > -1;
|
|
if (!existsOnNpm && isFormatted) {
|
|
isValid = true;
|
|
} else if (existsOnNpm) {
|
|
console.log("This version already exists. Please enter a new version.");
|
|
} else if (!isFormatted) {
|
|
console.log("To publish a beta version you must have -beta.x in the version.");
|
|
}
|
|
}
|
|
// Allow the same version here, since we already check the version does not exist on npm.
|
|
execSync(`npm --no-git-tag-version --allow-same-version version ${newVersion}`, {stdio: 'inherit'});
|
|
done();
|
|
}
|
|
|
|
// Build Blockly and prepare to check in the resulting built files.
|
|
const recompile = gulp.series(
|
|
buildTasks.cleanBuildDir,
|
|
buildTasks.build,
|
|
buildTasks.checkinBuilt,
|
|
typings.typings,
|
|
typings.checkinTypings,
|
|
);
|
|
|
|
// Package and publish to npm.
|
|
const publish = gulp.series(
|
|
recompile,
|
|
packageTasks.package,
|
|
checkBranch,
|
|
checkReleaseDir,
|
|
loginAndPublish
|
|
);
|
|
|
|
// Publish a beta version of Blockly.
|
|
const publishBeta = gulp.series(
|
|
updateBetaVersion,
|
|
recompile,
|
|
packageTasks.package,
|
|
checkBranch,
|
|
checkReleaseDir,
|
|
loginAndPublishBeta
|
|
);
|
|
|
|
// Switch to a new branch, update the version number, build Blockly
|
|
// and check in the resulting built files.
|
|
const recompileDevelop = gulp.series(
|
|
gitTasks.syncDevelop(),
|
|
gitTasks.createRebuildBranch,
|
|
updateVersionPrompt,
|
|
recompile,
|
|
gitTasks.pushRebuildBranch
|
|
);
|
|
|
|
module.exports = {
|
|
recompile: recompileDevelop,
|
|
publishBeta: publishBeta,
|
|
publish: publish
|
|
}
|