Skip to content

Commit

Permalink
feat: add scripts subdirectories support (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-bahdanau authored Jun 24, 2024
1 parent 5000db1 commit 4a705d1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Added support for scripts in subdirectories, for example `scripts/counter/deploy.ts`

## [0.21.0] - 2024-05-27

### Changed
Expand Down
4 changes: 4 additions & 0 deletions src/types/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type File = {
name: string;
path: string;
};
22 changes: 15 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import fs from 'fs/promises';
import { UIProvider } from './ui/UIProvider';
import { SCRIPTS_DIR, WRAPPERS_DIR } from './paths';
import { File } from './types/file';

export const tonDeepLink = (address: Address, amount: bigint, body?: Cell, stateInit?: Cell) =>
`ton://transfer/${address.toString({
Expand Down Expand Up @@ -34,15 +35,22 @@ export function oneOrZeroOf<T extends { [k: string]: boolean | undefined }>(opti

const compileEnd = '.compile.ts';

export const findCompiles = async () =>
export const findCompiles = async (): Promise<File[]> =>
(await fs.readdir(WRAPPERS_DIR))
.filter((f) => f.endsWith(compileEnd))
.map((f) => ({ path: path.join(WRAPPERS_DIR, f), name: f.slice(0, f.length - compileEnd.length) }));

export const findScripts = async () =>
(await fs.readdir(SCRIPTS_DIR))
.filter((f) => f.endsWith('.ts'))
.map((f) => ({ path: path.join(SCRIPTS_DIR, f), name: path.parse(f).name }));
export const findScripts = async (): Promise<File[]> => {
const dirents = await fs.readdir(SCRIPTS_DIR, { recursive: true, withFileTypes: true });
const scripts = dirents.filter((dirent) => dirent.isFile() && dirent.name.endsWith('.ts'));

return scripts
.map((script) => ({
name: path.join(script.path.slice(SCRIPTS_DIR.length), script.name),
path: path.join(SCRIPTS_DIR, script.path, script.name),
}))
.sort((a, b) => (a.name >= b.name ? 1 : -1));
};

export async function selectOption(
options: { name: string; value: string }[],
Expand All @@ -64,14 +72,14 @@ export async function selectOption(
}

export async function selectFile(
files: { name: string; path: string }[],
files: File[],
opts: {
ui: UIProvider;
hint?: string;
import?: boolean;
},
) {
let selected: { name: string; path: string };
let selected: File;

if (opts.hint) {
const found = files.find((f) => f.name.toLowerCase() === opts.hint?.toLowerCase());
Expand Down

0 comments on commit 4a705d1

Please sign in to comment.