Skip to content

Commit

Permalink
core: approve await (lavas-project#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
xtx1130 authored and easonyq committed Apr 29, 2018
1 parent dd98993 commit 98a83b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 6 additions & 6 deletions packages/lavas-core-vue/core/builder/base-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import template from 'lodash.template';
import {readFile, pathExists} from 'fs-extra';
import {readFile, pathExistsSync} from 'fs-extra';
import {join, basename, normalize} from 'path';

import HtmlWebpackPlugin from 'html-webpack-plugin';
Expand Down Expand Up @@ -118,7 +118,7 @@ export default class BaseBuilder {

async writeMiddleware() {
const middlewareTemplate = this.templatesPath('middleware.tmpl');
let isEmpty = !(await pathExists(join(this.config.globals.rootDir, 'middlewares')));
let isEmpty = !(pathExistsSync(join(this.config.globals.rootDir, 'middlewares')));

await this.writeFileToLavasDir(
'middleware.js',
Expand All @@ -130,7 +130,7 @@ export default class BaseBuilder {

async writeStore() {
const storeTemplate = this.templatesPath('store.tmpl');
let isEmpty = !(await pathExists(join(this.config.globals.rootDir, 'store')));
let isEmpty = !(pathExistsSync(join(this.config.globals.rootDir, 'store')));

await this.writeFileToLavasDir(
STORE_FILE,
Expand Down Expand Up @@ -173,12 +173,12 @@ export default class BaseBuilder {

// find core/spa.html.tmpl
templatePath = join(rootDir, `core/${SPA_TEMPLATE_HTML}`);
if (!await pathExists(templatePath)) {
if (!pathExistsSync(templatePath)) {
// find core/index.html.tmpl
templatePath = join(rootDir, `core/${TEMPLATE_HTML}`);
}

if (!await pathExists(templatePath)) {
if (!pathExistsSync(templatePath)) {
throw new Error(`${SPA_TEMPLATE_HTML} or ${TEMPLATE_HTML} required`);
}

Expand Down Expand Up @@ -320,7 +320,7 @@ export default class BaseBuilder {
resolveAliasPath(alias, currentRoute.componentPath)
];
for (let j = 0; j < resolvedPaths.length; j++) {
if (await pathExists(resolvedPaths[j])) {
if (pathExistsSync(resolvedPaths[j])) {
// in Windows, normalize will replace posix.sep`/` with win32.sep`\\`
currentRoute.componentPath = normalize(resolvedPaths[j])
.replace(/\\/g, '\\\\'); // escape backslash before writing to skeleton template
Expand Down
8 changes: 5 additions & 3 deletions packages/lavas-core-vue/core/builder/prod-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ export default class ProdBuilder extends BaseBuilder {
Logger.info('build', 'compiling routes completed.', true);

Logger.info('build', 'start writing files to /.lavas...', true);
await this.writeRuntimeConfig();
await this.writeMiddleware();
await this.writeStore();
await Promise.all([
this.writeRuntimeConfig(),
this.writeMiddleware(),
this.writeStore()
])
Logger.info('build', 'writing files to /.lavas completed', true);

// SSR build process
Expand Down

0 comments on commit 98a83b6

Please sign in to comment.