Skip to content

Commit

Permalink
fix: strf-8574, bump "hapi" and its modules to fix security issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGenash committed Aug 13, 2020
1 parent 7fcb7fa commit b520daa
Show file tree
Hide file tree
Showing 15 changed files with 1,117 additions and 1,677 deletions.
253 changes: 118 additions & 135 deletions bin/stencil-start
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
#!/usr/bin/env node

var Bs = require('browser-sync').create();
var Cycles = require('../lib/cycles');
var recursiveRead = require('recursive-readdir');
var Async = require('async');
var templateAssembler = require('../lib/template-assembler');
var Fs = require('fs');
var JspmAssembler = require('../lib/jspm-assembler');
var Path = require('path');
var Pkg = require('../package.json');
var Program = require('commander');
var Server = require('../server');
var ThemeConfig = require('../lib/theme-config');
var buildConfig = require('../lib/build-config');
var Url = require('url');
var Wreck = require('wreck');
var jsonLint = require('../lib/json-lint');
var versionCheck = require('../lib/version-check');
var themePath = process.cwd();
var browserSyncPort;
var templatePath = Path.join(themePath, 'templates');
var dotStencilFilePath = Path.join(themePath, '.stencil');
var themeConfigPath = Path.join(themePath, 'config.json');
var dotStencilFile;
var stencilServerPort;
var themeConfig;
var configuration;
var staplerUrl;
var headers;
let tunnel;
const Bs = require('browser-sync').create();
const Cycles = require('../lib/cycles');
const recursiveRead = require('recursive-readdir');
const Async = require('async');
const templateAssembler = require('../lib/template-assembler');
const Fs = require('fs');
const JspmAssembler = require('../lib/jspm-assembler');
const Path = require('path');
const Pkg = require('../package.json');
const Program = require('commander');
const Server = require('../server');
const ThemeConfig = require('../lib/theme-config');
const buildConfig = require('../lib/build-config');
const Url = require('url');
const Wreck = require('wreck');
const jsonLint = require('../lib/json-lint');
const versionCheck = require('../lib/version-check');
let themePath = process.cwd();
let templatePath = Path.join(themePath, 'templates');
let dotStencilFilePath = Path.join(themePath, '.stencil');
let themeConfigPath = Path.join(themePath, 'config.json');
require('colors');

Program
Expand Down Expand Up @@ -59,8 +51,7 @@ if (Program.variation === true) {
}

// Instantiate themeConfig
themeConfig = ThemeConfig.getInstance(themePath);

