-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools): add tools command (#156)
- Loading branch information
Showing
10 changed files
with
99 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@perf-profiler/tools", | ||
"version": "0.1.0", | ||
"author": { | ||
"name": "Almouro", | ||
"email": "alexandrem@bam.tech" | ||
}, | ||
"license": "MIT", | ||
"bin": { | ||
"perf-profiler-tools": "dist/bin.js" | ||
}, | ||
"scripts": { | ||
"test": "tsc" | ||
}, | ||
"dependencies": { | ||
"@perf-profiler/profiler": "^0.10.7", | ||
"@perf-profiler/shell": "^0.1.1", | ||
"commander": "^9.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env node | ||
|
||
import { program } from "commander"; | ||
import { processVideoFile } from "@perf-profiler/shell"; | ||
import { detectCurrentAppBundleId } from "@perf-profiler/profiler"; | ||
|
||
const toolsCommand = program.command("tools").description("Utility tools related to Flashlight"); | ||
|
||
toolsCommand | ||
.command("android_get_bundle_id") | ||
.description("Retrieves the focused app bundle id") | ||
.action(() => { | ||
console.log(detectCurrentAppBundleId().bundleId); | ||
}); | ||
|
||
toolsCommand | ||
.command("video_fix_metadata <videoFilePath>") | ||
.description( | ||
"When coming from AWS Device Farm or certain devices, it seems the video from flashlight test is not encoded properly" | ||
) | ||
.action((options) => { | ||
processVideoFile(options.video_file_path, "destinationPath"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../../tsconfig.module.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "./dist" | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { spawn } from "child_process"; | ||
|
||
const execAsync = (command: string) => | ||
new Promise<void>((resolve, reject) => { | ||
const parts = command.split(" "); | ||
const proc = spawn(parts[0], parts.slice(1)); | ||
|
||
proc.on("close", (code) => { | ||
if (code !== 0) { | ||
reject(new Error(`Command ${command} failed with code ${code}`)); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
|
||
proc.on("error", reject); | ||
}); | ||
|
||
export const processVideoFile = async (filePath: string, destinationPath: string) => { | ||
// When coming from AWS Device Farm or certain devices, it seems the video is not encoded properly | ||
// VSync 0 is important since we have variable frame rate from adb shell screenrecord | ||
await execAsync( | ||
`ffmpeg -y -vsync 0 -i ${filePath} -c:v libx264 -crf 23 -c:a aac -b:a 128k ${destinationPath} -loglevel error` | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters