Skip to content

Commit

Permalink
fix eject page when story already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
eiserfey authored and eiserfey committed Nov 12, 2024
1 parent 940bfc8 commit 31f0254
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/bin/eject-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,27 @@ export async function command(params: { buildContext: BuildContext }) {
componentDirRelativeToThemeTypePath_i
);

const fs = require('fs');
const path = require('path');
const dirName = path.basename(destDirPath);
const tsFilePath = path.join(destDirPath, `${dirName}.component.ts`);
if (fs.existsSync(destDirPath) && fs.readdirSync(destDirPath).length !== 0) {
if (
componentDirRelativeToThemeTypePath_i ===
componentDirRelativeToThemeTypePath
) {
console.log(
`${pageIdOrComponent.split('.ftl')[0]} is already ejected, ${pathRelative(
process.cwd(),
destDirPath
)} already exists`
);
process.exit(-1);
// Check if the directory contains a .ts file with the same name as the directory
if (fs.existsSync(tsFilePath)) {
if (
componentDirRelativeToThemeTypePath_i ===
componentDirRelativeToThemeTypePath
) {
console.log(
`${pageIdOrComponent.split('.ftl')[0]} is already ejected, ${path.relative(
process.cwd(),
destDirPath
)} already exists and contains ${dirName}.ts`
);
process.exit(-1);
}
continue;
}
continue;
}

const localThemeTypeDirPath = pathJoin(
Expand Down

0 comments on commit 31f0254

Please sign in to comment.