Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
50 lines
2.0 KiB
Plaintext
50 lines
2.0 KiB
Plaintext
import fs from 'fs/promises';
|
|
import path from 'path';
|
|
async function pathOrFileExists(path) {
|
|
try {
|
|
await fs.access(path);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
/**
|
|
* Returns the path to the import map file. If the import map file is not found, it throws an error.
|
|
*/ export async function resolveImportMapFilePath({ adminRoute = '/admin', importMapFile, rootDir }) {
|
|
let importMapFilePath = undefined;
|
|
if (importMapFile?.length) {
|
|
if (!await pathOrFileExists(importMapFile)) {
|
|
try {
|
|
await fs.writeFile(importMapFile, '', {
|
|
flag: 'wx'
|
|
});
|
|
} catch (err) {
|
|
return new Error(`Could not find the import map file at ${importMapFile}${err instanceof Error && err?.message ? `: ${err.message}` : ''}`);
|
|
}
|
|
}
|
|
importMapFilePath = importMapFile;
|
|
} else {
|
|
const appLocation = path.resolve(rootDir, `app/(payload)${adminRoute}/`);
|
|
const srcAppLocation = path.resolve(rootDir, `src/app/(payload)${adminRoute}/`);
|
|
if (appLocation && await pathOrFileExists(appLocation)) {
|
|
importMapFilePath = path.resolve(appLocation, 'importMap.js');
|
|
if (!await pathOrFileExists(importMapFilePath)) {
|
|
await fs.writeFile(importMapFilePath, '', {
|
|
flag: 'wx'
|
|
});
|
|
}
|
|
} else if (srcAppLocation && await pathOrFileExists(srcAppLocation)) {
|
|
importMapFilePath = path.resolve(srcAppLocation, 'importMap.js');
|
|
if (!await pathOrFileExists(importMapFilePath)) {
|
|
await fs.writeFile(importMapFilePath, '', {
|
|
flag: 'wx'
|
|
});
|
|
}
|
|
} else {
|
|
return new Error(`Could not find Payload import map folder. Looked in ${appLocation} and ${srcAppLocation}`);
|
|
}
|
|
}
|
|
return importMapFilePath;
|
|
}
|
|
|
|
//# sourceMappingURL=resolveImportMapFilePath.js.map |