Files
blockly/scripts/gulpfiles/release_tasks.js
Christopher Allen 52a0d525d7 chore(build): Remove build products from the Blockly repository (#6475)
* feat(build): Make build tasks invoke their prerequisites

  - Divide gulp targets into three kinds: main sequence,
    manually invokable, and script-only.  The first two categories
    automatically invoke their prerequisites.
  - Give (most of) the affected gulp targets shorter and more memorable
    names that could become their npm script names in future.

* feat(build): Make package tasks invoke their prerequisites

  Have the package task invoke the cleanBuildDir (as well as
  cleanPackageDir) and build tasks.  Remove the checkBuildDir
  task as it is now redundant since a fresh build is done every
  time.

* feat(build): Make git tasks invoke their prerequisites

* feat(build): Make cleanup, license [sic] tasks invoke their prerequisites

  Turns out they don't have any, so this commit just classifies
  their gulp targets according to the established scheme.

* feat(build): Make appengine tasks invoke their prerequisites

  In this case prepareDeployDir will eventually depend on package
  but does not for now.

* feat(build): Have npm scripts run npm ci first where applicable

  Have any npm script that have external effects (e.g. publishing an
  npm package, pushing a new version to appengine, or updating GitHub
  Pages) start by running npm ci to ensure that all dependencies are
  up-to-date with respect to package-lock.json.

  (This is done by npm and not a gulp script because gulp itself
  might need updating.  So might npm, but that is less likely to
  make any difference to what gets published/pushed.)

* chore(build): have tests use package target

  Have the tests just run the package target (with debug flags)
  since that runs the the build target automatically.

* feat(tests): Write Closure Compiler output directly to dist/

  Since they are already UMD-wrapped, have Closure Compiler write
  output chunks directly to RELEASE_DIR, i.e. dist/.

* chore(tests): Use freshly-build files in compressed mode.

  Use the freshly-built build/*_compresssed.js files when bootstrapping
  in compressed mode, rather than using the checked-in files in the
  repository root.

  This helps ensure that compressed and uncompressed mode will be
  testing (as closely as possible) the same code.

  Obsoletes #6218 (though the issues discussed there have not actually
  yet been addressed in this branch).

* chore(build): Write intermediate langfiles to build/msg

  Write the results of create_messages.py to build/msg instead of
  build/msg/js.

* fix(build): Use build/msg/en.js instead of msg/messages.js in tests

  This has no direct effect but fixes a long-standing misdesign
  where we are testing against the input to, rather than the output
  of, the language file processing pipeline.

* feat(demos): Use freshly-built files

  Use the freshly-built dist/*_compresssed.js and build/msg/* files
  rather than using the checked-in files in the repository root.

  This helps ensure that these demos are using the most recent
  version of Blockly (even in the develop branch).

* fix(build): Update appengine deployment to include built files

  Modify the prepareDemos task as follows:

  - Use the git index instead of HEAD, so that most local changes
    will be applied (without copying whatever .gitignored cruft
    might be in the local directory).
  - Run clean and build and then copy build/msg and
    dist/*_compressed.js* to the deploy directory.

  This fixes the problem created by the previous commit, wherein the
  demos relied on built files that were not being deployed to
  appengine.

* fix(build): Update GitHub Pages deployment to include built files

  Modify the updateGithubPages task to run clean and build and
  then git add build/msg dist/*_compressed.js*, so that they will
  be included in the deployed pages.

  This fixes the problem created by the previous^2 commit,
  wherein the demos relied on built files that were not being
  deployed to GitHub Pages.

* chore(build): Remove build products from repository

  Remove *_compressed.js* and msg/js/* from the blockly repository.
  Also remove the now-obsolete checkinBuilt gulp task.

* chore(build): Apply relevant changes to test_tasks.js

  Apply changes made to run_all_tests.sh and check_metadata.sh to
  the corresponding parts of their JS replacements in
  test_tasks.js.

* chore(build): Make updates suggested in PR #6475

  - Remove `clean:builddir` and `clean:releasedir` - `clean`
    is sufficient.
  - Remove duplicate `require` from `appengine_tasks.js`.

* feat(build): Use shorter npm script names

  Since scripts that run build tasks now automatically run their
  prerequisite tasks, the previous naming scheme of task `build`
  running all the `build:subtask`s no longe really makes very
  much sense.

  Additionally, following a chat discussion, there seems to be a
  rough consensus to use "messages" to refer to the .json input
  files, and "langfiles" to the generated .js output files.

  Consequently, simplify npm script names by renaming as follows:

  - "generate:langfiles" -> "messages"
  - "build:langfiles" -> "langfiles"
  - "build:js" -> "tsc"
  - "build:deps" -> "deps"
  - "build:compiled" -> "minify"
  - "build:compressed": delete this synonym for "build:compiled",

  ("minify" was chosen as agnostic to Closure Compiler vs. WebPack.)

* chores(build): Add deprecation notice for old scripts

  To reduce potential confusion/frustration, restore the previous
  npm scripts but have them display a deprecation notice instead
  (note that npm prints the script contents before running it, so
  echo is not needed).

* docs(build): Add comments distinguishing 'messages' from 'langfiles'
2022-11-03 13:15:10 +00:00

184 lines
5.9 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 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'];
// 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();
}
// Rebuild, package and publish to npm.
const publish = gulp.series(
packageTasks.package, // Does clean + build.
checkBranch,
checkReleaseDir,
loginAndPublish
);
// Rebuild, package and publish a beta version of Blockly.
const publishBeta = gulp.series(
updateBetaVersion,
packageTasks.package, // Does clean + build.
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,
packageTasks.package, // Does clean + build.
gitTasks.pushRebuildBranch
);
module.exports = {
// Main sequence targets. Each should invoke any immediate prerequisite(s).
publishBeta,
publish,
// Legacy target, to be deleted.
recompile: recompileDevelop,
};