diff --git a/generators/repo/src/commands/generate.ts b/generators/repo/src/commands/generate.ts index b96335b101b..e9c47963b43 100644 --- a/generators/repo/src/commands/generate.ts +++ b/generators/repo/src/commands/generate.ts @@ -5,7 +5,7 @@ import os from "os"; import fs from "fs/promises"; import ansiEscapes from "ansi-escapes"; import chalk from "chalk"; -import { cleanDirectoryPath, copyFile, createRepoUrlFromRemote, ensureDirectoryPath, getGlobFiles, getRepoPropsFromRemote, isStringNullOrEmpty, RepoProps, writeHeader,isFilePath } from "../common/util"; +import { cleanDirectoryPath, ensureRelativeBasePath, copyFile, createRepoUrlFromRemote, ensureDirectoryPath, getGlobFiles, getRepoPropsFromRemote, isStringNullOrEmpty, RepoProps, writeHeader,isFilePath } from "../common/util"; import { AssetRule, GitRemote, RepomanCommand, RepomanCommandOptions, RepoManifest } from "../models"; import { GitRepo } from "../tools/git"; @@ -411,6 +411,7 @@ export class GenerateCommand implements RepomanCommand { let refPath = path.resolve(destFolderPath, path.normalize(match)) // Generate the relative path between the current processed file dir path & the referenced match path let relativePath = path.relative(destFolderPath, refPath) + relativePath = ensureRelativeBasePath(relativePath); // Finally convert the path back to a POSIX compatible path relativePath = relativePath.split(path.sep).join(path.posix.sep) diff --git a/generators/repo/src/common/util.ts b/generators/repo/src/common/util.ts index 42554da9005..fc3dc6155f4 100644 --- a/generators/repo/src/common/util.ts +++ b/generators/repo/src/common/util.ts @@ -66,6 +66,19 @@ export const cleanDirectoryPath = async (directoryPath: string, cleanGit: boolea await del(patterns, { cwd: directoryPath, force: true, dot: true }); } +export const ensureRelativeBasePath = (input : string) => { + const basePath =`.${path.sep}` + if(!input.startsWith(basePath) && !input.startsWith(`.${basePath}`)) { + input = `${basePath}${input}` + } + else{ + if (isDebug()) { + console.warn(chalk.yellowBright(` - ${input} already contains a relative base path.`)); + } + } + return input; +} + export const toArray = (data: Buffer): string[] => { if (!(data instanceof Buffer)) { throw new Error("Not an instance of buffer");