finally ui looks similar to now

This commit is contained in:
Igor Klopov 2016-08-18 22:29:50 +03:00
parent 2f98a07fed
commit 79bf1efea8
7 changed files with 61 additions and 29 deletions

View File

@ -7,15 +7,13 @@ import path from 'path';
import { tempPath } from './temp-path.js';
import thresholds from './thresholds.js';
const windows = process.platform === 'win32';
const buildPath = tempPath();
const nodePath = path.join(buildPath, 'node');
const patchesPath = path.resolve(__dirname, '../patches');
const nodeRepo = 'https://github.com/nodejs/node';
async function gitClone () {
log.info('Cloning Node.js from GitHub');
log.info('Cloning Node.js repository from GitHub...');
const args = [ 'clone', '--bare', '--progress', nodeRepo, 'node/.git' ];
const promise = spawn('git', args, { cwd: buildPath });
progress(promise, thresholds('clone'));
@ -23,7 +21,7 @@ async function gitClone () {
}
async function gitResetHard (nodeVersion) {
log.info(`Resetting to ${nodeVersion}`);
log.info(`Checking out ${nodeVersion}`);
const args = [ '--work-tree', '.', 'reset', '--hard', nodeVersion ];
await spawn('git', args, { cwd: nodePath });
}
@ -59,6 +57,15 @@ async function compileOnUnix (nodeVersion, targetArch) {
return path.join(nodePath, 'out/Release/node');
}
async function compile (nodeVersion, targetArch) {
log.info('Compiling Node.js from sources...');
if (process.platform === 'win32') {
return await compileOnWindows(nodeVersion, targetArch);
} else {
return await compileOnUnix(nodeVersion, targetArch);
}
}
export default async function build (
nodeVersion, targetArch, local
) {
@ -67,15 +74,7 @@ export default async function build (
await gitClone();
await gitResetHard(nodeVersion);
await applyPatches(nodeVersion);
log.info('Compiling Node.js sources');
let output;
if (windows) {
output = await compileOnWindows(nodeVersion, targetArch);
} else {
output = await compileOnUnix(nodeVersion, targetArch);
}
const output = await compile(nodeVersion, targetArch);
await mkdirp(path.dirname(local));
await copyFile(output, local);
await remove(buildPath);

View File

@ -42,7 +42,7 @@ export async function download (remote, local) {
const asset = assets[0];
const tempFile = local + '.downloading';
await mkdirp(path.dirname(tempFile));
await downloadAsset(asset, tempFile);
await downloadAsset(asset, tempFile, path.basename(local));
await remove(local);
await moveFile(tempFile, local);
await remove(tempFile);

View File

@ -75,9 +75,9 @@ export function uploadAsset (file, release, name) {
});
}
export function downloadAsset (asset, file) {
log.enableProgress();
log.showProgress('0%', 0);
export function downloadAsset (asset, file, short) {
log.enableProgress(short);
log.showProgress(0);
return new Promise((resolve, reject) => {
const headers = { Accept: 'application/octet-stream' };
const ws = fs.createWriteStream(file);
@ -89,7 +89,7 @@ export function downloadAsset (asset, file) {
}));
req.on('progress', (state) => {
const p = state.percentage;
log.showProgress((p * 100 | 0) + '%', p);
log.showProgress(p * 100);
});
req.pipe(ws);
});

View File

@ -1,6 +1,39 @@
import log from 'npmlog';
import Progress from 'progress';
import assert from 'assert';
log.heading = '>';
log.prefixStyle = { fg: 'cyan' };
class Log {
info (text) {
console.log('> ' + text);
}
export default log;
warn (text) {
console.log('> ' + text); // TODO warn?
}
error (text) {
console.log('> ' + text); // TODO error?
}
enableProgress (text) {
assert(!this.bar);
this.bar = new Progress(` ${text} [:bar] :percent`, {
width: 20,
complete: '=',
incomplete: ' ',
total: 100
});
}
showProgress (percentage) {
this.bar.update(percentage / 100);
}
disableProgress () {
assert(this.bar);
this.bar.update(1);
this.bar.terminate();
delete this.bar;
}
}
export default new Log();

View File

@ -4,7 +4,7 @@ import fs from 'fs';
import log from './log.js';
const MAX_LINES = 20;
const DEBUG_THRESHOLDS = true;
const DEBUG_THRESHOLDS = false;
function errorLines (lines) {
return lines.slice(-MAX_LINES)
@ -25,7 +25,7 @@ export function spawn (cmd, args, opts) {
for (const key in thresholds) {
if (data.indexOf(key) >= 0) {
const p = thresholds[key];
log.showProgress(p + '%', p / 100);
log.showProgress(p);
if (DEBUG_THRESHOLDS) {
lines.push([ time, '************' ]);
lines.push([ time, p + ': ' + key ]);
@ -61,10 +61,10 @@ export function spawn (cmd, args, opts) {
export function progress (promise, thresholds) {
promise.thresholds = thresholds;
log.enableProgress();
log.showProgress('0%', 0);
const start = (new Date()).getTime();
const { child, lines } = promise;
log.enableProgress(promise.child.spawnfile);
log.showProgress(0);
const start = (new Date()).getTime();
child.on('close', () => {
if (DEBUG_THRESHOLDS) {
const finish = (new Date()).getTime();

View File

@ -47,7 +47,7 @@ export default function thresholds (cmd, nodeVersion) {
'v8/src/heap/spaces.o.d.raw': 50, 'v8/src/hydrogen-sce.o.d.raw': 60,
'v8/src/parser.o.d.raw': 70, 'v8/src/token.o.d.raw': 80,
'v8/src/x64/stub-cache-x64.o.d.raw': 90
}
};
} else
if (/^v?4/.test(nodeVersion)) {
return {

View File

@ -19,8 +19,8 @@
"byline": "5.0.0",
"expand-template": "1.0.2",
"fs-promise": "0.5.0",
"progress": "1.1.8",
"minimist": "1.2.0",
"npmlog": "4.0.0",
"request": "2.74.0",
"request-progress": "2.0.1",
"semver": "5.3.0",