Skip to content

Commit

Permalink
Merge cb4fe04 into 0854baf
Browse files Browse the repository at this point in the history
  • Loading branch information
homer0 committed Aug 26, 2019
2 parents 0854baf + cb4fe04 commit 1f60684
Show file tree
Hide file tree
Showing 24 changed files with 1,569 additions and 669 deletions.
17 changes: 15 additions & 2 deletions documents/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ You can run this commands with either [yarn](https://yarnpkg.com), [npx](https:/
It builds a target and moves it bundle to the distribution directory.

```bash
projext build [target] [--type [type]] [--watch] [--run] [--inspect]
projext build [target] [--type [type]] [--watch] [--run] [--inspect] [--analyze]
```
- **target:** The name of the target you intend to build. If no target is specified, projext will try to use the default target (the one with the project's name or the first on an alphabetical list).
- **type:** Which build type: `development` (default) or `production`.
- **watch:** Watch the target files and update the build. If the target type is Node and it doesn't require bundling nor transpiling, it won't do anything.
- **run:** Run the target after the build is completed. It only works when the build type is `development`.
- **inspect:** Enable the Node inspector. It only works with the `run` flag and if the target type is `node`.
- **analyze:** Enable the bundle analyzer of the build engine. It only works on browser targets o Node targets with `bundle` set to `true`.
### Watching a target
Expand Down Expand Up @@ -54,6 +55,18 @@ projext inspect [target]
> This is basically an alias of `projext build` that uses the `--run` and `--inspect` flags by default.
### Analyzing a target bundle
This is for bundled targets, it tells the build engine to use the analyzer and show the stats for the generated bundle.
```bash
projext analyze [target] [--type [type]]
```
- **target:** The name of the target you intend to analyze. If no target is specified, projext will try to use the default target (the one with the project's name or the first on an alphabetical list).
- **type:** Which build type: `development` (default) or `production`.
> This is basically an alias of `projext build` that uses the `--analyze` flag by default.
### Cleaning previous builds
Removes the files from previous builds from the distribution directory.
Expand Down Expand Up @@ -111,4 +124,4 @@ Resources:
- `config`: Writes a configuration file with your target information.
- `html`: Writes a browser target default HTML file.
For more information about the generators, please check the Zero configuration document.
For more information about the generators, please check the Zero configuration document.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"name": "projext",
"description": "Bundle and run your javascript project without configuring an specific module bundler.",
"homepage": "https://homer0.github.io/projext/",
"version": "7.0.1",
"version": "7.1.0",
"repository": "homer0/projext",
"author": "Leonardo Apiwan (@homer0) <me@homer0.com>",
"license": "MIT",
"dependencies": {
"wootils": "^2.6.3",
"wootils": "^2.6.5",
"jimple": "^1.5.0",
"fs-extra": "^8.1.0",
"extend": "^3.0.2",
"del": "^5.0.0",
"del": "^5.1.0",
"shelljs": "0.8.3",
"glob": "^7.1.4",
"commander": "^3.0.0",
Expand All @@ -29,22 +29,22 @@
"watchpack": "^1.6.0",
"nodemon": "^1.19.1",
"prompt": "^1.0.0",
"dotenv": "^8.0.0",
"dotenv": "^8.1.0",
"dotenv-expand": "^5.1.0"
},
"devDependencies": {
"eslint": "^6.1.0",
"eslint": "^6.2.2",
"eslint-plugin-homer0": "^2.0.0",
"jest-ex": "^6.1.1",
"jest-cli": "^24.8.0",
"jest-cli": "^24.9.0",
"jasmine-expect": "^4.0.3",
"minimatch": "^3.0.4",
"esdoc": "^1.1.0",
"esdoc-standard-plugin": "^1.0.0",
"esdoc-node": "^1.0.4",
"leasot": "^8.0.0",
"coveralls": "^3.0.6",
"husky": "^3.0.3"
"husky": "^3.0.4"
},
"engine-strict": true,
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/abstracts/cliCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class CLICommand {
* @abstract
*/
handle() {
throw new Error('This method must to be overwritten');
throw new Error('This method must be overwritten');
}
/**
* A simple wrapper for a `console.log`. Outputs a variable to the CLI interface.
Expand Down
9 changes: 9 additions & 0 deletions src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const {

const {
cli,
cliAnalyzeCommand,
cliBuildCommand,
cliCleanCommand,
cliCopyProjectFilesCommand,
Expand All @@ -48,13 +49,15 @@ const {
cliInspectCommand,
cliRevisionCommand,
cliRunCommand,
cliSHAnalyzeCommand,
cliSHBuildCommand,
cliSHCopyCommand,
cliSHInspectCommand,
cliSHNodeRunCommand,
cliSHNodeWatchCommand,
cliSHRunCommand,
cliSHTranspileCommand,
cliSHValidateAnalyzeCommand,
cliSHValidateBuildCommand,
cliSHValidateInspectCommand,
cliSHValidateRunCommand,
Expand Down Expand Up @@ -122,6 +125,7 @@ class Projext extends Jimple {
this.register(builder);

this.register(cli);
this.register(cliAnalyzeCommand);
this.register(cliBuildCommand);
this.register(cliCleanCommand);
this.register(cliCopyProjectFilesCommand);
Expand All @@ -130,13 +134,15 @@ class Projext extends Jimple {
this.register(cliInspectCommand);
this.register(cliRevisionCommand);
this.register(cliRunCommand);
this.register(cliSHAnalyzeCommand);
this.register(cliSHBuildCommand);
this.register(cliSHCopyCommand);
this.register(cliSHInspectCommand);
this.register(cliSHNodeRunCommand);
this.register(cliSHNodeWatchCommand);
this.register(cliSHRunCommand);
this.register(cliSHTranspileCommand);
this.register(cliSHValidateAnalyzeCommand);
this.register(cliSHValidateBuildCommand);
this.register(cliSHValidateInspectCommand);
this.register(cliSHValidateRunCommand);
Expand Down Expand Up @@ -171,6 +177,7 @@ class Projext extends Jimple {
]);
// Start the CLI with the available commands.
this.get('cli').start([
this.get('cliAnalyzeCommand'),
this.get('cliBuildCommand'),
this.get('cliRunCommand'),
this.get('cliCleanCommand'),
Expand All @@ -179,13 +186,15 @@ class Projext extends Jimple {
this.get('cliInfoCommand'),
this.get('cliInspectCommand'),
this.get('cliRevisionCommand'),
this.get('cliSHAnalyzeCommand'),
this.get('cliSHBuildCommand'),
this.get('cliSHCopyCommand'),
this.get('cliSHInspectCommand'),
this.get('cliSHNodeRunCommand'),
this.get('cliSHNodeWatchCommand'),
this.get('cliSHRunCommand'),
this.get('cliSHTranspileCommand'),
this.get('cliSHValidateAnalyzeCommand'),
this.get('cliSHValidateBuildCommand'),
this.get('cliSHValidateInspectCommand'),
this.get('cliSHValidateRunCommand'),
Expand Down
2 changes: 1 addition & 1 deletion src/bin/projext
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if [ "$task" = "" ]; then
projext-cli --help
else
# ...otherwise, check if the task is a shell task that needs commands
if echo "$task" | grep -q "^\(build\|run\|watch\|inspect\)$"; then
if echo "$task" | grep -q "^\(build\|run\|watch\|inspect\|analyze\)$"; then
isSHTask=true
fi

Expand Down
8 changes: 6 additions & 2 deletions src/services/building/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@ class Builder {
* the build recreated when they changed.
* @param {boolean} [forceInspect=false] Whether or not the Node inspector should be enabled.
* Only valid for Node targets.
* @param {boolean} [forceAnalyze=false] Whether or not the target bundle should be analyzed.
* @return {string}
* @todo These parameters should be an object.
*/
getTargetBuildCommand(
target,
buildType,
forceRun = false,
forceWatch = false,
forceInspect = false
forceInspect = false,
forceAnalyze = false
) {
let command = '';
if (target.bundle !== false) {
Expand All @@ -79,7 +82,8 @@ class Builder {
buildType,
forceRun,
forceWatch,
forceInspect
forceInspect,
forceAnalyze
);
}

Expand Down
55 changes: 55 additions & 0 deletions src/services/cli/cliAnalyze.js
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,
};
6 changes: 6 additions & 0 deletions src/services/cli/cliBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class CLIBuildCommand extends CLICommand {
'Enables the Node inspector. It only works with Node targets',
false
);
this.addOption(
'analyze',
'-a, --analyze',
'Enables the bundle analyzer. It only works with targets with bundling',
false
);
/**
* Enable unknown options so other services can customize the build command.
* @type {boolean}
Expand Down
102 changes: 102 additions & 0 deletions src/services/cli/cliSHAnalyze.js
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,
};

0 comments on commit 1f60684

Please sign in to comment.