Skip to content

Commit e0daf7b

Browse files
authored
build: ensure .iroha dir before cloning (#233)
1 parent 4564818 commit e0daf7b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

etc/task-prep-iroha.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'jsr:@std/path'
44
import * as colors from 'jsr:@std/fmt/colors'
55
import $ from 'jsr:@david/dax'
66
import { assert, assertEquals } from '@std/assert'
7-
import { copy, emptyDir } from 'jsr:@std/fs'
7+
import { copy, emptyDir, ensureDir } from 'jsr:@std/fs'
88

99
const IROHA_REPO_DIR = resolveFromRoot('.iroha')
1010
const PREP_OUTPUT_DIR = resolveFromRoot('prep/iroha')
@@ -37,7 +37,7 @@ or
3737
Deno.exit(1)
3838
}
3939

40-
async function clean() {
40+
async function removeIroha() {
4141
console.log(' ' + colors.yellow(`remove ${pathRel(IROHA_REPO_DIR)}`))
4242
try {
4343
await Deno.remove(IROHA_REPO_DIR, { recursive: true })
@@ -47,7 +47,7 @@ async function clean() {
4747
}
4848

4949
async function linkPath(target: string) {
50-
await clean()
50+
await removeIroha()
5151

5252
const full = path.resolve(target)
5353
await Deno.symlink(full, IROHA_REPO_DIR)
@@ -56,9 +56,10 @@ async function linkPath(target: string) {
5656
}
5757

5858
async function cloneRepo(repo: string, tagOrRevision: string) {
59-
await clean()
59+
await removeIroha()
6060

6161
$.logStep(`Cloning repo ${colors.blue(repo)} at revision ${colors.yellow(tagOrRevision)}`)
62+
await ensureDir(IROHA_REPO_DIR)
6263
await $`git init --quiet`.cwd(IROHA_REPO_DIR)
6364
await $`git remote add origin ${repo}`.cwd(IROHA_REPO_DIR)
6465
await $`git fetch origin ${tagOrRevision}`.cwd(IROHA_REPO_DIR)
@@ -134,6 +135,8 @@ if (args.git) {
134135
assert(args['git-rev'], '--git requires --git-rev')
135136
assert(!args.path, 'either --git or --path, not both')
136137
await cloneRepo(args.git, args['git-rev'])
138+
console.log(' ' + colors.yellow(`empty ${pathRel(PREP_OUTPUT_DIR)}`))
139+
await emptyDir(PREP_OUTPUT_DIR)
137140
} else if (args.path) {
138141
assert(!args.git && !args['git-rev'], `--path conflicts with --git and --git-rev`)
139142
await linkPath(args.path)

0 commit comments

Comments
 (0)