The default behavior of the build task is to now apply the -snapshot suffix dynamically rather than us manually hardcoding and managing it within the source code itself. The `--release` flag will drop the -snapshot suffix on a build, which should be used for any release candidate. The default behavior of the build task has also changed to create rpm/deb packages as well. Since we've only confirmed that this works on linux, you can override that behavior by passing `skip-os-packages`. If you do not want to create any zip or tar.gz archives, you can pass `--skip-archives`.
57 lines
2 KiB
JavaScript
57 lines
2 KiB
JavaScript
import { execFileSync } from 'child_process';
|
|
import { readFileSync, writeFileSync } from 'fs';
|
|
import { join } from 'path';
|
|
|
|
export default (grunt) => {
|
|
grunt.registerTask('_rebuild:updateBuilds', function () {
|
|
const buildDir = grunt.config.get('buildDir');
|
|
|
|
const { newVersion, newBuildNum, newSha } = grunt.config.get('rebuild');
|
|
|
|
grunt.file.expand({ cwd: buildDir }, '*').forEach(build => {
|
|
const thisBuildDir = join(buildDir, build);
|
|
const thisBundlesDir = join(thisBuildDir, 'optimize', 'bundles');
|
|
|
|
const readmePath = join(thisBuildDir, 'README.txt');
|
|
const pkgjsonPath = join(thisBuildDir, 'package.json');
|
|
const bundlePaths = [
|
|
...grunt.file.expand({ cwd: thisBundlesDir }, '*.bundle.js'),
|
|
...grunt.file.expand({ cwd: thisBundlesDir }, '*.entry.js')
|
|
];
|
|
|
|
const { oldBuildNum, oldSha, oldVersion } = readBuildInfo(pkgjsonPath);
|
|
|
|
replaceIn(readmePath, oldVersion, newVersion);
|
|
replaceIn(pkgjsonPath, oldVersion, newVersion);
|
|
replaceIn(pkgjsonPath, `"number": ${oldBuildNum},`, `"number": ${newBuildNum},`);
|
|
replaceIn(pkgjsonPath, oldSha, newSha);
|
|
bundlePaths
|
|
.map(bundle => join(thisBundlesDir, bundle))
|
|
.forEach(file => {
|
|
replaceIn(file, `"kbnVersion":"${oldVersion}"`, `"kbnVersion":"${newVersion}"`);
|
|
replaceIn(file, `"buildNum":${oldBuildNum}`, `"buildNum":${newBuildNum}`);
|
|
});
|
|
|
|
const newBuild = build.replace(oldVersion, newVersion);
|
|
if (build !== newBuild) {
|
|
execFileSync('mv', [ build, newBuild ], { cwd: buildDir });
|
|
}
|
|
});
|
|
});
|
|
};
|
|
|
|
function readBuildInfo(path) {
|
|
const pkgjson = readFileSync(path).toString();
|
|
const pkg = JSON.parse(pkgjson);
|
|
return {
|
|
oldBuildNum: pkg.build.number,
|
|
oldSha: pkg.build.sha,
|
|
oldVersion: pkg.version
|
|
};
|
|
}
|
|
|
|
function replaceIn(path, oldValue, newValue) {
|
|
let contents = readFileSync(path).toString();
|
|
contents = contents.replace(oldValue, newValue);
|
|
writeFileSync(path, contents);
|
|
}
|