1
1
import process from 'node:process'
2
- import { log } from '@stacksjs/cli'
3
- import { app , cloud as cloudConfig } from '@stacksjs/config'
2
+ import { log , runCommand } from '@stacksjs/cli'
3
+ import { app } from '@stacksjs/config'
4
4
import { frameworkCloudPath , frameworkPath , projectPath } from '@stacksjs/path'
5
5
import { hasFiles } from '@stacksjs/storage'
6
+ import { slug } from '@stacksjs/strings'
6
7
import { $ } from 'bun'
7
8
8
9
export async function cleanAndCopy ( sourcePath : string , targetPath : string ) {
9
10
$ . cwd ( frameworkPath ( 'server' ) )
10
-
11
- await $ `rm -rf ${ targetPath } `
12
- await $ `cp -r ${ sourcePath } ${ targetPath } `
11
+ const r = await $ `rm -rf ${ targetPath } ` . text ( )
12
+ await $ `cp -r ${ sourcePath } ${ targetPath } ` . text ( )
13
13
}
14
14
15
15
export async function useCustomOrDefaultServerConfig ( ) {
@@ -26,9 +26,13 @@ export async function useCustomOrDefaultServerConfig() {
26
26
}
27
27
28
28
export async function buildServer ( ) {
29
- log . info ( 'Preparing server...' )
29
+ log . info ( 'Preparing build...' )
30
+
31
+ // delete old CDK relating files, to always build fresh
32
+ await $ `rm -rf ${ frameworkCloudPath ( 'cdk.out/' ) } `
33
+ await $ `rm -rf ${ frameworkCloudPath ( 'cdk.context.json' ) } `
34
+ await $ `rm -rf ${ frameworkCloudPath ( 'dist.zip' ) } `
30
35
31
- await cleanAndCopy ( frameworkPath ( 'core' ) , frameworkCloudPath ( 'core' ) )
32
36
await cleanAndCopy ( projectPath ( 'config' ) , frameworkCloudPath ( 'config' ) )
33
37
await cleanAndCopy ( projectPath ( 'routes' ) , frameworkCloudPath ( 'routes' ) )
34
38
await cleanAndCopy ( projectPath ( 'app' ) , frameworkCloudPath ( 'app' ) )
@@ -41,12 +45,13 @@ export async function buildServer() {
41
45
}
42
46
43
47
// TODO: need to build index.ts into index.js and then run that from within the Dockerfile
48
+ $ . cwd ( frameworkPath ( 'server' ) )
44
49
45
50
// TODO: also allow for a custom container name via a config option
46
51
// this currently does not need to be enabled because our CDK deployment handles the docker build process
47
- // await runCommand(`docker build --pull -t ${slug(app.name)} .`, {
48
- // cwd: frameworkPath('cloud'),
49
- // })
52
+ await runCommand ( `docker build --pull -t ${ slug ( app . name ) } .` , {
53
+ cwd : frameworkPath ( 'cloud' ) ,
54
+ } )
50
55
51
56
log . success ( 'Server ready to be built' )
52
57
}
0 commit comments