Skip to content

Commit aad86b9

Browse files
committed
fix($cli): 'vuepress eject' doesn't copy files (close: #1028)
1 parent 2a6d896 commit aad86b9

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

packages/@vuepress/cli/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ exports.bootstrap = function ({
101101
program
102102
.command('eject [targetDir]')
103103
.description('copy the default theme into .vuepress/theme for customization.')
104+
.option('--debug', 'eject in debug mode')
104105
.action((dir = '.') => {
105106
wrapCommand(eject)(path.resolve(dir))
106107
})

packages/@vuepress/core/lib/eject.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
const { path, chalk, fs, logger } = require('@vuepress/shared-utils')
44

5+
const EXCLUDED_FILES = [
6+
'__tests__',
7+
'.npmignore',
8+
'package.json',
9+
'package.json',
10+
'README.md'
11+
]
12+
513
module.exports = async (dir) => {
614
try {
715
require.resolve('@vuepress/theme-default')
@@ -10,7 +18,24 @@ module.exports = async (dir) => {
1018
process.exit(1)
1119
}
1220
const source = require.resolve('@vuepress/theme-default')
13-
const target = path.resolve(dir, '.vuepress/theme')
14-
await fs.copy(source, target)
15-
logger.success(`\nCopied default theme into ${chalk.cyan(target)}.\n`)
21+
logger.debug('entry', chalk.cyan(source))
22+
23+
const sourceDir = path.parse(source).dir
24+
const targetDir = path.resolve(dir, '.vuepress/theme')
25+
logger.debug('sourceDir', chalk.cyan(sourceDir))
26+
logger.debug('targetDir', chalk.cyan(targetDir))
27+
28+
await fs.copy(sourceDir, targetDir, {
29+
filter: src => {
30+
const relative = path.relative(sourceDir, src)
31+
if (EXCLUDED_FILES.includes(relative)) {
32+
return false
33+
}
34+
if (relative) {
35+
logger.debug('Copied', chalk.cyan(relative))
36+
}
37+
return true
38+
}
39+
})
40+
logger.success(`Copied default theme into ${chalk.cyan(targetDir)}.\n`)
1641
}

packages/@vuepress/shared-utils/lib/logger.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class Logger {
1010
constructor (options) {
1111
this.options = Object.assign(
1212
{
13-
logLevel: 3
13+
logLevel: process.argv.includes('--debug')
14+
? 4
15+
: 3
1416
},
1517
options
1618
)
@@ -84,6 +86,13 @@ class Logger {
8486
}
8587
console.log(chalk[color](label), ...args)
8688
}
89+
90+
developer (...args) {
91+
if (process.env.VUEPRESS_ENV !== 'developer') {
92+
return
93+
}
94+
this.status('cyan', 'developer', ...args)
95+
}
8796
}
8897

8998
/**

packages/@vuepress/shared-utils/lib/module.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ exports.resolveModule = function (request, context) {
4949
}
5050
return resolvedPath
5151
}
52-
resolvedPath = resolve(request, {
53-
// module.paths is for globally install packages.
54-
paths: [context || process.cwd(), ...module.paths]
55-
})
52+
53+
// module.paths is for globally install packages.
54+
const paths = [context || process.cwd(), ...module.paths]
55+
resolvedPath = resolve(request, { paths })
56+
5657
return resolvedPath
5758
}
5859

0 commit comments

Comments
 (0)