fix: stable output

This commit is contained in:
Cheng Liu 2024-03-11 15:59:10 -07:00
parent e6f85b42e6
commit 8cd75c52e3
No known key found for this signature in database
GPG key ID: EEC8452F7DB85CD6
4 changed files with 19 additions and 9 deletions

View file

@ -73,9 +73,12 @@ export class ListProfilesCommand implements ICommand<IListProfilesCommandOptions
} }
} }
if (profileProjects.has(project)) { const profilesContainProject: string[] | undefined = profileProjects.get(project);
if (profilesContainProject) {
// Ensure the stable order of the profiles
Sort.sortBy(profilesContainProject, (x) => x, Sort.compareByValue);
terminalService.terminal.writeLine( terminalService.terminal.writeLine(
`${project} was included in the below profiles:\n ${profileProjects.get(project)?.join('\n')}` `${project} was included in the below profiles:\n ${profilesContainProject.join('\n')}`
); );
} else { } else {
terminalService.terminal.writeErrorLine(`${project} is not included in any pre-configured profile`); terminalService.terminal.writeErrorLine(`${project} is not included in any pre-configured profile`);

View file

@ -1,4 +1,4 @@
Running "sparo clone git@github.com:tiktok/sparo.git --branch build-test": Running "sparo clone __GITHUB_HOSTNAME__:tiktok/sparo.git --branch build-test":
Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/ Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
Node.js version is __VERSION__ (LTS) Node.js version is __VERSION__ (LTS)

View file

@ -17,5 +17,5 @@ Checking out skeleton...
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
sparo-lib was included in the below profiles: sparo-lib was included in the below profiles:
sparo-development my-build-test
my-build-test sparo-development

View file

@ -107,10 +107,10 @@ export async function executeCommandsAndCollectOutputs({
const outputPath: string = path.join(tempFolder, `${name}.txt`); const outputPath: string = path.join(tempFolder, `${name}.txt`);
FileSystem.writeFile( FileSystem.writeFile(
outputPath, outputPath,
`Running "sparo ${args.join(' ')}":\n${processSparoOutput( processSparoOutput(
stdout, `Running "sparo ${args.join(' ')}":\n${stdout}`,
currentWorkingDirectory || process.cwd() currentWorkingDirectory || process.cwd()
)}` )
); );
break; break;
} }
@ -263,7 +263,8 @@ function processSparoOutput(text: string, workingDirectory: string): string {
replaceVersionString, replaceVersionString,
replaceDurationString, replaceDurationString,
replaceWorkingDirectoryPath, replaceWorkingDirectoryPath,
replaceFolderCountString replaceFolderCountString,
replaceGitHostname
].reduce((text, fn) => fn(text, workingDirectory), text); ].reduce((text, fn) => fn(text, workingDirectory), text);
} }
/** /**
@ -290,6 +291,12 @@ function replaceWorkingDirectoryPath(text: string, workingDirectory: string): st
function replaceFolderCountString(text: string): string { function replaceFolderCountString(text: string): string {
return text.replace(/Checking out \d+ folders/g, 'Checking out __FOLDER_COUNT__ folders'); return text.replace(/Checking out \d+ folders/g, 'Checking out __FOLDER_COUNT__ folders');
} }
/**
* Replace "https://github.com" and "git@github.com" with "__GITHUB_HOSTNAME__".
*/
function replaceGitHostname(text: string): string {
return text.replace(/(https?:\/\/|git\@)github\.com/g, '__GITHUB_HOSTNAME__');
}
async function* enumerateFolderPaths( async function* enumerateFolderPaths(
absoluteFolderPath: string, absoluteFolderPath: string,