11import simpleGit , { CleanOptions , CommitResult , SimpleGit , SimpleGitOptions } from 'simple-git'
22import yaml from 'js-yaml'
3- import fs from 'fs'
4- import path from 'path'
3+ import path , { dirname } from 'path'
54import axios , { AxiosResponse } from 'axios'
5+ import { existsSync , mkdirSync , readFileSync , writeFileSync } from 'fs'
66import { GitPullError } from './error'
77import { cleanEnv , TOOLS_HOST , USE_SOPS } from './validators'
88import { removeBlankAttributes } from './utils'
@@ -82,18 +82,20 @@ export class Repo {
8282 console . debug ( `Writing to file: ${ absolutePath } ` )
8383 const cleanedData = removeBlankAttributes ( data )
8484 const yamlStr = yaml . safeDump ( cleanedData , { indent : 4 } )
85- fs . writeFileSync ( absolutePath , yamlStr , 'utf8' )
85+ const dir = dirname ( absolutePath )
86+ if ( ! existsSync ( dir ) ) mkdirSync ( dir , { recursive : true } )
87+ writeFileSync ( absolutePath , yamlStr , 'utf8' )
8688 }
8789
8890 fileExists ( relativePath : string ) : boolean {
8991 const absolutePath = path . join ( this . path , relativePath )
90- return fs . existsSync ( absolutePath )
92+ return existsSync ( absolutePath )
9193 }
9294
9395 readFile ( relativePath ) : any {
9496 const absolutePath = path . join ( this . path , relativePath )
9597 console . info ( `Reading from file: ${ absolutePath } ` )
96- const doc = yaml . safeLoad ( fs . readFileSync ( absolutePath , 'utf8' ) )
98+ const doc = yaml . safeLoad ( readFileSync ( absolutePath , 'utf8' ) )
9799 return doc as any
98100 }
99101
@@ -172,7 +174,7 @@ export default async function cloneRepo(
172174 branch ,
173175 protocol = 'https' ,
174176) : Promise < Repo > {
175- if ( ! fs . existsSync ( localPath ) ) fs . mkdirSync ( localPath , 0o744 )
177+ if ( ! existsSync ( localPath ) ) mkdirSync ( localPath , 0o744 )
176178 const remotePathAuth = getRemotePathAuth ( remotePath , protocol , user , password )
177179 const repo = new Repo ( localPath , remotePath , user , email , remotePathAuth , branch )
178180 await repo . clone ( )
@@ -189,7 +191,7 @@ export async function initRepo(
189191 branch ,
190192 protocol = 'https' ,
191193) : Promise < Repo > {
192- if ( ! fs . existsSync ( localPath ) ) fs . mkdirSync ( localPath , 0o744 )
194+ if ( ! existsSync ( localPath ) ) mkdirSync ( localPath , 0o744 )
193195 const remotePathAuth = getRemotePathAuth ( remotePath , protocol , user , password )
194196
195197 const repo = new Repo ( localPath , remotePath , user , email , remotePathAuth , branch )
@@ -199,7 +201,7 @@ export async function initRepo(
199201}
200202
201203export async function initRepoBare ( location ) : Promise < SimpleGit > {
202- fs . mkdirSync ( location , 0o744 )
204+ mkdirSync ( location , 0o744 )
203205 const options : Partial < SimpleGitOptions > = {
204206 baseDir : location ,
205207 config : process . env . NODE_TLS_REJECT_UNAUTHORIZED === '0' ? [ 'http.sslVerify=false' ] : undefined ,
0 commit comments