Skip to content

Commit b64c9d1

Browse files
committed
feat: rename and test adapter-stack-destroy script
1 parent f34954f commit b64c9d1

File tree

4 files changed

+352
-29
lines changed

4 files changed

+352
-29
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This project contains a SvelteKit adapter to deploy SvelteKit to AWS using Pulum
3030

3131
### Destroy
3232

33-
1. `npx destroy`
33+
1. `npx adapter-stack-destroy`
3434

3535
## Basic setup example
3636

@@ -105,7 +105,34 @@ in the .env file.
105105

106106
## Destroy Command
107107

108-
A script is provided to destroy the infrastructure.
108+
A script is provided to destroy the infrastructure, with the following
109+
signature:
110+
111+
```
112+
adapter-stack-destroy [artifactPath]
113+
114+
Destroy the SvelteKit adapter's Pulumi stacks
115+
116+
Positionals:
117+
artifactPath directory containing the build artifacts. Defaults to 'build'
118+
[string]
119+
120+
Options:
121+
--version Show version number [boolean]
122+
-s stack name [string]
123+
--default-projects use the built-in Pulumi projects [boolean]
124+
-f, --force cancel ongoing stack updates [boolean]
125+
-h, --help Show help [boolean]
126+
```
127+
128+
When running locally, `adapter-stack-destroy` can be called with no arguments
129+
and it will remove the Pulumi stacks based on a config file in the `build`
130+
directory. If an alternative artifact path was used, pass this value to the
131+
script.
132+
133+
When running in a stateless environment, such as CI, passing the option `-s`
134+
with a stack name and `--default-projects` will delete the given stack based
135+
on the projects defined within the package.
109136

110137
## Dependencies
111138

bin/destroy.ts

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,52 @@ interface Arguments {
1616
[x: string]: unknown
1717
_: (string | number)[]
1818
$0: string
19+
f: boolean
1920
s: string | undefined
20-
'default-projects': string | undefined
21+
artifactPath: string
22+
defaultProjects: boolean
23+
force: boolean
2124
}
2225

2326
export async function main(args: string[]): Promise<void> {
2427
let pulumiPaths: string[] | undefined
2528
let stackName: string | undefined
2629

27-
var argv = yargs(process.argv.slice(2))
28-
.usage('Usage: $0 [options] <artifactPath>')
29-
.command('$0', '', (yargs) => {
30-
yargs
31-
.positional('artifactPath', {
32-
describe: 'directory containing the build artifacts',
33-
type: 'string',
34-
})
35-
.option('s', {
36-
describe: 'stack name',
37-
type: 'string',
38-
})
39-
.option('default-projects', {
40-
describe: 'use the built-in Pulumi projects',
41-
type: 'boolean',
42-
})
43-
})
30+
var argv = yargs(args.slice(2))
31+
.scriptName('adapter-stack-destroy')
32+
.usage(
33+
'$0 [artifactPath]',
34+
"Destroy the SvelteKit adapter's Pulumi stacks",
35+
(yargs) => {
36+
return yargs
37+
.positional('artifactPath', {
38+
describe:
39+
"directory containing the build artifacts. Defaults to 'build'",
40+
type: 'string',
41+
})
42+
.option('s', {
43+
describe: 'stack name',
44+
type: 'string',
45+
})
46+
.option('default-projects', {
47+
describe: 'use the built-in Pulumi projects',
48+
type: 'boolean',
49+
})
50+
.option('f', {
51+
alias: 'force',
52+
describe: 'cancel ongoing stack updates',
53+
type: 'boolean',
54+
})
55+
}
56+
)
4457
.alias('h', 'help')
4558
.help()
4659
.parseSync() as Arguments
4760

48-
console.log(argv)
49-
5061
let artifactPath = 'build'
5162

52-
if (argv._.length) {
53-
artifactPath = String(argv._[0])
63+
if (argv.artifactPath) {
64+
artifactPath = argv.artifactPath
5465
}
5566

5667
const absArtifactPath = path.resolve(process.cwd(), artifactPath)
@@ -69,7 +80,7 @@ export async function main(args: string[]): Promise<void> {
6980
}
7081
}
7182

72-
if ('default-projects' in argv) {
83+
if (argv.defaultProjects) {
7384
const serverPath = path.resolve(__dirname, '..', 'stacks', 'server')
7485
const mainPath = path.resolve(__dirname, '..', 'stacks', 'main')
7586
pulumiPaths = [serverPath, mainPath]
@@ -82,11 +93,11 @@ export async function main(args: string[]): Promise<void> {
8293
let abort: boolean = false
8394

8495
if (pulumiPaths === undefined) {
85-
console.log('Paths to pulumi projects could not be determined.')
96+
console.log('Paths to pulumi projects could not be determined')
8697
abort = true
8798
}
8899

89-
if (pulumiPaths === undefined) {
100+
if (stackName === undefined) {
90101
console.log('Stack name could not be determined')
91102
abort = true
92103
}
@@ -105,7 +116,7 @@ export async function main(args: string[]): Promise<void> {
105116
retries = 0
106117
exitCode = 1
107118

108-
if ('f' in argv || 'force' in argv) {
119+
if (argv.f || argv.force) {
109120
spawnSync('pulumi', ['cancel', '-s', stackName!, '-y'], {
110121
cwd: pulumiPath,
111122
stdio: [process.stdin, process.stdout, process.stderr],

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"types": "./index.d.ts",
3030
"bin": {
31-
"destroy": "./bin/destroy.js"
31+
"adapter-stack-destroy": "./bin/destroy.js"
3232
},
3333
"scripts": {
3434
"build": "yarn clean && tsc --project tsconfig.build.json && yarn copy-files",
@@ -63,6 +63,9 @@
6363
"sveltekit-adapter-aws-base": "^2.1.1",
6464
"yargs": "^17.7.1"
6565
},
66+
"resolutions": {
67+
"vitest/**/vite": "~4.2.0"
68+
},
6669
"release": {
6770
"branches": [
6871
"main"

0 commit comments

Comments
 (0)