diff --git a/plop/index.ts.hbs b/plop/index.ts.hbs index a291d29..ca5d9d9 100644 --- a/plop/index.ts.hbs +++ b/plop/index.ts.hbs @@ -3,7 +3,6 @@ import { tryLoadEnvs } from '@prisma/sdk'; import { mergeDeepRight } from 'ramda'; import path from 'path'; -import { findSync } from './utils'; import config from './config.json'; import * as models from './models'; diff --git a/prisma/sequelize/index.ts b/prisma/sequelize/index.ts index a291d29..ca5d9d9 100644 --- a/prisma/sequelize/index.ts +++ b/prisma/sequelize/index.ts @@ -3,7 +3,6 @@ import { tryLoadEnvs } from '@prisma/sdk'; import { mergeDeepRight } from 'ramda'; import path from 'path'; -import { findSync } from './utils'; import config from './config.json'; import * as models from './models'; diff --git a/prisma/sequelize/utils/find.ts b/prisma/sequelize/utils/find.ts deleted file mode 100644 index 4dde614..0000000 --- a/prisma/sequelize/utils/find.ts +++ /dev/null @@ -1,112 +0,0 @@ -import fs from 'fs'; -import path from 'path'; - -type ItemType = 'd' | 'f' | 'l'; -type Handler = (base: string, item: string, type: ItemType) => boolean | string; - -/** - * Transform a dirent to a file type - * @param dirent - * @returns - */ -function direntToType(dirent: fs.Dirent | fs.Stats) { - return dirent.isFile() ? 'f' : dirent.isDirectory() ? 'd' : dirent.isSymbolicLink() ? 'l' : undefined; -} - -/** - * Is true if at least one matched - * @param string to match aigainst - * @param regexs to be matched with - * @returns - */ -function isMatched(string: string, regexs: (RegExp | string)[]) { - for (const regex of regexs) { - if (typeof regex === 'string') { - if (string.includes(regex)) { - return true; - } - } else if (regex.exec(string)) { - return true; - } - } - - return false; -} - -/** - * Find paths that match a set of regexes - * @param root to start from - * @param match to match against - * @param types to select files, folders, links - * @param deep to recurse in the directory tree - * @param limit to limit the results - * @param handler to further filter results - * @param found to add to already found - * @param seen to add to already seen - * @returns found paths (symlinks preserved) - */ -export function findSync( - root: string, - match: (RegExp | string)[], - types: ('f' | 'd' | 'l')[] = ['f', 'd', 'l'], - deep: ('d' | 'l')[] = [], - limit: number = Infinity, - handler: Handler = () => true, - found: string[] = [], - seen: Record = {} -) { - try { - const realRoot = fs.realpathSync(root); - - // we make sure not to loop infinitely - if (seen[realRoot]) { - return found; - } - - // we stop if we found enough results - if (limit - found.length <= 0) { - return found; - } - - // we check that the root is a directory - if (direntToType(fs.statSync(realRoot)) !== 'd') { - return found; - } - - // we list the items in the current root - const items = fs.readdirSync(root, { withFileTypes: true }); - - //seen[realRoot] = true - for (const item of items) { - // we get the file info for each item - const itemName = item.name; - const itemType = direntToType(item); - const itemPath = path.join(root, item.name); - - // if the item is one of the selected - if (itemType && types.includes(itemType)) { - // if the path of an item has matched - if (isMatched(itemPath, match)) { - const value = handler(root, itemName, itemType); - - // if we changed the path value - if (typeof value === 'string') { - found.push(value); - } - // if we kept the default path - else if (value === true) { - found.push(itemPath); - } - } - } - - if (deep.includes(itemType as any)) { - // dive within the directory tree - // we recurse and continue mutating `found` - findSync(itemPath, match, types, deep, limit, handler, found, seen); - } - } - } catch {} - - return found; -} diff --git a/prisma/sequelize/utils/index.ts b/prisma/sequelize/utils/index.ts deleted file mode 100644 index 833bbb3..0000000 --- a/prisma/sequelize/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './find'; diff --git a/src/index.ts b/src/index.ts index 4983517..77a42f4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,7 +28,7 @@ generatorHandler({ try { const plop = nodePlop(path.join(__dirname, '../plop/plopfile.js'), { destBasePath: outputDir, force: true }); - const utilsGenerator = plop.getGenerator('utils'); + // const utilsGenerator = plop.getGenerator('utils'); const indexGenerator = plop.getGenerator('index.ts'); const modelGenerator = plop.getGenerator('Model.ts'); @@ -54,7 +54,7 @@ generatorHandler({ const { models } = transformDMMF(options.dmmf); await Promise.all([ - utilsGenerator.runActions({}), + // utilsGenerator.runActions({}), indexGenerator.runActions({ models, config: JSON.stringify(config, null, 2) }), ...models.map((model) => modelGenerator.runActions(model)), ]);