Remove rebuild task

This is a manual revert of 28aa6c9, which is not very useful with the
new build tasks, completely brittle, and a flawed idea from the start. I
regret having written it.
This commit is contained in:
Court Ewing 2016-07-22 16:40:06 -04:00
parent f3c047c18f
commit 2b842b0904
6 changed files with 0 additions and 196 deletions

View file

@ -91,5 +91,4 @@ module.exports = function (grunt) {
// load task definitions
grunt.task.loadTasks('tasks');
grunt.task.loadTasks('tasks/build');
grunt.task.loadTasks('tasks/rebuild');
};

View file

@ -1,36 +0,0 @@
import { execFileSync } from 'child_process';
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import { createInterface } from 'readline';
export default (grunt) => {
grunt.registerTask('_rebuild:confirm', function () {
const newVersion = grunt.option('buildversion') || grunt.config.get('pkg').version;
const newBuildNum = grunt.option('buildnum') || grunt.config.get('build.number');
const newSha = grunt.option('buildsha') || grunt.config.get('build.sha');
grunt.config('rebuild', { newVersion, newBuildNum, newSha });
grunt.log.writeln('Targets will be rebuilt with the following:');
grunt.log.writeln(`Version: ${newVersion}`);
grunt.log.writeln(`Build number: ${newBuildNum}`);
grunt.log.writeln(`Build sha: ${newSha}`);
const rl = createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('close', this.async());
rl.question('Do you want to rebuild these packages? [N/y] ', (resp) => {
const answer = resp.toLowerCase().trim();
if (answer === 'y') {
grunt.config.set('rebuild.continue', true);
}
rl.close();
});
});
};

View file

@ -1,23 +0,0 @@
import { execFileSync } from 'child_process';
import { join } from 'path';
export default (grunt) => {
grunt.registerTask('_rebuild:createArchives', function () {
const buildDir = grunt.config.get('buildDir');
const targetDir = grunt.config.get('target');
grunt.file.mkdir('target');
grunt.file.expand({ cwd: buildDir }, '*').forEach(build => {
const tar = join(targetDir, `${build}.tar.gz`);
execFileSync('tar', ['-zchf', tar, build], { cwd: buildDir });
const zip = join(targetDir, `${build}.zip`);
if (/windows/.test(build)) {
execFileSync('zip', ['-rq', '-ll', zip, build], { cwd: buildDir });
} else {
execFileSync('zip', ['-rq', zip, build], { cwd: buildDir });
}
});
});
};

View file

@ -1,14 +0,0 @@
import { execFileSync } from 'child_process';
export default (grunt) => {
grunt.registerTask('_rebuild:extractZips', function () {
const buildDir = grunt.config.get('buildDir');
const targetDir = grunt.config.get('target');
const zips = grunt.file.expand({ cwd: targetDir }, '*.zip');
zips.forEach(zip => {
execFileSync('unzip', [zip, '-d', buildDir], { cwd: targetDir });
});
});
};

View file

@ -1,65 +0,0 @@
import { execSync } from 'child_process';
import { trim } from 'lodash';
/**
* Repackages all of the current archives in target/ with the same build
* number, sha, and commit hash. This is useful when all you need to do is bump
* the version of the release and do not want to introduce any other changes.
*
* Even if there are new commits, the standard build task reinstalls all npm
* dependencies, which introduces at least a small amount of risk of
* introducing bugs into the build since not all dependencies have fixed
* versions.
*
* Options:
* --skip-archives Will skip the archive step, useful for debugging
* --buildversion="1.2.3" Sets new version to 1.2.3
* --buildnum="99999" Sets new build number to 99999
* --buildsha="9a5b2c1" Sets new build sha to 9a5b2c1 (use the full sha, though)
*/
export default (grunt) => {
grunt.registerTask('rebuild', 'Rebuilds targets as a new version', function () {
grunt.task.run([
'_rebuild:confirm',
'_rebuild:continue'
]);
});
grunt.registerTask('_rebuild:continue', function () {
grunt.task.requires('_rebuild:confirm');
if (!grunt.config.get('rebuild.continue')) {
grunt.log.writeln('Aborting without rebuilding anything');
} else {
grunt.task.run([
'_rebuild:builds',
'_rebuild:archives'
]);
}
});
grunt.registerTask('_rebuild:builds', function () {
grunt.task.requires('_rebuild:continue');
grunt.task.run([
'clean:build',
'_rebuild:extractZips',
'_rebuild:updateBuilds'
]);
});
grunt.registerTask('_rebuild:archives', function () {
grunt.task.requires('_rebuild:continue');
const skip = grunt.option('skip-archives');
if (skip) {
grunt.log.writeln('Skipping archive step since rebuild debugging was enabled');
} else {
grunt.task.run([
'clean:target',
'_rebuild:createArchives',
'_build:shasums'
]);
}
});
};

View file

@ -1,57 +0,0 @@
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);
}