Skip to content

Commit

Permalink
Better exports
Browse files Browse the repository at this point in the history
  • Loading branch information
esseswann committed Sep 30, 2023
1 parent ebd3468 commit c7c56c8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ydb-codegen",
"version": "0.2.7",
"version": "0.2.8",
"repository": {
"urL": "git+https://github.com/esseswann/ydb-ts-codegen.git",
"type": "git"
Expand Down
43 changes: 3 additions & 40 deletions src/index.ts
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 };
26 changes: 26 additions & 0 deletions src/processFiles.ts
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;
22 changes: 22 additions & 0 deletions src/processFolder.ts
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;

0 comments on commit c7c56c8

Please sign in to comment.