Skip to content

Fix for: Git clone timeout #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
package-lock.json
/nodule_modules
node_modules
12 changes: 10 additions & 2 deletions project/commands/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ exports.handler = async ( argv ) => {
* Clone the plugin git repo into the
* project path and set next step
*/
const gitTimeout = promptedInfo.gitTimeout;
await terminal.install( {
describe: `${ terminal.step }. Operator is cloning plugin repository`,
event: operator.getRepo( 'https://github.com/wp-strap/wordpress-plugin-boilerplate.git', projectPath ),
event: operator.getRepo(gitTimeout, 'https://github.com/wp-strap/wordpress-plugin-boilerplate.git', projectPath),
timeout: gitTimeout,
} );
terminal.setNextStep();

Expand All @@ -80,7 +82,8 @@ exports.handler = async ( argv ) => {
await terminal.setPredefinedAnswers( QuestionsWebpack, argv );
await terminal.install( {
describe: `${ terminal.step }. Operator is cloning webpack repository`,
event: operator.getRepo( 'https://github.com/wp-strap/wordpress-webpack-workflow.git', projectPath + '/wordpress-webpack-workflow' ),
event: operator.getRepo(gitTimeout, 'https://github.com/wp-strap/wordpress-webpack-workflow.git', projectPath + '/wordpress-webpack-workflow'),
timeout: gitTimeout,
} );
const promptedInfoWebpack = await operator.prompt( QuestionsWebpack, argv, true );
terminal.setNextStep();
Expand All @@ -91,6 +94,7 @@ exports.handler = async ( argv ) => {
await terminal.install( {
describe: `${ terminal.step }. Operator is replacing webpack data`,
event: scanner.searchReplaceWebPack( promptedInfoWebpack, projectPath ),
timeout: false,
} );
terminal.setNextStep();
}
Expand All @@ -102,6 +106,7 @@ exports.handler = async ( argv ) => {
await terminal.install( {
describe: `${ terminal.step }. Operator is replacing plugin data`,
event: scanner.searchReplace( promptedInfo, projectPath ),
timeout: false,
} );
terminal.setNextStep();

Expand All @@ -114,6 +119,7 @@ exports.handler = async ( argv ) => {
await terminal.install( {
describe: `${ terminal.step }. Operator is installing NPM dependencies, this may take a while..`,
event: operator.install( 'webpack', projectPath ),
timeout: false,
} );
terminal.setNextStep();
}
Expand All @@ -125,6 +131,7 @@ exports.handler = async ( argv ) => {
await terminal.install( {
describe: `${ terminal.step }. Operator is installing Composer dependencies`,
event: operator.install( 'composer', projectPath ),
timeout: false,
} );
terminal.setNextStep();

Expand All @@ -135,6 +142,7 @@ exports.handler = async ( argv ) => {
await terminal.install( {
describe: `${ terminal.step }. Operator is cleaning up`,
event: operator.cleanUp( projectPath ),
timeout: false,
} );
terminal.setNextStep();

Expand Down
9 changes: 8 additions & 1 deletion project/commands/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ exports.handler = async ( argv ) => {
* Clone the git repo into the
* project path and set next step
*/
const gitTimeout = promptedInfo.gitTimeout;

await terminal.install( {
describe: `${ terminal.step }. Operator is cloning repository`,
event: operator.getRepo( 'https://github.com/wp-strap/wordpress-webpack-workflow.git', projectPath ),
event: operator.getRepo( gitTimeout, 'https://github.com/wp-strap/wordpress-webpack-workflow.git', projectPath ),
timeout: gitTimeout,
} );
terminal.setNextStep();

Expand All @@ -80,6 +83,7 @@ exports.handler = async ( argv ) => {
await terminal.install( {
describe: `${ terminal.step }. Operator is replacing project data with your input`,
event: scanner.searchReplace( promptedInfo, projectPath ),
timeout: false,
} );
terminal.setNextStep();

Expand All @@ -91,11 +95,13 @@ exports.handler = async ( argv ) => {
await terminal.install( {
describe: `${ terminal.step }. Operator is installing NPM dependencies, this may take a while..`,
event: operator.install( 'webpack', currentPath ),
timeout: false,
} );
} else {
await terminal.install( {
describe: `${ terminal.step }. Operator is installing NPM dependencies, this may take a while..`,
event: operator.install( 'webpack', projectPath ),
timeout: false,
} );
}
terminal.setNextStep();
Expand All @@ -107,6 +113,7 @@ exports.handler = async ( argv ) => {
await terminal.install( {
describe: `${ terminal.step }. Operator is cleaning up`,
event: operator.cleanUp( projectPath ),
timeout: false,
} );
terminal.setNextStep();

Expand Down
17 changes: 14 additions & 3 deletions project/controllers/operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ class Operator {
if ( argument.skipPrompt ) {
// Check if the question should be skipped
continue;
} else if ( argument.buildFrom ) {
}
else if (argument.checkTimeout){
// Check if the timeout select is a number value
if(answers.gitTimeout !== 'custom') {
continue;
}
// Otherwise warn user, and ask for a custom number
const answer = await inquirer.prompt( argument );
// Fill in gitTimeout answer with custom value
answers.gitTimeout = answer.gitCustom;
}
else if ( argument.buildFrom ) {
// Check if the answer is being made automatically
const { how, name } = argument.buildFrom;
answers = { ...answers, [ argument.name ]: how( answers[ name ] ) };
Expand Down Expand Up @@ -115,10 +126,10 @@ class Operator {
/**
* Clones the repository to the project path
*/
async getRepo( repo, folderName, branch = '', ) {
async getRepo(gitTime, repo, folderName, branch = '') {
const repoCommand = branch.length ? `-b ${ branch } ${ repo }` : repo;
const command = `git clone ${ repoCommand } "${ folderName }"`;
return exec( command, { timeout: this.getRepoTimeout } );
return exec( command, { timeout: gitTime } );
}

/**
Expand Down
6 changes: 5 additions & 1 deletion project/controllers/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ class Terminal {
* Do installation
* @param describe
* @param event
* @param timeout
* @param isFatal
* @returns {Promise<void>}
*/
async install( { describe, event, isFatal = true } ) {
async install( { describe, event, timeout, isFatal = true } ) {
const spinner = ora( describe ).start();
const log = new Logger();
if ( !event ) {
Expand All @@ -109,6 +110,9 @@ class Terminal {
log.error( exception );
if ( isFatal ) {
log.error( `'${ describe }' was a required step, exiting now.` );
if( timeout ){
log.error( `git clone may have timed out. Your timeout setting is: '${ timeout }' milliseconds. Try again with a higher number.` );
}
process.exit( 1 );
}
} );
Expand Down
14 changes: 14 additions & 0 deletions project/packages/plugin/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
* @docs https://github.com/SBoudrias/Inquirer.js
*/
const Questions = {
// Include webpack tooling files
gitTimeout: {
name: 'gitTimeout',
describe: 'How fast is your internet? This installer includes a git clone command, that may not complete in time on slower speeds.',
type: 'list',
choices: [{key: 'fast', name: 'Fast', value: 30000}, {key: 'standard', name: 'Standard', value: 45000}, {key: 'slow', name: 'Slow', value: 60000}, {key: 'slowest', name: 'Slowest', value: 75000}, {key: 'custom', name: 'Custom', value: 1}],
},
gitCustom: {
type: 'number',
name: 'gitCustom',
describe: 'Custom time should only be used as a last resort, as it will freeze the setup process until the timer is up. Enter in milliseconds:',
default: 80000,
checkTimeout: true,
},
// Used for plugin name occurrences
projectName: {
type: 'text',
Expand Down
130 changes: 75 additions & 55 deletions project/packages/webpack/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,80 @@
* @docs https://github.com/SBoudrias/Inquirer.js
*/
const Questions = {
// Used for name occurrences
projectName: {
type: 'text',
name: 'projectName',
describe: 'Please enter your Webpack project name:',
default: 'The Project Name',
},
// Used for author name occurrences
author: {
type: 'text',
name: 'author',
describe: 'The author\'s name for the POT file:',
default: 'The Dev Company',
},
// Used for author email occurrences
authorEmail: {
type: 'text',
name: 'authorEmail',
describe: 'The author\'s e-mail address for the POT file:',
default: 'hello@the-dev-company.com',
},
// Used for author url & plugin url occurrences
url: {
type: 'text',
name: 'url',
describe: 'The author\'s url without https:// for the POT file:',
default: 'the-dev-company.com',
},
// Used for name of the folder, text domain name
package: {
type: 'text',
name: 'package',
describe: 'Package name: name of the folder, POT file, text domain name (e.g. plugin-name):',
buildFrom: {
name: 'projectName',
how: ( sourceArg ) => sourceArg.replace( /[^a-z0-9 -]/gi, '' ).toLowerCase().split( ' ' ).join( '-' ),
},
},
// Type of CSS
css: {
name: 'css',
describe: 'Use Sass+PostCSS or PostCSS-only?',
type: 'list',
choices: [ 'Sass+PostCSS', 'PostCSS-only' ]
},
// Install into the current folder or as a new folder
folder: {
name: 'folder',
describe: 'Install the Webpack workflow into the current folder or as a new folder?',
type: 'list',
choices: [ 'New folder', 'Current folder' ]
},
};
// Used for name occurrences
gitTimeout: {
name: 'gitTimeout',
describe: 'How fast is your internet? This installer includes a git clone command, that may not complete in time on slower speeds.',
type: 'list',
choices: [{key: 'fast', name: 'Fast', value: 30000}, {key: 'standard', name: 'Standard', value: 45000}, {key: 'slow', name: 'Slow', value: 60000}, {key: 'slowest', name: 'Slowest', value: 75000}, {key: 'custom', name: 'Custom', value: 'custom'}],
},
gitCustom: {
type: 'number',
name: 'gitCustom',
describe: 'Custom time should only be used as a last resort, as it will freeze the setup process until the timer is up. Enter in milliseconds:',
default: 80000,
checkTimeout: true,
},
projectName: {
type: 'text',
name: 'projectName',
describe: 'Please enter your Webpack project name:',
default: 'The Project Name'
},
// Used for author name occurrences
author: {
type: 'text',
name: 'author',
describe: "The author's name for the POT file:",
default: 'The Dev Company'
},
// Used for author email occurrences
authorEmail: {
type: 'text',
name: 'authorEmail',
describe: "The author's e-mail address for the POT file:",
default: 'hello@the-dev-company.com'
},
// Used for author url & plugin url occurrences
url: {
type: 'text',
name: 'url',
describe: "The author's url without https:// for the POT file:",
default: 'the-dev-company.com'
},
// Used for name of the folder, text domain name
package: {
type: 'text',
name: 'package',
describe:
'Package name: name of the folder, POT file, text domain name (e.g. plugin-name):',
buildFrom: {
name: 'projectName',
how: (sourceArg) =>
sourceArg
.replace(/[^a-z0-9 -]/gi, '')
.toLowerCase()
.split(' ')
.join('-')
}
},
// Type of CSS
css: {
name: 'css',
describe: 'Use Sass+PostCSS or PostCSS-only?',
type: 'list',
choices: ['Sass+PostCSS', 'PostCSS-only']
},
// Install into the current folder or as a new folder
folder: {
name: 'folder',
describe:
'Install the Webpack workflow into the current folder or as a new folder?',
type: 'list',
choices: ['New folder', 'Current folder']
}
}

module.exports = {
Questions,
};
Questions
}