-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- created a new `env` command - moved the `check` functionality under `env` command - implemented an `install` command to install all or individual deps - added the *env* section to *swanky.config* on `init` with default version from docker base-image - implemented the edit flow for the *env* section in *swanky.config*
- Loading branch information
1 parent
f1081b5
commit 7b0ccbf
Showing
12 changed files
with
336 additions
and
182 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Flags } from "@oclif/core"; | ||
import { SwankyCommand } from "../../lib/swankyCommand.js"; | ||
import { InputError } from "../../lib/errors.js"; | ||
import { installCliDevDeps } from "../../lib/tasks.js"; | ||
import { SUPPORTED_DEPS } from "../../lib/consts.js"; | ||
import { DependencyName, SwankyConfig, getSwankyConfig } from "../../index.js"; | ||
import { ConfigBuilder } from "../../lib/config-builder.js"; | ||
|
||
export class Install extends SwankyCommand<typeof Install> { | ||
static flags = { | ||
deps: Flags.string({ | ||
required: false, | ||
description: `Install the specified dev dependency name and version in the format <dependency@version>. The following options are supported: ${Object.keys( | ||
SUPPORTED_DEPS | ||
).join(", ")}. For installing rust nightly version run: env install --deps rust@nightly`, | ||
multiple: true, | ||
default: [], | ||
char: "d", | ||
}), | ||
}; | ||
|
||
async run(): Promise<void> { | ||
const { flags } = await this.parse(Install); | ||
|
||
const localConfig = getSwankyConfig('local') as SwankyConfig; | ||
const depsToInstall = flags.deps.length > 0 ? this.parseDeps(flags.deps) : localConfig.env; | ||
|
||
if (Object.keys(depsToInstall).length === 0) { | ||
this.log("No dependencies to install."); | ||
return; | ||
} | ||
|
||
await this.installDeps(depsToInstall); | ||
|
||
if (flags.deps.length > 0) { | ||
await this.updateLocalConfig(depsToInstall); | ||
} | ||
|
||
this.log("Swanky Dev Dependencies Installed successfully"); | ||
} | ||
|
||
parseDeps(deps: string[]): Record<string, string> { | ||
return deps.reduce((acc, dep) => { | ||
const [key, value] = dep.split('@'); | ||
if (!Object.keys(SUPPORTED_DEPS).includes(key)) { | ||
throw new InputError(`Unsupported dependency '${key}'. Supported: ${Object.keys(SUPPORTED_DEPS).join(", ")}`); | ||
} | ||
acc[key] = value || 'latest'; | ||
return acc; | ||
}, {} as Record<string, string>); | ||
} | ||
|
||
async installDeps(dependencies: Record<string, string>) { | ||
for (const [dep, version] of Object.entries(dependencies)) { | ||
await this.spinner.runCommand( | ||
() => installCliDevDeps(this.spinner, dep as DependencyName, version), | ||
`Installing ${dep}@${version}` | ||
); | ||
} | ||
} | ||
|
||
async updateLocalConfig(newDeps: Record<string, string>): Promise<void> { | ||
await this.spinner.runCommand(async () => { | ||
const newLocalConfig = new ConfigBuilder(getSwankyConfig('local')) | ||
.updateEnv(newDeps) | ||
.build(); | ||
await this.storeConfig(newLocalConfig, 'local'); | ||
}, "Updating Swanky config with new Dev Dependencies..."); | ||
} | ||
} |
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
Oops, something went wrong.