Skip to content

Commit

Permalink
feat: use prompts Closes: #64
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuoni committed Dec 13, 2023
1 parent d48930d commit f51dceb
Show file tree
Hide file tree
Showing 6 changed files with 1,433 additions and 1,603 deletions.
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"lint:style": "mcs lint --stylelint-only",
"lint:style-fix": "mcs lint --stylelint-only --fix",
"prepare": "is-ci || husky install",
"pub": "mcs release",
"prepublish": "pnpm run build",
"release": "lerna publish --force-publish=*",
"pub": "mcs release",
"simple": "cd examples/simple && pnpm start",
"test": "vitest run",
"test-pre:e2e": "npm run simple & npm run ui",
Expand Down Expand Up @@ -65,8 +65,5 @@
"vite": "^4.1.4",
"vitest": "^0.29.2"
},
"packageManager": "[email protected]",
"dependencies": {
"zx": "^7.2.3"
}
"packageManager": "[email protected]"
}
4 changes: 1 addition & 3 deletions packages/plugin-blocks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ export default (api: IApi) => {
// @ts-ignore
api?._modifyBlockFile?.((memo) => {
// TODO: 还有什么操作,都可以在这里处理
return memo
.replaceAll('@umijs/max', api.appData.umi.importSource)
.replaceAll('umi', api.appData.umi.importSource);
return memo.replaceAll('@umijs/max', api.appData.umi.importSource);
});
async function block(args: any = {}, opts = {}) {
const { config } = api;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-blocks/src/utils/addBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export async function addBlock(
skipModifyRoutes,
page: isPage,
layout: isLayout,
registry = '',
registry = 'https://registry.npmjs.org/',
js,
execution = 'shell',
} = args;
Expand Down
15 changes: 7 additions & 8 deletions packages/plugin-blocks/src/utils/list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IApi } from '@mongchhi/types';
import { fsExtra } from '@umijs/utils';
import { fsExtra,prompts } from '@umijs/utils';
import { writeFileSync } from 'fs';
import inquirer from 'inquirer';
import ora from 'ora';
import { dirname } from 'path';
import { addBlock } from './addBlock';
Expand All @@ -27,14 +26,14 @@ export async function selectInstallBlockArgs(blockArray: any[]) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
let locale = false;
const { block, path, uni18n } = await inquirer.prompt([
const { block, path, uni18n } = await prompts([
{
type: 'list',
name: 'block',
message: `⛰ 请选择区块(共 ${blockArray.length} 个 )`,
choices: blockArray,
},
{ type: 'input', name: 'path', message: '🏗 请输入输出安装区块的路径' },
{ type: 'text', name: 'path', message: '🏗 请输入输出安装区块的路径' },
// {
// type: 'confirm',
// name: 'js',
Expand All @@ -45,18 +44,18 @@ export async function selectInstallBlockArgs(blockArray: any[]) {
type: 'confirm',
name: 'uni18n',
message: '🌎 删除 i18n 代码? ',
default: false,
initial: false,
},
]);
// 默认不转 js
const js = false;
if (uni18n) {
const { region } = await inquirer.prompt([
const { region } = await prompts([
{
type: 'input',
type: 'text',
name: 'region',
message: '🌎 请输入你的选择的语言? ',
default: 'zh-CN',
initial: 'zh-CN',
},
]);
locale = region;
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-blocks/src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const genBlockName = (name) =>
.join('/');

/**
* 将区块转化为 inquirer 能用的数组
* 将区块转化为 prompts 能用的数组
* @param {*} blocks
* @returns {[
* name:string;
Expand All @@ -102,7 +102,7 @@ export function printBlocks(blocks, hasLink?) {
name += link;
}
blockArray.push({
name,
title: name,
value: blockName,
key: blockName,
});
Expand Down
Loading

0 comments on commit f51dceb

Please sign in to comment.