import fs from "fs" ; import path from "path" ; import os from "os" ; import { STS } from "aws-sdk" ; export * as Function from "./function" ; export function resolve ( root , relative ) { return path . resolve ( root , ".sst" , relative ) ; } export function stacksPath ( root ) { return path . join ( root , ".build" , "lib" ) ; } export function init ( root ) { const dir = directory ( root ) ; if ( fs . existsSync ( dir ) ) return ; fs . mkdirSync ( dir , { recursive : true } ) ; } export function directory ( root ) { return resolve ( root , "" ) ; } function resolveStage ( root ) { return resolve ( root , "stage" ) ; } export function getStage ( root ) { const file = resolveStage ( root ) ; try { return fs . readFileSync ( file ) . toString ( ) . trim ( ) ; } catch { return null ; } } export function setStage ( root , stage ) { const file = resolveStage ( root ) ; fs . writeFileSync ( file , stage ) ; } export async function suggestStage ( ) { const client = new STS ( ) ; const result = await client . getCallerIdentity ( ) . promise ( ) . then ( ( result ) => path . basename ( result . Arn ! ) ) . catch ( ( ) => os . userInfo ( ) . username ) ; return result . replace ( /[^A-Za-z0-9]/g , "-" ) ; }