Skip to content

Commit

Permalink
Merge pull request #96 from solana-program/febo/loop
Browse files Browse the repository at this point in the history
febo authored Oct 13, 2024
2 parents ed12c48 + 3487f44 commit 64aa0f9
Showing 5 changed files with 33 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-ducks-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-solana-program": patch
---

Use loop on program scripts
10 changes: 4 additions & 6 deletions template/base/scripts/program/build.mjs
Original file line number Diff line number Diff line change
@@ -14,10 +14,8 @@ import './dump.mjs';
const buildArgs = cliArguments();

// Build the programs.
await Promise.all(
getProgramFolders().map(async (folder) => {
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');
for (const folder of getProgramFolders()) {
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');

await $`cargo-build-sbf --manifest-path ${manifestPath} ${buildArgs}`;
})
);
await $`cargo-build-sbf --manifest-path ${manifestPath} ${buildArgs}`;
}
18 changes: 8 additions & 10 deletions template/base/scripts/program/format.mjs
Original file line number Diff line number Diff line change
@@ -18,14 +18,12 @@ const [cargoArgs, fmtArgs] = partitionArguments(formatArgs, '--');
const toolchain = getToolchainArgument('format');

// Format the programs.
await Promise.all(
getProgramFolders().map(async (folder) => {
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');
for (const folder of getProgramFolders()) {
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');

if (fix) {
await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fmtArgs}`;
} else {
await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- --check ${fmtArgs}`;
}
})
);
if (fix) {
await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fmtArgs}`;
} else {
await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- --check ${fmtArgs}`;
}
}
18 changes: 8 additions & 10 deletions template/base/scripts/program/lint.mjs
Original file line number Diff line number Diff line change
@@ -16,14 +16,12 @@ const fix = popArgument(lintArgs, '--fix');
const toolchain = getToolchainArgument('lint');

// Lint the programs using clippy.
await Promise.all(
getProgramFolders().map(async (folder) => {
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');
for (const folder of getProgramFolders()) {
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');

if (fix) {
await $`cargo ${toolchain} clippy --manifest-path ${manifestPath} --fix ${lintArgs}`;
} else {
await $`cargo ${toolchain} clippy --manifest-path ${manifestPath} ${lintArgs}`;
}
})
);
if (fix) {
await $`cargo ${toolchain} clippy --manifest-path ${manifestPath} --fix ${lintArgs}`;
} else {
await $`cargo ${toolchain} clippy --manifest-path ${manifestPath} ${lintArgs}`;
}
}
18 changes: 8 additions & 10 deletions template/base/scripts/program/test.mjs
Original file line number Diff line number Diff line change
@@ -16,14 +16,12 @@ const testArgs = cliArguments();
const hasSolfmt = await which('solfmt', { nothrow: true });

// Test the programs.
await Promise.all(
getProgramFolders().map(async (folder) => {
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');
for (const folder of getProgramFolders()) {
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');

if (hasSolfmt) {
await $`RUST_LOG=error cargo test-sbf --manifest-path ${manifestPath} ${testArgs} 2>&1 | solfmt`;
} else {
await $`RUST_LOG=error cargo test-sbf --manifest-path ${manifestPath} ${testArgs}`;
}
})
);
if (hasSolfmt) {
await $`RUST_LOG=error cargo test-sbf --manifest-path ${manifestPath} ${testArgs} 2>&1 | solfmt`;
} else {
await $`RUST_LOG=error cargo test-sbf --manifest-path ${manifestPath} ${testArgs}`;
}
}

0 comments on commit 64aa0f9

Please sign in to comment.