-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
Copy pathmigrate.js
105 lines (89 loc) · 2.5 KB
/
migrate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const {
chalk,
log,
error,
logWithSpinner,
stopSpinner,
loadModule,
resolvePluginId
} = require('@vue/cli-shared-utils')
const Migrator = require('./Migrator')
const PackageManager = require('./util/ProjectPackageManager')
const readFiles = require('./util/readFiles')
const getPkg = require('./util/getPkg')
const getChangedFiles = require('./util/getChangedFiles')
const isTestOrDebug = process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG
async function runMigrator (context, plugin, pkg = getPkg(context)) {
const afterInvokeCbs = []
const migrator = new Migrator(context, {
plugin,
pkg,
files: await readFiles(context),
afterInvokeCbs
})
log(`🚀 Running migrator of ${plugin.id}`)
await migrator.generate({
extractConfigFiles: true,
checkExisting: true,
sortPackageJson: false
})
const newDeps = migrator.pkg.dependencies
const newDevDeps = migrator.pkg.devDependencies
const depsChanged =
JSON.stringify(newDeps) !== JSON.stringify(pkg.dependencies) ||
JSON.stringify(newDevDeps) !== JSON.stringify(pkg.devDependencies)
if (!isTestOrDebug && depsChanged) {
log(`📦 Installing additional dependencies...`)
log()
const pm = new PackageManager({ context })
await pm.install()
}
if (afterInvokeCbs.length) {
logWithSpinner('⚓', `Running completion hooks...`)
for (const cb of afterInvokeCbs) {
await cb()
}
stopSpinner()
log()
}
log(
`${chalk.green(
'✔'
)} Successfully invoked migrator for plugin: ${chalk.cyan(plugin.id)}`
)
const changedFiles = getChangedFiles(context)
if (changedFiles.length) {
log(` The following files have been updated / added:\n`)
log(chalk.red(changedFiles.map(line => ` ${line}`).join('\n')))
log()
log(
` You should review these changes with ${chalk.cyan(
'git diff'
)} and commit them.`
)
log()
}
migrator.printExitLogs()
}
async function migrate (pluginId, { from }, context = process.cwd()) {
const pluginName = resolvePluginId(pluginId)
const pluginMigrator = loadModule(`${pluginName}/migrator`, context)
if (!pluginMigrator) {
log(`There's no migrator in ${pluginName}`)
return
}
await runMigrator(context, {
id: pluginName,
apply: pluginMigrator,
baseVersion: from
})
}
module.exports = (...args) => {
return migrate(...args).catch(err => {
error(err)
if (!process.env.VUE_CLI_TEST) {
process.exit(1)
}
})
}
module.exports.runMigrator = runMigrator