Skip to content

Commit

Permalink
refactor: replace Promises with async/await in stencil-start
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGenash committed Sep 21, 2020
1 parent d2c259b commit 9492a42
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions bin/stencil-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ try {
}

let browserSyncPort = dotStencilFile.port;
let stencilServerPort = ++dotStencilFile.port;
++dotStencilFile.port;
if (!(dotStencilFile.normalStoreUrl) || !(dotStencilFile.customLayouts)) {
console.error(
'Error: Your stencil config is outdated. Please run'.red +
Expand All @@ -84,16 +84,19 @@ if (!(dotStencilFile.normalStoreUrl) || !(dotStencilFile.customLayouts)) {
process.exit(2);
}

runAPICheck(dotStencilFile, PACKAGE_INFO.version)
.then(storeInfoFromAPI => {
run();

async function run () {
try {
const storeInfoFromAPI = await runAPICheck(dotStencilFile, PACKAGE_INFO.version);
dotStencilFile.storeUrl = storeInfoFromAPI.sslUrl;
dotStencilFile.normalStoreUrl = storeInfoFromAPI.baseUrl;
dotStencilFile.stencilServerPort = stencilServerPort;
})
.then(() => {
startServer();
})
.catch(err => console.error(err.message));

await startServer();
} catch (err) {
console.error(err.message);
}
}

/**
*
Expand Down Expand Up @@ -227,7 +230,7 @@ async function startServer() {
ignoreInitial: true,
ignored: watchIgnored.map(val => Path.join(THEME_PATH, val)),
},
proxy: "localhost:" + stencilServerPort,
proxy: "localhost:" + dotStencilFile.port,
tunnel,
});

Expand Down
2 changes: 1 addition & 1 deletion server/plugins/renderer/renderer.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ internals.getPencilResponse = function (data, request, response, configuration)
data.context.settings.theme_version_id = utils.int2uuid(1);
data.context.settings.theme_config_id = utils.int2uuid(request.app.themeConfig.variationIndex + 1);
data.context.settings.theme_session_id = null;
data.context.settings.maintenance = {secure_path: `http://localhost:${internals.options.stencilServerPort}`};
data.context.settings.maintenance = { secure_path: `http://localhost:${internals.options.port}` };

return new responses.PencilResponse({
template_file: internals.getTemplatePath(request.path, data),
Expand Down

0 comments on commit 9492a42

Please sign in to comment.