2022-03-22 12:01:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { join } = require('path');
|
|
|
|
const fse = require('fs-extra');
|
2022-04-14 14:55:57 +02:00
|
|
|
const { isUsingTypeScript } = require('@strapi/typescript-utils');
|
2022-03-22 12:01:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the custom admin entry file name
|
2022-03-23 10:39:31 +01:00
|
|
|
* @param {String} dir - Directory of the admin panel
|
2022-03-22 12:01:17 +01:00
|
|
|
* @returns String
|
|
|
|
*/
|
2022-04-14 10:59:42 +02:00
|
|
|
const getCustomAppConfigFile = async dir => {
|
2022-03-22 12:01:17 +01:00
|
|
|
const adminSrcPath = join(dir, 'src', 'admin');
|
2022-04-14 14:55:57 +02:00
|
|
|
const useTypeScript = await isUsingTypeScript(adminSrcPath, 'tsconfig.json');
|
2022-04-14 10:59:42 +02:00
|
|
|
|
2022-03-22 12:01:17 +01:00
|
|
|
const files = await fse.readdir(adminSrcPath);
|
|
|
|
|
2022-06-07 18:15:37 +02:00
|
|
|
const appJsx = files.find(file => /^app.jsx?$/.test(file));
|
|
|
|
const appTsx = files.find(file => /^app.tsx?$/.test(file));
|
2022-03-22 12:01:17 +01:00
|
|
|
|
2022-06-07 17:33:20 +02:00
|
|
|
if (useTypeScript) {
|
|
|
|
return appTsx || appJsx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return appJsx;
|
2022-03-22 12:01:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = getCustomAppConfigFile;
|