Skip to content

Commit

Permalink
Merge branch 'main' into dsp-remove-experimental-setup-command
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidprice authored May 8, 2023
2 parents 3849d04 + 8d05dd1 commit e78b1d9
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 49 deletions.
13 changes: 6 additions & 7 deletions packages/create-redwood-app/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import fs from 'node:fs'

import * as esbuild from 'esbuild'

// There's minimal bundling going on here by design. Only "src/create-redwood-app.js" and "src/telemetry.js"
// are bundled into a single "dist/create-redwood-app.js" file.
// As we audit more of this package's dependencies, we'll remove them from a handcrafted "external" list,
// instead of using the catch-all `packages: 'external'` option.
const result = await esbuild.build({
entryPoints: ['src/create-redwood-app.js'],
outfile: 'dist/create-redwood-app.js',

bundle: true,
minify: true,

platform: 'node',
target: ['node18'],
// See https://esbuild.github.io/getting-started/#bundling-for-node.
packages: 'external',
outfile: 'dist/create-redwood-app.js',
minify: true,

logLevel: 'info',

// For visualizing the bundle.
// See https://esbuild.github.io/api/#metafile and https://esbuild.github.io/analyze/.
Expand Down
129 changes: 94 additions & 35 deletions packages/create-redwood-app/src/create-redwood-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const { telemetry } = Parser(hideBin(process.argv))

const tui = new RedwoodTUI()

async function executeCompatibilityCheck(templateDir, yarnInstall) {
async function executeCompatibilityCheck(templateDir) {
const tuiContent = new ReactiveTUIContent({
mode: 'text',
content: 'Checking node and yarn compatibility',
Expand All @@ -38,20 +38,6 @@ async function executeCompatibilityCheck(templateDir, yarnInstall) {
})
tui.startReactive(tuiContent)

if (!yarnInstall) {
tuiContent.update({
spinner: {
enabled: false,
},
content: `${RedwoodStyling.warning(
'⚠'
)} Skipped compatibility check because yarn install was skipped via command line flag`,
})
tui.stopReactive()

return
}

const [checksPassed, checksData] = await checkNodeAndYarnVersion(templateDir)

if (checksPassed) {
Expand Down Expand Up @@ -244,10 +230,6 @@ async function installNodeModules(newAppDir) {
const yarnInstallSubprocess = execa('yarn install', {
shell: true,
cwd: newAppDir,
// For yarn 3 users, so that esbuild's postinstall script doesn't fail.
env: {
YARN_NODE_LINKER: 'node-modules',
},
})

try {
Expand Down Expand Up @@ -322,7 +304,7 @@ async function generateTypes(newAppDir) {
tui.stopReactive()
}

async function initialiseGit(newAppDir) {
async function initialiseGit(newAppDir, commitMessage) {
const tuiContent = new ReactiveTUIContent({
mode: 'text',
content: 'Initialising a git repo',
Expand All @@ -333,7 +315,7 @@ async function initialiseGit(newAppDir) {
tui.startReactive(tuiContent)

const gitSubprocess = execa(
'git init && git add . && git commit -m "Initial commit"',
`git init && git add . && git commit -m "${commitMessage}"`,
{
shell: true,
cwd: newAppDir,
Expand All @@ -360,7 +342,9 @@ async function initialiseGit(newAppDir) {
}

tuiContent.update({
content: `${RedwoodStyling.green('✔')} Initialised a git repo`,
content: `${RedwoodStyling.green(
'✔'
)} Initialised a git repo with commit message "${commitMessage}"`,
spinner: {
enabled: false,
},
Expand Down Expand Up @@ -425,6 +409,58 @@ async function handleGitPreference(gitInitFlag) {
}
}

/**
* @param {string?} commitMessageFlag
*/
async function handleCommitMessagePreference(commitMessageFlag) {
// Handle case where flag is set
if (commitMessageFlag !== null) {
return commitMessageFlag
}

// Prompt user for preference
try {
const response = await tui.prompt({
type: 'input',
name: 'commitMessage',
message: 'Enter a commit message',
initial: 'Initial commit',
})
return response.commitMessage
} catch (_error) {
recordErrorViaTelemetry('User cancelled install at commit message prompt')
await shutdownTelemetry()
process.exit(1)
}
}

/**
* @param {boolean?} yarnInstallFlag
*/
async function handleYarnInstallPreference(yarnInstallFlag) {
// Handle case where flag is set
if (yarnInstallFlag !== null) {
return yarnInstallFlag
}

// Prompt user for preference
try {
const response = await tui.prompt({
type: 'Toggle',
name: 'yarnInstall',
message: 'Do you want to run yarn install?',
enabled: 'Yes',
disabled: 'no',
initial: 'Yes',
})
return response.yarnInstall
} catch (_error) {
recordErrorViaTelemetry('User cancelled install at yarn install prompt')
await shutdownTelemetry()
process.exit(1)
}
}

/**
* This function creates a new RedwoodJS app.
*
Expand All @@ -447,17 +483,18 @@ async function createRedwoodApp() {
// TODO: Make all flags have the 'flag' suffix
const {
_: args,
'yarn-install': yarnInstall,
'yarn-install': yarnInstallFlag,
typescript: typescriptFlag,
overwrite,
// telemetry, // Extracted above to check if telemetry is disabled before we even reach this point
'git-init': gitInitFlag,
'commit-message': commitMessageFlag,
} = yargs(hideBin(process.argv))
.scriptName(name)
.usage('Usage: $0 <project directory> [option]')
.example('$0 newapp')
.option('yarn-install', {
default: true,
default: null,
type: 'boolean',
describe:
'Skip yarn install with --no-yarn-install. Also skips version requirements check.',
Expand Down Expand Up @@ -485,11 +522,17 @@ async function createRedwoodApp() {
type: 'boolean',
describe: 'Initialize a git repository.',
})
.option('commit-message', {
alias: 'm',
default: null,
type: 'string',
describe: 'Commit message for the initial commit.',
})
.version(version)
.parse()

// Record some of the arguments for telemetry
trace.getActiveSpan()?.setAttribute('yarn-install', yarnInstall)
trace.getActiveSpan()?.setAttribute('yarn-install', yarnInstallFlag)
trace.getActiveSpan()?.setAttribute('overwrite', overwrite)

// Get the directory for installation from the args
Expand Down Expand Up @@ -520,7 +563,7 @@ async function createRedwoodApp() {
const templatesDir = path.resolve(__dirname, '../templates')

// Engine check
await executeCompatibilityCheck(path.join(templatesDir, 'ts'), yarnInstall)
await executeCompatibilityCheck(path.join(templatesDir, 'ts'))

// Determine ts/js preference
const useTypescript = await handleTypescriptPreference(typescriptFlag)
Expand All @@ -532,9 +575,22 @@ async function createRedwoodApp() {
const useGit = await handleGitPreference(gitInitFlag)
trace.getActiveSpan()?.setAttribute('git', useGit)

/** @type {string} */
let commitMessage
if (useGit) {
commitMessage = await handleCommitMessagePreference(commitMessageFlag)
}

const yarnInstall = await handleYarnInstallPreference(yarnInstallFlag)

// Create project files
await createProjectFiles(newAppDir, { templateDir, overwrite })

// Initialise git repo
if (useGit) {
await initialiseGit(newAppDir, commitMessage)
}

// Install the node packages
if (yarnInstall) {
const yarnInstallStart = Date.now()
Expand All @@ -555,11 +611,6 @@ async function createRedwoodApp() {
await generateTypes(newAppDir)
}

// Initialise git repo
if (useGit) {
await initialiseGit(newAppDir)
}

// Post install message
tui.drawText(
[
Expand Down Expand Up @@ -610,10 +661,18 @@ async function createRedwoodApp() {
'',
`${RedwoodStyling.header(`Fire it up!`)} 🚀`,
'',
`${RedwoodStyling.redwood(
` > ${RedwoodStyling.green(`cd ${targetDir}`)}`
)}`,
`${RedwoodStyling.redwood(` > ${RedwoodStyling.green(`yarn rw dev`)}`)}`,
...[
`${RedwoodStyling.redwood(
` > ${RedwoodStyling.green(`cd ${targetDir}`)}`
)}`,
!yarnInstall &&
`${RedwoodStyling.redwood(
` > ${RedwoodStyling.green(`yarn install`)}`
)}`,
`${RedwoodStyling.redwood(
` > ${RedwoodStyling.green(`yarn rw dev`)}`
)}`,
].filter(Boolean),
'',
].join('\n')
)
Expand Down
14 changes: 7 additions & 7 deletions packages/studio/frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ __metadata:
languageName: node
linkType: hard

"@graphiql/react@npm:^0.17.2, @graphiql/react@npm:^0.17.3":
"@graphiql/react@npm:^0.17.3":
version: 0.17.3
resolution: "@graphiql/react@npm:0.17.3"
dependencies:
Expand Down Expand Up @@ -1785,22 +1785,22 @@ __metadata:
linkType: hard

"graphiql@npm:^2.4.0":
version: 2.4.2
resolution: "graphiql@npm:2.4.2"
version: 2.4.3
resolution: "graphiql@npm:2.4.3"
dependencies:
"@graphiql/react": ^0.17.2
"@graphiql/react": ^0.17.3
"@graphiql/toolkit": ^0.8.4
graphql-language-service: ^5.1.4
graphql-language-service: ^5.1.5
markdown-it: ^12.2.0
peerDependencies:
graphql: ^15.5.0 || ^16.0.0
react: ^16.8.0 || ^17.0.0 || ^18.0.0
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
checksum: 8cdfe56ec3fd0e2389451e9da0dd94c643188d083bc0f6f01f39a5a5b85a23adae2105c14b4ca758633c091f82fb9432a4e213b27b4eabcad6f368480ed39ecf
checksum: 13f35f3468ad97f7e122538a4e726fc1a77d479bfe8cc03e3175301c5b9b49e12b3c4ca0245b8767f1b36fe2d5cbb84cfb514a51d290edbc8476968984b3bff7
languageName: node
linkType: hard

"graphql-language-service@npm:5.1.5, graphql-language-service@npm:^5.1.4, graphql-language-service@npm:^5.1.5":
"graphql-language-service@npm:5.1.5, graphql-language-service@npm:^5.1.5":
version: 5.1.5
resolution: "graphql-language-service@npm:5.1.5"
dependencies:
Expand Down

0 comments on commit e78b1d9

Please sign in to comment.