Skip to content

Commit b6bf67f

Browse files
committed
feat: remove build directory after destroy
1 parent 8a38ce5 commit b6bf67f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

bin/destroy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env node
22

3+
import * as fs from 'fs'
34
import * as path from 'path'
45
import { fileURLToPath } from 'url'
56
import { spawnSync } from 'child_process'
7+
import { createRequire } from 'node:module';
68

79
import parseArgs from 'minimist'
810

@@ -39,6 +41,9 @@ export async function main(args: string[]): Promise<void> {
3941
stdio: [process.stdin, process.stdout, process.stderr],
4042
env: process.env,
4143
})
44+
45+
fs.rmSync(artifactPath, { recursive: true, force: true })
46+
4247
}
4348

4449
if (process.argv[1] === fileURLToPath(import.meta.url)) {

tests/bin.destroy.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ describe('bin/destroy.ts', () => {
4545

4646
const argv = ['node', 'destroy']
4747
await destroy.main(argv)
48-
48+
49+
expect(fs.existsSync(buildDir)).toBe(false)
4950
fs.rmSync(tmpDir, { recursive: true })
5051

5152
let spawnSyncMock = <any>spawnSync
@@ -78,7 +79,7 @@ describe('bin/destroy.ts', () => {
7879
const argv = ['node', 'destroy', tmpDir]
7980
await destroy.main(argv)
8081

81-
fs.rmSync(tmpDir, { recursive: true })
82+
expect(fs.existsSync(tmpDir)).toBe(false)
8283

8384
let spawnSyncMock = <any>spawnSync
8485
const args = spawnSyncMock.mock.calls[0]
@@ -94,4 +95,16 @@ describe('bin/destroy.ts', () => {
9495
])
9596
)
9697
})
98+
99+
it('main (no args or build)', async () => {
100+
const tmpDir = getTempDir()
101+
const spy = vi.spyOn(process, 'cwd')
102+
spy.mockReturnValue(tmpDir)
103+
104+
const argv = ['node', 'destroy']
105+
await destroy.main(argv)
106+
107+
fs.rmSync(tmpDir, { recursive: true })
108+
})
109+
97110
})

0 commit comments

Comments
 (0)