-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): allow --hot=* in dev/deploy commands
Passing an asterisk (*) to the --hot/--hot-reload option deploys all compatible services with hot reloading enabled (i.e. all services belonging to a module specifying the hotReload field). Also throw an error before initializing the environment or proceeding with deployment if one or more service names passed to the --hot/--hotReload option aren't configured for hot reloading.
- Loading branch information
Showing
5 changed files
with
89 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2018 Garden Technologies, Inc. <info@garden.io> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { ConfigGraph } from "../config-graph" | ||
import { Service } from "../types/service" | ||
|
||
export async function getHotReloadServiceNames( | ||
namesFromOpt: string[] | undefined, configGraph: ConfigGraph, | ||
) { | ||
const names = namesFromOpt || [] | ||
if (names[0] === "*") { | ||
return (await configGraph.getServices()) | ||
.filter(s => supportsHotReloading(s)) | ||
.map(s => s.name) | ||
} else { | ||
return names | ||
} | ||
} | ||
|
||
/** | ||
* Returns an error message string if one or more serviceNames refers to a service that's not configured for | ||
* hot reloading, or if one or more of serviceNames referes to a non-existent service. Returns null otherwise. | ||
*/ | ||
export async function validateHotReloadServiceNames( | ||
serviceNames: string[], configGraph: ConfigGraph, | ||
): Promise<string | null> { | ||
const services = await configGraph.getServices(serviceNames) | ||
const invalidNames = services | ||
.filter(s => !supportsHotReloading(s)) | ||
.map(s => s.name) | ||
if (invalidNames.length > 0) { | ||
return `The following requested services are not configured for hot reloading: ${invalidNames.join(", ")}` | ||
} else { | ||
return null | ||
} | ||
} | ||
|
||
// TODO: Add hotReload to baseModuleSpecSchema. It's bad form to dig into module type-specific fields | ||
// outside the scope of its plugins. | ||
function supportsHotReloading(service: Service) { | ||
return !!service.module.spec.hotReload | ||
} |