import * as ChildProcess from 'child_process' ; import * as Path from 'path' ; import * as ShellQuote from 'shell-quote' ; import * as v from 'villa' ; export async function writeTextFileToVolume ( dockerComposeProjectName , volume , path , text , mode ? ) { if ( Path . isAbsolute ( path ) ) { throw new Error ( 'The provided `path` must be relative' ) ; } let quotedPath = ShellQuote . quote ( [ Path . posix . join ( '/volume' , path ) ] ) ; let commands = [ `echo ${ ShellQuote . quote ( [ '-n' , text ] ) } > ${ quotedPath }` ] ; if ( mode ) { commands . push ( `chmod ${ ShellQuote . quote ( [ mode ] ) } ${ quotedPath }` ) ; } let subprocess = ChildProcess . spawn ( 'docker' , [ 'run' , '--rm' , '--volume' , `${ dockerComposeProjectName }_${ volume }:/volume` , 'alpine' , 'sh' , '-c' , commands . join ( ' && ' ) , ] ) ; await v . awaitable ( subprocess ) ; } export function createVolume ( name ) { ChildProcess . spawnSync ( 'docker' , [ 'volume' , 'create' , '--name' , name ] ) ; } export interface ParseGitURLResult { host : string ; project : string ; } export function parseGitURL ( url ) { let [ , host , project ] = ( url . match ( /@(.+?):(.+)\.git/ ) || [ ] ) as ( string | undefined ) [ ] ; return host && project ? { host , project } : undefined ; }