-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sort contracts when generating files
- Loading branch information
Showing
18 changed files
with
107 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"clarigen-deno": patch | ||
--- | ||
|
||
When generating files, contracts are sorted by name. This prevents git changes due to the indeterminant way that Clarinet outputs contract order |
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
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,45 @@ | ||
import { relative, resolve } from '../deps.ts'; | ||
import { SessionContract } from '../session.ts'; | ||
import { getContractName, toCamelCase } from '../utils.ts'; | ||
export { getContractName, toCamelCase, toKebabCase } from '../utils.ts'; | ||
|
||
export function encodeVariableName(name: string) { | ||
if (/^[A-Z\-_]*$/.test(name)) return name.replaceAll('-', '_'); | ||
return toCamelCase(name); | ||
} | ||
|
||
export async function fileExists(filename: string): Promise<boolean> { | ||
try { | ||
await Deno.stat(filename); | ||
// successful, file or directory must exist | ||
return true; | ||
} catch (error) { | ||
if (error instanceof Deno.errors.NotFound) { | ||
// file or directory does not exist | ||
return false; | ||
} else { | ||
// unexpected error, maybe permissions, pass it along | ||
throw error; | ||
} | ||
} | ||
} | ||
|
||
export function cwdResolve(...paths: string[]) { | ||
return resolve(Deno.cwd(), ...paths); | ||
} | ||
|
||
export function cwdRelative(path: string) { | ||
return relative(Deno.cwd(), path); | ||
} | ||
|
||
// Sort contracts alphabetically by their contract name. | ||
// Used to preserve ordering when generating files | ||
export function sortContracts(contracts: SessionContract[]) { | ||
const nameSorted = [...contracts].sort((a, b) => { | ||
if (getContractName(a.contract_id) < getContractName(b.contract_id)) { | ||
return -1; | ||
} | ||
return 1; | ||
}); | ||
return nameSorted; | ||
} |
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
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
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
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
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
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
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