netlify-cli 8.0.13 → 8.1.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/README.md +12 -13
  2. package/bin/run +38 -2
  3. package/npm-shrinkwrap.json +260 -6244
  4. package/package.json +13 -35
  5. package/src/commands/addons/addons-auth.js +50 -0
  6. package/src/commands/addons/addons-config.js +180 -0
  7. package/src/commands/addons/addons-create.js +131 -0
  8. package/src/commands/addons/addons-delete.js +60 -0
  9. package/src/commands/addons/addons-list.js +62 -0
  10. package/src/commands/addons/addons.js +44 -0
  11. package/src/commands/addons/index.js +3 -24
  12. package/src/commands/api/api.js +75 -0
  13. package/src/commands/api/index.js +5 -0
  14. package/src/commands/base-command.js +509 -0
  15. package/src/commands/build/build.js +58 -0
  16. package/src/commands/build/index.js +3 -61
  17. package/src/commands/completion/completion.js +36 -0
  18. package/src/commands/completion/index.js +5 -0
  19. package/src/commands/{deploy.js → deploy/deploy.js} +295 -275
  20. package/src/commands/deploy/index.js +5 -0
  21. package/src/commands/dev/dev-exec.js +35 -0
  22. package/src/commands/dev/dev-trace.js +47 -0
  23. package/src/commands/dev/dev.js +340 -0
  24. package/src/commands/dev/index.js +3 -335
  25. package/src/commands/env/env-get.js +51 -0
  26. package/src/commands/env/env-import.js +93 -0
  27. package/src/commands/env/env-list.js +63 -0
  28. package/src/commands/env/env-set.js +67 -0
  29. package/src/commands/env/env-unset.js +66 -0
  30. package/src/commands/env/env.js +42 -0
  31. package/src/commands/env/index.js +3 -23
  32. package/src/commands/functions/functions-build.js +59 -0
  33. package/src/commands/functions/{create.js → functions-create.js} +130 -94
  34. package/src/commands/functions/functions-invoke.js +273 -0
  35. package/src/commands/functions/functions-list.js +106 -0
  36. package/src/commands/functions/functions-serve.js +63 -0
  37. package/src/commands/functions/functions.js +47 -0
  38. package/src/commands/functions/index.js +3 -45
  39. package/src/commands/index.js +7 -0
  40. package/src/commands/init/index.js +6 -0
  41. package/src/commands/{init.js → init/init.js} +79 -68
  42. package/src/commands/link/index.js +6 -0
  43. package/src/{utils/link/link-by-prompt.js → commands/link/link.js} +141 -14
  44. package/src/commands/lm/index.js +3 -19
  45. package/src/commands/lm/lm-info.js +42 -0
  46. package/src/commands/lm/lm-install.js +33 -0
  47. package/src/commands/lm/lm-setup.js +106 -0
  48. package/src/commands/lm/lm-uninstall.js +25 -0
  49. package/src/commands/lm/lm.js +34 -0
  50. package/src/commands/login/index.js +6 -0
  51. package/src/commands/login/login.js +55 -0
  52. package/src/commands/logout/index.js +5 -0
  53. package/src/commands/logout/logout.js +43 -0
  54. package/src/commands/main.js +188 -0
  55. package/src/commands/open/index.js +3 -39
  56. package/src/commands/open/open-admin.js +60 -0
  57. package/src/commands/open/open-site.js +53 -0
  58. package/src/commands/open/open.js +38 -0
  59. package/src/commands/sites/index.js +5 -20
  60. package/src/commands/sites/sites-create.js +187 -0
  61. package/src/commands/sites/sites-delete.js +104 -0
  62. package/src/commands/sites/sites-list.js +89 -0
  63. package/src/commands/sites/sites.js +32 -0
  64. package/src/commands/status/index.js +3 -118
  65. package/src/commands/status/status-hooks.js +69 -0
  66. package/src/commands/status/status.js +124 -0
  67. package/src/commands/switch/index.js +5 -0
  68. package/src/commands/switch/switch.js +50 -0
  69. package/src/commands/unlink/index.js +5 -0
  70. package/src/commands/unlink/unlink.js +48 -0
  71. package/src/commands/watch/index.js +5 -0
  72. package/src/commands/watch/watch.js +121 -0
  73. package/src/lib/build.js +21 -7
  74. package/src/lib/exec-fetcher.js +5 -3
  75. package/src/lib/fs.js +54 -36
  76. package/src/lib/functions/background.js +1 -1
  77. package/src/lib/functions/form-submissions-handler.js +2 -1
  78. package/src/lib/functions/local-proxy.js +2 -1
  79. package/src/lib/functions/netlify-function.js +4 -1
  80. package/src/lib/functions/registry.js +4 -6
  81. package/src/lib/functions/runtimes/go/index.js +2 -1
  82. package/src/lib/functions/runtimes/js/builders/netlify-lambda.js +6 -4
  83. package/src/lib/functions/runtimes/js/builders/zisi.js +3 -3
  84. package/src/lib/functions/runtimes/rust/index.js +4 -3
  85. package/src/lib/functions/server.js +2 -3
  86. package/src/lib/functions/synchronous.js +2 -1
  87. package/src/lib/functions/utils.js +2 -3
  88. package/src/lib/functions/watcher.js +1 -0
  89. package/src/lib/http-agent.js +5 -5
  90. package/src/lib/log.js +2 -1
  91. package/src/lib/spinner.js +22 -0
  92. package/src/utils/addons/diffs/index.js +1 -0
  93. package/src/utils/addons/diffs/options.js +3 -1
  94. package/src/utils/addons/prepare.js +13 -6
  95. package/src/utils/addons/prompts.js +2 -1
  96. package/src/utils/addons/render.js +3 -1
  97. package/src/utils/command-helpers.js +116 -43
  98. package/src/utils/create-stream-promise.js +5 -5
  99. package/src/utils/deferred.js +1 -0
  100. package/src/utils/deploy/deploy-site.js +1 -1
  101. package/src/utils/deploy/index.js +4 -0
  102. package/src/utils/detect-server-settings.js +10 -12
  103. package/src/utils/dev.js +18 -10
  104. package/src/utils/dot-env.js +4 -2
  105. package/src/utils/{edge-handlers.js → functions/edge-handlers.js} +8 -7
  106. package/src/utils/functions/functions.js +36 -0
  107. package/src/utils/{get-functions.js → functions/get-functions.js} +2 -1
  108. package/src/utils/functions/index.js +8 -26
  109. package/src/utils/get-global-config.js +3 -2
  110. package/src/utils/get-repo-data.js +1 -0
  111. package/src/utils/gh-auth.js +1 -0
  112. package/src/utils/gitignore.js +7 -5
  113. package/src/utils/headers.js +1 -2
  114. package/src/utils/index.js +42 -0
  115. package/src/utils/init/config-github.js +12 -5
  116. package/src/utils/init/config-manual.js +9 -2
  117. package/src/utils/init/config.js +13 -7
  118. package/src/utils/init/frameworks.js +1 -0
  119. package/src/utils/init/node-version.js +4 -2
  120. package/src/utils/init/plugins.js +2 -4
  121. package/src/utils/init/utils.js +10 -6
  122. package/src/utils/live-tunnel.js +3 -4
  123. package/src/utils/lm/install.js +10 -15
  124. package/src/utils/lm/requirements.js +3 -1
  125. package/src/utils/lm/steps.js +1 -1
  126. package/src/utils/lm/ui.js +7 -3
  127. package/src/utils/open-browser.js +8 -2
  128. package/src/utils/parse-raw-flags.js +4 -4
  129. package/src/utils/proxy.js +6 -5
  130. package/src/utils/read-repo-url.js +1 -0
  131. package/src/utils/redirects.js +3 -5
  132. package/src/utils/rules-proxy.js +2 -1
  133. package/src/utils/state-config.js +1 -1
  134. package/src/utils/telemetry/index.js +2 -113
  135. package/src/utils/telemetry/request.js +3 -1
  136. package/src/utils/telemetry/telemetry.js +117 -0
  137. package/src/utils/telemetry/validation.js +13 -12
  138. package/src/utils/traffic-mesh.js +3 -3
  139. package/oclif.manifest.json +0 -1
  140. package/src/commands/addons/auth.js +0 -42
  141. package/src/commands/addons/config.js +0 -177
  142. package/src/commands/addons/create.js +0 -127
  143. package/src/commands/addons/delete.js +0 -69
  144. package/src/commands/addons/list.js +0 -54
  145. package/src/commands/api.js +0 -84
  146. package/src/commands/dev/exec.js +0 -32
  147. package/src/commands/dev/trace.js +0 -61
  148. package/src/commands/env/get.js +0 -44
  149. package/src/commands/env/import.js +0 -90
  150. package/src/commands/env/list.js +0 -49
  151. package/src/commands/env/set.js +0 -64
  152. package/src/commands/env/unset.js +0 -58
  153. package/src/commands/functions/build.js +0 -60
  154. package/src/commands/functions/invoke.js +0 -277
  155. package/src/commands/functions/list.js +0 -102
  156. package/src/commands/functions/serve.js +0 -70
  157. package/src/commands/link.js +0 -133
  158. package/src/commands/lm/info.js +0 -36
  159. package/src/commands/lm/install.js +0 -30
  160. package/src/commands/lm/setup.js +0 -107
  161. package/src/commands/lm/uninstall.js +0 -17
  162. package/src/commands/login.js +0 -54
  163. package/src/commands/logout.js +0 -37
  164. package/src/commands/open/admin.js +0 -51
  165. package/src/commands/open/site.js +0 -43
  166. package/src/commands/sites/create.js +0 -191
  167. package/src/commands/sites/delete.js +0 -116
  168. package/src/commands/sites/list.js +0 -84
  169. package/src/commands/status/hooks.js +0 -60
  170. package/src/commands/switch.js +0 -44
  171. package/src/commands/unlink.js +0 -38
  172. package/src/commands/watch.js +0 -115
  173. package/src/hooks/init.js +0 -46
  174. package/src/index.js +0 -25
  175. package/src/lib/help.js +0 -26
  176. package/src/utils/chalk.js +0 -16
  177. package/src/utils/check-command-inputs.js +0 -21
  178. package/src/utils/command.js +0 -261
  179. package/src/utils/detect-functions-builder.js +0 -25
  180. package/src/utils/difference.js +0 -4
  181. package/src/utils/header.js +0 -18
  182. package/src/utils/logo.js +0 -11
  183. package/src/utils/show-help.js +0 -5
  184. package/src/utils/telemetry/tracked-command.js +0 -51
