-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle deployment selection inconsistencies (#161)
- Loading branch information
1 parent
951f2db
commit 35788d4
Showing
5 changed files
with
194 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { relativePath } from './filePath'; | ||
import { stripPrefix, stripSuffix } from './utils'; | ||
|
||
/** | ||
* Extracts the contract name from a file path like: | ||
* /projects/projectName/dist/func_contractName.abi | ||
*/ | ||
export function extractContractName( | ||
contractFilePath: string, | ||
projectPath: string, | ||
): string { | ||
let filePath = relativePath(contractFilePath, projectPath); | ||
|
||
filePath = stripPrefix(filePath, 'dist/'); | ||
|
||
// Remove either 'tact_' or 'func_' from start, if present | ||
filePath = stripPrefix(filePath, 'tact_'); | ||
filePath = stripPrefix(filePath, 'func_'); | ||
|
||
// Remove extension | ||
filePath = stripSuffix(filePath, '.abi'); | ||
|
||
return filePath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ContractLanguage, Tree } from '@/interfaces/workspace.interface'; | ||
import { replaceFileExtension } from './filePath'; | ||
import { getFileExtension, stripPrefix, stripSuffix } from './utils'; | ||
|
||
export function filterABIFiles( | ||
files: Tree[], | ||
basePath: string, | ||
lang: ContractLanguage, | ||
) { | ||
return files | ||
.filter((file) => { | ||
const fileExtension = getFileExtension(file.name); | ||
const isAbiFile = | ||
file.path.startsWith(`${basePath}/dist`) && fileExtension === 'abi'; | ||
|
||
if (lang === 'func') { | ||
return isAbiFile; | ||
} | ||
|
||
// For tact we have to check if both ABI and It's wrapper TS file is present. | ||
const hasTsFile = files.some( | ||
(f) => f.path === replaceFileExtension(file.path, '.abi', '.ts'), | ||
); | ||
return isAbiFile && hasTsFile; | ||
}) | ||
.map((file) => ({ | ||
id: file.id, | ||
name: cleanAbiFileName(file.name), | ||
path: file.path, | ||
})); | ||
} | ||
|
||
/** | ||
* A convenience function to remove .abi if at the end, | ||
* and also remove 'tact_' or 'func_' prefixes if at the start. | ||
*/ | ||
export function cleanAbiFileName(rawName: string): string { | ||
let name = stripSuffix(rawName, '.abi'); | ||
name = stripPrefix(name, 'tact_'); | ||
name = stripPrefix(name, 'func_'); | ||
return name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { stripPrefix } from './utils'; | ||
|
||
export function relativePath(fullPath: string, basePath: string): string { | ||
let path = stripPrefix(fullPath, basePath); | ||
|
||
// If there's a leading slash (after removing basePath), remove it: | ||
if (path.startsWith('/')) { | ||
path = path.slice(1); | ||
} | ||
|
||
return path; | ||
} | ||
|
||
export function replaceFileExtension( | ||
filePath: string, | ||
oldExt: string, | ||
newExt: string, | ||
): string { | ||
if (filePath.endsWith(oldExt)) { | ||
return filePath.slice(0, -oldExt.length) + newExt; | ||
} | ||
// If the file doesn’t end with `oldExt`, return unchanged, or handle otherwise | ||
return filePath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters