From 6736405bb3ca95f3c4028a49394ff8bfbb12cdd5 Mon Sep 17 00:00:00 2001 From: Hattan Shobokshi Date: Sat, 27 Aug 2022 19:12:33 -0700 Subject: [PATCH 1/3] Adding relative base path ./ to path rewrites. Co-authored-by: Hadwa Gaber --- generators/repo/src/commands/generate.ts | 3 ++- generators/repo/src/common/util.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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..2d597079832 100644 --- a/generators/repo/src/common/util.ts +++ b/generators/repo/src/common/util.ts @@ -66,6 +66,16 @@ export const cleanDirectoryPath = async (directoryPath: string, cleanGit: boolea await del(patterns, { cwd: directoryPath, force: true, dot: true }); } +export const ensureRelativeBasePath = (input : string) => { + if(!input.startsWith("./") && !input.startsWith("../")) { + input = `.${path.sep}${input}` + } + else{ + 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"); From 03fb050455fac573f42f67a21fd71cfbd5a9b4a2 Mon Sep 17 00:00:00 2001 From: Hattan Shobokshi Date: Sun, 28 Aug 2022 16:22:22 -0700 Subject: [PATCH 2/3] Modifying base path check to use path.sep Co-authored-by: Hadwa Gaber --- generators/repo/src/common/util.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/generators/repo/src/common/util.ts b/generators/repo/src/common/util.ts index 2d597079832..9ca5bd9df4b 100644 --- a/generators/repo/src/common/util.ts +++ b/generators/repo/src/common/util.ts @@ -67,13 +67,14 @@ export const cleanDirectoryPath = async (directoryPath: string, cleanGit: boolea } export const ensureRelativeBasePath = (input : string) => { - if(!input.startsWith("./") && !input.startsWith("../")) { - input = `.${path.sep}${input}` + const basePath =`.${path.sep}` + if(!input.startsWith(basePath) && !input.startsWith(`.${basePath}`)) { + input = `${basePath}${input}` } else{ console.warn(chalk.yellowBright(` - ${input} already contains a relative base path.`)); } - return input + return input; } export const toArray = (data: Buffer): string[] => { From fcb09edbde199f94650dd44eb298a9e1ae7e041a Mon Sep 17 00:00:00 2001 From: Hattan Shobokshi Date: Tue, 30 Aug 2022 23:41:16 -0700 Subject: [PATCH 3/3] Normalization warning message only appears when running in debug mode. Co-authored-by: Hadwa Gaber --- generators/repo/src/common/util.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/generators/repo/src/common/util.ts b/generators/repo/src/common/util.ts index 9ca5bd9df4b..fc3dc6155f4 100644 --- a/generators/repo/src/common/util.ts +++ b/generators/repo/src/common/util.ts @@ -72,7 +72,9 @@ export const ensureRelativeBasePath = (input : string) => { input = `${basePath}${input}` } else{ - console.warn(chalk.yellowBright(` - ${input} already contains a relative base path.`)); + if (isDebug()) { + console.warn(chalk.yellowBright(` - ${input} already contains a relative base path.`)); + } } return input; }