Skip to content

Commit

Permalink
fix: find ecosystem.config.cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Oct 5, 2023
1 parent 8c9033f commit 71ca665
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
35 changes: 17 additions & 18 deletions packages/wb/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Project {
private _dirPath: string;
private _rootDirPath: string | undefined;
private _dockerfile: string | undefined;
private _dockerfilePath: string | undefined;
private _hasDockerfile: boolean | undefined;
private _name: string | undefined;
private _nameWithoutNamespace: string | undefined;
private _rootPackageJson: PackageJson | undefined;
private _dockerPackageJson: PackageJson | undefined;
private _packageJson: PackageJson | undefined;
private _pathByName = new Map<string, string>();

constructor() {
this._dirPath = process.cwd();
Expand All @@ -43,27 +43,14 @@ class Project {
}

get dockerfile(): string {
return (this._dockerfile ??= fs.readFileSync(this.dockerfilePath, 'utf8'));
}

get dockerfilePath(): string {
if (this._dockerfilePath) return this._dockerfilePath;

if (fs.existsSync(path.join(this.dirPath, 'Dockerfile'))) {
this._dockerfilePath = path.join(this.dirPath, 'Dockerfile');
} else if (fs.existsSync(path.join(this.dirPath, '..', '..', 'Dockerfile'))) {
this._dockerfilePath = path.join(this.dirPath, '..', '..', 'Dockerfile');
} else {
throw new Error('Dockerfile not found');
}
return this._dockerfilePath;
return (this._dockerfile ??= fs.readFileSync(this.findFile('Dockerfile'), 'utf8'));
}

get hasDockerfile(): boolean {
if (this._hasDockerfile !== undefined) return this._hasDockerfile;

try {
this._hasDockerfile = !!this.dockerfilePath;
this._hasDockerfile = !!this.findFile('Dockerfile');
} catch {
this._hasDockerfile = false;
}
Expand Down Expand Up @@ -96,9 +83,21 @@ class Project {

get dockerPackageJson(): PackageJson {
return (this._dockerPackageJson ??=
path.dirname(this.dockerfilePath) === this.dirPath
path.dirname(this.findFile('Dockerfile')) === this.dirPath
? this.packageJson
: JSON.parse(fs.readFileSync(path.join(path.dirname(this.dockerfilePath), 'package.json'), 'utf8')));
: JSON.parse(fs.readFileSync(path.join(path.dirname(this.findFile('Dockerfile')), 'package.json'), 'utf8')));
}

findFile(fileName: string): string {
let filePath = this._pathByName.get(fileName);
if (filePath) return filePath;

filePath = [fileName, path.join('..', '..', fileName)].find((p) => fs.existsSync(p));
if (!filePath) {
throw new Error(`File not found: ${fileName}`);
}
this._pathByName.set(fileName, filePath);
return filePath;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/wb/src/scripts/dockerScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DockerScripts {
const prefix = project.dockerPackageJson.scripts?.['docker/build/prepare']
? 'yarn run docker/build/prepare && '
: '';
return `cd ${path.dirname(project.dockerfilePath)}
return `cd ${path.dirname(project.findFile('Dockerfile'))}
&& ${prefix}YARN wb optimizeForDockerBuild --outside
&& YARN wb retry -- docker build -t ${project.nameWithoutNamespace}
--build-arg ARCH=$([ $(uname -m) = 'arm64' ] && echo arm64 || echo amd64)
Expand Down
4 changes: 2 additions & 2 deletions packages/wb/src/scripts/execution/blitzScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BlitzScripts extends BaseExecutionScripts {
return `${appEnv}NODE_ENV=production YARN concurrently --raw --kill-others-on-fail
"${prismaScripts.reset()} && ${project.getBuildCommand(
argv
)} && PORT=${port} pm2-runtime start ecosystem.config.cjs ${argv.normalizedArgsText ?? ''}"
)} && PORT=${port} pm2-runtime start ${project.findFile('ecosystem.config.cjs')} ${argv.normalizedArgsText ?? ''}"
"${this.waitAndOpenApp(argv, port)}"`;
}

Expand All @@ -36,7 +36,7 @@ class BlitzScripts extends BaseExecutionScripts {
playwrightArgs = 'test tests/e2e',
startCommand = `${prismaScripts.reset()} && ${project.getBuildCommand(
argv
)} && pm2-runtime start ecosystem.config.cjs`,
)} && pm2-runtime start ${project.findFile('ecosystem.config.cjs')}`,
}: TestE2EOptions
): string {
return super.testE2E(argv, {
Expand Down
4 changes: 2 additions & 2 deletions packages/wb/src/scripts/execution/nextScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class NextScripts extends BaseExecutionScripts {
return `NODE_ENV=production YARN concurrently --raw --kill-others-on-fail
"${prismaScripts.reset()} && ${project.getBuildCommand(
argv
)} && PORT=${port} pm2-runtime start ecosystem.config.cjs ${argv.normalizedArgsText ?? ''}"
)} && PORT=${port} pm2-runtime start ${project.findFile('ecosystem.config.cjs')} ${argv.normalizedArgsText ?? ''}"
"${this.waitAndOpenApp(argv, port)}"`;
}

Expand All @@ -34,7 +34,7 @@ class NextScripts extends BaseExecutionScripts {
playwrightArgs = 'test tests/e2e',
startCommand = `${prismaScripts.reset()} && ${project.getBuildCommand(
argv
)} && pm2-runtime start ecosystem.config.cjs`,
)} && pm2-runtime start ${project.findFile('ecosystem.config.cjs')}`,
}: TestE2EOptions
): string {
return super.testE2E(argv, {
Expand Down
4 changes: 2 additions & 2 deletions packages/wb/src/scripts/execution/remixScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RemixScripts extends BaseExecutionScripts {
return `NODE_ENV=production YARN concurrently --raw --kill-others-on-fail
"${prismaScripts.reset()} && ${project.getBuildCommand(
argv
)} && PORT=${port} pm2-runtime start ecosystem.config.cjs ${argv.normalizedArgsText ?? ''}"
)} && PORT=${port} pm2-runtime start ${project.findFile('ecosystem.config.cjs')} ${argv.normalizedArgsText ?? ''}"
"${this.waitAndOpenApp(argv, port)}"`;
}

Expand All @@ -34,7 +34,7 @@ class RemixScripts extends BaseExecutionScripts {
playwrightArgs = 'test tests/e2e',
startCommand = `${prismaScripts.reset()} && ${project.getBuildCommand(
argv
)} && pm2-runtime start ecosystem.config.cjs`,
)} && pm2-runtime start ${project.findFile('ecosystem.config.cjs')}`,
}: TestE2EOptions
): string {
return super.testE2E(argv, { playwrightArgs, prismaDirectory: 'prisma', startCommand });
Expand Down

0 comments on commit 71ca665

Please sign in to comment.