Skip to content

Commit

Permalink
fix: moved fs modules to utils/file
Browse files Browse the repository at this point in the history
  • Loading branch information
saadjutt01 committed May 29, 2021
1 parent c02e258 commit d79e1d7
Show file tree
Hide file tree
Showing 64 changed files with 138 additions and 330 deletions.
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
ReturnCode,
test
} from './main'
import { fileExists } from './utils/file'
import { fileExists } from '@sasjs/utils/file'
import path from 'path'
import dotenv from 'dotenv'
import { Command, parseCommand } from './utils/command'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/add/addCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
saveToGlobalConfig,
saveToLocalConfig
} from '../../utils/config'
import { createFile } from '../../utils/file'
import { createFile } from '@sasjs/utils/file'
import { getAndValidateServerUrl, getCredentialsInput } from './internal/input'
import { TargetScope } from '../../types/targetScope'

Expand Down
2 changes: 1 addition & 1 deletion src/commands/add/spec/add-credential.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ServerType, Target, SasAuthResponse } from '@sasjs/utils'
import dotenv from 'dotenv'
import path from 'path'
import * as authUtils from '../../../utils/auth'
import * as fileUtils from '../../../utils/file'
import * as fileUtils from '@sasjs/utils/file'
import * as configUtils from '../../../utils/config'
import * as inputModule from '../internal/input'
import { getDefaultValues } from '../internal/input'
Expand Down
10 changes: 5 additions & 5 deletions src/commands/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Target, ServerType } from '@sasjs/utils/types'
import { createWebAppServices } from '../web'
import {
readFile,
getSubFoldersInFolder,
getFilesInFolder,
listSubFoldersInFolder,
listFilesInFolder,
createFile
} from '../../utils/file'
} from '@sasjs/utils/file'
import { asyncForEach } from '@sasjs/utils'
import { removeComments, chunk } from '../../utils/utils'
import { getLocalConfig, getMacroCorePath } from '../../utils/config'
Expand Down Expand Up @@ -161,7 +161,7 @@ function getWebServiceScriptInvocation(serverType: ServerType, filePath = '') {
*/
async function getFolderContent(serverType: ServerType) {
const { buildDestinationFolder } = await getConstants()
const buildSubFolders = await getSubFoldersInFolder(buildDestinationFolder)
const buildSubFolders = await listSubFoldersInFolder(buildDestinationFolder)

let folderContent = ''
let folderContentJSON: any = { members: [] }
Expand Down Expand Up @@ -214,7 +214,7 @@ async function getContentFor(
members: []
}

const files = await getFilesInFolder(folderPath)
const files = await listFilesInFolder(folderPath)

await asyncForEach(files, async (file) => {
const fileContent = await readFile(path.join(folderPath, file))
Expand Down
2 changes: 1 addition & 1 deletion src/commands/build/internal/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path'
import { Target } from '@sasjs/utils/types'
import { getConstants } from '../../../constants'
import { getConfiguration } from '../../../utils/config'
import { readFile } from '../../../utils/file'
import { readFile } from '@sasjs/utils/file'

export const getBuildInit = async (target: Target) => {
const { buildSourceFolder } = await getConstants()
Expand Down
3 changes: 2 additions & 1 deletion src/commands/build/spec/cb.spec.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
removeTestApp,
verifyStep
} from '../../../utils/test'
import { copy, deleteFile } from '../../../utils/file'
import { deleteFile } from '@sasjs/utils/file'
import { copy } from '@sasjs/utils/file'
import { generateTimestamp } from '../../../utils/utils'
import { compile } from '../../compile/compile'
import { build } from '../build'
Expand Down
22 changes: 11 additions & 11 deletions src/commands/compile/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
getTestTearDown
} from '../../utils/config'
import {
getSubFoldersInFolder,
getFilesInFolder,
copy,
listSubFoldersInFolder,
listFilesInFolder,
fileExists,
deleteFolder,
createFolder,
isSasFile,
folderExists
} from '../../utils/file'
} from '@sasjs/utils/file'
import { copy } from '@sasjs/utils/file'
import { isSasFile } from '../../utils/file'
import { asyncForEach, listFilesAndSubFoldersInFolder } from '@sasjs/utils'
import { Target } from '@sasjs/utils/types'
import { getConstants } from '../../constants'
Expand Down Expand Up @@ -185,8 +185,8 @@ const compileServiceFolder = async (
? serviceFolder
: path.join(buildSourceFolder, serviceFolder)
const destinationPath = await getDestinationServicePath(folderPath)
const subFolders = await getSubFoldersInFolder(destinationPath)
const filesNamesInPath = await getFilesInFolder(destinationPath)
const subFolders = await listSubFoldersInFolder(destinationPath)
const filesNamesInPath = await listFilesInFolder(destinationPath)

await asyncForEach(filesNamesInPath, async (fileName) => {
const filePath = path.join(destinationPath, fileName)
Expand All @@ -199,7 +199,7 @@ const compileServiceFolder = async (
})

await asyncForEach(subFolders, async (subFolder) => {
const fileNames = await getFilesInFolder(path.join(folderPath, subFolder))
const fileNames = await listFilesInFolder(path.join(folderPath, subFolder))

await asyncForEach(fileNames, async (fileName) => {
const filePath = path.join(destinationPath, subFolder, fileName)
Expand All @@ -224,8 +224,8 @@ const compileJobFolder = async (
? jobFolder
: path.join(buildSourceFolder, jobFolder)
const destinationPath = await getDestinationJobPath(folderPath)
const subFolders = await getSubFoldersInFolder(destinationPath)
const filesNamesInPath = await getFilesInFolder(destinationPath)
const subFolders = await listSubFoldersInFolder(destinationPath)
const filesNamesInPath = await listFilesInFolder(destinationPath)

await asyncForEach(filesNamesInPath, async (fileName) => {
const filePath = path.join(destinationPath, fileName)
Expand All @@ -236,7 +236,7 @@ const compileJobFolder = async (
})

await asyncForEach(subFolders, async (subFolder) => {
const fileNames = await getFilesInFolder(path.join(folderPath, subFolder))
const fileNames = await listFilesInFolder(path.join(folderPath, subFolder))

await asyncForEach(fileNames, async (fileName) => {
const filePath = path.join(destinationPath, subFolder, fileName)
Expand Down
3 changes: 2 additions & 1 deletion src/commands/compile/compileSingleFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path'
import { getProgramFolders, getMacroFolders } from '../../utils/config'
import { copy, fileExists, deleteFolder, createFolder } from '../../utils/file'
import { fileExists, deleteFolder, createFolder } from '@sasjs/utils/file'
import { copy } from '@sasjs/utils/file'
import { Target } from '@sasjs/utils/types'
import { compileServiceFile } from './internal/compileServiceFile'
import { compileJobFile } from './internal/compileJobFile'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/internal/checkCompileStatus.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Target, asyncForEach } from '@sasjs/utils'
import path from 'path'
import { getConstants } from '../../../constants'
import { folderExists } from '../../../utils/file'
import { folderExists } from '@sasjs/utils/file'
import { compareFolders } from './compareFolders'
import { getAllJobFolders } from './getAllJobFolders'
import { getAllServiceFolders } from './getAllServiceFolders'
Expand Down
18 changes: 11 additions & 7 deletions src/commands/compile/internal/compareFolders.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
folderExists,
getSubFoldersInFolder,
getFilesInFolder
} from '../../../utils/file'
listSubFoldersInFolder,
listFilesInFolder
} from '@sasjs/utils/file'
import { isTestFile } from './compileTestFile'

export const compareFolders = async (
Expand All @@ -26,15 +26,19 @@ export const compareFolders = async (
}
}

const sourceSubFolders = (await getSubFoldersInFolder(sourcePath)) as string[]
const destinationSubFolders = (await getSubFoldersInFolder(
const sourceSubFolders = (await listSubFoldersInFolder(
sourcePath
)) as string[]
const destinationSubFolders = (await listSubFoldersInFolder(
destinationPath
)) as string[]

const sourceFiles = (await getFilesInFolder(sourcePath).then((files) =>
const sourceFiles = (await listFilesInFolder(sourcePath).then((files) =>
files.filter((file: string) => !isTestFile(file))
)) as string[]
const destinationFiles = (await getFilesInFolder(destinationPath)) as string[]
const destinationFiles = (await listFilesInFolder(
destinationPath
)) as string[]

const areSubFoldersMatching = sourceSubFolders.every((subFolder) =>
exceptions?.includes(subFolder)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/internal/compileJobFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Target } from '@sasjs/utils/types'

import { createFile } from '../../../utils/file'
import { createFile } from '@sasjs/utils/file'
import { loadDependencies } from './loadDependencies'

export async function compileJobFile(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/internal/compileServiceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path'
import { Target, ServerType } from '@sasjs/utils/types'

import { getMacroCorePath } from '../../../utils/config'
import { createFile, readFile } from '../../../utils/file'
import { createFile, readFile } from '@sasjs/utils/file'
import { loadDependencies } from './loadDependencies'
import { getServerType } from './getServerType'

Expand Down
9 changes: 5 additions & 4 deletions src/commands/compile/internal/compileTestFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { getConstants } from '../../../constants'
import {
createFile,
copy,
getFilesInFolder,
listFilesInFolder,
fileExists
} from '../../../utils/file'
} from '@sasjs/utils/file'
import { loadDependencies } from './loadDependencies'
import { createFolder, sasFileRegExp } from '../../../utils/file'
import { createFolder } from '@sasjs/utils/file'
import { sasFileRegExp } from '../../../utils/file'
import chalk from 'chalk'
import {
Target,
Expand Down Expand Up @@ -68,7 +69,7 @@ export async function moveTestFile(filePath: string) {
.slice(0, filePath.split(path.sep).length - 1)
.join(path.sep)

if ((await getFilesInFolder(sourceFolder)).length === 0) {
if ((await listFilesInFolder(sourceFolder)).length === 0) {
await deleteFolder(sourceFolder)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/internal/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Target } from '@sasjs/utils/types'
import { readFile } from '../../../utils/file'
import { readFile } from '@sasjs/utils/file'
import path from 'path'
import { getConstants } from '../../../constants'
import { getLocalOrGlobalConfig } from '../../../utils/config'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/internal/loadDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Target, asyncForEach } from '@sasjs/utils'
import { getConstants } from '../../../constants'
import { getLocalOrGlobalConfig } from '../../../utils/config'
import { readFile } from '../../../utils/file'
import { readFile } from '@sasjs/utils/file'
import { chunk } from '../../../utils/utils'
import {
getDependencyPaths,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/internal/spec/compileTestFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../../../../utils/test'
import { removeFromGlobalConfig } from '../../../../utils/config'
import { generateTimestamp } from '../../../../utils/utils'
import { copy, readFile, fileExists, createFile } from '../../../../utils/file'
import { copy, readFile, fileExists, createFile } from '../../../'@sasjs/utils/file'
import path from 'path'
import { compile } from '../../compile'
import chalk from 'chalk'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/spec/compareFolders.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path'
import { createFile, createFolder, deleteFolder } from '../../../utils/file'
import { createFile, createFolder, deleteFolder } from '@sasjs/utils/file'
import { generateTimestamp } from '../../../utils/utils'
import { compareFolders } from '../internal/compareFolders'

Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/spec/compile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
readFile,
fileExists,
deleteFolder
} from '../../../utils/file'
} from '@sasjs/utils/file'
import { Command } from '../../../utils/command'
import * as compileModule from '../compile'
import { compileSingleFile } from '../compileSingleFile'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/spec/compileJobFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../../../utils/test'
import { generateTimestamp } from '../../../utils/utils'
import { compileJobFile } from '../internal/compileJobFile'
import { copy, fileExists, createFolder, readFile } from '../../../utils/file'
import { copy, fileExists, createFolder, readFile } from '@sasjs/utils/file'

const fakeJobInit = `/**
@file
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/spec/compileServiceFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../../../utils/test'
import { generateTimestamp } from '../../../utils/utils'
import { compileServiceFile } from '../internal/compileServiceFile'
import { copy, fileExists, createFolder, readFile } from '../../../utils/file'
import { copy, fileExists, createFolder, readFile } from '@sasjs/utils/file'

const fakeJobInit = `/**
@file
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/spec/getDependencyPaths.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Target } from '@sasjs/utils/types'
import path from 'path'
import { removeFromGlobalConfig } from '../../../utils/config'
import { readFile } from '../../../utils/file'
import { readFile } from '@sasjs/utils/file'
import {
createTestGlobalTarget,
createTestMinimalApp,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compile/spec/getProgramDependencies.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path'
import { readFile } from '../../../utils/file'
import { readFile } from '@sasjs/utils/file'
import {
getProgramDependencies,
getProgramList,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/context/export.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { displayError, displaySuccess } from '../../utils/displayResult'
import path from 'path'
import { createFile, sanitizeFileName } from '../../utils/file'
import { createFile } from '@sasjs/utils/file'
import { sanitizeFileName } from '../../utils/file'
import SASjs from '@sasjs/adapter/node'

/**
Expand Down
4 changes: 2 additions & 2 deletions src/commands/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { edit } from './edit'
import { remove } from './remove'
import { list } from './list'
import { exportContext } from './export'
import { fileExists, readFile } from '../../utils/file'
import { fileExists, readFile } from '@sasjs/utils/file'
import { getAccessToken, findTargetInConfiguration } from '../../utils/config'
import { displayError } from '../../utils/displayResult'
import { Command } from '../../utils/command'
Expand Down Expand Up @@ -98,7 +98,7 @@ export async function processContext(command: Command) {

const contextName = getContextName()

parsedConfig = parseConfig(config)
parsedConfig = parseConfig(config as string)

output = await edit(
contextName,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/context/spec/context.spec.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
readFile,
createFile,
deleteFolder
} from '../../../utils/file'
} from '@sasjs/utils/file'
import SASjs from '@sasjs/adapter/node'
import { generateTimestamp } from '../../../utils/utils'
import { removeFromGlobalConfig } from '../../../utils/config'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/create/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
createTemplateApp
} from '../../utils/utils'

import { createFolder, fileExists } from '../../utils/file'
import { createFolder, fileExists } from '@sasjs/utils/file'
import { createReadme } from './internal/createReadme'
import { createFileStructure } from '../shared/createFileStructure'
import { createLintConfigFile } from '../shared/createLintConfigFile'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/create/internal/createReadme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path'

import { createFile, fileExists } from '../../../utils/file'
import { createFile, fileExists } from '@sasjs/utils/file'

const contentReadMe = `
# SASjs Project Repo
Expand Down
2 changes: 1 addition & 1 deletion src/commands/create/spec/create.spec.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dotenv from 'dotenv'
import path from 'path'
import { verifyFolder, verifyPackageJsonContent } from '../../../utils/test'
import { createFolder, deleteFolder } from '../../../utils/file'
import { createFolder, deleteFolder } from '@sasjs/utils/file'
import { generateTimestamp } from '../../../utils/utils'
import { getFolders } from '../../../utils/config'
import { minimalAppFiles } from './minimalAppFiles'
Expand Down

0 comments on commit d79e1d7

Please sign in to comment.