Skip to content

Commit

Permalink
Revert "feat: resolve vcsPath correctly when sourcePath was suppl…
Browse files Browse the repository at this point in the history
…ied beforehand, refactor metadata generation procedures"

This reverts commit 568f43b.
  • Loading branch information
3y3 committed Jul 11, 2024
1 parent 6f3c8b2 commit 1c251e5
Show file tree
Hide file tree
Showing 23 changed files with 783 additions and 833 deletions.
1 change: 1 addition & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export interface MetaDataOptions {
isContributorsEnabled?: boolean;
vcsConnector?: VCSConnector;
addSystemMeta?: boolean;
addSourcePath?: boolean;
resources?: Resources;
shouldAlwaysAddVCSPath?: boolean;
}
Expand Down
18 changes: 8 additions & 10 deletions src/resolvers/md2md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,30 @@ import {ArgvService, PluginService} from '../services';
import {getVarsPerFile, logger} from '../utils';
import {PluginOptions, ResolveMd2MdOptions} from '../models';
import {PROCESSING_FINISHED} from '../constants';
import {getContentWithUpdatedMetadata} from '../services/metadata';
import {ChangelogItem} from '@diplodoc/transform/lib/plugins/changelog/types';
import {enrichWithFrontMatter} from '../services/metadata';

export async function resolveMd2Md(options: ResolveMd2MdOptions): Promise<void> {
const {inputPath, outputPath, metadata: metadataOptions} = options;
const {input, output, changelogs: changelogsSetting} = ArgvService.getConfig();
const resolvedInputPath = resolve(input, inputPath);

const vars = getVarsPerFile(inputPath);
const varsPreset = getVarsPerFile(inputPath);

const content = await enrichWithFrontMatter({
fileContent: readFileSync(resolvedInputPath, 'utf8'),
const content = await getContentWithUpdatedMetadata(
readFileSync(resolvedInputPath, 'utf8'),
metadataOptions,
resolvedFrontMatterVars: {
systemVars: vars.__system as unknown,
metadataVars: vars.__metadata,
},
});
varsPreset.__system as unknown,
varsPreset.__metadata,
);

const {result, changelogs} = transformMd2Md(content, {
path: resolvedInputPath,
destPath: outputPath,
root: resolve(input),
destRoot: resolve(output),
collectOfPlugins: PluginService.getCollectOfPlugins(),
vars: vars,
vars: varsPreset,
log,
copyFile,
});
Expand Down
33 changes: 18 additions & 15 deletions src/services/authors.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {Contributor} from '../models';
import {replaceDoubleToSingleQuotes} from '../utils';
import {VCSConnector} from '../vcs-connector/connector-models';

async function updateAuthorMetadataStringByAuthorData(
authorLogin: string | object,
async function updateAuthorMetadataStringByAuthorLogin(
authorLogin: string,
vcsConnector?: VCSConnector,
): Promise<Contributor | null> {
): Promise<string> {
if (!vcsConnector) {
return null;
return '';
}

const user = await getAuthorDetails(vcsConnector, authorLogin);
Expand All @@ -15,49 +15,52 @@ async function updateAuthorMetadataStringByAuthorData(
return user;
}

return null;
return '';
}

async function updateAuthorMetadataStringByFilePath(
filePath: string,
vcsConnector?: VCSConnector,
): Promise<Contributor | null> {
): Promise<string> {
if (!vcsConnector) {
return null;
return '';
}

const user = vcsConnector.getExternalAuthorByPath(filePath);

if (user) {
return user;
const author = replaceDoubleToSingleQuotes(JSON.stringify(user));
return author;
}

return null;
return '';
}

async function getAuthorDetails(
vcsConnector: VCSConnector,
author: string | object,
): Promise<Contributor | null> {
): Promise<string | null> {
if (typeof author === 'object') {
return author as Contributor;
// Avoiding problems when adding to html markup
return replaceDoubleToSingleQuotes(JSON.stringify(author));
}

try {
return JSON.parse(author);
JSON.parse(author);
return replaceDoubleToSingleQuotes(author);
} catch {
const user = await vcsConnector.getUserByLogin(author);

if (user) {
return user;
return replaceDoubleToSingleQuotes(JSON.stringify(user));
}

return null;
}
}

export {
updateAuthorMetadataStringByAuthorData as updateAuthorMetadataStringByAuthorLogin,
updateAuthorMetadataStringByAuthorLogin,
updateAuthorMetadataStringByFilePath,
getAuthorDetails,
};
21 changes: 17 additions & 4 deletions src/services/contributors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {readFile} from 'fs/promises';
import {dirname, join} from 'path';

import {replaceDoubleToSingleQuotes} from '../utils';
import {REGEXP_INCLUDE_CONTENTS, REGEXP_INCLUDE_FILE_PATH} from '../constants';
import {Contributor, Contributors} from '../models';
import {FileContributors, VCSConnector} from '../vcs-connector/connector-models';
Expand All @@ -10,10 +12,19 @@ export interface ContributorsServiceFileData {
fileContent: string;
}

export async function getFileContributors(
async function getFileContributorsMetadata(
fileData: ContributorsServiceFileData,
vcsConnector: VCSConnector,
): Promise<Contributor[]> {
): Promise<string> {
const contributors = await getFileContributorsString(fileData, vcsConnector);

return `contributors: ${contributors}`;
}

async function getFileContributorsString(
fileData: ContributorsServiceFileData,
vcsConnector: VCSConnector,
): Promise<string> {
const {resolvedFilePath, inputFolderPathLength} = fileData;

const relativeFilePath = resolvedFilePath.substring(inputFolderPathLength);
Expand All @@ -35,7 +46,7 @@ export async function getFileContributors(
fileContributorsWithContributorsIncludedFiles,
).map(([, contributor]) => contributor);

return contributorsArray;
return replaceDoubleToSingleQuotes(JSON.stringify(contributorsArray));
}

async function getContributorsForNestedFiles(
Expand Down Expand Up @@ -112,7 +123,7 @@ function getRelativeIncludeFilePaths(
return relativeIncludeFilePaths;
}

export async function getFileIncludes(fileData: ContributorsServiceFileData) {
async function getFileIncludes(fileData: ContributorsServiceFileData) {
const {fileContent, inputFolderPathLength} = fileData;

const results = new Set<string>();
Expand Down Expand Up @@ -150,3 +161,5 @@ export async function getFileIncludes(fileData: ContributorsServiceFileData) {

return Array.from(results.values());
}

export {getFileContributorsMetadata, getFileContributorsString, getFileIncludes};
Loading

0 comments on commit 1c251e5

Please sign in to comment.