mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
fix: seeds file-system directory
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// @ts-nocheck
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
/**
|
||||
* Detarmines the module type of the given file path.
|
||||
@@ -35,8 +36,32 @@ export async function importFile(filepath: string): any {
|
||||
/**
|
||||
*
|
||||
* @param {string} moduleName
|
||||
* @param {string} seedsDirectory - The seeds directory path from config
|
||||
* @returns
|
||||
*/
|
||||
export async function importWebpackSeedModule(moduleName: string): any {
|
||||
return import(`../../database/seeds/core/${moduleName}`);
|
||||
export async function importWebpackSeedModule(
|
||||
moduleName: string,
|
||||
seedsDirectory: string,
|
||||
): any {
|
||||
// Convert the seeds directory to a relative path from this file's location
|
||||
const utilsDir = __dirname;
|
||||
const seedsDirAbsolute = path.isAbsolute(seedsDirectory)
|
||||
? seedsDirectory
|
||||
: path.resolve(process.cwd(), seedsDirectory);
|
||||
|
||||
// Get relative path from Utils.js location to seeds directory
|
||||
const relativePath = path.relative(utilsDir, seedsDirAbsolute);
|
||||
|
||||
// Convert to forward slashes for import (works on all platforms)
|
||||
const importPath = relativePath.split(path.sep).join('/');
|
||||
|
||||
// Construct the import path (add ./ prefix if not already present, or handle empty/current dir)
|
||||
let finalPath = importPath;
|
||||
if (!finalPath || finalPath === '.') {
|
||||
finalPath = './';
|
||||
} else if (!finalPath.startsWith('.')) {
|
||||
finalPath = `./${finalPath}`;
|
||||
}
|
||||
|
||||
return import(`${finalPath}/${moduleName}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user