-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,569 additions
and
669 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { provider } = require('jimple'); | ||
const CLICommand = require('../../abstracts/cliCommand'); | ||
/** | ||
* This is a fake command the app uses to show the information of the analyze task. In reality, | ||
* this command is handled by a shell script. | ||
* @extends {CLICommand} | ||
*/ | ||
class CLIAnalyzeCommand extends CLICommand { | ||
/** | ||
* Class constructor. | ||
* @ignore | ||
*/ | ||
constructor() { | ||
super(); | ||
/** | ||
* The instruction needed to trigger the command. | ||
* @type {string} | ||
*/ | ||
this.command = 'analyze [target]'; | ||
/** | ||
* A description of the command for the help interface. | ||
* @type {string} | ||
*/ | ||
this.description = 'Build a target that can be bundled and open the bundle analyzer'; | ||
/** | ||
* Enable unknown options so other services can customize the run command. | ||
* @type {boolean} | ||
*/ | ||
this.allowUnknownOptions = true; | ||
this.addOption( | ||
'type', | ||
'-t, --type [type]', | ||
'Which build type: development (default) or production', | ||
'development' | ||
); | ||
} | ||
} | ||
/** | ||
* The service provider that once registered on the app container will set an instance of | ||
* `CLIAnalyzeCommand` as the `cliAnalyzeCommand` service. | ||
* @example | ||
* // Register it on the container | ||
* container.register(cliAnalyzeCommand); | ||
* // Getting access to the service instance | ||
* const cliAnalyzeCommand = container.get('cliAnalyzeCommand'); | ||
* @type {Provider} | ||
*/ | ||
const cliAnalyzeCommand = provider((app) => { | ||
app.set('cliAnalyzeCommand', () => new CLIAnalyzeCommand()); | ||
}); | ||
|
||
module.exports = { | ||
CLIAnalyzeCommand, | ||
cliAnalyzeCommand, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const { provider } = require('jimple'); | ||
const CLICommand = require('../../abstracts/cliCommand'); | ||
/** | ||
* This is the _'real analyze command'_. This is a private command the shell script executes in | ||
* order to get a list of commands it should execute. | ||
* @extends {CLICommand} | ||
*/ | ||
class CLISHAnalyzeCommand extends CLICommand { | ||
/** | ||
* Class constructor. | ||
* @param {CLIBuildCommand} cliBuildCommand The analyze command is actually an alias for the | ||
* build command with the `--analyze` flag set to true. | ||
* @param {Targets} targets To get the name of the default target if no other is | ||
* specified. | ||
*/ | ||
constructor(cliBuildCommand, targets) { | ||
super(); | ||
/** | ||
* A local reference for the `cliBuildCommand` service. | ||
* @type {CLIBuildCommand} | ||
*/ | ||
this.cliBuildCommand = cliBuildCommand; | ||
/** | ||
* A local reference for the `targets` service. | ||
* @type {Targets} | ||
*/ | ||
this.targets = targets; | ||
/** | ||
* The instruction needed to trigger the command. | ||
* @type {string} | ||
*/ | ||
this.command = 'sh-analyze [target]'; | ||
/** | ||
* A description of the command, just to follow the interface as the command won't show up on | ||
* the help interface. | ||
* @type {string} | ||
*/ | ||
this.description = 'Get the build commands for the shell program to execute'; | ||
/** | ||
* Hide the command from the help interface. | ||
* @type {boolean} | ||
*/ | ||
this.hidden = true; | ||
/** | ||
* Enable unknown options so other services can customize the run command. | ||
* @type {boolean} | ||
*/ | ||
this.allowUnknownOptions = true; | ||
this.addOption( | ||
'type', | ||
'-t, --type [type]', | ||
'Which build type: development (default) or production', | ||
'development' | ||
); | ||
} | ||
/** | ||
* Handle the execution of the command and outputs the list of commands to run. | ||
* @param {?string} name The name of the target. | ||
* @param {Command} command The executed command (sent by `commander`). | ||
* @param {Object} options The command options. | ||
* @param {string} options.type The type of build. | ||
* @param {Object} unknownOptions A dictionary of extra options that command may have received. | ||
*/ | ||
handle(name, command, options, unknownOptions) { | ||
const target = name ? | ||
// If the target doesn't exist, this will throw an error. | ||
this.targets.getTarget(name) : | ||
// Get the default target or throw an error if the project doesn't have targets. | ||
this.targets.getDefaultTarget(); | ||
|
||
this.output(this.cliBuildCommand.generate(Object.assign( | ||
{}, | ||
unknownOptions, | ||
{ | ||
target: target.name, | ||
type: options.type, | ||
analyze: true, | ||
} | ||
))); | ||
} | ||
} | ||
/** | ||
* The service provider that once registered on the app container will set an instance of | ||
* `CLISHAnalyzeCommand` as the `cliSHAnalyzeCommand` service. | ||
* @example | ||
* // Register it on the container | ||
* container.register(cliSHAnalyzeCommand); | ||
* // Getting access to the service instance | ||
* const cliSHAnalyzeCommand = container.get('cliSHAnalyzeCommand'); | ||
* @type {Provider} | ||
*/ | ||
const cliSHAnalyzeCommand = provider((app) => { | ||
app.set('cliSHAnalyzeCommand', () => new CLISHAnalyzeCommand( | ||
app.get('cliBuildCommand'), | ||
app.get('targets') | ||
)); | ||
}); | ||
|
||
module.exports = { | ||
CLISHAnalyzeCommand, | ||
cliSHAnalyzeCommand, | ||
}; |
Oops, something went wrong.