mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
42
packages/server/src/libs/migration-seed/Utils.ts
Normal file
42
packages/server/src/libs/migration-seed/Utils.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
// @ts-nocheck
|
||||
import * as fs from 'fs';
|
||||
|
||||
/**
|
||||
* Detarmines the module type of the given file path.
|
||||
* @param {string} filepath
|
||||
* @returns {boolean}
|
||||
*/
|
||||
async function isModuleType(filepath: string): boolean {
|
||||
if (process.env.npm_package_json) {
|
||||
const { promisify } = require('util');
|
||||
const readFile = promisify(fs.readFile);
|
||||
// npm >= 7.0.0
|
||||
const packageJson = JSON.parse(
|
||||
await readFile(process.env.npm_package_json, 'utf-8'),
|
||||
);
|
||||
if (packageJson.type === 'module') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return process.env.npm_package_type === 'module' || filepath.endsWith('.mjs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports content of the given file path.
|
||||
* @param {string} filepath
|
||||
* @returns
|
||||
*/
|
||||
export async function importFile(filepath: string): any {
|
||||
return (await isModuleType(filepath))
|
||||
? import(require('url').pathToFileURL(filepath))
|
||||
: require(filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} moduleName
|
||||
* @returns
|
||||
*/
|
||||
export async function importWebpackSeedModule(moduleName: string): any {
|
||||
return import(`../../database/seeds/core/${moduleName}`);
|
||||
}
|
||||
Reference in New Issue
Block a user