let themeConfig = ThemeConfig.getInstance(themePath);
if (Program.variation) {
try {
themeConfig.setVariationByName(Program.variation);
Expand All @@ -69,30 +60,27 @@ if (Program.variation) {
}
}

configuration = themeConfig.getConfig();

dotStencilFile = Fs.readFileSync(dotStencilFilePath, {encoding: 'utf-8'});

let configuration = themeConfig.getConfig();
let dotStencilFile = Fs.readFileSync(dotStencilFilePath, {encoding: 'utf-8'});
try {
dotStencilFile = jsonLint.parse(dotStencilFile, dotStencilFilePath);
} catch (e) {
return console.error(e.stack);
}

browserSyncPort = dotStencilFile.port;
stencilServerPort = ++dotStencilFile.port;

let browserSyncPort = dotStencilFile.port;
let stencilServerPort = ++dotStencilFile.port;
if (!(dotStencilFile.normalStoreUrl) || !(dotStencilFile.customLayouts)) {
return console.error(
'Error: Your stencil config is outdated. Please run'.red +
' $ stencil init'.cyan + ' again.'.red
);
}

headers = {
let staplerUrl;
const headers = {
'stencil-cli': Pkg.version,
};

if (dotStencilFile.staplerUrl) {
staplerUrl = dotStencilFile.staplerUrl;
headers['stencil-store-url'] = dotStencilFile.normalStoreUrl;
Expand All @@ -108,7 +96,7 @@ Wreck.get(
rejectUnauthorized: false,
},
function (err, res, payload) {
var bundleTask;
let bundleTask;

if (err || !payload) {
console.error(
Expand Down Expand Up @@ -147,116 +135,111 @@ Wreck.get(
/**
* Starts up the local Stencil Server as well as starts up BrowserSync and sets some watch options.
*/
function startServer() {
var params = {
async function startServer() {
await Server.create({
dotStencilFile: dotStencilFile,
variationIndex: themeConfig.variationIndex || 0,
useCache: Program.cache,
themePath: themePath,
};

Server(params, err => {
var watchFiles = [
'/assets',
'/templates',
'/lang',
'/.config'
];
var watchIgnored = [
'/assets/scss',
'/assets/css',
'/assets/jspm_packages',
];

if (err) {
throw err;
}
});

// Display Set up information
console.log(startUpInformation());
let watchFiles = [
'/assets',
'/templates',
'/lang',
'/.config'
];
let watchIgnored = [
'/assets/scss',
'/assets/css',
'/assets/jspm_packages',
];

// Display Set up information
console.log(getStartUpInfo());

// Watch sccs directory and automatically reload all css files if a file changes
Bs.watch(Path.join(themePath, 'assets/scss'), event => {
if (event === 'change') {
Bs.reload('*.css');
}
});

// Watch sccs directory and automatically reload all css files if a file changes
Bs.watch(Path.join(themePath, 'assets/scss'), event => {
if (event === 'change') {
Bs.reload('*.css');
Bs.watch('config.json', (event) => {
if (event === 'change') {
try {
configuration = themeConfig.getConfig();
} catch (e) {
return console.error(e);
}
});

Bs.watch('config.json', (event) => {
if (event === 'change') {
try {
configuration = themeConfig.getConfig();
} catch (e) {
return console.error(e);
}
Bs.reload();
}
});

Bs.reload();
}
});
Bs.watch('.config/storefront.json', (event, file) => {
if (event === 'change') {
console.log("storefront json changed");
Bs.emitter.emit("storefront_config_file:changed", {
event: event,
path: file,
namespace: ""
});
Bs.reload();
}
});

Bs.watch('.config/storefront.json', (event, file) => {
if (event === 'change') {
console.log("storefront json changed");
Bs.emitter.emit("storefront_config_file:changed", {
event: event,
path: file,
namespace: ""
});
Bs.reload();
Bs.watch(templatePath, {ignoreInitial: true}, () => {
assembleTemplates(templatePath, (err, results) => {
if (err) {
return console.error(err);
}
});

Bs.watch(templatePath, {ignoreInitial: true}, () => {
assembleTemplates(templatePath, (err, results) => {
if (err) {
return console.error(err);
}

try {
new Cycles(results).detect();
} catch (e) {
console.error(e);
}
})
});
try {
new Cycles(results).detect();
} catch (e) {
console.error(e);
}
})
});

if (buildConfig.watchOptions && buildConfig.watchOptions.files) {
watchFiles = buildConfig.watchOptions.files;
}
if (buildConfig.watchOptions && buildConfig.watchOptions.files) {
watchFiles = buildConfig.watchOptions.files;
}

if (buildConfig.watchOptions && buildConfig.watchOptions.ignored) {
watchIgnored = buildConfig.watchOptions.ignored;
}
if (buildConfig.watchOptions && buildConfig.watchOptions.ignored) {
watchIgnored = buildConfig.watchOptions.ignored;
}

// check for tunnel argument
if (typeof Program.tunnel === 'undefined') { tunnel = false; }
else if (Program.tunnel === true) { tunnel = true; }
else { tunnel = Program.tunnel; }

Bs.init({
open: !!Program.open,
port: browserSyncPort,
files: watchFiles.map(val => Path.join(themePath, val)),
watchOptions: {
ignoreInitial: true,
ignored: watchIgnored.map(val => Path.join(themePath, val)),
},
proxy: "localhost:" + stencilServerPort,
tunnel: tunnel,
});
const tunnel = typeof Program.tunnel === 'undefined'
? false
: Program.tunnel === true
? true
: Program.tunnel;

Bs.init({
open: !!Program.open,
port: browserSyncPort,
files: watchFiles.map(val => Path.join(themePath, val)),
watchOptions: {
ignoreInitial: true,
ignored: watchIgnored.map(val => Path.join(themePath, val)),
},
proxy: "localhost:" + stencilServerPort,
tunnel,
});

// Handle manual reloading of browsers by typing 'rs';
// Borrowed from https:/remy/nodemon
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', data => {
data = (data + '').trim().toLowerCase();
// Handle manual reloading of browsers by typing 'rs';
// Borrowed from https:/remy/nodemon
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', data => {
data = (data + '').trim().toLowerCase();

// if the keys entered match the restartable value, then restart!
if (data === 'rs') {
Bs.reload();
}
});
// if the keys entered match the restartable value, then restart!
if (data === 'rs') {
Bs.reload();
}
});

if (buildConfig.development) {
Expand Down Expand Up @@ -302,7 +285,7 @@ function fileExist(path) {
* Displays information about your environment and configuration.
* @return {string}
*/
function startUpInformation() {
function getStartUpInfo() {
let information = '\n';

information += '-----------------Startup Information-------------\n'.gray;
Expand Down
Loading

0 comments on commit b520daa

Please sign in to comment.