From 947d3884df5825aa746f7f8c9dc47b9cea839f0d Mon Sep 17 00:00:00 2001 From: liam-b-dev <44777489+liam-b-dev@users.noreply.github.com> Date: Thu, 17 Feb 2022 04:01:43 +1100 Subject: [PATCH 1/3] node_modules --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f3426c8..1782f33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ package-lock.json -/nodule_modules \ No newline at end of file +nodule_modules \ No newline at end of file From c17edc675d62761b28ae7fe4109b52c3e44174ac Mon Sep 17 00:00:00 2001 From: liam-b-dev <44777489+liam-b-dev@users.noreply.github.com> Date: Thu, 17 Feb 2022 04:02:54 +1100 Subject: [PATCH 2/3] fix .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1782f33..074ab52 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ package-lock.json -nodule_modules \ No newline at end of file +node_modules \ No newline at end of file From 9c68c91735b476bd2354a935e4d0c268526ca1dd Mon Sep 17 00:00:00 2001 From: liam-b-dev <44777489+liam-b-dev@users.noreply.github.com> Date: Thu, 17 Feb 2022 04:16:58 +1100 Subject: [PATCH 3/3] Add in a timeout option across commands and terminal --- project/commands/plugin.js | 12 ++- project/commands/webpack.js | 9 +- project/controllers/operator.js | 17 +++- project/controllers/terminal.js | 6 +- project/packages/plugin/questions.js | 14 +++ project/packages/webpack/questions.js | 130 +++++++++++++++----------- 6 files changed, 126 insertions(+), 62 deletions(-) diff --git a/project/commands/plugin.js b/project/commands/plugin.js index 430f4ee..739faca 100644 --- a/project/commands/plugin.js +++ b/project/commands/plugin.js @@ -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(); @@ -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(); @@ -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(); } @@ -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(); @@ -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(); } @@ -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(); @@ -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(); diff --git a/project/commands/webpack.js b/project/commands/webpack.js index 4a6422c..cdf6f4d 100644 --- a/project/commands/webpack.js +++ b/project/commands/webpack.js @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/project/controllers/operator.js b/project/controllers/operator.js index ef66431..09fc903 100644 --- a/project/controllers/operator.js +++ b/project/controllers/operator.js @@ -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 ] ) }; @@ -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 } ); } /** diff --git a/project/controllers/terminal.js b/project/controllers/terminal.js index a21177b..2055f5e 100644 --- a/project/controllers/terminal.js +++ b/project/controllers/terminal.js @@ -93,10 +93,11 @@ class Terminal { * Do installation * @param describe * @param event + * @param timeout * @param isFatal * @returns {Promise} */ - async install( { describe, event, isFatal = true } ) { + async install( { describe, event, timeout, isFatal = true } ) { const spinner = ora( describe ).start(); const log = new Logger(); if ( !event ) { @@ -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 ); } } ); diff --git a/project/packages/plugin/questions.js b/project/packages/plugin/questions.js index 70eb206..2468b0b 100644 --- a/project/packages/plugin/questions.js +++ b/project/packages/plugin/questions.js @@ -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', diff --git a/project/packages/webpack/questions.js b/project/packages/webpack/questions.js index 88db7c2..8076908 100644 --- a/project/packages/webpack/questions.js +++ b/project/packages/webpack/questions.js @@ -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, -}; \ No newline at end of file + Questions +}