Skip to content

Commit eaf7fe1

Browse files
authored
Merge pull request #9 from SoCreate/master
merge
2 parents f9b7ce8 + 7336e23 commit eaf7fe1

11 files changed

+336
-121
lines changed

CHANGELOG.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,54 @@
1+
<a name="3.0.0"></a>
2+
3+
# 3.0.0 (2017-12-01)
4+
5+
### Features
6+
* **cli:** Added a boat-load of new CLI configuration options. Every option available
7+
in the `angular-playground.json` file is now also available as a CLI argument
8+
(except @angular/cli arguments). [Read more about it in our docs](http://angularplayground.it/docs/api/configuration).
9+
([9dc1066](https://github.com/SoCreate/angular-playground/commit/9dc1066))
10+
* **new docs:** Speaking of docs, check out our newly-designed
11+
[docs page](http://angularplayground.it/docs/getting-started/introduction).
12+
* **new error checking utility:** A new CLI option has been introduced that will run and visit
13+
all sandbox scenarios in headless chrome, surfacing any errors that appear in the
14+
console. [Never forget to mock a dependency again!](http://angularplayground.it/docs/how-to/run-the-test-suite)
15+
([6074586](https://github.com/SoCreate/angular-playground/commit/6074586))
16+
* **report formats for builds:** Used in conjunction with the checking utility, you can now
17+
generate a JSON report that your build system can read for error reporting. Read all
18+
about it [here](http://angularplayground.it/docs/api/reporter-formats).
19+
([7e0f5a8](https://github.com/SoCreate/angular-playground/commit/7e0f5a8))
20+
21+
* **command bar shows all components as default:** Got the Playground running but don't know where
22+
to begin? We'll help you out by showing all of your available scenarios.
23+
([51680fd](https://github.com/SoCreate/angular-playground/commit/51680fd)
24+
25+
### Breaking Changes
26+
* **no default configuration argument**: The CLI no longer supports a default configuration file argument.
27+
**Note:** `angular-playground` with no arguments will still default to using the
28+
`angular-playground.json` file as expected.
29+
([9dc1066](https://github.com/SoCreate/angular-playground/commit/9dc1066))
30+
31+
Before:
32+
```
33+
angular-playground my-configuration-file.json
34+
```
35+
After:
36+
```
37+
angular-playground --config my-configuration-file.json
38+
```
39+
40+
* **new cli argument style**: CLI arguments now match typical npm style: `--argument` for full name, `-A` for abbreviation.
41+
42+
Before:
43+
```
44+
-no-watch -no-serve
45+
```
46+
47+
After:
48+
```
49+
--no-watch --no-serve
50+
```
51+
152
<a name="2.3.0"></a>
253
# 2.3.0 (2017-11-13)
354

package-lock.json

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-playground",
3-
"version": "2.3.0",
3+
"version": "3.0.0",
44
"description": "A drop in app module for working on Angular components in isolation (aka Scenario Driven Development).",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -45,7 +45,10 @@
4545
"zone.js": ">=0.8.14"
4646
},
4747
"dependencies": {
48-
"node-watch": "^0.4.1"
48+
"async": "^2.6.0",
49+
"node-watch": "^0.4.1",
50+
"ts-node": "^3.3.0",
51+
"puppeteer": "^0.13.0"
4952
},
5053
"devDependencies": {
5154
"@angular/common": "^5.0.0",
@@ -63,9 +66,7 @@
6366
"glob": "^7.1.2",
6467
"gulp": "^3.9.1",
6568
"gulp-inline-ng2-template": "^4.0.0",
66-
"puppeteer": "^0.13.0",
6769
"rxjs": "^5.5.2",
68-
"ts-node": "^3.3.0",
6970
"tslint": "5.3.2",
7071
"typescript": "2.4.2",
7172
"zone.js": "0.8.4"

src/cli/cli.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { startWatch } from './start-watch';
55
import { runAngularCli } from './run-angular-cli';
66
import { Configuration } from './shared/configuration';
77
import { verifySandboxes } from './verify-sandboxes';
8+
import { findFirstFreePort } from './shared/find-port';
89

910
(async () => {
1011
await run();
@@ -13,28 +14,36 @@ import { verifySandboxes } from './verify-sandboxes';
1314
async function run() {
1415
const rawArgs = process.argv.slice(2);
1516
const config = new Configuration(rawArgs);
17+
let sandboxPort, playgroundConfig;
1618

17-
let configFile = path.resolve(config.configFilePath);
18-
let playgroundConfig;
19+
let configFile = path.resolve(config.flags.config.value);
1920
try {
2021
playgroundConfig = require(configFile.replace(/.json$/, ''));
2122
} catch (e) {
2223
process.stdout.write(`[angular-playground]: \x1b[31mFailed to load config file ${configFile}\x1b[0m\n`);
2324
process.exit(1);
2425
}
2526

27+
// Parity between command line arguments and configuration file
28+
config.applyConfigurationFile(playgroundConfig);
2629
const sandboxesPath = await build(playgroundConfig.sourceRoot);
27-
config.port = playgroundConfig.angularCli.port ? playgroundConfig.angularCli.port : 4201;
2830

29-
if (config.runWatch) {
30-
startWatch(playgroundConfig, () => build(playgroundConfig.sourceRoot));
31+
if (config.flags.checkErrors.value) {
32+
// get port dynamically
33+
const port = await findFirstFreePort('127.0.0.1', 7000, 9000);
34+
sandboxPort = port;
35+
config.flags.angularCli.port.value = port;
3136
}
3237

33-
if (config.runAngularCliServe && playgroundConfig.angularCli) {
34-
runAngularCli(playgroundConfig.angularCli);
38+
if (!config.flags.noWatch.value) {
39+
startWatch(config.flags.sourceRoot.value, () => build(config.flags.sourceRoot.value));
3540
}
3641

37-
if (config.runCheckErrors) {
38-
verifySandboxes(config, sandboxesPath);
42+
if (!config.flags.noServe.value && playgroundConfig.angularCli) {
43+
runAngularCli(config, playgroundConfig.angularCli);
44+
}
45+
46+
if (config.flags.checkErrors.value) {
47+
verifySandboxes(config, sandboxesPath, sandboxPort);
3948
}
4049
}

src/cli/reporters/json-reporter.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class JSONStats {
2+
suites = 1;
3+
passes: number;
4+
pending = 0;
5+
duration = 0;
6+
time = 0;
7+
8+
constructor(
9+
public tests: number,
10+
public failures: number,
11+
public start = 0,
12+
public end = 0
13+
) {
14+
this.passes = this.tests - this.failures;
15+
}
16+
17+
}
18+
19+
export class JSONReporter {
20+
constructor (
21+
public errors: any[],
22+
public scenarioNames: string[]
23+
) {}
24+
25+
getJson() {
26+
return JSON.stringify({
27+
stats: new JSONStats(this.scenarioNames.length, this.errors.length),
28+
failures: this.errors.map(failure => {
29+
if (!failure) return;
30+
return {
31+
title: failure.scenario,
32+
err: {
33+
message: failure.descriptions[0]
34+
}
35+
};
36+
}),
37+
passes: this.scenarioNames.map(pass => {
38+
return { title: pass };
39+
}),
40+
skips: []
41+
}, null, 2);
42+
}
43+
}

src/cli/run-angular-cli.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1+
import { Configuration } from './shared/configuration';
2+
13
const fs = require('fs');
24
const path = require('path');
35
const childProcess = require('child_process');
46

5-
export const runAngularCli = (angularCliConfig) => {
6-
let port = angularCliConfig.port ? angularCliConfig.port : 4201;
7-
let cliName = '@angular/cli';
8-
try {
9-
fs.accessSync(path.resolve('node_modules/@angular/cli/bin/ng'));
10-
} catch (e) {
11-
cliName = 'angular-cl';
12-
}
13-
let cliPath = `node_modules/${cliName}/bin/ng`;
14-
let args = [cliPath, 'serve', '-no-progress'];
7+
export const runAngularCli = (config: Configuration, angularCliConfig: any) => {
8+
const cliConfig = config.flags.angularCli;
9+
let args = [cliConfig.cmdPath.value, 'serve', '-no-progress'];
1510
args.push('--port');
16-
args.push(port.toString());
17-
if (angularCliConfig.appName) {
18-
args.push(`-a=${angularCliConfig.appName}`);
11+
args.push(cliConfig.port.value.toString());
12+
if (cliConfig.appName.value) {
13+
args.push(`-a=${cliConfig.appName.value}`);
1914
}
20-
if (angularCliConfig.environment) {
21-
args.push(`-e=${angularCliConfig.environment}`);
15+
if (cliConfig.environment.value) {
16+
args.push(`-e=${cliConfig.environment.value}`);
2217
}
2318
if (angularCliConfig.args) {
2419
args = args.concat(angularCliConfig.args);

0 commit comments

Comments
 (0)