netlify-cli 8.5.0 → 8.6.0
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.
- package/README.md +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/commands/env/env-migrate.js +108 -0
- package/src/commands/env/env.js +3 -0
package/README.md
CHANGED
|
@@ -134,6 +134,7 @@ Local dev server
|
|
|
134
134
|
| [`env:get`](/docs/commands/env.md#envget) | Get resolved value of specified environment variable (includes netlify.toml) |
|
|
135
135
|
| [`env:import`](/docs/commands/env.md#envimport) | Import and set environment variables from .env file |
|
|
136
136
|
| [`env:list`](/docs/commands/env.md#envlist) | Lists resolved environment variables for site (includes netlify.toml) |
|
|
137
|
+
| [`env:migrate`](/docs/commands/env.md#envmigrate) | Migrate environment variables from one site to another |
|
|
137
138
|
| [`env:set`](/docs/commands/env.md#envset) | Set value of environment variable |
|
|
138
139
|
| [`env:unset`](/docs/commands/env.md#envunset) | Unset an environment variable which removes it from the UI |
|
|
139
140
|
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "netlify-cli",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.0",
|
|
4
4
|
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "netlify-cli",
|
|
9
|
-
"version": "8.
|
|
9
|
+
"version": "8.6.0",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
package/package.json
CHANGED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
const { isEmpty } = require('lodash')
|
|
4
|
+
|
|
5
|
+
const { chalk, error: logError, log } = require('../../utils')
|
|
6
|
+
|
|
7
|
+
const safeGetSite = async (api, siteId) => {
|
|
8
|
+
try {
|
|
9
|
+
const data = await api.getSite({ siteId })
|
|
10
|
+
return { data }
|
|
11
|
+
} catch (error) {
|
|
12
|
+
return { error }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The env:migrate command
|
|
18
|
+
* @param {string} siteIdA Site (From)
|
|
19
|
+
* @param {string} siteIdB Site (To)
|
|
20
|
+
* @param {import('commander').OptionValues} options
|
|
21
|
+
* @param {import('../base-command').BaseCommand} command
|
|
22
|
+
* @returns {Promise<boolean>}
|
|
23
|
+
*/
|
|
24
|
+
const envMigrate = async (options, command) => {
|
|
25
|
+
const { api, site } = command.netlify
|
|
26
|
+
|
|
27
|
+
if (!site.id && !options.from) {
|
|
28
|
+
log(
|
|
29
|
+
'Please include the source site Id as the `--from` option, or run `netlify link` to link this folder to a Netlify site',
|
|
30
|
+
)
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const siteId = {
|
|
35
|
+
from: options.from || site.id,
|
|
36
|
+
to: options.to,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const [{ data: siteFrom, error: errorFrom }, { data: siteTo, error: errorTo }] = await Promise.all([
|
|
40
|
+
safeGetSite(api, siteId.from),
|
|
41
|
+
safeGetSite(api, siteId.to),
|
|
42
|
+
])
|
|
43
|
+
|
|
44
|
+
if (errorFrom) {
|
|
45
|
+
logError(`Can't find site with id ${chalk.bold(siteId.from)}. Please make sure the site exists.`)
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (errorTo) {
|
|
50
|
+
logError(`Can't find site with id ${chalk.bold(siteId.to)}. Please make sure the site exists.`)
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const [
|
|
55
|
+
{
|
|
56
|
+
build_settings: { env: envFrom = {} },
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
build_settings: { env: envTo = {} },
|
|
60
|
+
},
|
|
61
|
+
] = [siteFrom, siteTo]
|
|
62
|
+
|
|
63
|
+
if (isEmpty(envFrom)) {
|
|
64
|
+
log(`${chalk.greenBright(siteFrom.name)} has no environment variables, nothing to migrate`)
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Merge from site A to site B
|
|
69
|
+
const mergedEnv = {
|
|
70
|
+
...envTo,
|
|
71
|
+
...envFrom,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Apply environment variable updates
|
|
75
|
+
await api.updateSite({
|
|
76
|
+
siteId: siteId.to,
|
|
77
|
+
body: {
|
|
78
|
+
build_settings: {
|
|
79
|
+
env: mergedEnv,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
log(
|
|
85
|
+
`Successfully migrated environment variables from ${chalk.greenBright(siteFrom.name)} to ${chalk.greenBright(
|
|
86
|
+
siteTo.name,
|
|
87
|
+
)}`,
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Creates the `netlify env:migrate` command
|
|
93
|
+
* @param {import('../base-command').BaseCommand} program
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
const createEnvMigrateCommand = (program) =>
|
|
97
|
+
program
|
|
98
|
+
.command('env:migrate')
|
|
99
|
+
.option('-f, --from <from>', 'Site ID (From)')
|
|
100
|
+
.requiredOption('-t, --to <to>', 'Site ID (To)')
|
|
101
|
+
.description(`Migrate environment variables from one site to another`)
|
|
102
|
+
.addExamples([
|
|
103
|
+
'netlify env:migrate --to <to-site-id>',
|
|
104
|
+
'netlify env:migrate --to <to-site-id> --from <from-site-id>',
|
|
105
|
+
])
|
|
106
|
+
.action(envMigrate)
|
|
107
|
+
|
|
108
|
+
module.exports = { createEnvMigrateCommand }
|
package/src/commands/env/env.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const { createEnvGetCommand } = require('./env-get')
|
|
3
3
|
const { createEnvImportCommand } = require('./env-import')
|
|
4
4
|
const { createEnvListCommand } = require('./env-list')
|
|
5
|
+
const { createEnvMigrateCommand } = require('./env-migrate')
|
|
5
6
|
const { createEnvSetCommand } = require('./env-set')
|
|
6
7
|
const { createEnvUnsetCommand } = require('./env-unset')
|
|
7
8
|
|
|
@@ -25,6 +26,7 @@ const createEnvCommand = (program) => {
|
|
|
25
26
|
createEnvListCommand(program)
|
|
26
27
|
createEnvSetCommand(program)
|
|
27
28
|
createEnvUnsetCommand(program)
|
|
29
|
+
createEnvMigrateCommand(program)
|
|
28
30
|
|
|
29
31
|
return program
|
|
30
32
|
.command('env')
|
|
@@ -35,6 +37,7 @@ const createEnvCommand = (program) => {
|
|
|
35
37
|
'netlify env:set VAR_NAME value',
|
|
36
38
|
'netlify env:unset VAR_NAME',
|
|
37
39
|
'netlify env:import fileName',
|
|
40
|
+
'netlify env:migrate --to <to-site-id>',
|
|
38
41
|
])
|
|
39
42
|
.action(env)
|
|
40
43
|
}
|