Repository: MotiaDev/motia
File: packages/snap/src/cloud/new-deployment/build.ts (TypeScript)

Code before:
}

export const build = async (listener: BuildListener): Promise<Builder> => {
  const builder = new Builder(projectDir, listener)
  const stepFiles = getStepFiles(projectDir)

  if (stepFiles.length === 0) {
    throw new Error('Project contains no steps, please add some steps before building')
  }

  // Register language-specific builders
  builder.registerBuilder('node', new NodeBuilder(builder, listener))

  fs.rmSync(distDir, { recursive: true, force: true })
  fs.mkdirSync(distDir, { recursive: true })

  const lockedData = new LockedData(projectDir, 'memory', new NoPrinter())

  if (hasPythonSteps(stepFiles)) {
    builder.registerBuilder('python', new PythonBuilder(builder, listener))
  }

  const invalidSteps = await collectFlows(projectDir, lockedData).catch((err) => {
    const errorMessage = err.filePath 
        ? `Compilation error in ${err.filePath}`
        : 'Compilation error'
    
    const finalMessage = `${errorMessage}\nPlease check the logs above for details`
      
    throw new BuildError(BuildErrorType.COMPILATION, err.filePath, finalMessage, err)
  })

  if (invalidSteps.length > 0) {
    throw new Error('Project contains invalid steps, please fix them before building')
  }

  await Promise.all(lockedData.activeSteps.map((step) => builder.buildStep(step)))
  await builder.buildApiSteps(lockedData.activeSteps.filter(isApiStep))

  const streams = lockedData.listStreams()

  for (const stream of streams) {
    if (stream.config.baseConfig.storageType === 'default') {
      builder.registerStateStream(stream)
    } else {
      listener.onWarning(stream.filePath, 'Custom streams are not supported yet in the cloud')
    }
  }

  const stepsFile: StepsConfigFile = {
    steps: builder.stepsConfig,

Review comment (suggestion):
We're not actually compiling, so let's change it to Build error


```suggestion
        ? `Build error in ${err.filePath}`
        : 'Build error'
```

Code after:

export const build = async (listener: BuildListener): Promise<Builder> => {
  const builder = new Builder(projectDir, listener)
  const stepFiles = getStepFiles(projectDir)

  if (stepFiles.length === 0) {
    throw new Error('Project contains no steps, please add some steps before building')
  }

  // Register language-specific builders
  builder.registerBuilder('node', new NodeBuilder(builder, listener))

  fs.rmSync(distDir, { recursive: true, force: true })
  fs.mkdirSync(distDir, { recursive: true })

  const lockedData = new LockedData(projectDir, 'memory', new NoPrinter())

  if (hasPythonSteps(stepFiles)) {
    builder.registerBuilder('python', new PythonBuilder(builder, listener))
  }

  const invalidSteps = await collectFlows(projectDir, lockedData).catch((err) => {
    const errorMessage = err.filePath ? `Build error in ${err.filePath}` : 'Build error'

    const finalMessage = `${errorMessage}\nPlease check the logs above for details`

    throw new BuildError(BuildErrorType.COMPILATION, err.filePath, finalMessage, err)
  })

  if (invalidSteps.length > 0) {
    throw new Error('Project contains invalid steps, please fix them before building')
  }

  await Promise.all(lockedData.activeSteps.map((step) => builder.buildStep(step)))
  await builder.buildApiSteps(lockedData.activeSteps.filter(isApiStep))

  const streams = lockedData.listStreams()

  for (const stream of streams) {
    if (stream.config.baseConfig.storageType === 'default') {
      builder.registerStateStream(stream)
    } else {
      listener.onWarning(stream.filePath, 'Custom streams are not supported yet in the cloud')
    }
  }

  const stepsFile: StepsConfigFile = {
    steps: builder.stepsConfig,
    streams: builder.streamsConfig,
    routers: builder.routersConfig,
  }