Skip to content

Commit

Permalink
fix(mini-runner): 加上文件编译提示
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jan 7, 2020
1 parent bd31812 commit 1203737
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 6 deletions.
6 changes: 3 additions & 3 deletions 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": {
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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),
Expand Down
70 changes: 70 additions & 0 deletions 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']
Expand Down Expand Up @@ -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'
}
}
27 changes: 26 additions & 1 deletion packages/taro-mini-runner/src/utils/index.ts
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 1203737

Please sign in to comment.