Skip to content

Commit

Permalink
feat: add processing when download
Browse files Browse the repository at this point in the history
  • Loading branch information
elrrrrrrr committed Oct 31, 2023
1 parent f1d68ff commit 2e4984f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"version": "lerna version --conventional-commits --sign-git-commit --sign-git-tag --no-push --no-private"
},
"devDependencies": {
"lerna": "^7.1.4",
"@eggjs/tsconfig": "^1.0.0",
"@types/mocha": "^8.2.0",
"@types/node": "^18.16.3",
Expand All @@ -37,7 +38,6 @@
"eslint-config-egg": "^12.0.0",
"espower-typescript": "^9.0.2",
"intelli-espower-loader": "^1.0.1",
"lerna": "^7.1.4",
"mm": "^2.2.0",
"mocha": "^8.2.1",
"nock": "^13.0.9",
Expand All @@ -52,8 +52,5 @@
},
"engines": {
"node": ">=14.19.1"
},
"dependencies": {
"cli-progress": "^3.12.0"
}
}
2 changes: 0 additions & 2 deletions packages/cli/lib/download_dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ async function download(options) {
}
}
}
// console.time('[rapid] generate fs meta');

console.log('[rapid] generate fs meta');

Expand All @@ -112,7 +111,6 @@ async function download(options) {
// FIXME atomic write
await fs.writeFile(npmCacheConfigPath, JSON.stringify(tocMap), 'utf8');
await fs.writeFile(npmIndexConfigPath, JSON.stringify(indices), 'utf8');
// console.timeEnd('[rapid] generate fs meta');
return {
depsTree,
};
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/lib/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Downloader {
async shutdown() {
if (!this.rapidDownloader) return;
await this.rapidDownloader.shutdown();
this.bar.stop();
}

createRapidDownloader() {
Expand Down Expand Up @@ -66,6 +67,7 @@ class Downloader {
this.bar = new Bar({
type: 'download',
total: tasks.length,
autoFinish: false,
});
await this.rapidDownloader.batchDownloads(tasks);
}
Expand Down
22 changes: 15 additions & 7 deletions packages/cli/lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const cliProgress = require('cli-progress');

const MAX_TITLE_LENGTH = 11;

function padCenter(str, length, char = ' ') {
const padLength = length - str.length;
const padLeft = Math.floor(padLength / 2);
Expand All @@ -8,8 +10,8 @@ function padCenter(str, length, char = ' ') {
}

class Bar {
constructor({ type, total }) {
const title = padCenter(type, 11);
constructor({ type, total, autoFinish = true }) {
const title = padCenter(type, MAX_TITLE_LENGTH);
this.multiBar = new cliProgress.MultiBar(
{
clearOnComplete: false,
Expand All @@ -20,6 +22,7 @@ class Bar {
);

this.startTime = Date.now();
this.autoFinish = autoFinish;

// init
this.bar = this.multiBar.create(total, 0, {
Expand All @@ -38,15 +41,20 @@ class Bar {
}

if (value >= total - 1) {
this.bar.update(total, {
status: 'Complete',
message: Date.now() - this.startTime + 'ms',
});
this.stop();
if (this.autoFinish) {
this.stop();
} else {
this.bar.update(total - 1, { status: 'Processing', message: 'Processing...' });
}
}
}

stop() {
const { total } = this.bar;
this.bar.update(total, {
status: 'Complete',
message: Date.now() - this.startTime + 'ms',
});
this.multiBar.stop();
}
}
Expand Down
8 changes: 1 addition & 7 deletions packages/cli/lib/nydusd/fuse_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ async function startNydusFs(cwd, pkg) {
console.log('[rapid] mount nydusd');
await mountNydus(cwd, pkg);

console.log('[rapid] mount overlay');
console.log('[rapid] mount overlay, it may take a few seconds');
await mountOverlay(cwd, pkg);
}

async function generateBootstrapFile(cwd, pkg) {
// console.time('[rapid] generate bootstrap');
const allPkgs = await getAllPkgPaths(cwd, pkg);
const bar = new Bar({ type: 'bootstrap', total: allPkgs.length });
await Promise.all(allPkgs.map(async pkgPath => {
Expand All @@ -42,7 +41,6 @@ async function generateBootstrapFile(cwd, pkg) {
await execa.command(`${BOOTSTRAP_BIN} --stargz-config-path=${tarIndex} --stargz-dir=${tarBucketsDir} --bootstrap=${bootstrap}`);
bar.update(nodeModulesDir);
}));
// console.timeEnd('[rapid] generate bootstrap');
}

async function mountNydus(cwd, pkg) {
Expand All @@ -56,10 +54,8 @@ async function mountNydus(cwd, pkg) {
// 需要串行 mount,并发创建时 nydusd 会出现问题
for (const pkgPath of allPkgs) {
const { dirname, bootstrap } = await getWorkdir(cwd, pkgPath);
// console.time(`[rapid] mount '/${dirname}' to nydusd daemon using socket api`);
await nydusdApi.mount(`/${dirname}`, cwd, bootstrap);
bar.update(dirname);
// console.timeEnd(`[rapid] mount '/${dirname}' to nydusd daemon using socket api`);
}
}

Expand Down Expand Up @@ -116,10 +112,8 @@ ${upper}=RW:${mnt}=RO \
${nodeModulesDir}`;
}
// console.info('[rapid] mountOverlay: `%s`', shScript);
// console.time(`[rapid] overlay ${overlay} mounted.`);
await execa.command(shScript);
bar.update(nodeModulesDir);
// console.timeEnd(`[rapid] overlay ${overlay} mounted.`);
}));
}

Expand Down

0 comments on commit 2e4984f

Please sign in to comment.