1 | const Command = require('../utils/command')
|
2 | const { track } = require('../utils/telemetry')
|
3 |
|
4 | class UnlinkCommand extends Command {
|
5 | async run() {
|
6 | const { site, state } = this.netlify
|
7 | const siteId = site.id
|
8 |
|
9 | if (!siteId) {
|
10 | this.log(`Folder is not linked to a Netlify site. Run 'netlify link' to link it`)
|
11 | return this.exit()
|
12 | }
|
13 |
|
14 | await this.config.runHook('analytics', {
|
15 | eventName: 'command',
|
16 | payload: {
|
17 | command: 'unlink'
|
18 | }
|
19 | })
|
20 |
|
21 | let siteData = {}
|
22 | try {
|
23 | siteData = await this.netlify.api.getSite({ siteId })
|
24 | } catch (e) {
|
25 |
|
26 | }
|
27 |
|
28 | state.delete('siteId')
|
29 |
|
30 | await track('sites_unlinked', {
|
31 | siteId: siteData.id || siteId
|
32 | })
|
33 |
|
34 | if (site) {
|
35 | this.log(`Unlinked ${site.configPath} from ${siteData ? siteData.name : siteId}`)
|
36 | } else {
|
37 | this.log('Unlinked site')
|
38 | }
|
39 | }
|
40 | }
|
41 |
|
42 | UnlinkCommand.description = `Unlink a local folder from a Netlify site`
|
43 |
|
44 | module.exports = UnlinkCommand
|