Skip to content

Commit

Permalink
feat: cli多打包 (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
Muyu-art authored Aug 20, 2024
1 parent 7781cfe commit da79036
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
30 changes: 26 additions & 4 deletions packages/toolkits/pro/src/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
removedCommand,
removeDependencies,
ServerFrameworks,
VueVersion,
} from './interfaces';
import utils from './utils';
import { existsSync, rmSync, writeFileSync } from 'fs';
Expand Down Expand Up @@ -56,6 +57,18 @@ const getProjectInfo = (): Promise<ProjectInfo> => {
default: VUE_TEMPLATE_PATH,
prefix: '*',
},
{
type: 'list',
name: 'vueVersion',
message: '请选择你需要创建的Vue版本: ',
choices: [
{ name: 'Vue 2', value: VueVersion.Vue2 },
{ name: 'Vue 3', value: VueVersion.Vue3 },
],
default: VueVersion.Vue3,
prefix: '*',
when: (answer) => answer.framework === VUE_TEMPLATE_PATH,
},
{
type: 'list',
name: 'serverFramework',
Expand Down Expand Up @@ -216,19 +229,26 @@ const packageJsonProcess = (
return;
}
deps.forEach((dep) => {
packages.devDependencies[dep] = undefined;
if (packages.devDependencies[dep]) {
packages.devDependencies[dep] = undefined;
}
});
}
});
const dependencies = removeDependencies[buildTool];
dependencies.forEach((dep: string | RegExp) => {
if (typeof dep === 'string') {
if (!packages.dependencies[dep]) {
return;
}
packages.dependencies[dep] = undefined;
return;
}
if (dep instanceof RegExp) {
const keys = match(dep, Object.keys(packages.devDependencies));
keys.forEach((key) => {
if (!packages.dependencies[key]) {
return;
}
packages.dependencies[key] = undefined;
});
}
Expand Down Expand Up @@ -282,13 +302,15 @@ const packageJsonProcess = (
* @dbAnswers 询问服务端配置的选择值
*/
const createProjectSync = (answers: ProjectInfo) => {
const { framework, description, name, serverConfirm, buildTool } = answers;
const { framework, description, name, serverConfirm, buildTool, vueVersion } =
answers;
const templatePath =
framework === VUE_TEMPLATE_PATH ? VUE_TEMPLATE_PATH : NG_TEMPLATE_PATH;
framework === VUE_TEMPLATE_PATH ? vueVersion : NG_TEMPLATE_PATH;
// 模板来源目录
const from = utils.getTemplatePath(templatePath);
// 复制模板的目标目录
const to = utils.getDistPath(serverConfirm ? `${name}/web` : name);
console.log(from, to);
fs.copyTpl(from, to);
// 将项目名称、描述写入 package.json中
try {
Expand Down
20 changes: 14 additions & 6 deletions packages/toolkits/pro/src/lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export interface CliOption {
clientOptions: any;
}

export enum VueVersion {
Vue2 = 'tinyvue2',
Vue3 = 'tinyvue',
}

/**
* 服务端类型
*/
Expand Down Expand Up @@ -40,17 +45,19 @@ export const devCommand = {
rspack: 'rspack serve',
};

export const removedCommand = ['dev:wp', 'dev:rp', 'build:wp', 'build:rp'];
export const removedCommand = [
'dev:wp',
'dev:rp',
'build:wp',
'build:rp',
'dev',
];

/**
* 需要删除的包
*/
export const removeDependencies = {
vite: [
'@gaonengwww/mock-server',
'style-resources-loader',
'vue-style-loader',
],
vite: ['style-resources-loader', 'vue-style-loader'],
webpack: [],
rspack: [],
};
Expand Down Expand Up @@ -90,4 +97,5 @@ export interface ProjectInfo {
username?: string;
password?: string;
buildTool: BuildTool;
vueVersion: VueVersion;
}

0 comments on commit da79036

Please sign in to comment.