chore: format ANSI chars ta a more readable format

This commit is contained in:
Cheng Liu 2024-03-13 14:14:44 -07:00
parent 57842c3938
commit cf9b018949
No known key found for this signature in database
GPG key ID: EEC8452F7DB85CD6
13 changed files with 68 additions and 55 deletions

View file

@ -1,6 +1,6 @@
Running "sparo checkout --help":
Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__

View file

@ -1,6 +1,6 @@
Running "sparo clone --help":
Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__

View file

@ -1,6 +1,6 @@
Running "sparo --help":
Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__

View file

@ -1,10 +1,10 @@
Running "sparo nonexistent-command":
Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__
--[ git nonexistent-command ]--------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git nonexistent-command[normal] [gray]]--------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]

View file

@ -1,24 +1,24 @@
Running "sparo checkout --profile my-build-test":
Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__
--[ git checkout ]-------------------------------------------------------------
Your branch is up to date with 'origin/build-test'.
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git checkout[normal] [gray]]-------------------------------------------------------------[default]
Your branch is up to date with 'origin/test-artifacts/sparo-real-repo-test'.
[gray]-------------------------------------------------------------------------------[default]
Syncing checkout with the Sparo profile: my-build-test
Checking out and updating core files...
--[ git sparse-checkout ]------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git sparse-checkout[normal] [gray]]------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
Checking out skeleton...
--[ git sparse-checkout ]------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git sparse-checkout[normal] [gray]]------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
Sparse checkout completed in __DURATION__

View file

@ -1,29 +1,29 @@
Running "sparo checkout --profile my-build-test":
Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__
--[ git checkout ]-------------------------------------------------------------
Your branch is up to date with 'origin/build-test'.
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git checkout[normal] [gray]]-------------------------------------------------------------[default]
Your branch is up to date with 'origin/test-artifacts/sparo-real-repo-test'.
[gray]-------------------------------------------------------------------------------[default]
Syncing checkout with the Sparo profile: my-build-test
Checking out and updating core files...
--[ git sparse-checkout ]------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git sparse-checkout[normal] [gray]]------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
Checking out skeleton...
--[ git sparse-checkout ]------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git sparse-checkout[normal] [gray]]------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
Checking out __FOLDER_COUNT__ folders...
--[ git sparse-checkout ]------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git sparse-checkout[normal] [gray]]------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
Sparse checkout completed in __DURATION__

View file

@ -1,40 +1,40 @@
Running "sparo clone https://github.com/tiktok/sparo.git --branch build-test":
Running "sparo clone https://github.com/tiktok/sparo.git --branch test-artifacts/sparo-real-repo-test":
Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__
Initializing working directory...
--[ git clone ]----------------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git clone[normal] [gray]]----------------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
Checking out and updating core files...
--[ git sparse-checkout ]------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git sparse-checkout[normal] [gray]]------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
Checking out skeleton...
--[ git sparse-checkout ]------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git sparse-checkout[normal] [gray]]------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
Applying recommended configuration...
--[ git maintenance ]----------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git maintenance[normal] [gray]]----------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
Success: Working directory "sparo" was prepared in __DURATION__.
[green]Success: Working directory "sparo" was prepared in __DURATION__.[default]
Don't forget to change your shell path:
cd sparo
[cyan]cd sparo[default]
Your next step is to choose a Sparo profile for checkout.
To see available profiles in this repo:
sparo list-profiles
[cyan]sparo list-profiles[default]
To checkout and set profile:
sparo checkout --profile <profile_name>
[cyan]sparo checkout --profile <profile_name>[default]
To checkout and add profile:
sparo checkout --add-profile <profile_name>
[cyan]sparo checkout --add-profile <profile_name>[default]
To create a new profile:
sparo init-profile --profile <profile_name>
[cyan]sparo init-profile --profile <profile_name>[default]

View file

@ -1,11 +1,11 @@
Running "sparo init-profile --profile my-build-test":
Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__
Successfully initialized the "my-build-test" profile.
[green]Successfully initialized the "my-build-test" profile.[default]
Next step: Open this file in your editor and configure the project selectors:
__WORKING_DIRECTORY__/common/sparo-profiles/my-build-test.json
[cyan]__WORKING_DIRECTORY__/common/sparo-profiles/my-build-test.json[default]

View file

@ -1,6 +1,6 @@
Running "sparo list-profiles --project sparo-lib":
Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__
@ -8,13 +8,13 @@ Listing profiles...
Checking out and updating core files...
--[ git sparse-checkout ]------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git sparse-checkout[normal] [gray]]------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
Checking out skeleton...
--[ git sparse-checkout ]------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git sparse-checkout[normal] [gray]]------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
sparo-lib was included in the below profiles:
my-build-test

View file

@ -1,6 +1,6 @@
Running "sparo list-profiles":
Sparo accelerator for Git __VERSION__ - https://tiktok.github.io/sparo/
[bold]Sparo accelerator for Git __VERSION__ -[normal][cyan] https://tiktok.github.io/sparo/[default]
Node.js version is __VERSION__ (LTS)
Git version is __VERSION__
@ -8,13 +8,13 @@ Listing profiles...
Checking out and updating core files...
--[ git sparse-checkout ]------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git sparse-checkout[normal] [gray]]------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
Checking out skeleton...
--[ git sparse-checkout ]------------------------------------------------------
-------------------------------------------------------------------------------
[gray]--[[default] [bold]git sparse-checkout[normal] [gray]]------------------------------------------------------[default]
[gray]-------------------------------------------------------------------------------[default]
All available profiles:
my-build-test

View file

@ -12,7 +12,8 @@
"dependencies": {
"@rushstack/node-core-library": "~3.64.2",
"jest-diff": "~29.7.0",
"sparo": "workspace:*"
"sparo": "workspace:*",
"@rushstack/terminal": "~0.8.1"
},
"devDependencies": {
"@rushstack/heft": "0.64.3",

View file

@ -1,6 +1,7 @@
import * as path from 'path';
import * as os from 'os';
import { Async, Executable, FileSystem, Text, type FolderItem } from '@rushstack/node-core-library';
import { AnsiEscape } from '@rushstack/terminal';
import { diff } from 'jest-diff';
import type { ChildProcess } from 'child_process';
import type { IScopedLogger } from '@rushstack/heft';
@ -264,7 +265,8 @@ function processSparoOutput(text: string, workingDirectory: string): string {
replaceVersionString,
replaceDurationString,
replaceWorkingDirectoryPath,
replaceFolderCountString
replaceFolderCountString,
formatForTests
].reduce((text, fn) => fn(text, workingDirectory), text);
}
/**
@ -298,6 +300,13 @@ function replaceWorkingDirectoryPath(text: string, workingDirectory: string): st
function replaceFolderCountString(text: string): string {
return text.replace(/Checking out \d+ folders/g, 'Checking out __FOLDER_COUNT__ folders');
}
/**
* ANSI characters are a bit awkward and they are not well rendered in the website.
* So we replace them with a more readable format.
*/
function formatForTests(text: string): string {
return AnsiEscape.formatForTests(text);
}
async function* enumerateFolderPaths(
absoluteFolderPath: string,

View file

@ -210,6 +210,9 @@ importers:
'@rushstack/node-core-library':
specifier: ~3.64.2
version: 3.64.2(@types/node@20.11.16)
'@rushstack/terminal':
specifier: ~0.8.1
version: 0.8.1(@types/node@20.11.16)
jest-diff:
specifier: ~29.7.0
version: 29.7.0