@@ -1,70 +0,0 @@
1
- const { join } = require('path')
2
-
3
- const { flags: flagsLib } = require('@oclif/command')
4
-
5
- const { startFunctionsServer } = require('../../lib/functions/server')
6
- const Command = require('../../utils/command')
7
- const { acquirePort, getSiteInformation, injectEnvVariables } = require('../../utils/dev')
8
- const { getFunctionsDir } = require('../../utils/functions')
9
-
10
- const DEFAULT_PORT = 9999
11
-
12
- class FunctionsServeCommand extends Command {
13
- async run() {
14
- const { flags } = this.parse(FunctionsServeCommand)
15
-
16
- const { netlify } = this
17
- const { api, config, site, siteInfo } = netlify
18
-
19
- const functionsDir = getFunctionsDir({ flags, config }, join('netlify', 'functions'))
20
-
21
- await injectEnvVariables({ env: this.netlify.cachedConfig.env, site })
22
-
23
- const { capabilities, siteUrl, timeouts } = await getSiteInformation({
24
- flags,
25
- api,
26
- site,
27
- siteInfo,
28
- })
29
-
30
- const functionsPort = await acquirePort({
31
- configuredPort: flags.port || (config.dev && config.dev.functionsPort),
32
- defaultPort: DEFAULT_PORT,
33
- errorMessage: 'Could not acquire configured functions port',
34
- })
35
-
36
- await startFunctionsServer({
37
- config,
38
- settings: { functions: functionsDir, functionsPort },
39
- site,
40
- siteUrl,
41
- capabilities,
42
- timeouts,
43
- functionsPrefix: '/.netlify/functions/',
44
- buildersPrefix: '/.netlify/builders/',
45
- })
46
- }
47
- }
48
-
49
- FunctionsServeCommand.description = `(Beta) Serve functions locally
50
-
51
- Helpful for debugging functions.
52
- `
53
- FunctionsServeCommand.aliases = ['function:serve']
54
- FunctionsServeCommand.flags = {
55
- functions: flagsLib.string({
56
- char: 'f',
57
- description: 'Specify a functions directory to serve',
58
- }),
59
- port: flagsLib.integer({
60
- char: 'p',
61
- description: 'Specify a port for the functions server',
62
- }),
63
- offline: flagsLib.boolean({
64
- char: 'o',
65
- description: 'disables any features that require network access',
66
- }),
67
- ...FunctionsServeCommand.flags,
68
- }
69
-
70
- module.exports = FunctionsServeCommand
@@ -1,133 +0,0 @@
1
- const path = require('path')
2
- const process = require('process')
3
-
4
- const { flags: flagsLib } = require('@oclif/command')
5
- const chalk = require('chalk')
6
-
7
- const { listSites } = require('../lib/api')
8
- const Command = require('../utils/command')
9
- const { error, exit, log } = require('../utils/command-helpers')
10
- const ensureNetlifyIgnore = require('../utils/gitignore')
11
- const linkPrompt = require('../utils/link/link-by-prompt')
12
- const { track } = require('../utils/telemetry')
13
-
14
- class LinkCommand extends Command {
15
- async run() {
16
- await this.authenticate()
17
-
18
- const { flags } = this.parse(LinkCommand)
19
- const {
20
- api,
21
- repositoryRoot,
22
- site: { id: siteId },
23
- state,
24
- } = this.netlify
25
-
26
- let siteData
27
- try {
28
- siteData = await api.getSite({ siteId })
29
- } catch {
30
- // silent api error
31
- }
32
-
33
- // Add .netlify to .gitignore file
34
- await ensureNetlifyIgnore(repositoryRoot)
35
-
36
- // Site id is incorrect
37
- if (siteId && !siteData) {
38
- console.log(`"${siteId}" was not found in your Netlify account.`)
39
- console.log(`Please double check your siteID and which account you are logged into via \`netlify status\`.`)
40
- return exit()
41
- }
42
-
43
- // If already linked to site. exit and prompt for unlink
44
- if (siteData) {
45
- log(`Site already linked to "${siteData.name}"`)
46
- log(`Admin url: ${siteData.admin_url}`)
47
- log()
48
- log(`To unlink this site, run: ${chalk.cyanBright('netlify unlink')}`)
49
- return exit()
50
- }
51
-
52
- if (flags.id) {
53
- try {
54
- siteData = await api.getSite({ site_id: flags.id })
55
- } catch (error_) {
56
- if (error_.status === 404) {
57
- error(new Error(`Site id ${flags.id} not found`))
58
- } else {
59
- error(error_)
60
- }
61
- }
62
-
63
- // Save site ID
64
- state.set('siteId', siteData.id)
65
- log(`Linked to ${siteData.name} in ${state.path}`)
66
-
67
- await track('sites_linked', {
68
- siteId: siteData.id,
69
- linkType: 'manual',
70
- kind: 'byId',
71
- })
72
-
73
- return exit()
74
- }
75
-
76
- if (flags.name) {
77
- let results
78
- try {
79
- results = await listSites({
80
- api,
81
- options: {
82
- name: flags.name,
83
- filter: 'all',
84
- },
85
- })
86
- } catch (error_) {
87
- if (error_.status === 404) {
88
- error(new Error(`${flags.name} not found`))
89
- } else {
90
- error(error_)
91
- }
92
- }
93
-
94
- if (results.length === 0) {
95
- error(new Error(`No sites found named ${flags.name}`))
96
- }
97
- const [firstSiteData] = results
98
- state.set('siteId', firstSiteData.id)
99
-
100
- log(`Linked to ${firstSiteData.name} in ${path.relative(path.join(process.cwd(), '..'), state.path)}`)
101
-
102
- await track('sites_linked', {
103
- siteId: (firstSiteData && firstSiteData.id) || siteId,
104
- linkType: 'manual',
105
- kind: 'byName',
106
- })
107
-
108
- return exit()
109
- }
110
-
111
- siteData = await linkPrompt(this, flags)
112
- return siteData
113
- }
114
- }
115
-
116
- LinkCommand.description = `Link a local repo or project folder to an existing site on Netlify`
117
-
118
- LinkCommand.examples = ['netlify link', 'netlify link --id 123-123-123-123', 'netlify link --name my-site-name']
119
-
120
- LinkCommand.flags = {
121
- id: flagsLib.string({
122
- description: 'ID of site to link to',
123
- }),
124
- name: flagsLib.string({
125
- description: 'Name of site to link to',
126
- }),
127
- gitRemoteName: flagsLib.string({
128
- description: 'Name of Git remote to use. e.g. "origin"',
129
- }),
130
- ...LinkCommand.flags,
131
- }
132
-
133
- module.exports = LinkCommand
@@ -1,36 +0,0 @@
1
- const Listr = require('listr')
2
-
3
- const Command = require('../../utils/command')
4
- const {
5
- checkGitLFSVersionStep,
6
- checkGitVersionStep,
7
- checkHelperVersionStep,
8
- checkLFSFiltersStep,
9
- } = require('../../utils/lm/steps')
10
-
11
- class LmInfoCommand extends Command {
12
- async run() {
13
- this.parse(LmInfoCommand)
14
- const steps = [
15
- checkGitVersionStep,
16
- checkGitLFSVersionStep,
17
- checkLFSFiltersStep((ctx, task, installed) => {
18
- if (!installed) {
19
- throw new Error('Git LFS filters are not installed, run `git lfs install` to install them')
20
- }
21
- }),
22
- checkHelperVersionStep,
23
- ]
24
-
25
- const tasks = new Listr(steps, { concurrent: true, exitOnError: false })
26
- try {
27
- await tasks.run()
28
- } catch {
29
- // an error is already reported when a task fails
30
- }
31
- }
32
- }
33
-
34
- LmInfoCommand.description = `Show large media requirements information.`
35
-
36
- module.exports = LmInfoCommand
@@ -1,30 +0,0 @@
1
- const { flags: flagsLib } = require('@oclif/command')
2
-
3
- const Command = require('../../utils/command')
4
- const { installPlatform } = require('../../utils/lm/install')
5
- const { printBanner } = require('../../utils/lm/ui')
6
-
7
- class LmInstallCommand extends Command {
8
- async run() {
9
- const { flags } = this.parse(LmInstallCommand)
10
-
11
- const installed = await installPlatform({ force: flags.force })
12
- if (installed) {
13
- printBanner(this, flags.force)
14
- }
15
- }
16
- }
17
-
18
- LmInstallCommand.aliases = ['lm:init']
19
- LmInstallCommand.flags = {
20
- force: flagsLib.boolean({
21
- char: 'f',
22
- description: 'Force the credentials helper installation',
23
- }),
24
- }
25
-
26
- LmInstallCommand.description = `Configures your computer to use Netlify Large Media.
27
- It installs the required credentials helper for Git,
28
- and configures your Git environment with the right credentials.`
29
-
30
- module.exports = LmInstallCommand
@@ -1,107 +0,0 @@
1
- const { flags: flagsLib } = require('@oclif/command')
2
- const execa = require('execa')
3
- const Listr = require('listr')
4
-
5
- const Command = require('../../utils/command')
6
- const { error } = require('../../utils/command-helpers')
7
- const { installPlatform } = require('../../utils/lm/install')
8
- const { checkHelperVersion } = require('../../utils/lm/requirements')
9
- const { printBanner } = require('../../utils/lm/ui')
10
-
11
- const installHelperIfMissing = async function ({ force }) {
12
- let installHelper = false
13
- try {
14
- const version = await checkHelperVersion()
15
- if (!version) {
16
- installHelper = true
17
- }
18
- } catch {
19
- installHelper = true
20
- }
21
-
22
- if (installHelper) {
23
- return installPlatform({ force })
24
- }
25
-
26
- return false
27
- }
28
-
29
- const provisionService = async function (siteId, api) {
30
- const addonName = 'large-media'
31
-
32
- if (!siteId) {
33
- throw new Error('No site id found, please run inside a site folder or `netlify link`')
34
- }
35
- try {
36
- await api.createServiceInstance({
37
- siteId,
38
- addon: addonName,
39
- body: {},
40
- })
41
- } catch (error_) {
42
- // error is JSONHTTPError
43
- throw new Error(error_.json.error)
44
- }
45
- }
46
-
47
- const configureLFSURL = async function (siteId, api) {
48
- const siteInfo = await api.getSite({ siteId })
49
- const url = `https://${siteInfo.id_domain}/.netlify/large-media`
50
-
51
- return execa('git', ['config', '-f', '.lfsconfig', 'lfs.url', url])
52
- }
53
-
54
- class LmSetupCommand extends Command {
55
- async run() {
56
- await this.authenticate()
57
-
58
- const { flags } = this.parse(LmSetupCommand)
59
- const { api, site } = this.netlify
60
-
61
- let helperInstalled = false
62
- if (!flags['skip-install']) {
63
- try {
64
- helperInstalled = await installHelperIfMissing({ force: flags['force-install'] })
65
- } catch (error_) {
66
- error(error_)
67
- }
68
- }
69
-
70
- const tasks = new Listr([
71
- {
72
- title: 'Provisioning Netlify Large Media',
73
- async task() {
74
- await provisionService(site.id, api)
75
- },
76
- },
77
- {
78
- title: 'Configuring Git LFS for this site',
79
- async task() {
80
- await configureLFSURL(site.id, api)
81
- },
82
- },
83
- ])
84
- await tasks.run().catch(() => {})
85
-
86
- if (helperInstalled) {
87
- printBanner(this, flags['force-install'])
88
- }
89
- }
90
- }
91
-
92
- LmSetupCommand.flags = {
93
- 'skip-install': flagsLib.boolean({
94
- char: 's',
95
- description: 'Skip the credentials helper installation check',
96
- }),
97
- 'force-install': flagsLib.boolean({
98
- char: 'f',
99
- description: 'Force the credentials helper installation',
100
- }),
101
- ...LmSetupCommand.flags,
102
- }
103
-
104
- LmSetupCommand.description = `Configures your site to use Netlify Large Media.
105
- It runs the install command if you have not installed the dependencies yet.`
106
-
107
- module.exports = LmSetupCommand
@@ -1,17 +0,0 @@
1
- const Command = require('../../utils/command')
2
- const { uninstall } = require('../../utils/lm/install')
3
-
4
- class LmUninstallCommand extends Command {
5
- async run() {
6
- this.parse(LmUninstallCommand)
7
- await uninstall()
8
- }
9
- }
10
-
11
- LmUninstallCommand.aliases = ['lm:remove']
12
- LmUninstallCommand.hidden = true
13
-
14
- LmUninstallCommand.description =
15
- 'Uninstalls Netlify git credentials helper and cleans up any related configuration changes made by the install command.'
16
-
17
- module.exports = LmUninstallCommand
@@ -1,54 +0,0 @@
1
- const { flags: flagsLib } = require('@oclif/command')
2
- const chalk = require('chalk')
3
-
4
- const Command = require('../utils/command')
5
- const { exit, getToken, log } = require('../utils/command-helpers')
6
-
7
- class LoginCommand extends Command {
8
- async run() {
9
- const [accessToken, location] = await getToken()
10
- const { flags } = this.parse(LoginCommand)
11
-
12
- this.setAnalyticsPayload({ new: flags.new })
13
-
14
- if (accessToken && !flags.new) {
15
- log(`Already logged in ${msg(location)}`)
16
- log()
17
- log(`Run ${chalk.cyanBright('netlify status')} for account details`)
18
- log()
19
- log(`To see all available commands run: ${chalk.cyanBright('netlify help')}`)
20
- log()
21
- return exit()
22
- }
23
-
24
- await this.expensivelyAuthenticate()
25
-
26
- return exit()
27
- }
28
- }
29
-
30
- const msg = function (location) {
31
- switch (location) {
32
- case 'env':
33
- return 'via process.env.NETLIFY_AUTH_TOKEN set in your terminal session'
34
- case 'flag':
35
- return 'via CLI --auth flag'
36
- case 'config':
37
- return 'via netlify config on your machine'
38
- default:
39
- return ''
40
- }
41
- }
42
-
43
- LoginCommand.flags = {
44
- new: flagsLib.boolean({
45
- description: 'Login to new Netlify account',
46
- }),
47
- ...LoginCommand.flags,
48
- }
49
- LoginCommand.description = `Login to your Netlify account
50
-
51
- Opens a web browser to acquire an OAuth token.
52
- `
53
-
54
- module.exports = LoginCommand
@@ -1,37 +0,0 @@
1
- const Command = require('../utils/command')
2
- const { exit, getToken, log } = require('../utils/command-helpers')
3
- const { track } = require('../utils/telemetry')
4
-
5
- class LogoutCommand extends Command {
6
- async run() {
7
- const [accessToken, location] = await getToken()
8
-
9
- if (!accessToken) {
10
- log(`Already logged out`)
11
- log()
12
- log('To login run "netlify login"')
13
- exit()
14
- }
15
-
16
- await track('user_logout')
17
-
18
- // unset userID without deleting key
19
- this.netlify.globalConfig.set('userId', null)
20
-
21
- if (location === 'env') {
22
- log('The "process.env.NETLIFY_AUTH_TOKEN" is still set in your terminal session')
23
- log()
24
- log('To logout completely, unset the environment variable')
25
- log()
26
- exit()
27
- }
28
-
29
- log(`Logging you out of Netlify. Come back soon!`)
30
- }
31
- }
32
-
33
- LogoutCommand.description = `Logout of your Netlify account`
34
-
35
- LogoutCommand.hidden = true
36
-
37
- module.exports = LogoutCommand
@@ -1,51 +0,0 @@
1
- const Command = require('../../utils/command')
2
- const { error, exit, log, warn } = require('../../utils/command-helpers')
3
- const { openBrowser } = require('../../utils/open-browser')
4
-
5
- class OpenAdminCommand extends Command {
6
- async run() {
7
- const { api, site } = this.netlify
8
-
9
- await this.authenticate()
10
-
11
- const siteId = site.id
12
-
13
- if (!siteId) {
14
- warn(`No Site ID found in current directory.
15
- Run \`netlify link\` to connect to this folder to a site`)
16
- return false
17
- }
18
-
19
- let siteData
20
- try {
21
- siteData = await api.getSite({ siteId })
22
- log(`Opening "${siteData.name}" site admin UI:`)
23
- log(`> ${siteData.admin_url}`)
24
- } catch (error_) {
25
- // unauthorized
26
- if (error_.status === 401) {
27
- warn(`Log in with a different account or re-link to a site you have permission for`)
28
- error(`Not authorized to view the currently linked site (${siteId})`)
29
- }
30
- // site not found
31
- if (error_.status === 404) {
32
- log()
33
- log('Please double check this ID and verify you are logged in with the correct account')
34
- log()
35
- log('To fix this, run `netlify unlink` then `netlify link` to reconnect to the correct site ID')
36
- log()
37
- error(`Site "${siteId}" not found in account`)
38
- }
39
- error(error_)
40
- }
41
-
42
- await openBrowser({ url: siteData.admin_url })
43
- exit()
44
- }
45
- }
46
-
47
- OpenAdminCommand.description = `Opens current site admin UI in Netlify`
48
-
49
- OpenAdminCommand.examples = ['netlify open:admin']
50
-
51
- module.exports = OpenAdminCommand
@@ -1,43 +0,0 @@
1
- const Command = require('../../utils/command')
2
- const { error, exit, log, warn } = require('../../utils/command-helpers')
3
- const { openBrowser } = require('../../utils/open-browser')
4
-
5
- class OpenAdminCommand extends Command {
6
- async run() {
7
- const { api, site } = this.netlify
8
- await this.authenticate()
9
-
10
- const siteId = site.id
11
-
12
- if (!siteId) {
13
- warn(`No Site ID found in current directory.
14
- Run \`netlify link\` to connect to this folder to a site`)
15
- return false
16
- }
17
-
18
- let siteData
19
- let url
20
- try {
21
- siteData = await api.getSite({ siteId })
22
- url = siteData.ssl_url || siteData.url
23
- log(`Opening "${siteData.name}" site url:`)
24
- log(`> ${url}`)
25
- } catch (error_) {
26
- // unauthorized
27
- if (error_.status === 401) {
28
- warn(`Log in with a different account or re-link to a site you have permission for`)
29
- error(`Not authorized to view the currently linked site (${siteId})`)
30
- }
31
- error(error_)
32
- }
33
-
34
- await openBrowser({ url })
35
- exit()
36
- }
37
- }
38
-
39
- OpenAdminCommand.description = `Opens current site url in browser`
40
-
41
- OpenAdminCommand.examples = ['netlify open:site']
42
-
43
- module.exports = OpenAdminCommand