Skip to content

Commit

Permalink
fix: show monorepo template when create a sub package (ice-lab#539)
Browse files Browse the repository at this point in the history
* fix: show monorepo tempalte when create a sub package

* chore: changeset
  • Loading branch information
luhc228 committed May 11, 2023
1 parent 7bdfe78 commit d815b5e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-beans-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/create-pkg': patch
---

fix: show monorepo templates when creating a sub package
2 changes: 1 addition & 1 deletion packages/create-pkg/src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function create(dirPath: string, dirname: string, options: CliOptions): Pr

let templateNpmName = options.template;
if (!templateNpmName) {
templateNpmName = await inquireTemplateNpmName();
templateNpmName = await inquireTemplateNpmName(options.workspace);
}

const npmName = options.npmName ?? (templateNpmName.startsWith('@ice/template-pkg-monorepo') ? '' : await inquirePackageName());
Expand Down
60 changes: 33 additions & 27 deletions packages/create-pkg/src/inquireTemplateNpmName.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
import inquirer from 'inquirer';
import getInfo from './langs/index.js';

export default async function inquireTemplateNpmName() {

export default async function inquireTemplateNpmName(workspace?: boolean) {
const info = await getInfo();
const baseTemplateChoices = [
{
name: info.reactComponent,
value: '@ice/template-pkg-react',
},
{
name: info.nodeModule,
value: '@ice/template-pkg-node',
},
{
name: info.webLibrary,
value: '@ice/template-pkg-web',
},
{
name: info.raxComponent,
value: '@ice/template-pkg-rax',
},
];
const monorepoTemplateChoices = [
{
name: info.reactMonorepo,
value: '@ice/template-pkg-monorepo-react',
},
{
name: info.nodeMonorepo,
value: '@ice/template-pkg-monorepo-node',
},
];
// If create a sub package(the cli flag is `-w`), don't show the monorepo templates.
const choices = baseTemplateChoices.concat(!workspace ? monorepoTemplateChoices : []);
const { templateNpmName } = await inquirer.prompt([
{
type: 'list',
message: info.selectProjectType,
name: 'templateNpmName',
default: '@ice/template-pkg-react',
choices: [
{
name: info.reactComponent,
value: '@ice/template-pkg-react',
},
{
name: info.nodeModule,
value: '@ice/template-pkg-node',
},
{
name: info.webLibrary,
value: '@ice/template-pkg-web',
},
{
name: info.raxComponent,
value: '@ice/template-pkg-rax',
},
{
name: info.reactMonorepo,
value: '@ice/template-pkg-monorepo-react',
},
{
name: info.nodeMonorepo,
value: '@ice/template-pkg-monorepo-node',
},
],
choices,
},
]);
return templateNpmName;
Expand Down

0 comments on commit d815b5e

Please sign in to comment.