-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(detection.js, createstrapi.js, packagedetection.js,yarnpackagehel…
…per.js): bugfix for yarn pm bugfix to give use the option to choose package manager of their choice if yarn npm both exists and if yarn is provided in the quickstart option and yarn not installed install it for them.
- Loading branch information
Sudeep Patel
authored and
Sudeep Patel
committed
Jun 6, 2023
1 parent
4e62acb
commit f1aecfc
Showing
4 changed files
with
159 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { exec } = require(`child_process`); | ||
const isWindows = process.platform === `win32`; | ||
|
||
async function checkPackage(packageName) { | ||
return new Promise((resolve) => { | ||
const command = isWindows ? `where ${packageName}` : `which ${packageName}`; | ||
exec(command, (error) => { | ||
if (error) { | ||
resolve(false); | ||
} else { | ||
resolve(true); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
async function checkInstalledPackages() { | ||
const npmExists = await checkPackage(`npm`); | ||
const yarnExists = await checkPackage(`yarn`); | ||
|
||
if (npmExists && yarnExists) { | ||
return [`npm`, `yarn`]; | ||
} else if (npmExists) { | ||
return [`npm`]; | ||
} else if (yarnExists) { | ||
return [`yarn`]; | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
module.exports = { | ||
checkInstalledPackages | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const { exec } = require(`child_process`); | ||
const { config } = require(`./config`); | ||
const {checkInstalledPackages} = require(`./packageDetection`); | ||
const prompts = require(`prompts`); | ||
const { spinner, chalk } = require(`./utils`); | ||
|
||
async function installYarn() { | ||
return new Promise((resolve, reject) => { | ||
exec(`npm install -g yarn`, (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`Error: ${error.message}`); | ||
reject(error); | ||
return; | ||
} | ||
if (stderr) { | ||
console.error(`Stderr: ${stderr}`); | ||
reject(new Error(stderr)); | ||
return; | ||
} | ||
resolve(stdout); | ||
}); | ||
}); | ||
} | ||
|
||
async function checkForYarnPackage() { | ||
if (config.packageManager === `yarn`) { | ||
const checkIfYarnIsInstalled = await checkInstalledPackages(); | ||
let response = ``; | ||
if (!checkIfYarnIsInstalled.includes(`yarn`)) { | ||
response = await prompts([ | ||
{ | ||
name: `installYarnPrompt`, | ||
message: `Yarn not installed! Shall we install it for you? (Strapi Recommended)`, | ||
active: `Yes`, | ||
inactive: `No`, | ||
type: `toggle` | ||
} | ||
]); | ||
|
||
if (response[`installYarnPrompt`] === true) { | ||
await installYarn(); | ||
config.packageManager = `yarn`; | ||
spinner.stopAndPersist({ | ||
text: `\n✅ Yarn installed successfully!\n` | ||
}); | ||
} else { | ||
config.packageManager = `npm`; | ||
} | ||
} | ||
|
||
spinner.stopAndPersist({ | ||
symbol: `📦`, | ||
text: ` Using ${chalk.bold.blueBright( | ||
config.packageManager.toUpperCase() | ||
)} \n` | ||
}); | ||
} | ||
} | ||
|
||
|
||
module.exports = { | ||
installYarn, | ||
checkForYarnPackage | ||
}; |