mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
fix: seeds file-system directory
This commit is contained in:
@@ -11,6 +11,7 @@ class FsMigrations {
|
|||||||
private sortDirsSeparately: boolean;
|
private sortDirsSeparately: boolean;
|
||||||
private migrationsPaths: string[];
|
private migrationsPaths: string[];
|
||||||
private loadExtensions: string[];
|
private loadExtensions: string[];
|
||||||
|
private seedsDirectory: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
@@ -30,6 +31,8 @@ class FsMigrations {
|
|||||||
}
|
}
|
||||||
this.migrationsPaths = migrationDirectories;
|
this.migrationsPaths = migrationDirectories;
|
||||||
this.loadExtensions = loadExtensions || DEFAULT_LOAD_EXTENSIONS;
|
this.loadExtensions = loadExtensions || DEFAULT_LOAD_EXTENSIONS;
|
||||||
|
// Store the seeds directory (first path is the seeds directory)
|
||||||
|
this.seedsDirectory = migrationDirectories[0] || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,7 +96,10 @@ class FsMigrations {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
public getMigration(migration: MigrateItem): string {
|
public getMigration(migration: MigrateItem): string {
|
||||||
return importWebpackSeedModule(migration.file.replace('.ts', ''));
|
return importWebpackSeedModule(
|
||||||
|
migration.file.replace('.ts', ''),
|
||||||
|
this.seedsDirectory,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detarmines the module type of the given file 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} moduleName
|
||||||
|
* @param {string} seedsDirectory - The seeds directory path from config
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function importWebpackSeedModule(moduleName: string): any {
|
export async function importWebpackSeedModule(
|
||||||
return import(`../../database/seeds/core/${moduleName}`);
|
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