File tree Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Original file line number Diff line number Diff line change 1
1
import process from 'node:process'
2
2
import { handleError } from '@stacksjs/error-handling'
3
- import { parseOptions } from '@stacksjs/cli'
3
+ import { log , parseOptions } from '@stacksjs/cli'
4
4
import { ExitCode } from '@stacksjs/types'
5
+ import { purchaseDomain } from '@stacksjs/cloud'
5
6
6
7
interface PurchaseOptions {
7
8
domain : string
@@ -91,11 +92,12 @@ if (!options.domain) {
91
92
process . exit ( ExitCode . FatalError )
92
93
}
93
94
94
- function purchaseDomain
95
-
96
- const result = await purchaseDomain ( options . domain )
95
+ const result = purchaseDomain ( options . domain , options )
97
96
98
97
if ( result . isErr ( ) ) {
99
98
handleError ( result . error )
100
- process . exit ( 1 )
99
+ process . exit ( ExitCode . FatalError )
101
100
}
101
+
102
+ log . info ( result . value )
103
+ process . exit ( ExitCode . Success )
Original file line number Diff line number Diff line change 1
1
import { log } from '@stacksjs/cli'
2
+ import { err , ok } from '@stacksjs/error-handling'
2
3
import aws from 'aws-sdk'
3
4
4
5
export * from './drivers'
@@ -44,10 +45,10 @@ interface PurchaseOptions {
44
45
verbose ?: boolean
45
46
}
46
47
47
- export function purchaseDomain ( options : PurchaseOptions ) {
48
+ export function purchaseDomain ( domain : string , options : PurchaseOptions ) {
48
49
const route53domains = new aws . Route53Domains ( { region : 'us-east-1' } )
49
50
const params = {
50
- DomainName : options . domain ,
51
+ DomainName : domain ,
51
52
DurationInYears : options . years || 1 ,
52
53
AutoRenew : options . autoRenew || true ,
53
54
AdminContact : {
@@ -94,10 +95,16 @@ export function purchaseDomain(options: PurchaseOptions) {
94
95
PrivacyProtectTechContact : options . privacyTech || options . privacy || true ,
95
96
}
96
97
97
- route53domains . registerDomain ( params , ( err , data ) => {
98
- if ( err )
99
- handleError ( err , err . stack )
100
- else
101
- log . info ( data )
98
+ const result = route53domains . registerDomain ( params , ( error , data ) => {
99
+ if ( error )
100
+ return error
101
+
102
+ log . info ( data )
103
+ return data
102
104
} )
105
+
106
+ if ( result instanceof Error )
107
+ return err ( result )
108
+
109
+ return ok ( result )
103
110
}
You can’t perform that action at this time.
0 commit comments