Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/services/start/docker.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ const buildConfigType = async (context: ConfigContext): Promise<PartialConfigFil
};

const assertDockerCompose = async () => {
if (existsSync(DOCKER_COMPOSE_FILENAME)) {
return;
}

const {image}: {image: string} = await prompts({
const {image}: {image: 'skylab' | 'satellite' | undefined} = await prompts({
type: 'select',
name: 'image',
message: 'What kind of emulator would you like to run locally?',
Expand All @@ -125,6 +121,9 @@ const assertDockerCompose = async () => {
sourceFolder: TEMPLATE_PATH
});

// We should assert the config before creating the docker file otherwise we cannot know if the docker file should reference a TS, JS or JSON config file.
await assertAndInitJunoConfig(image === 'skylab');

const readConfig = image === 'satellite' ? junoDevConfigFile : junoConfigFile;
const {configPath} = readConfig();
const configFile = basename(configPath);
Expand All @@ -134,15 +133,24 @@ const assertDockerCompose = async () => {
.replaceAll('<JUNO_CONFIG>', configFile);

await writeFile(join(DESTINATION_PATH, DOCKER_COMPOSE_FILENAME), content, 'utf-8');

return {dockerImage: image};
};

const assertAndInitConfig = async () => {
await assertDockerCompose();
if (existsSync(DOCKER_COMPOSE_FILENAME)) {
const dockerCompose = await readFile(DOCKER_COMPOSE_FILENAME, 'utf-8');
const isSkylab = /image:\s*junobuild\/skylab(:[^\s]*)?/.test(dockerCompose);

await assertAndInitJunoConfig(isSkylab);
return;
}

const dockerCompose = await readFile(DOCKER_COMPOSE_FILENAME, 'utf-8');
const isSkylab = /image:\s*junobuild\/skylab(:[^\s]*)?/.test(dockerCompose);
await assertDockerCompose();
};

if (isSkylab) {
const assertAndInitJunoConfig = async (skylab: boolean) => {
if (skylab) {
await assertJunoConfig();
return;
}
Expand Down