Fix develop command

Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
soupette 2022-03-09 17:49:27 +01:00 committed by Convly
parent 3cbc9c24df
commit d47d741664
2 changed files with 22 additions and 13 deletions

View File

@ -18,21 +18,25 @@ const { buildTypeScript, buildAdmin } = require('./builders');
* *
*/ */
module.exports = async function({ build, watchAdmin, polling, browser }) { module.exports = async function({ build, watchAdmin, polling, browser }) {
let dir = process.cwd(); const currentDirectory = process.cwd();
const isTSProject = await tsUtils.isTypeScriptProject(dir); const isTSProject = await tsUtils.isTypeScriptProject(currentDirectory);
const buildDestDir = isTSProject ? path.join(currentDirectory, 'dist') : currentDirectory;
if (isTSProject) {
dir = path.join(dir, 'dist');
}
try { try {
if (cluster.isMaster || cluster.isPrimary) { if (cluster.isMaster || cluster.isPrimary) {
return primaryProcess({ dir, build, browser, watchAdmin }); return primaryProcess({
buildDestDir,
currentDirectory,
dir: buildDestDir,
build,
browser,
watchAdmin,
});
} }
if (cluster.isWorker) { if (cluster.isWorker) {
return workerProcess({ dir, watchAdmin, polling }); return workerProcess({ dir: buildDestDir, watchAdmin, polling });
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -40,23 +44,28 @@ module.exports = async function({ build, watchAdmin, polling, browser }) {
} }
}; };
const primaryProcess = async ({ dir, build, watchAdmin, browser }) => { const primaryProcess = async ({ buildDestDir, currentDirectory, build, watchAdmin, browser }) => {
const currentDirectory = process.cwd();
const isTSProject = await tsUtils.isTypeScriptProject(currentDirectory); const isTSProject = await tsUtils.isTypeScriptProject(currentDirectory);
if (isTSProject) { if (isTSProject) {
await buildTypeScript({ srcDir: currentDirectory, watch: true }); await buildTypeScript({ srcDir: currentDirectory, watch: true });
} }
const config = loadConfiguration(dir); const config = loadConfiguration(buildDestDir);
const serveAdminPanel = getOr(true, 'admin.serveAdminPanel')(config); const serveAdminPanel = getOr(true, 'admin.serveAdminPanel')(config);
const buildExists = fs.existsSync(path.join(dir, 'build')); const buildExists = fs.existsSync(path.join(buildDestDir, 'build'));
// Don't run the build process if the admin is in watch mode // Don't run the build process if the admin is in watch mode
if (build && !watchAdmin && serveAdminPanel && !buildExists) { if (build && !watchAdmin && serveAdminPanel && !buildExists) {
try { try {
await buildAdmin({ dir, optimization: false, forceBuild: false }); await buildAdmin({
buildDestDir,
forceBuild: false,
isTSProject,
optimization: false,
srcDir: currentDirectory,
});
} catch (err) { } catch (err) {
process.exit(1); process.exit(1);
} }