UNPKG

654 BPlain TextView Raw
1import * as path from 'path';
2
3const unadjustedRelativePath = (from: string, to: string) =>
4 path.relative(path.dirname(from), path.join(path.dirname(to), path.basename(to, '.ts')));
5
6// Have to manually add ./ when relative path is to file in the same directory.
7const adjustedRelativePath = (path: string) => (path.startsWith('.') ? path : `./${path}`);
8
9export const relativePath = (from: string, to: string) =>
10 adjustedRelativePath(unadjustedRelativePath(from, to));
11
12export const outputPath = (fragmentOrOperationName: string, filePath: string) =>
13 path.join(path.join(path.dirname(filePath), '__generated__'), fragmentOrOperationName + '.ts');