Skip to content

Commit

Permalink
(chore): Check path is real dir
Browse files Browse the repository at this point in the history
  • Loading branch information
NarongOk committed Oct 9, 2024
1 parent 497c2d3 commit 72be8c0
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions libs/aws-cdk-stack/src/lib/lambda-asset-code/typescript-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as child_process from 'child_process';
import * as fs from 'fs';
import * as mkdirp from 'mkdirp';
import { logger } from '@nx/devkit';
import { copy, ensureFileSync } from 'fs-extra';
import { ensureFileSync } from 'fs-extra';

const typeScriptAlreadyBuilt: string[] = []; // list of source code paths already built in this session

Expand Down Expand Up @@ -70,6 +70,7 @@ export class TypeScriptAssetCode extends AssetCode {
copySourceToBePackaged(path, distPath);
destPath = distPath;
}
destPath = destPath.trim();
super(pathModule.join(destPath, '.deploy'));
this.originalSourcePath = path;
// Remember the original source folder
Expand All @@ -92,9 +93,16 @@ export class TypeScriptAssetCode extends AssetCode {
logger.info(
`Building typescript application from source path:${this.typeScriptSourcePath}`
);

// Check typeScriptSourcePath is directory
if (!this.isDirectoryPath(this.typeScriptSourcePath)) {
throw new Error('Source path is invalid: ' + this.typeScriptSourcePath);
}

if (typeScriptAlreadyBuilt.includes(this.typeScriptSourcePath)) {
return;
}

typeScriptAlreadyBuilt.push(this.typeScriptSourcePath);

// Ensure the deploy path exists
Expand Down Expand Up @@ -200,7 +208,15 @@ export class TypeScriptAssetCode extends AssetCode {
}
}
}

private isDirectoryPath(filePath: string): boolean {
return (
pathModule.extname(filePath) === '' &&
pathModule.basename(filePath) !== ''
);
}
}
function copySync(srcPath: string, outputPath: string) {
throw new Error('Function not implemented.');
}

// function copySync(srcPath: string, outputPath: string) {
// throw new Error('Function not implemented.');
// }

0 comments on commit 72be8c0

Please sign in to comment.