-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
41 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
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,42 +1,5 @@ | ||
import { readFile } from "fs/promises"; | ||
import path from "path"; | ||
import glob from "tiny-glob"; | ||
import { Driver, snakeToCamelCaseConversion } from "ydb-sdk"; | ||
import emit from "./emit"; | ||
import processFile from "./processFile"; | ||
import processFolder from "./processFolder"; | ||
import processFiles from "./processFiles"; | ||
|
||
export const processFiles = async (files: File[], driver: Driver) => { | ||
let result: File[] = []; | ||
for (const file of files) { | ||
const processedFile = await processFile( | ||
snakeToCamelCaseConversion.ydbToJs(file.name), | ||
file.content, | ||
driver | ||
); | ||
result.push({ | ||
name: snakeToCamelCaseConversion.ydbToJs(file.name), | ||
content: emit(processedFile), | ||
}); | ||
} | ||
return result; | ||
}; | ||
|
||
type File = { | ||
name: string; | ||
content: string; | ||
}; | ||
|
||
export const processFolder = async (source: string, driver: Driver) => { | ||
const target = `${source}/**/*.sql`; | ||
const filenames = await glob(target, { | ||
absolute: true, | ||
filesOnly: true, | ||
}); | ||
const files = await Promise.all( | ||
filenames.map(async (filename) => ({ | ||
name: path.parse(filename).name, | ||
content: await readFile(filename, "utf-8"), | ||
})) | ||
); | ||
return processFiles(files, driver); | ||
}; | ||
export { processFile, processFolder, processFiles }; |
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,26 @@ | ||
import { Driver, snakeToCamelCaseConversion } from "ydb-sdk"; | ||
import emit from "./emit"; | ||
import processFile from "./processFile"; | ||
|
||
const processFiles = async (files: File[], driver: Driver) => { | ||
let result: File[] = []; | ||
for (const file of files) { | ||
const processedFile = await processFile( | ||
snakeToCamelCaseConversion.ydbToJs(file.name), | ||
file.content, | ||
driver | ||
); | ||
result.push({ | ||
name: snakeToCamelCaseConversion.ydbToJs(file.name), | ||
content: emit(processedFile), | ||
}); | ||
} | ||
return result; | ||
}; | ||
|
||
type File = { | ||
name: string; | ||
content: string; | ||
}; | ||
|
||
export default processFiles; |
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,22 @@ | ||
import { readFile } from "fs/promises"; | ||
import path from "path"; | ||
import glob from "tiny-glob"; | ||
import { Driver } from "ydb-sdk"; | ||
import processFiles from "./processFiles"; | ||
|
||
const processFolder = async (source: string, driver: Driver) => { | ||
const target = `${source}/**/*.sql`; | ||
const filenames = await glob(target, { | ||
absolute: true, | ||
filesOnly: true, | ||
}); | ||
const files = await Promise.all( | ||
filenames.map(async (filename) => ({ | ||
name: path.parse(filename).name, | ||
content: await readFile(filename, "utf-8"), | ||
})) | ||
); | ||
return processFiles(files, driver); | ||
}; | ||
|
||
export default processFolder; |