From b7cbb9e2248ff85dc90a752e3209ee0f93949142 Mon Sep 17 00:00:00 2001 From: ehowey Date: Mon, 12 Sep 2022 06:17:43 -0600 Subject: [PATCH 01/11] Add engine check and prompt --- .../src/create-redwood-app.js | 117 ++++++++++++------ 1 file changed, 78 insertions(+), 39 deletions(-) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 743ffd95892f..2a0946931bc1 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -61,6 +61,10 @@ import { name, version } from '../package' )}` ) + // Template dir for Redwood files + // Needed higher up for engine checks + const templateDir = path.resolve(__dirname, '../template') + // Extract the args as provided by the user in the command line const { _: args, @@ -117,6 +121,80 @@ import { name, version } from '../package' Object.assign(userArgs, { typescript: false }) } + // Check Node/Yarn/Engines Compatability + // This checks all engine requirements, including Node.js and Yarn + let hasPassedEngineCheck = null + let engineErrorLog = [] + + await new Listr( + [ + { + title: 'Checking node and yarn compatibility', + skip: () => { + if (yarnInstall === false) { + return 'Warning: skipping check on request' + } + }, + task: () => { + return new Promise((resolve) => { + const { engines } = require(path.join(templateDir, 'package.json')) + + // this checks all engine requirements, including Node.js and Yarn + checkNodeVersion(engines, (_error, result) => { + if (result.isSatisfied) { + hasPassedEngineCheck = true + return resolve() + } + + const logStatements = Object.keys(result.versions) + .filter((name) => !result.versions[name].isSatisfied) + .map((name) => { + const { version, wanted } = result.versions[name] + return style.error( + `${name} ${wanted} required, but you have ${version}` + ) + }) + engineErrorLog = [...logStatements] + hasPassedEngineCheck = false + return resolve() + }) + }) + }, + }, + ], + { clearOutput: true } + ).run() + + // Show a success message if required engines are present + if (hasPassedEngineCheck === true) { + console.log(style.success(`✔️ Compatability checks passed.`)) + } + + // Show an error and prompt if failed engines + if (hasPassedEngineCheck === false) { + console.log(style.error(`✖️ Compatability checks failed.`)) + console.log(`${engineErrorLog.join('\n')}`) + console.log(style.header(`\nVisit requirements documentation:`)) + console.log( + style.warning( + `/docs/tutorial/chapter1/prerequisites/#nodejs-and-yarn-versions\n` + ) + ) + const response = await prompts({ + type: 'select', + name: 'override-engine-error', + message: 'How would you like to proceed?', + choices: [ + { title: 'Ignore error and continue install', value: true }, + { title: 'Quit install', value: false }, + ], + initial: 0, + }) + if (response['override-engine-error'] === false) { + process.exit(1) + } + } + // User prompts // See https://github.com/terkelg/prompts const questions = [ @@ -159,48 +237,9 @@ import { name, version } from '../package' const newAppDir = path.resolve(process.cwd(), targetDir) const appDirExists = fs.existsSync(newAppDir) - const templateDir = path.resolve(__dirname, '../template') const createProjectTasks = ({ newAppDir, overwrite }) => { return [ - { - title: 'Checking node and yarn compatibility', - skip: () => { - if (yarnInstall === false) { - return 'Warning: skipping check on request' - } - }, - task: () => { - return new Promise((resolve, reject) => { - const { engines } = require(path.join(templateDir, 'package.json')) - - // this checks all engine requirements, including Node.js and Yarn - checkNodeVersion(engines, (_error, result) => { - if (result.isSatisfied) { - return resolve() - } - - const logStatements = Object.keys(result.versions) - .filter((name) => !result.versions[name].isSatisfied) - .map((name) => { - const { version, wanted } = result.versions[name] - return style.error( - `${name} ${wanted} required, but you have ${version}` - ) - }) - logStatements.push( - style.header(`\nVisit requirements documentation:`) - ) - logStatements.push( - style.warning( - `/docs/tutorial/chapter1/prerequisites/#nodejs-and-yarn-versions\n` - ) - ) - return reject(new Error(logStatements.join('\n'))) - }) - }) - }, - }, { title: `${ appDirExists ? 'Using' : 'Creating' From 6f55e05c351740ef260a8372f1c37f45abf65b06 Mon Sep 17 00:00:00 2001 From: ehowey Date: Mon, 12 Sep 2022 06:28:58 -0600 Subject: [PATCH 02/11] Language tweak --- packages/create-redwood-app/src/create-redwood-app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 2a0946931bc1..4b9e9b7a3e42 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -185,7 +185,7 @@ import { name, version } from '../package' name: 'override-engine-error', message: 'How would you like to proceed?', choices: [ - { title: 'Ignore error and continue install', value: true }, + { title: 'Override error and continue install', value: true }, { title: 'Quit install', value: false }, ], initial: 0, From 1e30054d427d74dbbcfd026806eaac4e7e6056b5 Mon Sep 17 00:00:00 2001 From: ehowey Date: Mon, 26 Sep 2022 06:06:13 -0600 Subject: [PATCH 03/11] Add link and additional text to error --- packages/create-redwood-app/package.json | 1 + .../create-redwood-app/src/create-redwood-app.js | 12 +++++++++--- yarn.lock | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/create-redwood-app/package.json b/packages/create-redwood-app/package.json index c34d6e8fc795..78fd6e45d829 100644 --- a/packages/create-redwood-app/package.json +++ b/packages/create-redwood-app/package.json @@ -33,6 +33,7 @@ "fs-extra": "10.1.0", "listr": "0.14.3", "prompts": "2.4.2", + "terminal-link": "2.1.1", "yargs": "17.5.1" }, "devDependencies": { diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 4b9e9b7a3e42..b0556e6be457 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -15,6 +15,7 @@ import execa from 'execa' import fs from 'fs-extra' import Listr from 'listr' import prompts from 'prompts' +import terminalLink from 'terminal-link' import { hideBin } from 'yargs/helpers' import yargs from 'yargs/yargs' @@ -123,6 +124,10 @@ import { name, version } from '../package' // Check Node/Yarn/Engines Compatability // This checks all engine requirements, including Node.js and Yarn + const engineErrorDocsLink = terminalLink( + 'Tutorial - Chapter 1 - Prerequisites', + 'https://redwoodjs.com/docs/tutorial/chapter1/prerequisites' + ) let hasPassedEngineCheck = null let engineErrorLog = [] @@ -174,12 +179,13 @@ import { name, version } from '../package' if (hasPassedEngineCheck === false) { console.log(style.error(`✖️ Compatability checks failed.`)) console.log(`${engineErrorLog.join('\n')}`) - console.log(style.header(`\nVisit requirements documentation:`)) console.log( - style.warning( - `/docs/tutorial/chapter1/prerequisites/#nodejs-and-yarn-versions\n` + style.error( + `\nThis might make your RedwoodJS project incompatible with some deploy targets.` ) ) + console.log(style.header(`\nRelated documentation:`)) + console.log(style.warning(`${engineErrorDocsLink}\n`)) const response = await prompts({ type: 'select', name: 'override-engine-error', diff --git a/yarn.lock b/yarn.lock index a7848f7358cf..4dc01f855000 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13653,6 +13653,7 @@ __metadata: jest: 29.0.3 listr: 0.14.3 prompts: 2.4.2 + terminal-link: 2.1.1 typescript: 4.7.4 yargs: 17.5.1 bin: From 1e4af7b2c5feadc3b1cff193883aab3adfa538f1 Mon Sep 17 00:00:00 2001 From: ehowey Date: Wed, 5 Oct 2022 05:58:19 -0600 Subject: [PATCH 04/11] Migrate to Listr2 --- packages/create-redwood-app/src/create-redwood-app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 980f744257d1..b11214b16fe2 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -167,7 +167,7 @@ import { name, version } from '../package' }, }, ], - { clearOutput: true } + { rendererOptions: { clearOutput: true } } ).run() // Show a success message if required engines are present From 49e970dbbdbc528b70a2c6227cd685e216cd26c4 Mon Sep 17 00:00:00 2001 From: ehowey Date: Wed, 12 Oct 2022 11:44:44 -0600 Subject: [PATCH 05/11] WIP --- packages/create-redwood-app/package.json | 2 +- .../src/create-redwood-app.js | 266 +++++++++++------- yarn.lock | 2 +- 3 files changed, 161 insertions(+), 109 deletions(-) diff --git a/packages/create-redwood-app/package.json b/packages/create-redwood-app/package.json index 8b89d4769e10..b89f42aa703d 100644 --- a/packages/create-redwood-app/package.json +++ b/packages/create-redwood-app/package.json @@ -29,10 +29,10 @@ "chalk": "4.1.2", "check-node-version": "4.2.1", "core-js": "3.25.5", + "enquirer": "2.3.6", "execa": "5.1.1", "fs-extra": "10.1.0", "listr2": "5.0.5", - "prompts": "2.4.2", "terminal-link": "2.1.1", "yargs": "17.5.1" }, diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index b11214b16fe2..6c67dd392868 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -14,7 +14,6 @@ import checkNodeVersion from 'check-node-version' import execa from 'execa' import fs from 'fs-extra' import { Listr } from 'listr2' -import prompts from 'prompts' import terminalLink from 'terminal-link' import { hideBin } from 'yargs/helpers' import yargs from 'yargs/yargs' @@ -109,18 +108,18 @@ import { name, version } from '../package' .version(version) .parse() - // Variable to hold the user args as an object that can be used for prompt overides - // This gets more useful as there are more prompts to override - let userArgs = {} + // // Variable to hold the user args as an object that can be used for prompt overides + // // This gets more useful as there are more prompts to override + // let userArgs = {} - // Handle if typescript is selected via --ts - if (typescript === true) { - Object.assign(userArgs, { typescript: true }) - } - // Handle if typescript is skipped via --no-ts - if (typescript === false) { - Object.assign(userArgs, { typescript: false }) - } + // // Handle if typescript is selected via --ts + // if (typescript === true) { + // Object.assign(userArgs, { typescript: true }) + // } + // // Handle if typescript is skipped via --no-ts + // if (typescript === false) { + // Object.assign(userArgs, { typescript: false }) + // } // Check Node/Yarn/Engines Compatability // This checks all engine requirements, including Node.js and Yarn @@ -128,97 +127,97 @@ import { name, version } from '../package' 'Tutorial - Chapter 1 - Prerequisites', 'https://redwoodjs.com/docs/tutorial/chapter1/prerequisites' ) - let hasPassedEngineCheck = null - let engineErrorLog = [] - - await new Listr( - [ - { - title: 'Checking node and yarn compatibility', - skip: () => { - if (yarnInstall === false) { - return 'Warning: skipping check on request' - } - }, - task: () => { - return new Promise((resolve) => { - const { engines } = require(path.join(templateDir, 'package.json')) - - // this checks all engine requirements, including Node.js and Yarn - checkNodeVersion(engines, (_error, result) => { - if (result.isSatisfied) { - hasPassedEngineCheck = true - return resolve() - } - - const logStatements = Object.keys(result.versions) - .filter((name) => !result.versions[name].isSatisfied) - .map((name) => { - const { version, wanted } = result.versions[name] - return style.error( - `${name} ${wanted} required, but you have ${version}` - ) - }) - engineErrorLog = [...logStatements] - hasPassedEngineCheck = false - return resolve() - }) - }) - }, - }, - ], - { rendererOptions: { clearOutput: true } } - ).run() - - // Show a success message if required engines are present - if (hasPassedEngineCheck === true) { - console.log(style.success(`✔️ Compatability checks passed.`)) - } - - // Show an error and prompt if failed engines - if (hasPassedEngineCheck === false) { - console.log(style.error(`✖️ Compatability checks failed.`)) - console.log(`${engineErrorLog.join('\n')}`) - console.log( - style.error( - `\nThis might make your RedwoodJS project incompatible with some deploy targets.` - ) - ) - console.log(style.header(`\nRelated documentation:`)) - console.log(style.warning(`${engineErrorDocsLink}\n`)) - const response = await prompts({ - type: 'select', - name: 'override-engine-error', - message: 'How would you like to proceed?', - choices: [ - { title: 'Override error and continue install', value: true }, - { title: 'Quit install', value: false }, - ], - initial: 0, - }) - if (response['override-engine-error'] === false) { - process.exit(1) - } - } - - // User prompts - // See https://github.com/terkelg/prompts - const questions = [ - { - type: 'confirm', - name: 'typescript', - message: 'Use TypeScript?', - initial: true, - active: 'Yes', - inactive: 'No', - }, - ] - - // Override prompts based on initial args from user - prompts.override(userArgs) - - // Get the answers from the user - const answers = await prompts(questions) + // let hasPassedEngineCheck = null + // let engineErrorLog = [] + + // await new Listr( + // [ + // { + // title: 'Checking node and yarn compatibility', + // skip: () => { + // if (yarnInstall === false) { + // return 'Warning: skipping check on request' + // } + // }, + // task: () => { + // return new Promise((resolve) => { + // const { engines } = require(path.join(templateDir, 'package.json')) + + // // this checks all engine requirements, including Node.js and Yarn + // checkNodeVersion(engines, (_error, result) => { + // if (result.isSatisfied) { + // hasPassedEngineCheck = true + // return resolve() + // } + + // const logStatements = Object.keys(result.versions) + // .filter((name) => !result.versions[name].isSatisfied) + // .map((name) => { + // const { version, wanted } = result.versions[name] + // return style.error( + // `${name} ${wanted} required, but you have ${version}` + // ) + // }) + // engineErrorLog = [...logStatements] + // hasPassedEngineCheck = false + // return resolve() + // }) + // }) + // }, + // }, + // ], + // { rendererOptions: { clearOutput: true } } + // ).run() + + // // Show a success message if required engines are present + // if (hasPassedEngineCheck === true) { + // console.log(style.success(`✔️ Compatability checks passed.`)) + // } + + // // Show an error and prompt if failed engines + // if (hasPassedEngineCheck === false) { + // console.log(style.error(`✖️ Compatability checks failed.`)) + // console.log(`${engineErrorLog.join('\n')}`) + // console.log( + // style.error( + // `\nThis might make your RedwoodJS project incompatible with some deploy targets.` + // ) + // ) + // console.log(style.header(`\nRelated documentation:`)) + // console.log(style.warning(`${engineErrorDocsLink}\n`)) + // const response = await prompts({ + // type: 'select', + // name: 'override-engine-error', + // message: 'How would you like to proceed?', + // choices: [ + // { title: 'Override error and continue install', value: true }, + // { title: 'Quit install', value: false }, + // ], + // initial: 0, + // }) + // if (response['override-engine-error'] === false) { + // process.exit(1) + // } + // } + + // // User prompts + // // See https://github.com/terkelg/prompts + // const questions = [ + // { + // type: 'confirm', + // name: 'typescript', + // message: 'Use TypeScript?', + // initial: true, + // active: 'Yes', + // inactive: 'No', + // }, + // ] + + // // Override prompts based on initial args from user + // prompts.override(userArgs) + + // // Get the answers from the user + // const answers = await prompts(questions) // Get the directory for installation from the args const targetDir = String(args).replace(/,/g, '-') @@ -362,6 +361,56 @@ import { name, version } from '../package' new Listr( [ + { + title: 'Checking node and yarn compatibility', + skip: () => { + if (yarnInstall === false) { + return 'Warning: skipping check on request' + } + }, + task: () => { + return new Promise((resolve) => { + const { engines } = require(path.join(templateDir, 'package.json')) + + // this checks all engine requirements, including Node.js and Yarn + checkNodeVersion(engines, (_error, result) => { + if (result.isSatisfied) { + return resolve() + } + if (!result.isSatisfied) { + console.log('Failed') + return resolve() + } + }) + }) + }, + }, + { + title: 'Checking installation preferences', + task: async (ctx, task) => + task.newListr([ + { + title: 'Language preference', + skip: () => typescript !== null, + task: async (ctx, task) => { + ctx.useTs = await task.prompt({ + type: 'Select', + name: 'language', + choices: ['TypeScript', 'JavaScript'], + message: 'Select your preferred coding language', + initial: 'TypeScript', + }) + if (ctx.useTs === 'TypeScript') { + task.output = 'TypeScript selected' + } + if (ctx.useTs === 'JavaScript') { + task.output = 'JavaScript selected' + } + }, + options: { persistentOutput: true }, + }, + ]), + }, { title: 'Creating Redwood app', task: () => new Listr(createProjectTasks({ newAppDir, overwrite })), @@ -374,9 +423,8 @@ import { name, version } from '../package' title: 'Convert TypeScript files to JavaScript', // Enabled if user selects no to typescript prompt // Enabled if user specified --no-ts via command line - enabled: () => - yarnInstall === true && - (typescript === false || answers.typescript === false), + enabled: (ctx) => + yarnInstall === true && (typescript === false || ctx.useTs === false), task: () => { return execa('yarn rw ts-to-js', { shell: true, @@ -395,7 +443,11 @@ import { name, version } from '../package' }, }, ], - { rendererOptions: { collapse: false }, exitOnError: true } + { + rendererOptions: { collapse: false }, + exitOnError: true, + concurrent: false, + } ) .run() .then(() => { diff --git a/yarn.lock b/yarn.lock index 519b0e9a67cc..3da76d0204fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13602,11 +13602,11 @@ __metadata: chalk: 4.1.2 check-node-version: 4.2.1 core-js: 3.25.5 + enquirer: 2.3.6 execa: 5.1.1 fs-extra: 10.1.0 jest: 29.1.2 listr2: 5.0.5 - prompts: 2.4.2 terminal-link: 2.1.1 typescript: 4.7.4 yargs: 17.5.1 From 45593ef281c20c1c0b1d1495600981c92df2ceca Mon Sep 17 00:00:00 2001 From: ehowey Date: Sat, 15 Oct 2022 10:53:38 -0600 Subject: [PATCH 06/11] Complete engine checks --- .../src/create-redwood-app.js | 196 +++++++----------- 1 file changed, 70 insertions(+), 126 deletions(-) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 6c67dd392868..9db713ed5e81 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -11,6 +11,7 @@ import path from 'path' import chalk from 'chalk' import checkNodeVersion from 'check-node-version' +import { prompt } from 'enquirer' import execa from 'execa' import fs from 'fs-extra' import { Listr } from 'listr2' @@ -61,10 +62,6 @@ import { name, version } from '../package' )}` ) - // Template dir for Redwood files - // Needed higher up for engine checks - const templateDir = path.resolve(__dirname, '../template') - // Extract the args as provided by the user in the command line const { _: args, @@ -108,117 +105,6 @@ import { name, version } from '../package' .version(version) .parse() - // // Variable to hold the user args as an object that can be used for prompt overides - // // This gets more useful as there are more prompts to override - // let userArgs = {} - - // // Handle if typescript is selected via --ts - // if (typescript === true) { - // Object.assign(userArgs, { typescript: true }) - // } - // // Handle if typescript is skipped via --no-ts - // if (typescript === false) { - // Object.assign(userArgs, { typescript: false }) - // } - - // Check Node/Yarn/Engines Compatability - // This checks all engine requirements, including Node.js and Yarn - const engineErrorDocsLink = terminalLink( - 'Tutorial - Chapter 1 - Prerequisites', - 'https://redwoodjs.com/docs/tutorial/chapter1/prerequisites' - ) - // let hasPassedEngineCheck = null - // let engineErrorLog = [] - - // await new Listr( - // [ - // { - // title: 'Checking node and yarn compatibility', - // skip: () => { - // if (yarnInstall === false) { - // return 'Warning: skipping check on request' - // } - // }, - // task: () => { - // return new Promise((resolve) => { - // const { engines } = require(path.join(templateDir, 'package.json')) - - // // this checks all engine requirements, including Node.js and Yarn - // checkNodeVersion(engines, (_error, result) => { - // if (result.isSatisfied) { - // hasPassedEngineCheck = true - // return resolve() - // } - - // const logStatements = Object.keys(result.versions) - // .filter((name) => !result.versions[name].isSatisfied) - // .map((name) => { - // const { version, wanted } = result.versions[name] - // return style.error( - // `${name} ${wanted} required, but you have ${version}` - // ) - // }) - // engineErrorLog = [...logStatements] - // hasPassedEngineCheck = false - // return resolve() - // }) - // }) - // }, - // }, - // ], - // { rendererOptions: { clearOutput: true } } - // ).run() - - // // Show a success message if required engines are present - // if (hasPassedEngineCheck === true) { - // console.log(style.success(`✔️ Compatability checks passed.`)) - // } - - // // Show an error and prompt if failed engines - // if (hasPassedEngineCheck === false) { - // console.log(style.error(`✖️ Compatability checks failed.`)) - // console.log(`${engineErrorLog.join('\n')}`) - // console.log( - // style.error( - // `\nThis might make your RedwoodJS project incompatible with some deploy targets.` - // ) - // ) - // console.log(style.header(`\nRelated documentation:`)) - // console.log(style.warning(`${engineErrorDocsLink}\n`)) - // const response = await prompts({ - // type: 'select', - // name: 'override-engine-error', - // message: 'How would you like to proceed?', - // choices: [ - // { title: 'Override error and continue install', value: true }, - // { title: 'Quit install', value: false }, - // ], - // initial: 0, - // }) - // if (response['override-engine-error'] === false) { - // process.exit(1) - // } - // } - - // // User prompts - // // See https://github.com/terkelg/prompts - // const questions = [ - // { - // type: 'confirm', - // name: 'typescript', - // message: 'Use TypeScript?', - // initial: true, - // active: 'Yes', - // inactive: 'No', - // }, - // ] - - // // Override prompts based on initial args from user - // prompts.override(userArgs) - - // // Get the answers from the user - // const answers = await prompts(questions) - // Get the directory for installation from the args const targetDir = String(args).replace(/,/g, '-') @@ -242,6 +128,7 @@ import { name, version } from '../package' const newAppDir = path.resolve(process.cwd(), targetDir) const appDirExists = fs.existsSync(newAppDir) + const templateDir = path.resolve(__dirname, '../template') const createProjectTasks = ({ newAppDir, overwrite }) => { return [ @@ -359,7 +246,18 @@ import { name, version } from '../package' const startTime = Date.now() - new Listr( + // Engine check Listr. Seperate Listr to avoid https://github.com/cenk1cenk2/listr2/issues/296 + // Boolean flag + let hasPassedEngineCheck = null + // Array of strings + let engineErrorLog = [] + // Docs link for engine errors + const engineErrorDocsLink = terminalLink( + 'Tutorial - Prerequisites', + 'https://redwoodjs.com/docs/tutorial/chapter1/prerequisites' + ) + + await new Listr( [ { title: 'Checking node and yarn compatibility', @@ -375,35 +273,80 @@ import { name, version } from '../package' // this checks all engine requirements, including Node.js and Yarn checkNodeVersion(engines, (_error, result) => { if (result.isSatisfied) { + hasPassedEngineCheck = true return resolve() } - if (!result.isSatisfied) { - console.log('Failed') - return resolve() - } + const logStatements = Object.keys(result.versions) + .filter((name) => !result.versions[name].isSatisfied) + .map((name) => { + const { version, wanted } = result.versions[name] + return style.error( + `${name} ${wanted} required, but you have ${version}` + ) + }) + engineErrorLog = logStatements + hasPassedEngineCheck = false + return resolve() }) }) }, }, + ], + { rendererOptions: { clearOutput: true } } + ).run() + + // Show a success message if required engines are present + if (hasPassedEngineCheck === true) { + console.log(style.success(`✔️ Compatability checks passed.`)) + } + + // Show an error and prompt if failed engines check + if (hasPassedEngineCheck === false) { + console.log(style.error(`✖️ Compatability checks failed.`)) + console.log(`${engineErrorLog.join('\n')}`) + console.log( + style.error( + `\nThis might make your RedwoodJS project incompatible with some deploy targets.` + ) + ) + console.log(style.header(`\nRelated documentation:`)) + console.log(style.warning(`${engineErrorDocsLink}\n`)) + const response = await prompt({ + type: 'select', + name: 'override-engine-error', + message: 'How would you like to proceed?', + choices: [ + { title: 'Override error and continue install', value: true }, + { title: 'Quit install', value: false }, + ], + initial: 0, + }) + if (response['override-engine-error'] === false) { + process.exit(1) + } + } + + // Main install Listr + new Listr( + [ { - title: 'Checking installation preferences', + title: 'Configuring installation preferences', task: async (ctx, task) => task.newListr([ { title: 'Language preference', skip: () => typescript !== null, task: async (ctx, task) => { - ctx.useTs = await task.prompt({ + ctx.language = await task.prompt({ type: 'Select', - name: 'language', choices: ['TypeScript', 'JavaScript'], message: 'Select your preferred coding language', initial: 'TypeScript', }) - if (ctx.useTs === 'TypeScript') { + if (ctx.language === 'TypeScript') { task.output = 'TypeScript selected' } - if (ctx.useTs === 'JavaScript') { + if (ctx.language === 'JavaScript') { task.output = 'JavaScript selected' } }, @@ -424,7 +367,8 @@ import { name, version } from '../package' // Enabled if user selects no to typescript prompt // Enabled if user specified --no-ts via command line enabled: (ctx) => - yarnInstall === true && (typescript === false || ctx.useTs === false), + yarnInstall === true && + (typescript === false || ctx.language === 'JavaScript'), task: () => { return execa('yarn rw ts-to-js', { shell: true, From 715885b8095650eac20a593105336fcf4759d460 Mon Sep 17 00:00:00 2001 From: ehowey Date: Mon, 24 Oct 2022 21:05:09 -0600 Subject: [PATCH 07/11] Typo, concurrent, simpler output --- packages/create-redwood-app/src/create-redwood-app.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 9db713ed5e81..3084e6b71fba 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -246,7 +246,7 @@ import { name, version } from '../package' const startTime = Date.now() - // Engine check Listr. Seperate Listr to avoid https://github.com/cenk1cenk2/listr2/issues/296 + // Engine check Listr. Separate Listr to avoid https://github.com/cenk1cenk2/listr2/issues/296 // Boolean flag let hasPassedEngineCheck = null // Array of strings @@ -343,12 +343,7 @@ import { name, version } from '../package' message: 'Select your preferred coding language', initial: 'TypeScript', }) - if (ctx.language === 'TypeScript') { - task.output = 'TypeScript selected' - } - if (ctx.language === 'JavaScript') { - task.output = 'JavaScript selected' - } + task.output = ctx.language }, options: { persistentOutput: true }, }, @@ -390,7 +385,6 @@ import { name, version } from '../package' { rendererOptions: { collapse: false }, exitOnError: true, - concurrent: false, } ) .run() From e7cb72141bd609e0da9c25261a155d7317a3abaf Mon Sep 17 00:00:00 2001 From: ehowey Date: Tue, 25 Oct 2022 20:38:48 -0600 Subject: [PATCH 08/11] Fix broken quit process, add quit install message --- .../create-redwood-app/src/create-redwood-app.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 3084e6b71fba..2cca2c793e38 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -316,12 +316,20 @@ import { name, version } from '../package' name: 'override-engine-error', message: 'How would you like to proceed?', choices: [ - { title: 'Override error and continue install', value: true }, - { title: 'Quit install', value: false }, + // See https://github.com/enquirer/enquirer#defining-choices + // Does not seem to be working properly with the values as strings or booleans + // Possibly an upstream problem in Listr2 + // { name: 'Override error and continue install', value: 'true' }, + // { name: 'Quit install', value: 'false' }, + 'Override error and continue install', + 'Quit install', ], initial: 0, }) - if (response['override-engine-error'] === false) { + // TODO improve this logic if bug above can be fixed + // if (response['override-engine-error'] === false) + if (response['override-engine-error'] === 'Quit install') { + console.log(style.warning(`\nInstallation process ended.\n`)) process.exit(1) } } From a591b09b3488692ea04367318488b946c61448ae Mon Sep 17 00:00:00 2001 From: ehowey Date: Thu, 27 Oct 2022 21:01:11 -0600 Subject: [PATCH 09/11] Remove ToDo, update code comments --- .../create-redwood-app/src/create-redwood-app.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 2cca2c793e38..2cece4a8db81 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -311,23 +311,15 @@ import { name, version } from '../package' ) console.log(style.header(`\nRelated documentation:`)) console.log(style.warning(`${engineErrorDocsLink}\n`)) + // Prompt user for how to proceed const response = await prompt({ type: 'select', name: 'override-engine-error', message: 'How would you like to proceed?', - choices: [ - // See https://github.com/enquirer/enquirer#defining-choices - // Does not seem to be working properly with the values as strings or booleans - // Possibly an upstream problem in Listr2 - // { name: 'Override error and continue install', value: 'true' }, - // { name: 'Quit install', value: 'false' }, - 'Override error and continue install', - 'Quit install', - ], + choices: ['Override error and continue install', 'Quit install'], initial: 0, }) - // TODO improve this logic if bug above can be fixed - // if (response['override-engine-error'] === false) + // Quit the install if user selects this option, otherwise it will proceed if (response['override-engine-error'] === 'Quit install') { console.log(style.warning(`\nInstallation process ended.\n`)) process.exit(1) From 3b1bf340957b0095ea935d2b1e586ccfd8ff5c68 Mon Sep 17 00:00:00 2001 From: ehowey Date: Fri, 4 Nov 2022 21:10:47 -0600 Subject: [PATCH 10/11] Make suggested visual changes --- .../src/create-redwood-app.js | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index 2cece4a8db81..aa5dfb18318f 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -14,7 +14,7 @@ import checkNodeVersion from 'check-node-version' import { prompt } from 'enquirer' import execa from 'execa' import fs from 'fs-extra' -import { Listr } from 'listr2' +import { Listr, figures } from 'listr2' import terminalLink from 'terminal-link' import { hideBin } from 'yargs/helpers' import yargs from 'yargs/yargs' @@ -280,9 +280,7 @@ import { name, version } from '../package' .filter((name) => !result.versions[name].isSatisfied) .map((name) => { const { version, wanted } = result.versions[name] - return style.error( - `${name} ${wanted} required, but you have ${version}` - ) + return `${name} ${wanted} required, but you have ${version}` }) engineErrorLog = logStatements hasPassedEngineCheck = false @@ -297,20 +295,21 @@ import { name, version } from '../package' // Show a success message if required engines are present if (hasPassedEngineCheck === true) { - console.log(style.success(`✔️ Compatability checks passed.`)) + console.log(`${style.success(figures.tick)} Compatibility checks passed`) } // Show an error and prompt if failed engines check if (hasPassedEngineCheck === false) { - console.log(style.error(`✖️ Compatability checks failed.`)) - console.log(`${engineErrorLog.join('\n')}`) + console.log(`${style.error(figures.cross)} Compatibility checks failed`) console.log( - style.error( - `\nThis might make your RedwoodJS project incompatible with some deploy targets.` - ) + [ + ` ${style.warning(figures.warning)} ${engineErrorLog.join('\n')}`, + '', + ` This may make your project incompatible with some deploy targets.`, + ` See: ${engineErrorDocsLink}`, + '', + ].join('\n') ) - console.log(style.header(`\nRelated documentation:`)) - console.log(style.warning(`${engineErrorDocsLink}\n`)) // Prompt user for how to proceed const response = await prompt({ type: 'select', @@ -318,10 +317,10 @@ import { name, version } from '../package' message: 'How would you like to proceed?', choices: ['Override error and continue install', 'Quit install'], initial: 0, + onCancel: () => process.exit(1), }) // Quit the install if user selects this option, otherwise it will proceed if (response['override-engine-error'] === 'Quit install') { - console.log(style.warning(`\nInstallation process ended.\n`)) process.exit(1) } } From d0e4505bd817a7ca0c36a4a7d501dd73b0d011c9 Mon Sep 17 00:00:00 2001 From: ehowey Date: Fri, 4 Nov 2022 21:15:09 -0600 Subject: [PATCH 11/11] Collapse Listr --- .../src/create-redwood-app.js | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/packages/create-redwood-app/src/create-redwood-app.js b/packages/create-redwood-app/src/create-redwood-app.js index aa5dfb18318f..56327be9216e 100644 --- a/packages/create-redwood-app/src/create-redwood-app.js +++ b/packages/create-redwood-app/src/create-redwood-app.js @@ -329,24 +329,21 @@ import { name, version } from '../package' new Listr( [ { - title: 'Configuring installation preferences', - task: async (ctx, task) => - task.newListr([ - { - title: 'Language preference', - skip: () => typescript !== null, - task: async (ctx, task) => { - ctx.language = await task.prompt({ - type: 'Select', - choices: ['TypeScript', 'JavaScript'], - message: 'Select your preferred coding language', - initial: 'TypeScript', - }) - task.output = ctx.language - }, - options: { persistentOutput: true }, - }, - ]), + title: 'Language preference', + skip: () => typescript !== null, + task: async (ctx, task) => { + ctx.language = await task.prompt({ + type: 'Select', + choices: ['TypeScript', 'JavaScript'], + message: 'Select your preferred coding language', + initial: 'TypeScript', + }) + + task.output = ctx.language + }, + options: { + persistentOutput: true, + }, }, { title: 'Creating Redwood app',