Skip to content

Commit

Permalink
bug/issue 1302 install fails when no args are provided (#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 authored Nov 8, 2024
1 parent f199112 commit 1ce74c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"eslint": "^8.51.0",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-no-only-tests": "^2.6.0",
"gallinago": "^0.8.1",
"gallinago": "^0.8.2",
"glob-promise": "^3.4.0",
"jsdom": "^16.5.0",
"lerna": "^3.16.4",
Expand Down
19 changes: 12 additions & 7 deletions packages/init/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,21 @@ const cleanUp = async () => {

const run = async () => {
try {
const firstArg = process.argv[process.argv.length - 1].split(' ')[0];
const taskRunner = program.yarn ? 'yarn' : 'npm run';
// bypassing commander here for my-app directory option, since I couldn't get it to work as an argument :/
// https://github.com/tj/commander.js?tab=readme-ov-file#command-arguments
const shouldChangeDirectory = !firstArg.startsWith('--') && firstArg !== '';
// bit of a hack job for now and its known custom directory and additional flags don't well together right now
// https://github.com/ProjectEvergreen/greenwood/issues/1302
// https://stackoverflow.com/a/31643053/417806
const args = process.argv;
const noArgs = args.length === 2;
const lastArg = args[args.length - 1].split(' ')[0];
const hasCustomDirectoryArg = !noArgs && !lastArg.startsWith('--');
const taskRunner = program.yarn ? 'yarn' : 'npm run';
const shouldInstallDeps = program.install || program.yarn;
const instructions = [];

if (shouldChangeDirectory) {
TARGET_DIR = path.join(TARGET_DIR, `./${firstArg}`);
if (hasCustomDirectoryArg) {
TARGET_DIR = path.join(TARGET_DIR, `./${lastArg}`);

if (!fs.existsSync(TARGET_DIR)) {
fs.mkdirSync(TARGET_DIR);
Expand Down Expand Up @@ -297,8 +302,8 @@ const run = async () => {
console.log(`${chalk.rgb(175, 207, 71)('Initializing new project complete!')}`);
console.log(`${chalk.rgb(175, 207, 71)('Complete the follow steps to get started:')}`);

if (shouldChangeDirectory) {
instructions.push(`Change directories by running => cd ${firstArg}`);
if (hasCustomDirectoryArg) {
instructions.push(`Change directories by running => cd ${lastArg}`);
}

if (!shouldInstallDeps) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8768,10 +8768,10 @@ fuzzy@0.1.3:
resolved "https://registry.yarnpkg.com/fuzzy/-/fuzzy-0.1.3.tgz#4c76ec2ff0ac1a36a9dccf9a00df8623078d4ed8"
integrity sha512-/gZffu4ykarLrCiP3Ygsa86UAo1E5vEVlvTrpkKywXSbP9Xhln3oSp9QSV57gEq3JFFpGJ4GZ+5zdEp3FcUh4w==

gallinago@^0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/gallinago/-/gallinago-0.8.1.tgz#47eb2358bf27f5d16d2755df36577f03caddfd80"
integrity sha512-uE7LyJHtfl650PAZUQiZLzxuYcJAVMJ7p32cEDEskfYrCmHKDu5KkuBqMnwKEcJTDOdWEvhlii/o0pvucX0CgQ==
gallinago@^0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/gallinago/-/gallinago-0.8.2.tgz#c719c28700b3a354a2f5e4b0c10160c29ba72180"
integrity sha512-OGKhpSVFQUw953tWrqRSgOuPteDqftoH5I01qDzQSDOYfeWCoBcnVNEGO0zZHjzS0vJsGVClsVWoJJsJbCdRig==

gauge@^3.0.0:
version "3.0.2"
Expand Down

0 comments on commit 1ce74c7

Please sign in to comment.