Skip to content

Commit 5a99877

Browse files
author
Vladislav Yevtushenko
committed
fix(#368): Apply elapsed to all logging cases
Wraps all command operations with the elapsed utility to provide consistent timing information across the entire CLI toolchain. This resolves TODO #368 completely by applying elapsed to all logging cases that require output of elapsed time. Changes: - parse, register, lint, print, sodg, latex commands - java/transpile, java/resolve, java/link commands - jeo/assemble, jeo/disassemble commands - js/transpile, js/link commands - docs command
1 parent 89db6d4 commit 5a99877

File tree

14 files changed

+211
-172
lines changed

14 files changed

+211
-172
lines changed

src/commands/docs.js

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const fs = require('fs');
77
const path = require('path');
88
const SaxonJS = require('saxon-js');
99
const { marked } = require('marked');
10+
const {elapsed} = require('../elapsed');
1011

1112
/**
1213
* Recursively reads all .xmir files from a directory.
@@ -125,44 +126,46 @@ function wrapHtml(name, html, css) {
125126
* Command to generate documentation.
126127
* @param {Hash} opts - All options
127128
*/
128-
module.exports = async function(opts) {
129-
try {
130-
const input = path.resolve(opts.target, '1-parse');
131-
const output = path.resolve(opts.target, 'docs');
132-
fs.mkdirSync(output, {recursive: true});
133-
const css = path.join(output, 'styles.css');
134-
fs.writeFileSync(css, '');
135-
const packages_info = {};
136-
const all_xmir_htmls = [];
137-
const xmirs = readXmirsRecursively(input);
138-
for (const xmir of xmirs) {
139-
const relative = path.relative(input, xmir);
140-
const name = path.parse(xmir).name;
141-
const xmir_html = createXmirHtmlBlock(xmir);
142-
const html_app = path.join(output, path.dirname(relative),`${name}.html`);
143-
fs.mkdirSync(path.dirname(html_app), {recursive: true});
144-
fs.writeFileSync(html_app, wrapHtml(name, xmir_html, css));
145-
const packages = path.dirname(relative).split(path.sep).join('.');
146-
const html_package = path.join(output, `package_${packages}.html`);
147-
if (!(packages in packages_info)) {
148-
packages_info[packages] = {
149-
xmir_htmls : [],
150-
path: html_package
151-
};
129+
module.exports = function(opts) {
130+
return elapsed(async (tracked) => {
131+
try {
132+
const input = path.resolve(opts.target, '1-parse');
133+
const output = path.resolve(opts.target, 'docs');
134+
fs.mkdirSync(output, {recursive: true});
135+
const css = path.join(output, 'styles.css');
136+
fs.writeFileSync(css, '');
137+
const packages_info = {};
138+
const all_xmir_htmls = [];
139+
const xmirs = readXmirsRecursively(input);
140+
for (const xmir of xmirs) {
141+
const relative = path.relative(input, xmir);
142+
const name = path.parse(xmir).name;
143+
const xmir_html = createXmirHtmlBlock(xmir);
144+
const html_app = path.join(output, path.dirname(relative),`${name}.html`);
145+
fs.mkdirSync(path.dirname(html_app), {recursive: true});
146+
fs.writeFileSync(html_app, wrapHtml(name, xmir_html, css));
147+
const packages = path.dirname(relative).split(path.sep).join('.');
148+
const html_package = path.join(output, `package_${packages}.html`);
149+
if (!(packages in packages_info)) {
150+
packages_info[packages] = {
151+
xmir_htmls : [],
152+
path: html_package
153+
};
154+
}
155+
packages_info[packages].xmir_htmls.push(xmir_html);
156+
all_xmir_htmls.push(xmir_html);
152157
}
153-
packages_info[packages].xmir_htmls.push(xmir_html);
154-
all_xmir_htmls.push(xmir_html);
155-
}
156-
for (const package_name of Object.keys(packages_info)) {
157-
fs.mkdirSync(path.dirname(packages_info[package_name].path), {recursive: true});
158-
fs.writeFileSync(packages_info[package_name].path,
159-
generatePackageHtml(`${package_name} package`, packages_info[package_name].xmir_htmls, css));
158+
for (const package_name of Object.keys(packages_info)) {
159+
fs.mkdirSync(path.dirname(packages_info[package_name].path), {recursive: true});
160+
fs.writeFileSync(packages_info[package_name].path,
161+
generatePackageHtml(`${package_name} package`, packages_info[package_name].xmir_htmls, css));
162+
}
163+
const packages = path.join(output, 'packages.html');
164+
fs.writeFileSync(packages, generatePackageHtml('overall package', all_xmir_htmls, css));
165+
tracked.print(`Documentation generation completed in the ${output} directory`);
166+
} catch (error) {
167+
console.error('Error generating documentation:', error);
168+
throw error;
160169
}
161-
const packages = path.join(output, 'packages.html');
162-
fs.writeFileSync(packages, generatePackageHtml('overall package', all_xmir_htmls, css));
163-
console.info('Documentation generation completed in the %s directory', output);
164-
} catch (error) {
165-
console.error('Error generating documentation:', error);
166-
throw error;
167-
}
170+
});
168171
};

src/commands/java/link.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55

66
const rel = require('relative');
77
const {mvnw, flags} = require('../../mvnw');
8+
const {elapsed} = require('../../elapsed');
89
const path = require('path');
910

1011
/**
1112
* Command to link binaries into a single executable binary.
1213
* @param {Object} opts - All options
1314
* @return {Promise} of link task
1415
*/
15-
module.exports = async function(opts) {
16+
module.exports = function(opts) {
1617
const jar = path.resolve(opts.target, 'eoc.jar');
17-
const r = await mvnw(['jar:jar', 'shade:shade'].concat(flags(opts)), opts.target, opts.batch);
18-
console.info('Executable JAR created at %s', rel(jar));
19-
return r;
18+
return elapsed(async (tracked) => {
19+
const r = await mvnw(['jar:jar', 'shade:shade'].concat(flags(opts)), opts.target, opts.batch);
20+
tracked.print(`Executable JAR created at ${rel(jar)}`);
21+
return r;
22+
});
2023
};

src/commands/java/resolve.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55

66
const rel = require('relative');
77
const {mvnw, flags} = require('../../mvnw');
8+
const {elapsed} = require('../../elapsed');
89
const path = require('path');
910

1011
/**
1112
* Command to resolve all the dependencies for compilation.
1213
* @param {Object} opts - All options
1314
* @return {Promise} of resolve task
1415
*/
15-
module.exports = async function(opts) {
16-
await mvnw(['eo:resolve'].concat(flags(opts)), opts.target, opts.batch);
17-
const sources = path.resolve(opts.target, 'eo/6-resolve');
18-
console.info('Dependencies resolved in %s', rel(sources));
19-
const r = await mvnw(['eo:place'].concat(flags(opts)), opts.target, opts.batch);
20-
const classes = path.resolve(opts.target, 'classes');
21-
console.info('Dependencies placed in %s', rel(classes));
22-
return r;
16+
module.exports = function(opts) {
17+
return elapsed(async (tracked) => {
18+
await mvnw(['eo:resolve'].concat(flags(opts)), opts.target, opts.batch);
19+
const sources = path.resolve(opts.target, 'eo/6-resolve');
20+
console.info('Dependencies resolved in %s', rel(sources));
21+
const r = await mvnw(['eo:place'].concat(flags(opts)), opts.target, opts.batch);
22+
const classes = path.resolve(opts.target, 'classes');
23+
tracked.print(`Dependencies placed in ${rel(classes)}`);
24+
return r;
25+
});
2326
};

src/commands/java/transpile.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55

66
const rel = require('relative');
77
const {mvnw, flags} = require('../../mvnw');
8+
const {elapsed} = require('../../elapsed');
89
const path = require('path');
910

1011
/**
1112
* Command to transpile XMIR files into target language.
1213
* @param {Object} opts - All options
1314
* @return {Promise} of transpile task
1415
*/
15-
module.exports = async function(opts) {
16+
module.exports = function(opts) {
1617
const sources = path.resolve(opts.target, 'generated-sources');
17-
const r = await mvnw(['eo:transpile'].concat(flags(opts)), opts.target, opts.batch);
18-
console.info('Java sources generated in %s', rel(sources));
19-
return r;
18+
return elapsed(async (tracked) => {
19+
const r = await mvnw(['eo:transpile'].concat(flags(opts)), opts.target, opts.batch);
20+
tracked.print(`Java sources generated in ${rel(sources)}`);
21+
return r;
22+
});
2023
};

src/commands/jeo/assemble.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,31 @@
55

66
const rel = require('relative');
77
const {mvnw, flags} = require('../../mvnw');
8+
const {elapsed} = require('../../elapsed');
89
const path = require('path');
910

1011
/**
1112
* Assemble .xmir files from .class files.
1213
* @param {Object} opts - All options
1314
* @return {Promise} of assemble task
1415
*/
15-
module.exports = async function(opts) {
16-
const r = await mvnw(
17-
['jeo:assemble']
18-
.concat(flags(opts))
19-
.concat(
20-
[
21-
`-Djeo.version=${opts.jeoVersion}`,
22-
`-Djeo.assemble.sourcesDir=${path.resolve(opts.target, opts.xmirs)}`,
23-
`-Djeo.assemble.outputDir=${path.resolve(opts.target, opts.classes)}`,
24-
]
25-
),
26-
opts.target, opts.batch
27-
);
28-
console.info(
29-
'EO .xmir files from %s assembled to .class files in %s',
30-
rel(opts.xmirs), rel(opts.classes)
31-
);
32-
return r;
16+
module.exports = function(opts) {
17+
return elapsed(async (tracked) => {
18+
const r = await mvnw(
19+
['jeo:assemble']
20+
.concat(flags(opts))
21+
.concat(
22+
[
23+
`-Djeo.version=${opts.jeoVersion}`,
24+
`-Djeo.assemble.sourcesDir=${path.resolve(opts.target, opts.xmirs)}`,
25+
`-Djeo.assemble.outputDir=${path.resolve(opts.target, opts.classes)}`,
26+
]
27+
),
28+
opts.target, opts.batch
29+
);
30+
tracked.print(
31+
`EO .xmir files from ${rel(opts.xmirs)} assembled to .class files in ${rel(opts.classes)}`
32+
);
33+
return r;
34+
});
3335
};

src/commands/jeo/disassemble.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,31 @@
55

66
const rel = require('relative');
77
const {mvnw, flags} = require('../../mvnw');
8+
const {elapsed} = require('../../elapsed');
89
const path = require('path');
910

1011
/**
1112
* Disassemble .class files to .xmir files.
1213
* @param {Object} opts - All options
1314
* @return {Promise} of disassemble task
1415
*/
15-
module.exports = async function(opts) {
16-
const r = await mvnw(
17-
['jeo:disassemble']
18-
.concat(flags(opts))
19-
.concat(
20-
[
21-
`-Djeo.version=${opts.jeoVersion}`,
22-
`-Djeo.disassemble.sourcesDir=${path.resolve(opts.target, opts.classes)}`,
23-
`-Djeo.disassemble.outputDir=${path.resolve(opts.target, opts.xmirs)}`,
24-
]
25-
),
26-
opts.target, opts.batch
27-
);
28-
console.info(
29-
'Bytecode .class files from %s disassembled to .xmir files in %s',
30-
rel(opts.classes), rel(opts.xmirs)
31-
);
32-
return r;
16+
module.exports = function(opts) {
17+
return elapsed(async (tracked) => {
18+
const r = await mvnw(
19+
['jeo:disassemble']
20+
.concat(flags(opts))
21+
.concat(
22+
[
23+
`-Djeo.version=${opts.jeoVersion}`,
24+
`-Djeo.disassemble.sourcesDir=${path.resolve(opts.target, opts.classes)}`,
25+
`-Djeo.disassemble.outputDir=${path.resolve(opts.target, opts.xmirs)}`,
26+
]
27+
),
28+
opts.target, opts.batch
29+
);
30+
tracked.print(
31+
`Bytecode .class files from ${rel(opts.classes)} disassembled to .xmir files in ${rel(opts.xmirs)}`
32+
);
33+
return r;
34+
});
3335
};

src/commands/js/link.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
const rel = require('relative');
77
const path = require('path');
88
const eo2jsw = require('../../eo2jsw');
9+
const {elapsed} = require('../../elapsed');
910
const {program} = require('commander');
1011

1112
/**
1213
* Command to create and build NPM project.
1314
* @param {Object} opts - All options
1415
* @return {Promise} of link task
1516
*/
16-
module.exports = async function(opts) {
17-
const tests = program.args[0] === 'test' || Boolean(opts.tests);
18-
const r = await eo2jsw('link', { ...opts, alone: true, project: 'project', tests });
19-
console.info(`NPM project generated in ${rel(path.resolve(opts.target, 'project'))}`);
20-
return r;
17+
module.exports = function(opts) {
18+
return elapsed(async (tracked) => {
19+
const tests = program.args[0] === 'test' || Boolean(opts.tests);
20+
const r = await eo2jsw('link', { ...opts, alone: true, project: 'project', tests });
21+
tracked.print(`NPM project generated in ${rel(path.resolve(opts.target, 'project'))}`);
22+
return r;
23+
});
2124
};

src/commands/js/transpile.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55

66
const rel = require('relative');
77
const eo2jsw = require('../../eo2jsw');
8+
const {elapsed} = require('../../elapsed');
89
const path = require('path');
910

1011
/**
1112
* Command to transpile XMIR files into target language.
1213
* @param {Object} opts - All options
1314
* @return {Promise} of transpile task
1415
*/
15-
module.exports = async function(opts) {
16-
const r = await eo2jsw('transpile', { ...opts, alone: true, project: 'project' });
17-
console.info(`JS sources generated in ${rel(path.resolve(opts.target, 'project'))}`);
18-
return r;
16+
module.exports = function(opts) {
17+
return elapsed(async (tracked) => {
18+
const r = await eo2jsw('transpile', { ...opts, alone: true, project: 'project' });
19+
tracked.print(`JS sources generated in ${rel(path.resolve(opts.target, 'project'))}`);
20+
return r;
21+
});
1922
};

src/commands/latex.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
const rel = require('relative');
77
const {mvnw, flags} = require('../mvnw');
8+
const {elapsed} = require('../elapsed');
89
const path = require('path');
910
const fs = require('fs');
1011

@@ -13,9 +14,11 @@ const fs = require('fs');
1314
* @param {Object} opts - All options
1415
* @return {Promise} of latex generation task
1516
*/
16-
module.exports = async function(opts) {
17+
module.exports = function(opts) {
1718
const latex = path.resolve(opts.target, 'latex');
18-
const r = await mvnw(['eo:latex'].concat(flags(opts)), opts.target, opts.batch);
19-
console.info('LaTeX files generated in %s', rel(latex));
20-
return r;
19+
return elapsed(async (tracked) => {
20+
const r = await mvnw(['eo:latex'].concat(flags(opts)), opts.target, opts.batch);
21+
tracked.print(`LaTeX files generated in ${rel(latex)}`);
22+
return r;
23+
});
2124
};

0 commit comments

Comments
 (0)