Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/browser-sync/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/dist/*
/dist_backup/*
/dist2/*
meta1.json
meta2.json
36 changes: 36 additions & 0 deletions packages/browser-sync/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { writeFileSync } = require("fs");
const out1 = require("esbuild").buildSync({
entryPoints: ["./dist/index.js"],
bundle: true,
platform: "node",
packages: "external",
outfile: "dist2/index.js",
sourcemap: "inline",
metafile: true
});

writeFileSync("meta1.json", JSON.stringify(out1.metafile));

const out2 = require("esbuild").buildSync({
entryPoints: ["./dist/bin.js"],
bundle: true,
platform: "node",
packages: "external",
outfile: "dist2/bin.js",
sourcemap: "inline",
metafile: true
});

writeFileSync("meta2.json", JSON.stringify(out2.metafile));

// require("esbuild").buildSync({
// entryPoints: ["./lodash.custom.js"],
// bundle: true,
// platform: "node",
// format: "esm",
// packages: "external",
// outfile: "lib/underbar.js",
// banner: {
// js: "// @ts-nocheck"
// }
// });
56 changes: 18 additions & 38 deletions packages/browser-sync/lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Immutable = require("immutable");
var utils = require("./utils");
var pluginUtils = require("./plugins");
var connectUtils = require("./connect-utils");
var chalk = require("chalk");
var chalk = require("chalk");

module.exports = {
/**
Expand Down Expand Up @@ -63,24 +63,19 @@ module.exports = {
socketPort = bs.options.getIn(["socket", "port"]);
}

utils.getPort(
bs.options.get("listen", "localhost"),
socketPort,
null,
function(err, port) {
if (err) {
return utils.fail(true, err, bs.cb);
}
done(null, {
optionsIn: [
{
path: ["socket", "port"],
value: port
}
]
});
utils.getPort(bs.options.get("listen", "localhost"), socketPort, null, function(err, port) {
if (err) {
return utils.fail(true, err, bs.cb);
}
);
done(null, {
optionsIn: [
{
path: ["socket", "port"],
value: port
}
]
});
});
},
/**
* Some features require an internet connection.
Expand All @@ -91,10 +86,7 @@ module.exports = {
* @param {Function} done
*/
getOnlineStatus: function(bs, done) {
if (
_.isUndefined(bs.options.get("online")) &&
_.isUndefined(process.env.TESTING)
) {
if (_.isUndefined(bs.options.get("online")) && _.isUndefined(process.env.TESTING)) {
require("dns").resolve("www.google.com", function(err) {
var online = false;
if (err) {
Expand All @@ -103,10 +95,7 @@ module.exports = {
chalk.magenta("online: false")
);
} else {
bs.debug(
"Resolved www.google.com, setting %s",
chalk.magenta("online: true")
);
bs.debug("Resolved www.google.com, setting %s", chalk.magenta("online: true"));
online = true;
}
done(null, {
Expand Down Expand Up @@ -158,9 +147,7 @@ module.exports = {
snippet: connectUtils.enabled(bs.options)
? connectUtils.scriptTags(bs.options)
: false,
scriptPaths: Immutable.fromJS(
connectUtils.clientScript(bs.options, true)
),
scriptPaths: Immutable.fromJS(connectUtils.clientScript(bs.options, true)),
files: bs.pluginManager.hook(
"files:watch",
bs.options.get("files"),
Expand Down Expand Up @@ -195,10 +182,7 @@ module.exports = {
mergeMiddlewares: function(bs, done) {
done(null, {
options: {
middleware: bs.pluginManager.hook(
"server:middleware",
bs.options.get("middleware")
)
middleware: bs.pluginManager.hook("server:middleware", bs.options.get("middleware"))
}
});
},
Expand Down Expand Up @@ -289,11 +273,7 @@ module.exports = {
) {
uiOpts = bs.options
.get("ui")
.mergeDeep(
Immutable.fromJS(
bs.pluginManager.pluginOptions[PLUGIN_NAME]
)
);
.mergeDeep(Immutable.fromJS(bs.pluginManager.pluginOptions[PLUGIN_NAME]));
}

/**
Expand Down
17 changes: 6 additions & 11 deletions packages/browser-sync/lib/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const startOpts = require("../cli-options/opts.start.json");
const reloadOpts = require("../cli-options/opts.reload.json");
const recipeOpts = require("../cli-options/opts.recipe.json");
const chalk = require("chalk");
const chalk = require("chalk");
const pkg = require("../package.json");
import * as utils from "./utils";
import { resolve } from "path";
Expand Down Expand Up @@ -38,7 +38,7 @@ if (!module.parent) {
}

function freshYargs() {
return require("yargs")(process.argv.slice(2));
return require("yargs")(process.argv.slice(2));
}

function runFromCli() {
Expand Down Expand Up @@ -132,9 +132,7 @@ function handleNoCommand(argv, input, yargs) {
.filter(item => item.isUrl === false)
.map(item => item.resolved);

const urls = withoutErrors
.filter(item => item.isUrl === true)
.map(item => item.userInput);
const urls = withoutErrors.filter(item => item.isUrl === true).map(item => item.userInput);

/**
* If a URL was given, switch to proxy mode and use
Expand Down Expand Up @@ -183,8 +181,7 @@ function processStart(yargs) {
.options(startOpts)
.example("$0 start -s app", "- Use the App directory to serve files")
.example("$0 start -p www.bbc.co.uk", "- Proxy an existing website")
.default("cwd", () => process.cwd())
.argv;
.default("cwd", () => process.cwd()).argv;
}

/**
Expand All @@ -210,17 +207,15 @@ function handleIncoming(command, yargs) {
.options(reloadOpts)
.example("$0 reload")
.example("$0 reload --port 4000")
.default("cwd", () => process.cwd())
.argv;
.default("cwd", () => process.cwd()).argv;
}
if (command === "recipe") {
out = yargs
.usage("Usage: $0 recipe <recipe-name>")
.option(recipeOpts)
.example("$0 recipe ls", "list the recipes")
.example("$0 recipe gulp.sass", "use the gulp.sass recipe")
.default("cwd", () => process.cwd())
.argv;
.default("cwd", () => process.cwd()).argv;
}

if (out.help) {
Expand Down
8 changes: 2 additions & 6 deletions packages/browser-sync/lib/browser-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var config = require("./config");
var connectUtils = require("./connect-utils");
var utils = require("./utils");
var logger = require("./logger");
var chalk = require("chalk");
var chalk = require("chalk");

var eachSeries = utils.eachSeries;
var _ = require("./lodash.custom");
Expand Down Expand Up @@ -535,11 +535,7 @@ BrowserSync.prototype.setOptionIn = function(path, value, opts) {

opts = opts || {};

bs.debug(
"Setting Option: {cyan:%s} - {magenta:%s",
path.join("."),
value.toString()
);
bs.debug("Setting Option: {cyan:%s} - {magenta:%s", path.join("."), value.toString());
bs.options = bs.options.setIn(path, value);
if (!opts.silent) {
bs.events.emit("options:set", {
Expand Down
22 changes: 6 additions & 16 deletions packages/browser-sync/lib/cli/command.recipe.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
var logger = require("../logger").logger;
var chalk = require("chalk");
var chalk = require("chalk");

/**
* $ browser-sync recipe <name> <options>
Expand All @@ -22,7 +22,7 @@ module.exports = function(opts) {
var dirs = fs.readdirSync(path.join(dir, "recipes"));
logger.info(
"Install one of the following with %s\n",
chalk.cyan('browser-sync recipe <name>')
chalk.cyan("browser-sync recipe <name>")
);
dirs.forEach(function(name) {
console.log(" " + name);
Expand All @@ -42,15 +42,11 @@ module.exports = function(opts) {

input = input[0];
var flags = opts.cli.flags;
var output = flags.output
? path.resolve(flags.output)
: path.join(process.cwd(), input);
var output = flags.output ? path.resolve(flags.output) : path.join(process.cwd(), input);
var targetDir = path.join(dir, "recipes", input);

if (fs.existsSync(output)) {
return opts.cb(
new Error("Target folder exists remove it first and then try again")
);
return opts.cb(new Error("Target folder exists remove it first and then try again"));
}

if (fs.existsSync(targetDir)) {
Expand All @@ -59,18 +55,12 @@ module.exports = function(opts) {
opts.cb(err);
} else {
logger.info("Recipe copied into %s", chalk.cyan(output));
logger.info(
"Next, inside that folder, run %s",
chalk.cyan("npm i && npm start")
);
logger.info("Next, inside that folder, run %s", chalk.cyan("npm i && npm start"));
opts.cb(null);
}
});
} else {
logger.info(
"Recipe %s not found. The following are available though",
chalk.cyan(input)
);
logger.info("Recipe %s not found. The following are available though", chalk.cyan(input));
logRecipes();
opts.cb();
}
Expand Down
20 changes: 6 additions & 14 deletions packages/browser-sync/lib/cli/command.start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ export default function(opts) {
const conf = require(maybeconf);
input = _.merge({}, conf, flags);
} else {
utils.fail(
true,
new Error(`Configuration file '${flags.config}' not found`),
opts.cb
);
utils.fail(true, new Error(`Configuration file '${flags.config}' not found`), opts.cb);
}
} else {
if (existsSync(maybepkg)) {
Expand All @@ -52,11 +48,10 @@ export default function(opts) {
* @returns {*}
*/
function preprocessFlags(flags) {
return [
stripUndefined,
legacyFilesArgs,
removeWatchBooleanWhenFalse
].reduce((flags, fn) => fn.call(null, flags), flags);
return [stripUndefined, legacyFilesArgs, removeWatchBooleanWhenFalse].reduce(
(flags, fn) => fn.call(null, flags),
flags
);
}

/**
Expand All @@ -82,10 +77,7 @@ function stripUndefined(subject) {
*/
function legacyFilesArgs(flags) {
if (flags.files && flags.files.length) {
flags.files = flags.files.reduce(
(acc, item) => acc.concat(explodeFilesArg(item)),
[]
);
flags.files = flags.files.reduce((acc, item) => acc.concat(explodeFilesArg(item)), []);
}
return flags;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const defaultIgnorePatterns = [
".idea"
];

export function addDefaultIgnorePatterns(
incoming: BsTempOptions
): TransformResult {
export function addDefaultIgnorePatterns(incoming: BsTempOptions): TransformResult {
if (!incoming.get("watch")) {
return [incoming, []];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { BsTempOptions, TransformResult } from "../cli-options";

export function appendServerDirectoryOption(
incoming: BsTempOptions
): TransformResult {
export function appendServerDirectoryOption(incoming: BsTempOptions): TransformResult {
if (!incoming.get("server")) return [incoming, []];
if (incoming.get("directory")) {
return [
incoming.setIn(["server", "directory"], incoming.has("directory")),
[]
];
return [incoming.setIn(["server", "directory"], incoming.has("directory")), []];
}
return [incoming, []];
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { BsTempOptions, TransformResult } from "../cli-options";

export function appendServerIndexOption(
incoming: BsTempOptions
): TransformResult {
export function appendServerIndexOption(incoming: BsTempOptions): TransformResult {
if (!incoming.get("server")) return [incoming, []];
const value = incoming.get("index");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { List } from "immutable";
import { BsTempOptions, TransformResult } from "../cli-options";

export function copyCLIIgnoreToWatchOptions(
incoming: BsTempOptions
): TransformResult {
export function copyCLIIgnoreToWatchOptions(incoming: BsTempOptions): TransformResult {
if (!incoming.get("ignore")) {
return [incoming, []];
}
const output = incoming.updateIn(
["watchOptions", "ignored"],
List([]),
ignored => {
return List([]).concat(ignored, incoming.get("ignore"));
}
);
const output = incoming.updateIn(["watchOptions", "ignored"], List([]), ignored => {
return List([]).concat(ignored, incoming.get("ignore"));
});

return [output, []];
}
Loading