Skip to content

Commit

Permalink
fix: Revert "feat: implement an option to always provide vcsPath in…
Browse files Browse the repository at this point in the history
… metadata for md->md transformations (sans tests)"

This reverts commit ad1b879.
  • Loading branch information
3y3 committed Jul 11, 2024
1 parent 1c251e5 commit a3455a5
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 185 deletions.
38 changes: 9 additions & 29 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,6 @@ export type UserByLoginFunction = (login: string) => Promise<Contributor | null>
export type CollectionOfPluginsFunction = (output: string, options: PluginOptions) => string;
export type GetModifiedTimeByPathFunction = (filepath: string) => number | undefined;

/**
* VCS integration configuration object.
* Future VCS futures should be configured with this one, not with
* `VCSConnectorConfig`.
*/
interface VCSConfiguration {
/**
* Externally accessible base URI for a resource where a particular documentation
* source is hosted.
*
* This configuration parameter is used to directly control the Edit button behaviour
* in the Diplodoc documentation viewer(s).
*
* For example, if the following applies:
* - Repo with doc source is hosted on GitHub (say, https://github.com/foo-org/bar),
* - Within that particular repo, the directory that is being passed as an `--input`
* parameter to the CLI is located at `docs/`,
* - Whenever the Edit button is pressed, you wish to direct your readers to the
* respective document's source on `main` branch
*
* you should pass `https://github.com/foo-org/bar/tree/main/docs` as a value for this parameter.
*/
remoteBase: string;
}

interface YfmConfig {
varsPreset: VarsPreset;
ignore: string[];
Expand All @@ -66,7 +41,6 @@ interface YfmConfig {
ignoreStage: string;
singlePage: boolean;
removeHiddenTocItems: boolean;
vcs?: VCSConfiguration;
connector?: VCSConnectorConfig;
lang?: Lang;
langs?: Lang[];
Expand Down Expand Up @@ -225,14 +199,20 @@ export interface Contributors {
[email: string]: Contributor;
}

export interface FileData {
tmpInputFilePath: string;
inputFolderPathLength: number;
fileContent: string;
sourcePath?: string;
}

export interface MetaDataOptions {
pathData: PathData;
fileData: FileData;
isContributorsEnabled?: boolean;
vcsConnector?: VCSConnector;
addSystemMeta?: boolean;
addSourcePath?: boolean;
resources?: Resources;
shouldAlwaysAddVCSPath?: boolean;
}

export interface PluginOptions {
Expand All @@ -256,7 +236,7 @@ export interface Plugin {
export interface ResolveMd2MdOptions {
inputPath: string;
outputPath: string;
metadata: MetaDataOptions;
metadata?: MetaDataOptions;
}

export interface ResolverOptions {
Expand Down
13 changes: 6 additions & 7 deletions src/resolvers/md2md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ import {getContentWithUpdatedMetadata} from '../services/metadata';
import {ChangelogItem} from '@diplodoc/transform/lib/plugins/changelog/types';

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

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

const content = await getContentWithUpdatedMetadata(
readFileSync(resolvedInputPath, 'utf8'),
metadataOptions,
varsPreset.__system as unknown,
varsPreset.__metadata,
metadata,
vars.__system,
vars.__metadata,
);

const {result, changelogs} = transformMd2Md(content, {
Expand All @@ -31,7 +30,7 @@ export async function resolveMd2Md(options: ResolveMd2MdOptions): Promise<void>
root: resolve(input),
destRoot: resolve(output),
collectOfPlugins: PluginService.getCollectOfPlugins(),
vars: varsPreset,
vars,
log,
copyFile,
});
Expand Down
35 changes: 16 additions & 19 deletions src/services/contributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ 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 {Contributor, Contributors, FileData} from '../models';
import {FileContributors, VCSConnector} from '../vcs-connector/connector-models';

export interface ContributorsServiceFileData {
resolvedFilePath: string;
inputFolderPathLength: number;
fileContent: string;
}

async function getFileContributorsMetadata(
fileData: ContributorsServiceFileData,
fileData: FileData,
vcsConnector: VCSConnector,
): Promise<string> {
const contributors = await getFileContributorsString(fileData, vcsConnector);
Expand All @@ -22,12 +16,12 @@ async function getFileContributorsMetadata(
}

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

const relativeFilePath = resolvedFilePath.substring(inputFolderPathLength);
const relativeFilePath = tmpInputFilePath.substring(inputFolderPathLength);
const fileContributors: FileContributors =
await vcsConnector.getContributorsByPath(relativeFilePath);
let nestedContributors: Contributors = {};
Expand All @@ -50,7 +44,7 @@ async function getFileContributorsString(
}

async function getContributorsForNestedFiles(
fileData: ContributorsServiceFileData,
fileData: FileData,
vcsConnector: VCSConnector,
): Promise<Contributors> {
const {fileContent, inputFolderPathLength} = fileData;
Expand Down Expand Up @@ -83,10 +77,10 @@ async function getContributorsForNestedFiles(
throw err;
}

const newFileData: ContributorsServiceFileData = {
const newFileData: FileData = {
...fileData,
fileContent: contentIncludeFile,
resolvedFilePath: relativeIncludeFilePath,
tmpInputFilePath: relativeIncludeFilePath,
};

nestedContributors = await getContributorsForNestedFiles(newFileData, vcsConnector);
Expand All @@ -101,9 +95,10 @@ async function getContributorsForNestedFiles(
}

function getRelativeIncludeFilePaths(
{resolvedFilePath: tmpInputFilePath}: ContributorsServiceFileData,
fileData: Pick<FileData, 'tmpInputFilePath'>,
includeContents: string[],
): Set<string> {
const {tmpInputFilePath} = fileData;
const relativeIncludeFilePaths: Set<string> = new Set();

includeContents.forEach((includeContent: string) => {
Expand All @@ -123,8 +118,10 @@ function getRelativeIncludeFilePaths(
return relativeIncludeFilePaths;
}

async function getFileIncludes(fileData: ContributorsServiceFileData) {
const {fileContent, inputFolderPathLength} = fileData;
async function getFileIncludes(
fileData: Pick<FileData, 'fileContent' | 'tmpInputFilePath' | 'inputFolderPathLength'>,
) {
const {fileContent, tmpInputFilePath, inputFolderPathLength} = fileData;

const results = new Set<string>();

Expand All @@ -133,7 +130,7 @@ async function getFileIncludes(fileData: ContributorsServiceFileData) {
return [];
}
const relativeIncludeFilePaths: Set<string> = getRelativeIncludeFilePaths(
fileData,
{tmpInputFilePath},
includeContents,
);
for (const relativeIncludeFilePath of relativeIncludeFilePaths.values()) {
Expand All @@ -154,7 +151,7 @@ async function getFileIncludes(fileData: ContributorsServiceFileData) {
const includedPaths = await getFileIncludes({
inputFolderPathLength,
fileContent: contentIncludeFile,
resolvedFilePath: relativeIncludeFilePath,
tmpInputFilePath: relativeIncludeFilePath,
});
includedPaths.forEach((path) => results.add(path));
}
Expand Down
Loading

0 comments on commit a3455a5

Please sign in to comment.