secret-polar-reworks
Version:
Polar is a development environment to compile, deploy, test, run scrt contracts on different networks.
21 lines (17 loc) • 699 B
text/typescript
import path from "path";
import { PolarError } from "../internal/core/errors";
import { ERRORS } from "../internal/core/errors-list";
function normalizePaths (mainPath: string, paths: string[]): string[] {
return paths.map(n => path.relative(mainPath, n));
}
export function assertDirChildren (dir: string, scriptNames: string[]): string[] {
const normalized = normalizePaths(".", scriptNames);
const nonScriptPaths = normalized
.filter(scriptName => !path.relative(".", scriptName).startsWith(dir));
if (nonScriptPaths.length !== 0) {
throw new PolarError(ERRORS.BUILTIN_TASKS.SCRIPTS_OUTSIDE_SCRIPTS_DIRECTORY, {
scripts: nonScriptPaths
});
}
return normalized;
}