Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
feat(output): short output tips
Browse files Browse the repository at this point in the history
  • Loading branch information
NewFuture committed Sep 8, 2019
1 parent 90bca50 commit 7788002
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bin/mp-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ed(str) { return colors.gray(str) }

var argv = require("yargs")
.scriptName("mp")
.usage(colors.whiteBright.inverse.bold("\nWechat MiniProgram build tools <微信小程序编译打包工具>\n"))
.usage(colors.whiteBright.inverse.bold("\n> Wechat MiniProgram build tools 微信小程序编译打包工具 <\n"))
.usage(`${colors.italic("Short Usage")} <短用法>: ${colors.bold.yellowBright("$0")} ${colors.cyanBright("[command...]")} ${colors.italic("[--option]")}`)
.usage(`${colors.italic("Full Name")} <完整名称>: ${colors.bold.yellowBright("miniprogram-build")} ${colors.cyanBright("[命令...]")} ${colors.italic("[--选项]")}`)
.example(colors.green.italic("$0 js js-watch"), ed("编译并监测生成js文件"))
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/build-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const warn = require("../log/warn");
const debug = require("../log/compile");
const size = require("../log/size");

const TITLE = "npm:";
const TITLE = "npm";

/**
* 组件component
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const debug = require("../log/compile");
const size = require('../log/size');
var error = require("../log/error");

var TITLE = 'javascript:';
var TITLE = 'javascript';
/**
* 编译TS
* @param {object} config *
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var multiReplace = require('../lib/multi-replace');
const pkgVar = require('../lib/package-var');
var jsonMini = require('../lib/json-mini');

var TITLE = 'json:';
var TITLE = 'json';
/**
* 复制 Json文件
* @param {object} config
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var replace = require("../lib/multi-replace");
// var tsImport = require("../lib/tsimport");
var error = require("../log/error");

var TITLE = "typescript:";
var TITLE = "typescript";
/**
* 编译TS
* @param {object} config *
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile-wxss.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const pkgVar = require('../lib/package-var');
var error = require("../log/error");
const debug = require("../log/compile");
const size = require("../log/size");
var TITLE = "wxss:";
var TITLE = "wxss";
/**
* 编译scss
* @param {object} config
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile-wxts.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const defaultConfig = {
// strictPropertyInitialization: true,
strictNullChecks: true,
};
var TITLE = "wxts:";
var TITLE = "wxts";
/**
* 编译TS
* @param {object} config *
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compress-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var imagemin = require('../lib/image-min');
var err = require('../log/error');
const size = require('../log/size');

var TITLE = 'image:';
var TITLE = 'image';
/**
*
* @param {string|string[]} imgsrc
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compress-wxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const size = require("../log/size");
var err = require("../log/error");
// var minimize = require("gulp-minimize");

var TITLE = "wxml:";
var TITLE = "wxml";
/**
*
* @param {object} config
Expand Down
2 changes: 1 addition & 1 deletion src/lib/image-min.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module.exports = (plugins, options) => {
}

if (options.verbose) {
log(color(`${PLUGIN_NAME}:`), chalk.underline(file.relative), chalk.gray(` (${msg})`));
log(color(`${PLUGIN_NAME}`), chalk.symbols.check, chalk.underline(file.relative), chalk.gray(` (${msg})`));
}

file.contents = data;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/multi-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var path = require('path');
var colors = require('ansi-colors');

var log = require('../log/logger');
var TITLE = 'replace:'
var TITLE = 'replace'

/**
*
Expand All @@ -17,8 +17,8 @@ var TITLE = 'replace:'
function logReplace(n, key, value, file) {
log.info(
colors.gray(TITLE),
colors.dim(colors.symbols.check.repeat(n)),
colors.gray.italic(key.toString()),
colors.gray.bold(colors.symbols.check.repeat(n)),
colors.gray.dim.italic.strikethrough(key.toString()),
colors.dim.gray(colors.symbols.pointerSmall),
typeof value === 'function' ? colors.cyan(colors.italic('Function:') + (value.name || '')) : colors.underline(value),
colors.gray('(' + colors.underline(
Expand Down
6 changes: 3 additions & 3 deletions src/log/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ let index = 0;
function color(str) {
str = str && str.trim();
if (!maps[str]) {
maps[str] = colors.gray.dim(index+'.')+colors
.reset
maps[str] = colors.gray.dim.italic.inverse('' + index) + colors
.reset
[availableStyle[index % availableStyle.length]]
[availableColors[index++ % availableColors.length]]
.bold(str);
.bold(str);
}
return maps[str];
}
Expand Down
2 changes: 1 addition & 1 deletion src/log/size.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = opts => {
}
size = opts.pretty ? prettyBytes(size) : (size + ' B');
duration = duration ? chalk.gray("[" + prettyTime(duration) + "]") : '';
fancyLog(title, sym, what, chalk.gray('(') + chalk[highlightSize ? 'magentaBright' : 'gray'](size) + chalk.gray(')') + duration);
fancyLog(title , sym , what, chalk.gray('(') + chalk[highlightSize ? 'magentaBright' : 'gray'](size) + chalk.gray(')') + duration);
}

return through.obj((file, enc, cb) => {
Expand Down
22 changes: 12 additions & 10 deletions src/tasks/devtool.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const colors = require('ansi-colors');

const logger = require('../log/logger');

const RAW_TITLE = 'devtool:';
const RAW_TITLE = 'devtool';
const TITLE = require('../log/color')(RAW_TITLE);
const errLog = require('../log/error')(RAW_TITLE);

Expand All @@ -19,19 +19,21 @@ const warnIcon = colors.yellowBright.bold(colors.symbols.warning);
const successIcon = colors.greenBright.bold.italic(colors.symbols.check);


function logStart(action, msg) {
logger(TITLE, startIcon, colors.cyan(action), msg);
}

function logSuccess(msg) {
logger(
TITLE,
successIcon,
colors.green(msg)
TITLE, successIcon, colors.green(msg)
);
}

/**
* 打开项目
*/
exports.open = function () {
logger.info(TITLE, startIcon, colors.cyan('open'), 'project in', colors.underline(exports.dist))
logStart('open', 'project in ' + colors.underline(exports.dist))
return devtool.cli('--open', path.resolve(exports.dist))
.then(function (res) {
if (res.stderr) {
Expand All @@ -48,7 +50,7 @@ exports.open = function () {
* 关闭项目
*/
exports.close = function (pass) {
logger.info(TITLE, startIcon, colors.cyan('close'), 'project in', colors.underline(exports.dist))
logStart('close', 'project in ' + colors.underline(exports.dist))
return exports.isOpenPort().then(function (isOpen) {
if (!isOpen) {
logger.warn(TITLE, warnIcon, '跳过关闭项目,请打安装[微信开发者工具]并打开[端口设置]');
Expand Down Expand Up @@ -80,7 +82,7 @@ exports.close = function (pass) {
* 退出
*/
exports.quit = function (pass) {
logger.info(TITLE, startIcon, colors.cyan('quit'), 'Wechat Devtools', colors.gray('尝试退出微信开发者工具...'))
logStart('quit', 'Wechat Devtools ' + colors.gray('尝试退出微信开发者工具...'))
return exports.isOpenPort().then(function (isOpen) {
if (isOpen) {
return devtool.cli('--quit', path.resolve(exports.dist))
Expand Down Expand Up @@ -130,7 +132,7 @@ function getSize(path) {
* @param {string} s
*/
function encode(s) {
return s.replace(/&|<|>/g, escape);
return s.replace(/&|<|>/g, escape).replace(/\n/g, ' ');
}

/**
Expand All @@ -140,7 +142,7 @@ exports.upload = function () {
const version = devtool.getPkgVersion() || '0.0.0';
const dist = path.resolve(exports.dist);
const uploadProject = version + '@' + dist;
logger.info(TITLE, startIcon, colors.cyan('upload'), 'project in', colors.underline(dist));
logStart('upload', 'project in ' + colors.underline(dist));
const logPath = path.join(os.tmpdir(), 'mplog-' + version + '-' + Date.now() + '.json')

return devtool.getCommitMsg()
Expand Down Expand Up @@ -170,7 +172,7 @@ exports.upload = function () {
*/
exports.autopreview = function () {
//cli --auto-preview /Users/username/demo --auto-preview-info-output /Users/username/info.json
logger.info(TITLE, startIcon, colors.cyan('auto preview'), 'project in', colors.underline(exports.dist));
logStart('auto-preview', 'project in ' + colors.underline(exports.dist));
const logPath = path.resolve(os.tmpdir(), 'mp-preview-log.' + Date.now() + '.json');
return devtool.cli('--auto-preview', path.resolve(exports.dist), '--auto-preview-info-output', logPath)
.then(function (res) {
Expand Down

0 comments on commit 7788002

Please sign in to comment.