From 29f14d6cb2088f2dffe6d9d82053ea727ef7c5ac Mon Sep 17 00:00:00 2001 From: chenshuai Date: Sun, 29 Sep 2019 15:45:32 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=81=20add=20emoji?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugins/commands/block/addBlock.ts | 6 ++++-- .../commands/block/ui/server/core/tasks/git_clone.ts | 4 ++-- .../block/ui/server/core/tasks/git_update.ts | 12 ++++++------ .../block/ui/server/core/tasks/run_generator.ts | 12 ++++++------ .../block/ui/server/core/tasks/write_routes.ts | 12 +++++++----- .../commands/block/ui/server/core/types/index.ts | 3 +++ .../src/plugins/commands/block/ui/server/index.ts | 2 +- .../plugins/commands/block/ui/server/util/index.ts | 5 +++-- 8 files changed, 32 insertions(+), 24 deletions(-) diff --git a/packages/umi-build-dev/src/plugins/commands/block/addBlock.ts b/packages/umi-build-dev/src/plugins/commands/block/addBlock.ts index ace0ef208d3b..09fa9898f326 100644 --- a/packages/umi-build-dev/src/plugins/commands/block/addBlock.ts +++ b/packages/umi-build-dev/src/plugins/commands/block/addBlock.ts @@ -65,6 +65,8 @@ export interface AddBlockOption { // 在 ci 与 function 中执行可以设置为 auto execution?: 'shell' | 'auto'; + index?: number; + // 传输 log 用 remoteLog?: (log: string) => void; } @@ -363,12 +365,12 @@ async function add( try { clipboardy.writeSync(viewUrl); log.success( - `probable url ${chalk.cyan(viewUrl)} ${chalk.dim( + `✨ Probable url ${chalk.cyan(viewUrl)} ${chalk.dim( '(copied to clipboard)', )} for view the block.`, ); } catch (e) { - log.success(`probable url ${chalk.cyan(viewUrl)} for view the block.`); + log.success(`✨ Probable url ${chalk.cyan(viewUrl)} for view the block.`); log.error('copy to clipboard failed'); } diff --git a/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/git_clone.ts b/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/git_clone.ts index 6e526036f4c0..753856461b0b 100644 --- a/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/git_clone.ts +++ b/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/git_clone.ts @@ -7,12 +7,12 @@ const clone = async (ctx: IFlowContext) => { return; } - logger.appendLog(`Start git clone from ${repo}`); + logger.appendLog(`🚚 Start git clone from ${repo}`); await execa('git', ['clone', repo, id, '--single-branch', '--recurse-submodules', '-b', branch], { cwd: blocksTempPath, env: process.env, }); - logger.appendLog('Success git clone\n'); + logger.appendLog('🎉 Success git clone\n'); }; export default clone; diff --git a/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/git_update.ts b/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/git_update.ts index 24af7acacfd4..5d7f5d8460b5 100644 --- a/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/git_update.ts +++ b/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/git_update.ts @@ -18,7 +18,7 @@ const clone = async (ctx: IFlowContext, args: IAddBlockOption) => { const { logger, execa } = ctx; const { branch, templateTmpDirPath, sourcePath, routePath } = ctx.stages.blockCtx as ICtxTypes; - logger.appendLog('Start git fetch'); + logger.appendLog('⚓ Start git fetch'); try { await execa('git', ['fetch'], { cwd: templateTmpDirPath, @@ -27,9 +27,9 @@ const clone = async (ctx: IFlowContext, args: IAddBlockOption) => { logger.appendLog(`Faild git fetch: ${e.message}`); throw new Error(e); } - logger.appendLog('Success git fetch\n'); + logger.appendLog('🎉 Success git fetch\n'); - logger.appendLog(`Start git checkout ${branch}`); + logger.appendLog(`⚓ Start git checkout ${branch}`); try { await execa('git', ['checkout', branch], { cwd: templateTmpDirPath, @@ -39,9 +39,9 @@ const clone = async (ctx: IFlowContext, args: IAddBlockOption) => { throw new Error(e); } - logger.appendLog(`Success git checkout ${branch}\n`); + logger.appendLog(`🎉 Success git checkout ${branch}\n`); - logger.appendLog('Start git pull'); + logger.appendLog('⚓ Start git pull'); try { await execa('git', ['pull'], { @@ -73,7 +73,7 @@ const clone = async (ctx: IFlowContext, args: IAddBlockOption) => { throw e; } - logger.appendLog('Success git pull\n'); + logger.appendLog('🎉 Success git pull\n'); assert(existsSync(sourcePath), `${sourcePath} don't exists`); let pkg; diff --git a/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/run_generator.ts b/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/run_generator.ts index 86a8ed4249f0..ef40e0080081 100644 --- a/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/run_generator.ts +++ b/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/run_generator.ts @@ -9,7 +9,7 @@ const generatorFunc = async (ctx: IFlowContext, args: IAddBlockOption) => { const { dryRun, page: isPage, js, execution = 'shell', uni18n } = args; logger.appendLog(); - logger.appendLog('Start generate files'); + logger.appendLog('📦 Start generate files'); const getBlockGenerator = require('../../../../getBlockGenerator'); const BlockGenerator = getBlockGenerator.default(ctx.api); @@ -76,20 +76,20 @@ const generatorFunc = async (ctx: IFlowContext, args: IAddBlockOption) => { } } - logger.appendLog('Success generate files\n'); + logger.appendLog('🎉 Success generate files\n'); // 调用 sylvanas 转化 ts if (js) { // opts.remoteLog('TypeScript to JavaScript'); // TODO: add log - logger.appendLog('Start TypeScript to JavaScript'); + logger.appendLog('🎭 Start TypeScript to JavaScript'); require('../../../../tsTojs').default(generator.blockFolderPath); - logger.appendLog('Success TypeScript to JavaScript\n'); + logger.appendLog('🎉 Success TypeScript to JavaScript\n'); } if (uni18n) { - logger.appendLog('Start remove i18n code'); + logger.appendLog('🌏 Start remove i18n code'); require('../../../../remove-locale').default(generator.blockFolderPath, uni18n); - logger.appendLog('Success remove i18n code\n'); + logger.appendLog('🎉 Success remove i18n code\n'); } ctx.stages.generator = generator; diff --git a/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/write_routes.ts b/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/write_routes.ts index 6ec975f999c8..133fa1ad7861 100644 --- a/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/write_routes.ts +++ b/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/tasks/write_routes.ts @@ -10,7 +10,7 @@ const writeRoutes = async (ctx: IFlowContext, args: IAddBlockOption) => { if (generator.needCreateNewRoute && api.config.routes && !skipModifyRoutes) { logger.appendLog( - `Start write route from ${generator.routePath} to ${api.service.userConfig.file}`, + `🛠 Start write route from ${generator.routePath} to ${api.service.userConfig.file}`, ); // 当前 _modifyBlockNewRouteConfig 只支持配置式路由 // 未来可以做下自动写入注释配置,支持约定式路由 @@ -29,12 +29,14 @@ const writeRoutes = async (ctx: IFlowContext, args: IAddBlockOption) => { logger.appendLog(`Faild to write route: ${e.message}\n`); throw new Error(e); } - logger.appendLog('Success write route\n'); + logger.appendLog('🎉 Success write route\n'); } if (!generator.isPageBlock) { logger.appendLog( - `Start write block component ${generator.blockFolderName} import to ${generator.entryPath}`, + `🍽 Start write block component ${generator.blockFolderName} import to ${ + generator.entryPath + }`, ); try { appendBlockToContainer({ @@ -47,12 +49,12 @@ const writeRoutes = async (ctx: IFlowContext, args: IAddBlockOption) => { logger.appendLog(`Faild write block component: ${e.message}\n`); throw new Error(e); } - logger.appendLog('Success write block component \n'); + logger.appendLog('🎉 Success write block component \n'); } // Final: show success message const viewUrl = `http://localhost:${process.env.PORT || '8000'}${generator.path.toLowerCase()}`; - logger.appendLog(`Probable url ${chalk.cyan(viewUrl)} for view the block.`); + logger.appendLog(`✨ Probable url ${chalk.cyan(viewUrl)} for view the block.`); }; export default writeRoutes; diff --git a/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/types/index.ts b/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/types/index.ts index ef7135e269cd..98a465ae034a 100644 --- a/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/types/index.ts +++ b/packages/umi-build-dev/src/plugins/commands/block/ui/server/core/types/index.ts @@ -45,6 +45,9 @@ export interface IAddBlockOption { // 在 ci 与 function 中执行可以设置为 auto execution?: 'shell' | 'auto'; + // 区块的位置 + index?: number; + // 传输 log 用 remoteLog?: (log: string) => void; diff --git a/packages/umi-build-dev/src/plugins/commands/block/ui/server/index.ts b/packages/umi-build-dev/src/plugins/commands/block/ui/server/index.ts index 36d2030d528d..95b5f735aa83 100644 --- a/packages/umi-build-dev/src/plugins/commands/block/ui/server/index.ts +++ b/packages/umi-build-dev/src/plugins/commands/block/ui/server/index.ts @@ -114,7 +114,7 @@ export default (api: IApi) => { case 'org.umi.block.list': (async () => { try { - const resourceId = (payload as { resourceId: string }).resourceId; + const { resourceId } = payload as { resourceId: string }; let data = blockListCache[resourceId]; if (!data || (payload as { force: boolean }).force) { data = await blockService.getBlockList(resourceId, resources); diff --git a/packages/umi-build-dev/src/plugins/commands/block/ui/server/util/index.ts b/packages/umi-build-dev/src/plugins/commands/block/ui/server/util/index.ts index 84b77c9bb507..bb4c7bf9b7e3 100644 --- a/packages/umi-build-dev/src/plugins/commands/block/ui/server/util/index.ts +++ b/packages/umi-build-dev/src/plugins/commands/block/ui/server/util/index.ts @@ -67,13 +67,14 @@ export const getFilesTreeData = ( !isDirectory && !fileName.includes('.tsx') && !fileName.includes('.jsx') && - !fileName.includes('.js') + !fileName.includes('.js') && + !fileName.includes('.ts') ) { return undefined; } const absPath = winPath(join(path, fileName)); const absPagePath = winPath(join(parentPath, fileName)); - const children = isDirectory ? getFolderTreeData(absPath, absPagePath, depth + 1) : []; + const children = isDirectory ? getFilesTreeData(absPath, absPagePath, depth + 1) : []; if (children && children.length > 0) { return { key: absPagePath,