-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,51 @@ | ||
// specific initialization steps for an emulator | ||
|
||
import { promptOnce } from "../prompt"; | ||
import { detectStartCommand } from "./apphosting/utils"; | ||
import { EmulatorLogger } from "./emulatorLogger"; | ||
import { Emulators } from "./types"; | ||
|
||
export const AdditionalInitFns: { | ||
[e in Emulators]: () => Promise<Record<string, string> | null>; | ||
} = { | ||
apphosting: async () => { | ||
// Auto-detect package manager and set startCommandOverride | ||
type InitFn = () => Promise<Record<string, string> | null>; | ||
type AdditionalInitFnsType = Partial<Record<Emulators, InitFn>>; | ||
|
||
export const AdditionalInitFns: AdditionalInitFnsType = { | ||
[Emulators.APPHOSTING]: async () => { | ||
const additionalConfigs = new Map<string, string>(); | ||
const logger = EmulatorLogger.forEmulator(Emulators.APPHOSTING); | ||
logger.log("BULLET", "Initializing App Hosting Emulator"); | ||
|
||
// get root directory | ||
const rootDirectory = await promptOnce({ | ||
name: "rootDir", | ||
type: "input", | ||
default: "./", | ||
message: "Specify your app's root directory relative to your repository", | ||
}); | ||
additionalConfigs.set("rootDirectory", rootDirectory); | ||
|
||
// Auto-detect package manager and set startCommandOverride | ||
// TODO: don't use cwd, instead try to find project root | ||
const backendRoot = process.cwd(); | ||
try { | ||
const startCommand = await detectStartCommand(backendRoot); | ||
additionalConfigs.set("startCommandOverride", startCommand); | ||
} catch (e) { | ||
logger.log( | ||
"WARN", | ||
"failed to auto-detect your project's start command, consider manually setting the start command by setting the startCommandOverride config", | ||
); | ||
} | ||
|
||
return { | ||
rootDirectory, | ||
}; | ||
// prompt for apphosting yaml to export | ||
}, | ||
auth: async () => { | ||
return null; | ||
}, | ||
hub: async () => { | ||
return null; | ||
}, | ||
functions: async () => { | ||
return null; | ||
}, | ||
firestore: async () => { | ||
return null; | ||
}, | ||
database: async () => { | ||
return null; | ||
}, | ||
hosting: async () => { | ||
return null; | ||
}, | ||
pubsub: async () => { | ||
return null; | ||
}, | ||
ui: async () => { | ||
return null; | ||
}, | ||
logging: async () => { | ||
return null; | ||
}, | ||
storage: async () => { | ||
return null; | ||
}, | ||
extensions: async () => { | ||
return null; | ||
}, | ||
eventarc: async () => { | ||
return null; | ||
}, | ||
dataconnect: async () => { | ||
return null; | ||
}, | ||
tasks: async () => { | ||
return null; | ||
|
||
return mapToObject(additionalConfigs); | ||
}, | ||
}; | ||
|
||
function mapToObject(map: Map<string, string>): Record<string, string> { | ||
let newObject: Record<string, string> = {}; | ||
Check failure on line 46 in src/emulator/initEmulators.ts GitHub Actions / lint (20)
Check failure on line 46 in src/emulator/initEmulators.ts GitHub Actions / unit (18)
|
||
for (let [key, value] of map) { | ||
Check failure on line 47 in src/emulator/initEmulators.ts GitHub Actions / lint (20)
Check failure on line 47 in src/emulator/initEmulators.ts GitHub Actions / lint (20)
Check failure on line 47 in src/emulator/initEmulators.ts GitHub Actions / unit (18)
Check failure on line 47 in src/emulator/initEmulators.ts GitHub Actions / unit (18)
Check failure on line 47 in src/emulator/initEmulators.ts GitHub Actions / unit (18)
|
||
newObject[key] = value; | ||
} | ||
return newObject; | ||
} |