-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add
install-npm
tool (#1343)
- Loading branch information
Showing
9 changed files
with
127 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Command, Option } from 'clipanion'; | ||
import prettyMilliseconds from 'pretty-ms'; | ||
import * as t from 'typanion'; | ||
import { installTool } from '../install-tool'; | ||
import { logger, validateVersion } from '../utils'; | ||
|
||
export class InstallNpmCommand extends Command { | ||
static override paths = [['install', 'npm']]; | ||
|
||
static override usage = Command.Usage({ | ||
description: 'Installs a npm package into the container.', | ||
examples: [ | ||
['Installs corepack 0.9.0', '$0 install npm corepack 0.9.0'], | ||
[ | ||
'Installs corepack with version via environment variable', | ||
'COREPACK_VERSION=0.9.0 $0 install npm corepack', | ||
], | ||
], | ||
}); | ||
|
||
name = Option.String({ required: true }); | ||
|
||
version = Option.String({ | ||
required: true, | ||
validator: t.cascade(t.isString(), validateVersion()), | ||
}); | ||
|
||
dryRun = Option.Boolean('-d,--dry-run', false); | ||
|
||
async execute(): Promise<number | void> { | ||
const start = Date.now(); | ||
let error = false; | ||
|
||
logger.info(`Installing npm package ${this.name} v${this.version}...`); | ||
try { | ||
return await installTool(this.name, this.version, this.dryRun, 'npm'); | ||
} catch (err) { | ||
logger.fatal(err); | ||
error = true; | ||
return 1; | ||
} finally { | ||
logger.info( | ||
`Installed npm package ${this.name} ${ | ||
error ? 'with errors ' : '' | ||
}in ${prettyMilliseconds(Date.now() - start)}.`, | ||
); | ||
} | ||
} | ||
} | ||
|
||
export class InstallNpmShortCommand extends InstallNpmCommand { | ||
static override paths = []; | ||
|
||
static override usage = Command.Usage({ | ||
description: 'Installs a npm package into the container.', | ||
examples: [ | ||
['Installs corepack v0.9.0', '$0 corepack 0.9.0'], | ||
[ | ||
'Installs corepack with version via environment variable', | ||
'NODE_VERSION=0.9.0 $0 corepack', | ||
], | ||
], | ||
}); | ||
} |
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
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