diff --git a/index.js b/index.js index a5f7faf..b83e1ff 100755 --- a/index.js +++ b/index.js @@ -16,14 +16,18 @@ const program = new commander.Command(packageJson.name) .version(packageJson.version) .arguments('') .usage(`${chalk.green('')}`) - .action((projectDirectory) => { - createApp(projectDirectory); + .option('-v, --verbose', 'Run with verbose logging') // <-- Add this line + .action((projectDirectory, options) => { + // <-- Update the action to take options + createApp(projectDirectory, options); }) .parse(process.argv); -function createApp(projectDirectory) { +function createApp(projectDirectory, options) { console.clear(); // Clears the console before anything else const root = path.resolve(projectDirectory); + const verboseFlag = options.verbose ? '--verbose' : ''; + const stdioOption = verboseFlag === '--verbose' ? 'inherit' : 'ignore'; // Check if the directory already exists if (fs.existsSync(root)) { @@ -51,24 +55,26 @@ function createApp(projectDirectory) { 'โณ Installing packages. This might take a couple of minutes.' ).start(); - execSync('npx create-react-app . --template typescript', { stdio: 'ignore' }); + execSync(`npx create-react-app . --template typescript ${verboseFlag}`, { + stdio: stdioOption, + }); spinner.succeed('๐Ÿ“ฆ Packages installed successfully.'); - installDependencies(); - installDevDependencies(); + installDependencies(verboseFlag, stdioOption); + installDevDependencies(verboseFlag, stdioOption); setupAntd(); setupSass(); - setupTesting(); - setupHusky(); - setupCommitlint(); + setupTesting(stdioOption); + setupHusky(stdioOption); + setupCommitlint(stdioOption); setupRedux(); createAtomicStructure(); updatePackageJson(); copyPreConfiguredFiles(root); // Copy pre-configured files like prettier-commit.js deletePreCommitHook(); // Delete the .husky/pre-commit hook - runGitCommands(); // Run git add . and git commit -m "feat: happy coding" - runPrettierCommit(); // Run npm run prettier:commit + runGitCommands(stdioOption); // Run git add . and git commit -m "feat: happy coding" + runPrettierCommit(stdioOption); // Run npm run prettier:commit printCommandSummary(); // Print the command summary console.log(chalk.green('๐ŸŽ‰ All done! Happy coding.')); // Ask the user where they want to open the project @@ -129,7 +135,7 @@ function openInTerminal(directory) { } } -function openInVSCode(directory) { +function openInVSCode(directory, stdioOption) { spawn('code', [directory], { stdio: 'inherit' }); } @@ -218,11 +224,11 @@ function printCommandSummary() { ); } -function runPrettierCommit() { +function runPrettierCommit(stdioOption) { const spinner = ora('๐ŸŽจ Running prettier:commit script...').start(); try { - execSync('npm run prettier:commit', { stdio: 'ignore' }); + execSync('npm run prettier:commit', { stdio: stdioOption }); spinner.succeed('โœ… Prettier commit script executed successfully.'); } catch (error) { spinner.fail('โŒ Failed to run prettier:commit script.'); @@ -230,12 +236,12 @@ function runPrettierCommit() { } } -function runGitCommands() { +function runGitCommands(stdioOption) { const spinner = ora('๐Ÿ”ง Running Git commands...').start(); try { - execSync('git add .', { stdio: 'ignore' }); - execSync('git commit -m "feat: happy coding"', { stdio: 'ignore' }); + execSync('git add .', { stdio: stdioOption }); + execSync('git commit -m "feat: happy coding"', { stdio: stdioOption }); spinner.succeed('โœ… Git commands executed successfully.'); } catch (error) { spinner.fail('โŒ Failed to execute Git commands.'); @@ -331,20 +337,20 @@ function copyPreConfiguredFiles(destinationPath) { spinner.succeed('๐Ÿ“ Pre-configured files copied.'); } -function installDependencies() { +function installDependencies(verboseFlag, stdioOption) { const spinner = ora('๐Ÿ”„ Installing additional dependencies...').start(); execSync( - 'npm install @babel/core @babel/preset-env @babel/preset-react @reduxjs/toolkit @testing-library/jest-dom @testing-library/react @testing-library/user-event @types/jest @types/node @types/react @types/react-dom ajv antd babel-loader css-loader jest playwright react react-dom react-redux react-scripts redux sass sass-loader style-loader typescript web-vitals webpack webpack-cli', - { stdio: 'ignore' } + `npm install @babel/core @babel/preset-env @babel/preset-react @reduxjs/toolkit @testing-library/jest-dom @testing-library/react @testing-library/user-event @types/jest @types/node @types/react @types/react-dom ajv antd babel-loader css-loader jest playwright react react-dom react-redux react-scripts redux sass sass-loader style-loader typescript web-vitals webpack webpack-cli ${verboseFlag}`, + { stdio: stdioOption } ); spinner.succeed('โœ… Additional dependencies installed.'); } -function installDevDependencies() { +function installDevDependencies(verboseFlag, stdioOption) { const spinner = ora('๐Ÿ”„ Installing additional dev dependencies...').start(); execSync( - 'npm install --save-dev @babel/plugin-proposal-private-property-in-object ora prettier @commitlint/cli @commitlint/config-conventional @svgr/webpack dotenv dotenv-webpack husky url-loader webpack-dev-server pretty-quick', - { stdio: 'ignore' } + `npm install --save-dev @babel/plugin-proposal-private-property-in-object ora prettier @commitlint/cli @commitlint/config-conventional @svgr/webpack dotenv dotenv-webpack husky url-loader webpack-dev-server pretty-quick ${verboseFlag}`, + { stdio: stdioOption } ); spinner.succeed('โœ… Additional dev dependencies installed.'); } @@ -364,20 +370,29 @@ function setupSass() { spinner.succeed('๐ŸŽจ SASS set up.'); } -function setupTesting() { +function setupTesting(stdioOption) { const spinner = ora('๐Ÿงช Setting up Playwright and Jest...').start(); - execSync('npx playwright install', { stdio: 'ignore' }); - spinner.succeed('๐Ÿงช Playwright and Jest set up.'); + try { + execSync('npx playwright install', { stdio: stdioOption }); + spinner.succeed('๐Ÿงช Playwright and Jest set up.'); + } catch (error) { + spinner.fail('โŒ Failed to set up Playwright and Jest.'); + console.error(error); + } } -function setupHusky() { +function setupHusky(stdioOption) { const spinner = ora('๐Ÿถ Setting up Husky...').start(); - execSync('npx husky-init && npm install', { stdio: 'ignore' }); - execSync('npx husky add .husky/pre-commit "npm test"', { stdio: 'ignore' }); + execSync('npx husky-init && npm install', { + stdio: stdioOption, + }); + execSync('npx husky add .husky/pre-commit "npm test"', { + stdio: stdioOption, + }); spinner.succeed('๐Ÿถ Husky set up.'); } -function setupCommitlint() { +function setupCommitlint(stdioOption) { const spinner = ora('๐Ÿ” Setting up Commitlint...').start(); const commitMsg = `#!/bin/sh . "$(dirname "$0")/_/husky.sh" @@ -391,12 +406,12 @@ node ./.husky/commit-msg-linter.js "$1"`; node .husky/lint-check.js`; execSync('npm install @commitlint/{config-conventional,cli} --save-dev', { - stdio: 'ignore', + stdio: stdioOption, }); - execSync('touch .husky/commit-msg', { stdio: 'ignore' }); - execSync('touch .husky/pre-push', { stdio: 'ignore' }); - execSync('chmod +x .husky/commit-msg', { stdio: 'ignore' }); - execSync('chmod +x .husky/pre-push', { stdio: 'ignore' }); + execSync('touch .husky/commit-msg', { stdio: stdioOption }); + execSync('touch .husky/pre-push', { stdio: stdioOption }); + execSync('chmod +x .husky/commit-msg', { stdio: stdioOption }); + execSync('chmod +x .husky/pre-push', { stdio: stdioOption }); fs.writeFileSync(path.resolve('.husky/commit-msg'), commitMsg); fs.writeFileSync(path.resolve('commitlint.config.js'), commitLintMsgLinter); diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 3760f21..93d8a93 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -8542,6 +8542,10 @@ "safe-buffer": "^5.1.0" } }, + "node_modules/react-crafter": { + "resolved": "", + "link": true + }, "node_modules/react-is": { "version": "18.3.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz", diff --git a/pre-files/webpack.config.js b/pre-files/webpack.config.js index c3c3aea..7906075 100644 --- a/pre-files/webpack.config.js +++ b/pre-files/webpack.config.js @@ -2,7 +2,6 @@ const path = require('path'); const Dotenv = require('dotenv-webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -console.log('PUBLIC_URL:', process.env.PUBLIC_URL); module.exports = { mode: 'development',