Skip to content

Commit 7f097a2

Browse files
author
Maurice Faber
committed
fix: mkdir for teams
1 parent 090956c commit 7f097a2

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/build-spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $RefParser from '@apidevtools/json-schema-ref-parser'
2-
import fs from 'fs'
2+
import { writeFileSync } from 'fs'
33
import path from 'path'
44

55
const clientPath = 'vendors/openapi/otomi-api.json'
@@ -9,10 +9,10 @@ async function buildOpenApisSpec(): Promise<void> {
99
const openApiPath = path.resolve(__dirname, 'openapi/api.yaml')
1010
console.log(`Loading api spec from: ${openApiPath}`)
1111
await $RefParser.dereference(openApiPath).then((schema) => {
12-
fs.writeFileSync(modelsPath, JSON.stringify(schema, undefined, ' '), 'utf8')
12+
writeFileSync(modelsPath, JSON.stringify(schema, undefined, ' '), 'utf8')
1313
})
1414
await $RefParser.bundle(openApiPath).then((schema) => {
15-
fs.writeFileSync(clientPath, JSON.stringify(schema, undefined, ' '), 'utf8')
15+
writeFileSync(clientPath, JSON.stringify(schema, undefined, ' '), 'utf8')
1616
})
1717
}
1818

src/otomi-stack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable class-methods-use-this */
22
import * as k8s from '@kubernetes/client-node'
3-
import fs from 'fs'
3+
import { readFileSync } from 'fs'
44
import yaml from 'js-yaml'
55
import { cloneDeep, merge, filter, get, omit, set, unset, isEqual, union, isEmpty } from 'lodash'
66
import generatePassword from 'password-generator'
@@ -81,7 +81,7 @@ export default class OtomiStack {
8181
constructor() {
8282
this.db = new Db(env.DB_PATH)
8383
const corePath = env.isProd ? '/etc/otomi/core.yaml' : './test/core.yaml'
84-
this.coreValues = yaml.safeLoad(fs.readFileSync(corePath, 'utf8')) as any
84+
this.coreValues = yaml.safeLoad(readFileSync(corePath, 'utf8')) as any
8585
this.decryptedFilePostfix = env.USE_SOPS ? '.dec' : ''
8686
}
8787

src/repo.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import simpleGit, { CleanOptions, CommitResult, SimpleGit, SimpleGitOptions } from 'simple-git'
22
import yaml from 'js-yaml'
3-
import fs from 'fs'
4-
import path from 'path'
3+
import path, { dirname } from 'path'
54
import axios, { AxiosResponse } from 'axios'
5+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
66
import { GitPullError } from './error'
77
import { cleanEnv, TOOLS_HOST, USE_SOPS } from './validators'
88
import { 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

201203
export 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

Comments
 (0)