Skip to content

Commit

Permalink
fix($cli): 'vuepress eject' doesn't copy files (close: #1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Nov 25, 2018
1 parent 2a6d896 commit aad86b9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/@vuepress/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ exports.bootstrap = function ({
program
.command('eject [targetDir]')
.description('copy the default theme into .vuepress/theme for customization.')
.option('--debug', 'eject in debug mode')
.action((dir = '.') => {
wrapCommand(eject)(path.resolve(dir))
})
Expand Down
31 changes: 28 additions & 3 deletions packages/@vuepress/core/lib/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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

const EXCLUDED_FILES = [
'__tests__',
'.npmignore',
'package.json',
'package.json',
'README.md'
]

module.exports = async (dir) => {
try {
require.resolve('@vuepress/theme-default')
Expand All @@ -10,7 +18,24 @@ module.exports = async (dir) => {
process.exit(1)
}
const source = require.resolve('@vuepress/theme-default')
const target = path.resolve(dir, '.vuepress/theme')
await fs.copy(source, target)
logger.success(`\nCopied default theme into ${chalk.cyan(target)}.\n`)
logger.debug('entry', chalk.cyan(source))

const sourceDir = path.parse(source).dir
const targetDir = path.resolve(dir, '.vuepress/theme')
logger.debug('sourceDir', chalk.cyan(sourceDir))
logger.debug('targetDir', chalk.cyan(targetDir))

await fs.copy(sourceDir, targetDir, {
filter: src => {
const relative = path.relative(sourceDir, src)
if (EXCLUDED_FILES.includes(relative)) {
return false
}
if (relative) {
logger.debug('Copied', chalk.cyan(relative))
}
return true
}
})
logger.success(`Copied default theme into ${chalk.cyan(targetDir)}.\n`)
}
11 changes: 10 additions & 1 deletion packages/@vuepress/shared-utils/lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class Logger {
constructor (options) {
this.options = Object.assign(
{
logLevel: 3
logLevel: process.argv.includes('--debug')
? 4
: 3
},
options
)
Expand Down Expand Up @@ -84,6 +86,13 @@ class Logger {
}
console.log(chalk[color](label), ...args)
}

developer (...args) {
if (process.env.VUEPRESS_ENV !== 'developer') {
return
}
this.status('cyan', 'developer', ...args)
}
}

/**
Expand Down
9 changes: 5 additions & 4 deletions packages/@vuepress/shared-utils/lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ exports.resolveModule = function (request, context) {
}
return resolvedPath
}
resolvedPath = resolve(request, {
// module.paths is for globally install packages.
paths: [context || process.cwd(), ...module.paths]
})

// module.paths is for globally install packages.
const paths = [context || process.cwd(), ...module.paths]
resolvedPath = resolve(request, { paths })

return resolvedPath
}

Expand Down

0 comments on commit aad86b9

Please sign in to comment.