Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit edada32

Browse files
authored
Adding plugins:link command to improve the contribution experience (#1169)
* Adding plugins:link command to improve the contribution experience * Removing unnecesary comment
1 parent 2241623 commit edada32

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

packages/plugins/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"@microsoft/bf-cli-command": "1.0.0",
88
"@oclif/command": "~1.5.19",
99
"@oclif/config": "~1.13.3",
10+
"@oclif/errors": "~1.2.2",
1011
"@oclif/plugin-plugins": "~1.7.9",
1112
"cli-ux": "^5.4.1",
1213
"tslib": "^2.0.3"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*!
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import {CLIError, Command, flags} from '@microsoft/bf-cli-command'
7+
import Plugins from '@oclif/plugin-plugins/lib/plugins'
8+
import cli from 'cli-ux'
9+
const fs = require('fs')
10+
11+
export default class PluginsLink extends Command {
12+
static description = `Links a plugin into the BF CLI for development
13+
Installation of a linked plugin will override a user-installed or core plugin.
14+
e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello' command will override the user-installed or core plugin implementation. This is useful for development work.
15+
`
16+
17+
static usage = 'plugins:link PLUGIN'
18+
19+
static args = [{name: 'path', description: 'path to plugin', required: true, default: '.'}]
20+
21+
static flags: flags.Input<any> = {
22+
help: flags.help({char: 'h'}),
23+
verbose: flags.boolean({char: 'v'}),
24+
}
25+
26+
plugins = new Plugins(this.config)
27+
28+
async run() {
29+
const {flags, args} = this.parse(PluginsLink)
30+
this.plugins.verbose = flags.verbose
31+
32+
if (!fs.existsSync(args.path)) {
33+
throw new CLIError('Path to plugin does not exist')
34+
}
35+
36+
cli.action.start(`Linking plugin ${args.path}`)
37+
await this.plugins.link(args.path)
38+
cli.action.stop()
39+
}
40+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {expect, test} from '@oclif/test'
2+
3+
describe('plugins:link', () => {
4+
test
5+
.stderr()
6+
.command(['plugins:link', 'someplugin'])
7+
.exit(1)
8+
.it('runs plugins:link someplugin', ctx => {
9+
expect(ctx.stderr).to.contain('Path to plugin does not exist')
10+
})
11+
})

0 commit comments

Comments
 (0)