Skip to content

Commit

Permalink
[#88] Refactor to ask for Vite or Webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Jul 25, 2022
1 parent a82f6a1 commit 7de1f68
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/cli-tool/src/commands/generate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { setUIFramework } from "../../add-ons/ui-framework/index";
import { setVersionControl } from "../../add-ons/version-control/index";
import { questions } from "../../helpers/questions";
import initializeViteApp from "../../template/initialize-vite-app";
import { template } from '@oclif/core/lib/help/util';
import { initializeTemplate } from '../../template/index';

export default class Generate extends Command {
static description = "Generate Nimble React application";
Expand Down Expand Up @@ -53,11 +55,11 @@ export default class Generate extends Command {
`Generating Nimble React app with the project name: ${appName}!`
);

await initializeViteApp({
appName,
dest,
branch: branch,
});
await initializeTemplate({
templateIptions: template,
...answers
})

setVersionControl(appPath, answers.versionControl);
await setUIFramework(appPath, answers.uiFramework);

Expand Down
8 changes: 8 additions & 0 deletions packages/cli-tool/src/helpers/questions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { UI_FRAMEWORK_OPTIONS } from '../add-ons/ui-framework/index';
import { VERSION_CONTROL_OPTIONS } from '../add-ons/version-control/index';
import { TEMPLATE_OPTIONS } from '../template/index';
import getChoices from './choices';

const uiFrameworkChoices = getChoices(UI_FRAMEWORK_OPTIONS);
const versionControlChoices = getChoices(VERSION_CONTROL_OPTIONS);
const templateOptions = getChoices(TEMPLATE_OPTIONS);

export const questions = [
{
type: 'list',
name: 'template',
message: 'Select a template:',
choices: templateOptions,
},
{
type: 'list',
name: 'versionControl',
Expand Down
32 changes: 32 additions & 0 deletions packages/cli-tool/src/template/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import initializeCraApp from "./initialize-cra-app";
import initializeViteApp from "./initialize-vite-app";

export type templateOptions = "webpack" | "vite";
export const TEMPLATE_OPTIONS = new Map<templateOptions, string>([
["webpack", "WebPack"],
["vite", "Vite"],
]);

export const initializeTemplate = async ({
appName,
templateOption,
branch,
dest,
}: {
appName: string;
templateOption: templateOptions;
branch: string;
dest: string;
}): Promise<void> => {
if (templateOption == "vite") {
await initializeViteApp({
appName,
dest,
branch: branch,
});

return;
}

await initializeCraApp(appName, branch, dest);
};

0 comments on commit 7de1f68

Please sign in to comment.