-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): extract compression service (#1202)
- Loading branch information
Showing
4 changed files
with
64 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createReadStream } from 'node:fs'; | ||
import { pipeline } from 'node:stream/promises'; | ||
import { execa } from 'execa'; | ||
import { injectable } from 'inversify'; | ||
import tar from 'tar'; | ||
|
||
export interface ExtractConfig { | ||
file: string; | ||
cwd: string; | ||
strip?: number; | ||
|
||
files?: string[]; | ||
} | ||
|
||
@injectable() | ||
export class CompressionService { | ||
async extract({ file, cwd, strip, files }: ExtractConfig): Promise<void> { | ||
if (file.endsWith('.zip')) { | ||
await execa('bsdtar', [ | ||
'-xf', | ||
file, | ||
'-C', | ||
cwd, | ||
...(strip ? ['--strip', `${strip}`] : []), | ||
...(files ?? []), | ||
]); | ||
return; | ||
} | ||
|
||
await pipeline(createReadStream(file), tar.x({ cwd, strip }, files)); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,14 +1,22 @@ | ||
import { Container } from 'inversify'; | ||
import { CompressionService } from './compression.service'; | ||
import { EnvService } from './env.service'; | ||
import { HttpService } from './http.service'; | ||
import { PathService } from './path.service'; | ||
import { VersionService } from './version.service'; | ||
|
||
export { EnvService, PathService, VersionService, HttpService }; | ||
export { | ||
EnvService, | ||
PathService, | ||
VersionService, | ||
HttpService, | ||
CompressionService, | ||
}; | ||
|
||
export const rootContainer = new Container(); | ||
|
||
rootContainer.bind(EnvService).toSelf(); | ||
rootContainer.bind(PathService).toSelf(); | ||
rootContainer.bind(VersionService).toSelf(); | ||
rootContainer.bind(HttpService).toSelf(); | ||
rootContainer.bind(CompressionService).toSelf(); |
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