Skip to content

Commit

Permalink
refactor: improve error message when executing assembler command with…
Browse files Browse the repository at this point in the history
…out installing assembler
  • Loading branch information
thetutlage committed Feb 26, 2020
1 parent 68751f0 commit 7d614f1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Ignitor/Ace/CoreCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ export class CoreCommands {
*/
public static commandsList = Object.keys(CoreCommands.getManifestJSON())

/**
* A local list of assembler commands. We need this, so that when assembler
* is not installed (probably in production) and someone is trying to
* build the project by running `serve` or `build`, we should give
* them a better descriptive error.
*
* Also, do note that at times this list will be stale, but we get it back
* in sync over time.
*/
public static localCommandsList = [
'build',
'serve',
'invoke',
]

/**
* Returns assembler manifest file for showing help
*/
Expand Down
12 changes: 12 additions & 0 deletions src/Ignitor/Ace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ export class Ace {
return
}

/**
* Trying to run an assembler command without installing assembler
*/
if (
CoreCommands.commandsList.length === 0 &&
CoreCommands.localCommandsList.includes(argv[0])
) {
throw new AceRuntimeException(
`Make sure to install "@adonisjs/assembler" before running "${argv[0]}" command`
)
}

/**
* Passing manifest json of core commands and generate manifest, so that
* we can append in the help output
Expand Down

0 comments on commit 7d614f1

Please sign in to comment.