Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize 4.49 #927

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
},
"dependencies": {
"@diplodoc/client": "^3.1.8",
"@diplodoc/translation": "^1.5.0",
"@diplodoc/translation": "^1.5.1",
"highlight.js": "^11.10.0",
"katex": "^0.16.9",
"shelljs": "0.8.5",
"threads": "1.7.0"
Expand Down
4 changes: 2 additions & 2 deletions src/commands/translate/commands/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ function pipeline(
output: string,
{useSource, useExperimentalParser}: ComposeOptions,
) {
return async (file: FileInfo) => {
return async function pipeline(file: FileInfo) {
const skeleton = new FileLoader(join(input, file.skl));
const xliff = new FileLoader<string>(join(input, file.xliff));

await Promise.all([skeleton.load(), xliff.load()]);

const content = new FileLoader(join(output, file.path));
const {schemas, ajvOptions} = await resolveSchemas({
content: content.data,
content: skeleton.data,
path: file.path,
});

Expand Down
75 changes: 55 additions & 20 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,26 +334,13 @@ export class Command extends BaseCommand {
addOption(o: Option | ExtendedOption): this {
super.addOption(o);

if (o.isBoolean() && (o as ExtendedOption)[OptionSource]) {
const original = (o as ExtendedOption)[OptionSource];
const flags = original.flags
// replace short flags with void
.replace(/(^|\s+|,)-\w+\s*($|,?\s*)/g, '')
// add negation to long options
.replace(/--/g, '--no-');

const negated = {
...original,
flags,
desc: 'auto negation',
hidden: true,
};

delete negated.default;
delete negated.defaultInfo;
delete negated.deprecated;

super.addOption(option(negated));
const camelcase = camelCaseOption(o as ExtendedOption);
if (camelcase) {
super.addOption(camelcase);
}

if (o.isBoolean()) {
super.addOption(negatedOption(o as ExtendedOption));
}

if (o.description) {
Expand All @@ -367,3 +354,51 @@ export class Command extends BaseCommand {
return new Help();
}
}

function camelCaseOption(o: ExtendedOption) {
const original = (o as ExtendedOption)[OptionSource];
const flags = original.flags
// replace short flags with void
.replace(/(^|\s+|,)-\w+\s*($|,?\s*)/g, '')
// convert to camel case (ignoring option first letter)
.replace(/([^-])-([a-z])/g, (_, $1, $2) => $1 + $2.toUpperCase());

if (original.flags.includes(flags)) {
return null;
}

const camelcase = {
...original,
flags,
desc: 'auto camelcase',
deprecated: 'Use "kebab case" variant of this option.',
hidden: true,
};

delete camelcase.default;
delete camelcase.defaultInfo;

return option(camelcase);
}

function negatedOption(o: ExtendedOption) {
const original = (o as ExtendedOption)[OptionSource];
const flags = original.flags
// replace short flags with void
.replace(/(^|\s+|,)-\w+\s*($|,?\s*)/g, '')
// add negation to long options
.replace(/--/g, '--no-');

const negated = {
...original,
flags,
desc: 'auto negation',
hidden: true,
};

delete negated.default;
delete negated.defaultInfo;
delete negated.deprecated;

return option(negated);
}
16 changes: 8 additions & 8 deletions src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
return this;
}

/**

Check warning on line 117 in src/logger/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Missing JSDoc @returns for function

Check warning on line 117 in src/logger/index.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Missing JSDoc for parameter 'consumer'
* Pipe local log channels to parent log channels.
* This doesn't pipe topics processing.
* So if child and parent has the same topic with name 'proc',
Expand Down Expand Up @@ -192,14 +192,6 @@
return this;
}

stat(): Record<LogLevels, number> {
return {
[LogLevel.INFO]: this[INFO].count,
[LogLevel.WARN]: this[WARN].count,
[LogLevel.ERROR]: this[ERROR].count,
};
}

[Write](level: LogLevels, message: string) {
if (this.options.quiet) {
return;
Expand Down Expand Up @@ -228,3 +220,11 @@

return String(error);
}

export function stats(logger: Logger) {
return {
[LogLevel.INFO]: logger[INFO].count,
[LogLevel.WARN]: logger[WARN].count,
[LogLevel.ERROR]: logger[ERROR].count,
};
}
4 changes: 2 additions & 2 deletions src/program/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {Command, Config, ExtendedOption} from '~/config';
import {AsyncSeriesWaterfallHook, Hook, HookMap, SyncHook} from 'tapable';
import {isAbsolute, resolve} from 'node:path';
import {once} from 'lodash';
import {Logger} from '~/logger';
import {Logger, stats} from '~/logger';
import log from '@diplodoc/transform/lib/log';
import {
resolveConfig,
Expand Down Expand Up @@ -152,7 +152,7 @@ export const BaseProgram = <
}

private async post() {
const stat = this.logger.stat();
const stat = stats(this.logger);
if (stat.error || (this.config.strict && stat.warn)) {
throw new HandledError('There is some processing errors.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/md2html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const getFileProps = async (options: ResolverOptions) => {
return {
data: {
...data,
title: data.meta.title || data.title || '',
title: data.title || data.meta.title || '',
leading: inputPath.endsWith('.yaml'),
},
router: {
Expand Down
Loading