From 1203737a8629806c0edfcb3f1895bb3e70078588 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Tue, 22 Oct 2019 11:34:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(mini-runner):=20=E5=8A=A0=E4=B8=8A=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=BC=96=E8=AF=91=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-mini-runner/package.json | 6 +- .../src/plugins/MiniPlugin.ts | 6 +- .../taro-mini-runner/src/utils/constants.ts | 70 +++++++++++++++++++ packages/taro-mini-runner/src/utils/index.ts | 27 ++++++- 4 files changed, 103 insertions(+), 6 deletions(-) diff --git a/packages/taro-mini-runner/package.json b/packages/taro-mini-runner/package.json index fbea11f745fb..8c2d7d4474eb 100644 --- a/packages/taro-mini-runner/package.json +++ b/packages/taro-mini-runner/package.json @@ -1,6 +1,6 @@ { "name": "@tarojs/mini-runner", - "version": "1.3.19", + "version": "1.3.21", "description": "Mini app runner for taro", "main": "index.js", "scripts": { @@ -32,8 +32,8 @@ }, "homepage": "https://github.com/NervJS/taro#readme", "dependencies": { - "@tarojs/taro": "1.3.19", - "@tarojs/transformer-wx": "1.3.19", + "@tarojs/taro": "1.3.21", + "@tarojs/transformer-wx": "1.3.21", "babel-core": "^6.26.3", "babel-generator": "^6.26.1", "babel-loader": "^8.0.6", diff --git a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts index 0a9d79daf368..d2e49d3f1dbc 100644 --- a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts +++ b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts @@ -15,9 +15,9 @@ import traverse from 'babel-traverse' import { Config as IConfig, PageConfig } from '@tarojs/taro' import * as _ from 'lodash' -import { REG_TYPESCRIPT, BUILD_TYPES, PARSE_AST_TYPE, MINI_APP_FILES, NODE_MODULES_REG, CONFIG_MAP, taroJsFramework, REG_SCRIPTS } from '../utils/constants' +import { REG_TYPESCRIPT, BUILD_TYPES, PARSE_AST_TYPE, MINI_APP_FILES, NODE_MODULES_REG, CONFIG_MAP, taroJsFramework, REG_SCRIPTS, processTypeEnum } from '../utils/constants' import { IComponentObj } from '../utils/types' -import { resolveScriptPath, buildUsingComponents, isNpmPkg, resolveNpmSync, isEmptyObject, promoteRelativePath } from '../utils' +import { resolveScriptPath, buildUsingComponents, isNpmPkg, resolveNpmSync, isEmptyObject, promoteRelativePath, printLog } from '../utils' import TaroSingleEntryDependency from '../dependencies/TaroSingleEntryDependency' import { getTaroJsQuickAppComponentsPath, generateQuickAppUx, getImportTaroSelfComponents, generateQuickAppManifest } from '../utils/helper' import parseAst from '../utils/parseAst' @@ -401,6 +401,7 @@ export default class MiniPlugin { if (!appPages || appPages.length === 0) { throw new Error('缺少页面') } + printLog(processTypeEnum.COMPILE, '发现入口', appEntry) this.getSubPackages(configObj) this.generateTabBarFiles(compiler, configObj) const template = '' @@ -618,6 +619,7 @@ export default class MiniPlugin { imports: new Set([...importTaroSelfComponents, ...importUsingComponent, ...importCustomComponents]) }) } + printLog(processTypeEnum.COMPILE, isRoot ? '发现页面' : '发现组件', file.path) taroFileTypeMap[file.path] = { type: isRoot ? PARSE_AST_TYPE.PAGE : PARSE_AST_TYPE.COMPONENT, config: merge({}, isComponentConfig, buildUsingComponents(file.path, this.sourceDir, {}, depComponents), configObj), diff --git a/packages/taro-mini-runner/src/utils/constants.ts b/packages/taro-mini-runner/src/utils/constants.ts index 093d1ef4e43b..2e4e927ed598 100644 --- a/packages/taro-mini-runner/src/utils/constants.ts +++ b/packages/taro-mini-runner/src/utils/constants.ts @@ -1,5 +1,7 @@ import * as os from 'os' +import chalk, { Chalk } from 'chalk' + export const CSS_EXT: string[] = ['.css', '.scss', '.sass', '.less', '.styl', '.wxss', '.acss'] export const SCSS_EXT: string[] = ['.scss'] export const JS_EXT: string[] = ['.js', '.jsx'] @@ -232,3 +234,71 @@ export enum PARSE_AST_TYPE { NORMAL = 'NORMAL', STATIC = 'STATIC' } + +export const enum processTypeEnum { + START = 'start', + CREATE = 'create', + COMPILE = 'compile', + CONVERT = 'convert', + COPY = 'copy', + GENERATE = 'generate', + MODIFY = 'modify', + ERROR = 'error', + WARNING = 'warning', + UNLINK = 'unlink', + REFERENCE = 'reference' +} + +export interface IProcessTypeMap { + [key: string] : { + name: string, + color: string | Chalk + } +} + +export const processTypeMap: IProcessTypeMap = { + [processTypeEnum.CREATE]: { + name: '创建', + color: 'cyan' + }, + [processTypeEnum.COMPILE]: { + name: '编译', + color: 'green' + }, + [processTypeEnum.CONVERT]: { + name: '转换', + color: chalk.rgb(255, 136, 0) + }, + [processTypeEnum.COPY]: { + name: '拷贝', + color: 'magenta' + }, + [processTypeEnum.GENERATE]: { + name: '生成', + color: 'blue' + }, + [processTypeEnum.MODIFY]: { + name: '修改', + color: 'yellow' + }, + [processTypeEnum.ERROR]: { + name: '错误', + color: 'red' + }, + [processTypeEnum.WARNING]: { + name: '警告', + color: 'yellowBright' + }, + [processTypeEnum.UNLINK]: { + name: '删除', + color: 'magenta' + }, + [processTypeEnum.START]: { + name: '启动', + color: 'green' + }, + [processTypeEnum.REFERENCE]: { + name: '引用', + color: 'blue' + } +} diff --git a/packages/taro-mini-runner/src/utils/index.ts b/packages/taro-mini-runner/src/utils/index.ts index 2f87f917f1ee..5680876036f7 100644 --- a/packages/taro-mini-runner/src/utils/index.ts +++ b/packages/taro-mini-runner/src/utils/index.ts @@ -4,8 +4,16 @@ import * as fs from 'fs-extra' import * as resolvePath from 'resolve' import * as t from 'babel-types' import { mergeWith } from 'lodash' +import chalk from 'chalk' -import { CONFIG_MAP, JS_EXT, TS_EXT, NODE_MODULES_REG } from './constants' +import { + CONFIG_MAP, + JS_EXT, + TS_EXT, + NODE_MODULES_REG, + processTypeMap, + processTypeEnum +} from './constants' import { IOption, IComponentObj } from './types' export const isNodeModule = (filename: string) => NODE_MODULES_REG.test(filename) @@ -211,3 +219,20 @@ export function getInstalledNpmPkgPath (pkgName: string, basedir: string): strin return null } } + +export function printLog (type: processTypeEnum, tag: string, filePath?: string) { + const typeShow = processTypeMap[type] + const tagLen = tag.replace(/[\u0391-\uFFE5]/g, 'aa').length + const tagFormatLen = 8 + if (tagLen < tagFormatLen) { + const rightPadding = new Array(tagFormatLen - tagLen + 1).join(' ') + tag += rightPadding + } + const padding = '' + filePath = filePath || '' + if (typeof typeShow.color === 'string') { + console.log(chalk[typeShow.color](typeShow.name), padding, tag, padding, filePath) + } else { + console.log(typeShow.color(typeShow.name), padding, tag, padding, filePath) + } +}