Skip to content

Commit

Permalink
#78: add user interaction that stops execution if cloud folder was found
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Aug 1, 2023
1 parent 1fba616 commit 665e230
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions lib/util/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const Init = {
* @returns {Promise.<void>} -
*/
async initProject(properties, credentialName) {
Init._checkPathForCloud();
if (!(await Init._checkPathForCloud())) {
return;
}

const skipInteraction = Util.skipInteraction;
if (!properties) {
Expand Down Expand Up @@ -196,7 +198,9 @@ const Init = {
* @returns {Promise.<void>} -
*/
async joinProject() {
Init._checkPathForCloud();
if (!(await Init._checkPathForCloud())) {
return;
}

const responses = await inquirer.prompt([
{
Expand Down Expand Up @@ -376,7 +380,9 @@ const Init = {
* @returns {Promise.<boolean>} success flag
*/
async upgradeProject(properties, initial, repoName) {
Init._checkPathForCloud();
if (!(await Init._checkPathForCloud())) {
return;
}

let status;
const versionBeforeUpgrade = properties?.version || '0.0.0';
Expand Down Expand Up @@ -412,25 +418,59 @@ const Init = {
return true;
},
/**
* check if git repo is being saved on a cloud service and warns the user
* check if git repo is being saved on a cloud service and warn the user
*
* @private
* @returns {void} throws errors if problems were found
*/
_checkPathForCloud() {
async _checkPathForCloud() {
const absolutePath = path.resolve('');
// popular cloud services and their respective default name for the absolute path
const cloudServices = ['Dropbox', 'OneDrive', 'Google Drive'];
// * CloudDocs is the default folder name for iCloud
const cloudServices = ['Dropbox', 'OneDrive', 'Google Drive', 'iCloud', 'CloudDocs'];
let cloudServiceFound = false;
for (const variable in cloudServices) {
if (absolutePath.includes(cloudServices[variable])) {
Util.logger.warn(
`It seems your project folder will be synchronized via '${cloudServices[variable]}'. This can reduce the overall performance of your computer due to conflicts with Git.`
`It seems your project folder will be synchronized via '${
cloudServices[variable] === 'CloudDocs' ? 'iCloud' : cloudServices[variable]
}'. This can reduce the overall performance of your computer due to conflicts with Git.`
);
Util.logger.warn(
`We strongly recommend moving your project folder outside of the '${cloudServices[variable]}' folder.`
`We strongly recommend moving your project folder outside of the '${
cloudServices[variable] === 'CloudDocs' ? 'iCloud' : cloudServices[variable]
}' folder.`
);
cloudServiceFound = true;
}
}
if (!cloudServiceFound && absolutePath.includes(process.env.USERPROFILE)) {
// warn user to not place project folder into user profile folder
Util.logger.warn(
`It seems your project folder is located in your user profile's default folder which is often synchronized to webservices like ${cloudServices.join(
', '
)}. This can reduce the overall performance of your computer due to conflicts between with Git.`
);
Util.logger.warn(
`We strongly recommend moving your project folder outside of this folder.`
);
cloudServiceFound = true;
}
if (cloudServiceFound) {
const responses = await inquirer.prompt([
{
type: 'confirm',
name: 'ignoreCloudWarning',
message: 'Do you want to continue anyways?',
default: false,
},
]);
if (!responses.ignoreCloudWarning) {
Util.logger.error('Exiting due to cloud service warning');
return false;
}
}
return true;
},

/**
Expand Down

0 comments on commit 665e230

Please sign in to comment.