Skip to content

Commit

Permalink
feat(util): log
Browse files Browse the repository at this point in the history
  • Loading branch information
KuangPF committed May 27, 2019
1 parent ebd70f6 commit 2da4830
Show file tree
Hide file tree
Showing 8 changed files with 2,348 additions and 53 deletions.
2 changes: 1 addition & 1 deletion bin/index.js
Expand Up @@ -26,7 +26,7 @@ function checkNodeVersion(wanted, id) {
process.exit(1)
}
}
checkNodeVersion(requiredVersion, 'vue-cli')
checkNodeVersion(requiredVersion, 'webpack-page-cli')
program.version(require('../package').version).usage('<command> [options]')

program
Expand Down
9 changes: 8 additions & 1 deletion lib/Creator.js
@@ -1,9 +1,11 @@
const debug = require('debug')
const inquirer = require('inquirer')
const chalk = require('chalk')
const PromptModuleAPI = require('./PromptModuleAPI')
const { clearConsole } = require('./util/clearConsole')
const { render } = require('./util/render')
const writeFileTree = require('./util/writeFileTree')
const { log } = require('./util/logger')

module.exports = class Creator {
constructor(name, context, promptModules) {
Expand All @@ -20,7 +22,7 @@ module.exports = class Creator {

// eslint-disable-next-line
async create(cliOptions = {}, preset = null) {
console.log('before creating......')
log(`🚀 Creating: ${chalk.cyan(this.name)}`)
if (process.env.WEBPACK_PAGE_CLI_TEST) {
preset = {
features: ['css-preprocessor', 'eslint', 'stylelint'],
Expand All @@ -35,6 +37,11 @@ module.exports = class Creator {
const file = await render('./template', Object.assign(preset, { name: this.name }))
const finalFile = await this.extractFinalFiles(preset, file)
await writeFileTree(this.context, finalFile)

log()
log(`🎉 Successfully created project ${chalk.yellow(this.name)}.`)
log(`👉 Get started with the following commands:\n\n${this.context === process.cwd() ? '' : chalk.cyan(` ${chalk.gray('$')} cd ${this.name}\n`)}`)
log()
}

async promptAndResolvePreset(answers = null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/promptModules/cssPreprocessors.js
Expand Up @@ -13,7 +13,7 @@ module.exports = cli => {
name: 'cssPreprocessor',
when: answers => answers.features.includes('css-preprocessor'),
type: 'list',
message: `Pick a CSS pre-processor${process.env.VUE_CLI_API_MODE ? '' : ` (${notice})`}:`,
message: `Pick a CSS pre-processor (${notice}):`,
description: `${notice}.`,
choices: [
{
Expand Down
33 changes: 33 additions & 0 deletions lib/util/logger.js
@@ -0,0 +1,33 @@
const chalk = require('chalk')
const padStart = require('string.prototype.padstart')
const EventEmitter = require('events')

exports.events = new EventEmitter()

/* eslint-disable-next-line */
function _log(type, tag, message) {
if (message) {
exports.events.emit('log', {
message,
type,
tag
})
}
}

const format = (label, msg) => {
return msg
.split('\n')
.map((line, i) => {
return i === 0 ? `${label} ${line}` : padStart(line, chalk.reset(label).length)
})
.join('\n')
}

const chalkTag = msg => chalk.bgBlackBright.white.dim(` ${msg} `)

exports.log = (msg = '', tag = null) => {
// eslint-disable-next-line no-unused-expressions
tag ? console.log(format(chalkTag(tag), msg)) : console.log(msg)
_log('log', tag, msg)
}
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -31,11 +31,14 @@
"fs-extra": "^8.0.1",
"globby": "^9.2.0",
"husky": "^2.3.0",
"i": "^0.3.6",
"inquirer": "^6.3.1",
"isbinaryfile": "^4.0.0",
"lint-staged": "^8.1.7",
"npm": "^6.9.0",
"readline": "^1.3.0",
"semver": "^6.0.0",
"string.prototype.padstart": "^3.0.0",
"yaml-front-matter": "^4.0.0"
},
"husky": {
Expand Down
2 changes: 0 additions & 2 deletions template/build/webpack.base.conf.js
Expand Up @@ -140,8 +140,6 @@ const baseWebpackConfig = {
],

node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
Expand Down
6 changes: 0 additions & 6 deletions template/config/index.js
@@ -1,6 +1,4 @@
'use strict'
// Template version: 1.2.6
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')

Expand Down Expand Up @@ -33,10 +31,6 @@ module.exports = {

// https://webpack.js.org/configuration/devtool/#development
devtool: 'eval-source-map',

// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,

// CSS Sourcemaps off by default because relative paths are "buggy"
Expand Down

0 comments on commit 2da4830

Please sign in to comment.