Skip to content

Commit 268e9c1

Browse files
committed
chore: wip
1 parent 85f5c0c commit 268e9c1

File tree

2 files changed

+56
-50
lines changed

2 files changed

+56
-50
lines changed

storage/framework/server/build.ts

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,13 @@
11
import process from 'node:process'
22
import { log } from '@stacksjs/cli'
3-
import { app, cloud as cloudConfig } from '@stacksjs/config'
4-
import { frameworkCloudPath, frameworkPath, projectPath } from '@stacksjs/path'
5-
import { hasFiles } from '@stacksjs/storage'
6-
import { $ } from 'bun'
7-
8-
// import { slug } from '@stacksjs/strings'
9-
10-
async function cleanAndCopy(sourcePath: string, targetPath: string) {
11-
$.cwd(frameworkPath('cloud'))
12-
await $`rm -rf ${targetPath}`
13-
await $`cp -r ${sourcePath} ${targetPath}`
14-
}
15-
16-
async function useCustomOrDefaultServerConfig() {
17-
if (hasFiles(projectPath('server'))) {
18-
$.cwd(frameworkPath('cloud'))
19-
20-
// if we have a custom server configuration, use it by copying it to the server directory
21-
await $`cp -r ../../../server .`
22-
23-
return log.info('Using custom server configuration')
24-
}
25-
26-
log.info('Using default server configuration')
27-
}
28-
29-
async function buildServer() {
30-
log.info('Preparing server...')
31-
32-
await cleanAndCopy(frameworkPath('core'), frameworkCloudPath('core'))
33-
await cleanAndCopy(projectPath('config'), frameworkCloudPath('config'))
34-
await cleanAndCopy(projectPath('routes'), frameworkCloudPath('routes'))
35-
await cleanAndCopy(projectPath('app'), frameworkCloudPath('app'))
36-
await cleanAndCopy(projectPath('docs'), frameworkCloudPath('docs'))
37-
await cleanAndCopy(projectPath('storage'), frameworkCloudPath('storage'))
38-
39-
if (!app.name) {
40-
log.error('Please provide a name for your app in your config file')
41-
process.exit(1)
42-
}
43-
44-
// TODO: also allow for a custom container name via a config option
45-
// this currently does not need to be enabled because our CDK deployment handles the docker build process
46-
// await runCommand(`docker build --pull -t ${slug(app.name)} .`, {
47-
// cwd: frameworkPath('cloud'),
48-
// })
49-
50-
log.success('Server ready to be built')
51-
}
3+
import { cloud } from '@stacksjs/config'
4+
import { buildServer, useCustomOrDefaultServerConfig } from './src/build'
525

536
async function main() {
547
await useCustomOrDefaultServerConfig()
55-
if (cloudConfig.api?.deploy) await buildServer()
8+
9+
if (cloud.api?.deploy)
10+
await buildServer()
5611
}
5712

5813
main().catch((error) => {

storage/framework/server/src/build.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import process from 'node:process'
2+
import { log } from '@stacksjs/cli'
3+
import { app, cloud as cloudConfig } from '@stacksjs/config'
4+
import { frameworkCloudPath, frameworkPath, projectPath } from '@stacksjs/path'
5+
import { hasFiles } from '@stacksjs/storage'
6+
import { $ } from 'bun'
7+
8+
export async function cleanAndCopy(sourcePath: string, targetPath: string) {
9+
$.cwd(frameworkPath('cloud'))
10+
await $`rm -rf ${targetPath}`
11+
await $`cp -r ${sourcePath} ${targetPath}`
12+
}
13+
14+
export async function useCustomOrDefaultServerConfig() {
15+
if (hasFiles(projectPath('server'))) {
16+
$.cwd(frameworkPath('cloud'))
17+
18+
// if we have a custom server configuration, use it by copying it to the server directory
19+
await $`cp -r ../../../server .`
20+
21+
return log.info('Using custom server configuration')
22+
}
23+
24+
log.info('Using default server configuration')
25+
}
26+
27+
export async function buildServer() {
28+
log.info('Preparing server...')
29+
30+
await cleanAndCopy(frameworkPath('core'), frameworkCloudPath('core'))
31+
await cleanAndCopy(projectPath('config'), frameworkCloudPath('config'))
32+
await cleanAndCopy(projectPath('routes'), frameworkCloudPath('routes'))
33+
await cleanAndCopy(projectPath('app'), frameworkCloudPath('app'))
34+
await cleanAndCopy(projectPath('docs'), frameworkCloudPath('docs'))
35+
await cleanAndCopy(projectPath('storage'), frameworkCloudPath('storage'))
36+
37+
if (!app.name) {
38+
log.error('Please provide a name for your app in your config file')
39+
process.exit(1)
40+
}
41+
42+
// TODO: need to build index.ts into index.js and then run that from within the Dockerfile
43+
44+
// TODO: also allow for a custom container name via a config option
45+
// this currently does not need to be enabled because our CDK deployment handles the docker build process
46+
// await runCommand(`docker build --pull -t ${slug(app.name)} .`, {
47+
// cwd: frameworkPath('cloud'),
48+
// })
49+
50+
log.success('Server ready to be built')
51+
}

0 commit comments

Comments
 (0)