UNPKG

887 BJavaScriptView Raw
1const Command = require('../base')
2const renderShortDesc = require('../utils/renderShortDescription')
3const { track } = require('../utils/telemetry')
4
5class UnlinkCommand extends Command {
6 async run() {
7 const { site, state } = this.netlify
8 const siteId = site.get('siteId')
9
10 if (!siteId) {
11 this.log(`Folder is not linked to a Netlify site`)
12 return this.exit()
13 }
14
15 let siteData = {}
16 try {
17 siteData = await this.netlify.api.getSite({ siteId })
18 } catch (e) {
19 // ignore errors if we can't get the site
20 }
21
22 state.delete('siteId')
23
24 await track('sites_unlinked', {
25 siteId: siteData.id || siteId,
26 })
27
28 this.log(`Unlinked ${site.configPath} from ${siteData ? siteData.name : siteId}`)
29 }
30}
31
32UnlinkCommand.description = `${renderShortDesc('Unlink a local folder from a Netlify site')}`
33
34module.exports = UnlinkCommand