-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split cli command/register to fix and make testing easier
- Loading branch information
Showing
21 changed files
with
339 additions
and
328 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
src/cli/commands/build.spec.ts → src/cli/commands/build/build.spec.ts
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
37 changes: 2 additions & 35 deletions
37
src/cli/commands/build.ts → src/cli/commands/build/build.ts
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,2 @@ | ||
export * from "./build"; | ||
export { default as registerBuild } from "./register"; |
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,32 @@ | ||
import { Command } from "commander"; | ||
import { DEFAULT_CONFIG } from "../../../config"; | ||
import { configureOptions, isUserOption, logger, matchLoadedConfigName } from "../../../core/utils"; | ||
import { build } from "./build"; | ||
|
||
export default function registerCommand(program: Command) { | ||
program | ||
.command("build [configName|appLocation]") | ||
.usage("[configName|appLocation] [options]") | ||
.description("build your project") | ||
.option("-a, --app-location <path>", "the folder containing the source code of the front-end application", DEFAULT_CONFIG.appLocation) | ||
.option("-i, --api-location <path>", "the folder containing the source code of the API application", DEFAULT_CONFIG.apiLocation) | ||
.option("-O, --output-location <path>", "the folder containing the built source of the front-end application", DEFAULT_CONFIG.outputLocation) | ||
.option("-A, --app-build-command <command>", "the command used to build your app", DEFAULT_CONFIG.appBuildCommand) | ||
.option("-I, --api-build-command <command>", "the command used to build your api", DEFAULT_CONFIG.apiBuildCommand) | ||
.option("--auto", "automatically detect how to build your app and api", false) | ||
.action(async (positionalArg: string | undefined, _options: SWACLIConfig, command: Command) => { | ||
positionalArg = positionalArg?.trim(); | ||
const options = await configureOptions(positionalArg, command.optsWithGlobals(), command, "build"); | ||
if (positionalArg && !matchLoadedConfigName(positionalArg)) { | ||
if (isUserOption("appLocation")) { | ||
logger.error(`swa build <appLocation> cannot be when with --app-location option is also set.`); | ||
logger.error(`You either have to use the positional argument or option, not both at the same time.`, true); | ||
} | ||
|
||
// If it's not the config name, then it's the app location | ||
options.appLocation = positionalArg; | ||
} | ||
|
||
await build(options); | ||
}); | ||
} |
12 changes: 6 additions & 6 deletions
12
src/cli/commands/deploy.spec.ts → src/cli/commands/deploy/deploy.spec.ts
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
74 changes: 6 additions & 68 deletions
74
src/cli/commands/deploy.ts → src/cli/commands/deploy/deploy.ts
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,2 @@ | ||
export * from "./deploy"; | ||
export { default as registerDeploy } from "./register"; |
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,62 @@ | ||
import { Command } from "commander"; | ||
import { DEFAULT_CONFIG } from "../../../config"; | ||
import { configureOptions, isUserOption, logger, matchLoadedConfigName } from "../../../core"; | ||
import { addSharedLoginOptionsToCommand } from "../login"; | ||
import { deploy } from "./deploy"; | ||
|
||
export default function registerCommand(program: Command) { | ||
const deployCommand = program | ||
.command("deploy [configName|outputLocation]") | ||
.usage("[configName|outputLocation] [options]") | ||
.description("deploy the current project to Azure Static Web Apps") | ||
.option("-a, --app-location <path>", "the folder containing the source code of the front-end application", DEFAULT_CONFIG.appLocation) | ||
.option("-i, --api-location <path>", "the folder containing the source code of the API application", DEFAULT_CONFIG.apiLocation) | ||
.option("-O, --output-location <path>", "the folder containing the built source of the front-end application", DEFAULT_CONFIG.outputLocation) | ||
.option( | ||
"-w, --swa-config-location <swaConfigLocation>", | ||
"the directory where the staticwebapp.config.json file is located", | ||
DEFAULT_CONFIG.swaConfigLocation | ||
) | ||
.option("-d, --deployment-token <secret>", "the secret token used to authenticate with the Static Web Apps") | ||
.option("-dr, --dry-run", "simulate a deploy process without actually running it", DEFAULT_CONFIG.dryRun) | ||
.option("-pt, --print-token", "print the deployment token", false) | ||
.option("--env [environment]", "the type of deployment environment where to deploy the project", DEFAULT_CONFIG.env) | ||
.action(async (positionalArg: string | undefined, _options: SWACLIConfig, command: Command) => { | ||
positionalArg = positionalArg?.trim(); | ||
const options = await configureOptions(positionalArg, command.optsWithGlobals(), command, "deploy"); | ||
if (positionalArg && !matchLoadedConfigName(positionalArg)) { | ||
if (isUserOption("outputLocation")) { | ||
logger.error(`swa deploy <outputLocation> cannot be used when --output-location option is also set.`); | ||
logger.error(`You either have to use the positional argument or option, not both at the same time.`, true); | ||
} | ||
|
||
// If it's not the config name, then it's the output location | ||
options.outputLocation = positionalArg; | ||
} | ||
|
||
await deploy(options); | ||
}) | ||
.addHelpText( | ||
"after", | ||
` | ||
Examples: | ||
Deploy using a deployment token | ||
swa deploy ./dist/ --api-location ./api/ --deployment-token <token> | ||
Deploy using a deployment token from env | ||
SWA_CLI_DEPLOYMENT_TOKEN=123 swa deploy ./dist/ --api-location ./api/ | ||
Deploy using swa-cli.config.json file | ||
swa deploy | ||
swa deploy myconfig | ||
Print the deployment token | ||
swa deploy --print-token | ||
Deploy to a specific environment | ||
swa deploy --env production | ||
` | ||
); | ||
addSharedLoginOptionsToCommand(deployCommand); | ||
} |
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,2 @@ | ||
export * from "./init"; | ||
export { default as registerInit } from "./register"; |
6 changes: 3 additions & 3 deletions
6
src/cli/commands/init.spec.ts → src/cli/commands/init/init.spec.ts
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,25 @@ | ||
import { Command } from "commander"; | ||
import process from "process"; | ||
import { configureOptions, isUserOption, logger } from "../../../core/utils"; | ||
import { init } from "./init"; | ||
|
||
export default function registerCommand(program: Command) { | ||
program | ||
.command("init [configName]") | ||
.usage("[configName] [options]") | ||
.description("initialize a new static web app project") | ||
.option("-y, --yes", "answer yes to all prompts (disable interactive mode)", false) | ||
.action(async (configName: string | undefined, _options: SWACLIConfig, command: Command) => { | ||
const options = await configureOptions(undefined, command.optsWithGlobals(), command, "init", false); | ||
if (configName) { | ||
if (isUserOption("configName")) { | ||
logger.error(`swa init <configName> cannot be used when --config-name option is also set.`); | ||
logger.error(`You either have to use the positional argument or option, not both at the same time.`, true); | ||
} | ||
|
||
options.configName = configName; | ||
} | ||
|
||
await init(options, !process.env.SWA_CLI_INTERNAL_COMMAND); | ||
}); | ||
} |
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,2 @@ | ||
export * from "./login"; | ||
export { default as registerLogin, addSharedLoginOptionsToCommand } from "./register"; |
Oops, something went wrong.