Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
feat: get scripts and contracts folder dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtekgrinder committed Jan 17, 2024
1 parent 11f8ac1 commit 1909eb8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
17 changes: 14 additions & 3 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
"lint": "echo 'linting...'",
"format": "echo 'formatting...'",
"test": "echo 'testing...'"
},
"packageManager": "[email protected]",
"dependencies": {
"js-yaml": "^4.1.0"
}
}
24 changes: 20 additions & 4 deletions toolchains/solidity/extension/src/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { exec } from "child_process";
import { workspace } from "vscode";
import * as path from 'path';
import * as os from 'os';
import yaml from 'js-yaml';

export type Contract = {
name: string;
Expand All @@ -14,10 +16,24 @@ export type Script = {
name: string;
}

Check warning on line 17 in toolchains/solidity/extension/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint (osmium-solidity)

Missing semicolon

async function getScriptFolder(): Promise<string> {
const foundryConfigContent = await workspace.fs.readFile(workspace.workspaceFolders[0].uri.with({ path: path.join(workspace.workspaceFolders[0].uri.path, 'foundry.toml') }));
const parsedFoundryConfig = yaml.load(foundryConfigContent.toString());

return parsedFoundryConfig.script ?? 'script';
}

async function getContractFolder(): Promise<string> {
const foundryConfigContent = await workspace.fs.readFile(workspace.workspaceFolders[0].uri.with({ path: path.join(workspace.workspaceFolders[0].uri.path, 'foundry.toml') }));
const parsedFoundryConfig = yaml.load(foundryConfigContent.toString());

return parsedFoundryConfig.contract ?? 'src';
}

async function getContracts(): Promise<Contract[]> {
const contracts: Contract[] = [];
// TODO read from config file the contract path
const contractFiles = await workspace.findFiles('**/src/*.sol');
const contractFolder = await getContractFolder();
const contractFiles = await workspace.findFiles(`**/${contractFolder}/*.sol`);
for (const contractFile of contractFiles) {
const contractContent = await workspace.fs.readFile(contractFile);
// TODO find a way to get the contract name
Expand All @@ -35,8 +51,8 @@ async function getContracts(): Promise<Contract[]> {

async function getScripts(): Promise<Script[]> {
const scripts: Script[] = [];
// TODO read from config file the script path
const scriptFiles = await workspace.findFiles('**/script/*.sol');
const scriptFolder = await getScriptFolder();
const scriptFiles = await workspace.findFiles(`**/${scriptFolder}/*.sol`);
for (const scriptFile of scriptFiles) {
// TODO find a way to get the script name
// TODO handle multiple scripts inside a single file
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3065,6 +3065,7 @@ __metadata:
resolution: "osmium@workspace:."
dependencies:
husky: "npm:^8.0.0"
js-yaml: "npm:^4.1.0"
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 1909eb8

Please sign in to comment.