Skip to content

Commit

Permalink
minor changes in packages
Browse files Browse the repository at this point in the history
  • Loading branch information
amitkroutthedev committed Jan 12, 2024
1 parent cde6deb commit 906879d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
34 changes: 20 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ const runCommand = (command) => {
return true;
}

const forceClosed = () => {
shell.echo(chalk.bold(chalk.redBright("Forced Closed")))
}

const generateQuestionsForFolder = async () => {
const folderName = await input({
message: 'Enter your folder name: ',
validate: async (input) => {
if (input === "") return 'Folder name cannot be empty'
return true
}
});
}).catch(e => { forceClosed(); process.exit(0) });
const typeOFScript = await select({
message: 'Will you be using TypeScript or JavaScript?',
choices: [
Expand All @@ -55,7 +59,7 @@ const generateQuestionsForFolder = async () => {
},
],
default: 'js'
})
}).catch(e => { forceClosed(); process.exit(0) })
const packageManger = await select({
message: 'Select a package manager:',
choices: [
Expand All @@ -70,10 +74,10 @@ const generateQuestionsForFolder = async () => {
description: 'yarn is an awesome package manager',
},
],
});
const addRouter = await confirm({ message: 'Do you want to add router to the project(react-router)?', });
const addAxios = await confirm({ message: 'Do you want to add axios for API calls?' });
const addRedux = await confirm({ message: 'Do you want to add redux?' })
}).catch(e => { forceClosed(); process.exit(0) });
const addRouter = await confirm({ message: 'Do you want to add router to the project(react-router)?', }).catch(e => { forceClosed(); process.exit(0) });
const addAxios = await confirm({ message: 'Do you want to add axios for API calls?' }).catch(e => { forceClosed(); process.exit(0) });
const addRedux = await confirm({ message: 'Do you want to add redux?' }).catch(e => { forceClosed(); process.exit(0) })
const reduxMiddlewareType = addRedux === true && await select({
message: `Please choose the Redux's middleware the project:`,
choices: [
Expand All @@ -89,7 +93,7 @@ const generateQuestionsForFolder = async () => {
},
],
default: "redux-thunk",
});
}).catch(e => { forceClosed(); process.exit(0) });
const cssFramework = await select({
message: 'Please choose the css framework',
choices: [
Expand All @@ -99,7 +103,7 @@ const generateQuestionsForFolder = async () => {
{ name: 'None of the above', value: 'None' },

],
});
}).catch(e => { forceClosed(); process.exit(0) });
return { folderName, typeOFScript, packageManger, addRouter, addAxios, addRedux, reduxMiddlewareType, cssFramework }
}

Expand Down Expand Up @@ -167,7 +171,7 @@ const installAxiosPkg = async (typePackage) => {
const installAxios = runCommand(`${typePackage} axios`);
if (!installAxios) process.exit(-1);
}
const installReduxPkg = async (typePackage,typeOFScript) => {
const installReduxPkg = async (typePackage, typeOFScript) => {
shell.echo(`Installing ${chalk.blue("redux")}`);
const installRedux = runCommand(
`${typePackage} redux @reduxjs/toolkit && ${typePackage} -D react-redux`
Expand All @@ -191,13 +195,15 @@ const installReduxThunkPkg = async (typePackage, typeOFScript) => {
shell.echo(`Installing and Setting ${chalk.blue("redux-thunk")}`);
const installReduxThunk = runCommand(`${typePackage} redux-thunk`);
if (!installReduxThunk) process.exit(-1);
const thunkStoreCode = `import { configureStore } from '@reduxjs/toolkit'
const thunkStoreCode = `
import { configureStore } from '@reduxjs/toolkit'
import thunk from 'redux-thunk'
const store = configureStore({
reducer: {},
middleware: [thunk]
middleware: (getDefaultMiddleware) => getDefaultMiddleware({thunk:true})
})
export default store`;
if (os.type() === "Windows_NT") {
fs.writeFileSync(`src/redux/action/config/store.${typeOFScript}x`, thunkStoreCode);
Expand Down Expand Up @@ -416,8 +422,8 @@ const generateFolder = async () => {

}
} catch (error) {
console.log(error)
shell.echo(chalk.bold(chalk.redBright("Forced Closed")))
forceClosed()
process.exit(0)
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"bin": {
"create-rp": "index.js"
},
"scripts": {},
"keywords": [
"axios",
"redux",
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/sample-react-typescript/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="globals.css" />
<title>Document</title>
<link rel="icon" href="favicon.ico"/>
<title>Project with react and webpack</title>
</head>
<body>
<div id="root"></div>
Expand Down

0 comments on commit 906879d

Please sign in to comment.