Skip to content

Commit

Permalink
Add option to provide start port for proxy, make errors clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
abmaonline committed May 16, 2018
1 parent 8983be4 commit 1c50000
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# aemfed changelog

## 0.0.4

* Update BrowserSync to fix issue with reloading all css [#1505](https://github.com/BrowserSync/browser-sync/issues/1505). It introduces a problem with Firefix and the web console however.
* Add option to specify start port for BrowserSync proxy, so it is easier to run multiple versions at the same time

## 0.0.3

* Fix exception when specific files or a directory were removed
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"aemsync": "abmaonline/aemsync#338c091",
"browser-sync": "^2.24.4",
"chalk": "^2.4.1",
"decode-html": "^2.0.0",
"graceful-fs": "^4.1.9",
"less-tree": "abmaonline/less-tree#6168498",
"minimist": "^1.2.0",
Expand Down
27 changes: 18 additions & 9 deletions src/bs-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { StyleTrees } from "./style-trees";
export interface IWrapperConfig {
bsOptions: browserSync.Options;
jcrContentRoots: string[];
proxyPort: number;
servers: string[];
dumpLibsPath?: string;
}
Expand Down Expand Up @@ -37,7 +38,6 @@ interface ITracerSettings {
}

const instances: { [key: string]: Instance } = {};
const port = 3000; // TODO make configurable

let styleTrees: StyleTrees;
let config: IWrapperConfig;
Expand Down Expand Up @@ -303,7 +303,7 @@ export function create(args: IWrapperConfig): Promise<void> {
clientlibTree: new ClientlibTree({ name, server }),
name,
online: true,
port: port + index * 2, // Claim numbers for proxy and ui
port: args.proxyPort + index * 2, // Claim numbers for proxy and ui
server
};
instances[host] = instance;
Expand All @@ -320,21 +320,30 @@ export function create(args: IWrapperConfig): Promise<void> {
promisesState.push(
setSlingTracerSettings(instance)
.then(sameInstance => {
const tracerEnabled =
instance.aemSettings.tracer &&
instance.aemSettings.tracer.enabled &&
instance.aemSettings.tracer.servletEnabled;
if (!tracerEnabled) {
if (instance.aemSettings.tracer) {
const tracerEnabled =
instance.aemSettings.tracer.enabled &&
instance.aemSettings.tracer.servletEnabled;
if (!tracerEnabled) {
console.log(
chalk`[{blue ${
instance.name
}}] {cyan Apache Sling Log Tracer is not enabled, so errors from compiling and minifying Less and Javascript by AEM cannot be shown. To enable it, go to [{yellow /system/console/configMgr}], search for 'Apache Sling Log Tracer' and turn on both 'Enabled' and 'Recording Servlet Enabled}'.`
);
}
} else {
console.log(
chalk`[{blue ${
instance.name
}}] {cyan Apache Sling Log Tracer is not enabled, so errors from compiling and minifying Less and Javascript by AEM cannot be shown. To enable it, go to [{yellow /system/console/configMgr}], search for 'Apache Sling Log Tracer' and turn on both 'Enabled' and 'Recording Servlet Enabled}'.`
}}] {cyan Apache Sling Log Tracer config was not found, so probably not supported in this version of AEM}.`
);
}
})
.catch(err => {
console.error(
chalk`[{blue ${instance.name}}] Something went wrong:`,
chalk`[{blue ${
instance.name
}}] [{red ERROR}] Something went wrong:`,
err
);
})
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Pipeline, Watcher } from "aemsync";
import chalk from "chalk";
import decode from "decode-html";
import gfs from "graceful-fs";
import minimist from "minimist";
import opn from "opn";
Expand All @@ -15,6 +16,7 @@ function separate() {
const MSG_HELP = `Usage: aemfed [OPTIONS]
Options:
-t targets Default is http://admin:admin@localhost:4502
-p proxy_port Default is 3000
-w path_to_watch Default is current
-e exclude_filter Anymatch exclude filter; disabled by default
-i sync_interval Update interval in milliseconds; default is 100
Expand All @@ -32,7 +34,9 @@ function reloadBrowser(
if (!error) {
bsWrapper.reload(host, inputList);
} else {
console.error(host + ": Error when pushing pack: ", error);
console.error(
chalk`[{blue ${host}}] [{red Error}] when pushing pack: ${decode(error)}`
);
}
}

Expand Down Expand Up @@ -71,14 +75,16 @@ export function init(): void {

// TODO make some sort of defaults file and get defaults from there (and use in all modules)
const targets: string = args.t || "http://admin:admin@localhost:4502";
const pushInterval: number = args.i || 100;
const proxyPort: number = parseInt(args.p, 10) || 3000;
const pushInterval: number = parseInt(args.i, 10) || 100;
const exclude: string = args.e || "";
const startPage: string = args.o || "false";
const startBrowser: string = args.browser || "google chrome";

separate();
console.log("Working dirs:", workingDirs);
console.log("Targets:", targets);
console.log("Proxy port:", proxyPort);
console.log("Interval:", pushInterval);
console.log("Exclude:", exclude);
separate();
Expand Down Expand Up @@ -116,6 +122,7 @@ export function init(): void {
]
},
jcrContentRoots: workingDirs,
proxyPort,
servers: targetList
});

Expand Down
1 change: 1 addition & 0 deletions src/types/decode-html.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function decode(html: string): string;

0 comments on commit 1c50000

Please sign in to comment.