Skip to content

Commit

Permalink
start without config file, improve error messaging on faulty config
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Aug 5, 2024
1 parent ce81284 commit c3c6533
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
8 changes: 7 additions & 1 deletion packages/core/src/build/hook/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import join from "@rcompat/fs/join";
import exclude from "@rcompat/object/exclude";
import stringify from "@rcompat/object/stringify";
import manifest from "@rcompat/package/manifest";
import root from "@rcompat/package/root";
import copy_includes from "./copy_includes.js";
import $router from "./router.js";

Expand Down Expand Up @@ -163,7 +164,12 @@ const post = async (app, mode, target) => {
await write_bootstrap(build_number, app, mode);

// copy config file
await app.root.join(config_filename).copy(app.path.build.join(config_filename));
const local_config = app.root.join(config_filename);
const build_config = app.path.build.join(config_filename);
const root_base = await root(import.meta.url);
const default_config = root_base.join("/src/private/config.js");
(await local_config.exists() ? local_config : default_config)
.copy(build_config);

const manifest_data = await manifest();
// create package.json
Expand Down
21 changes: 15 additions & 6 deletions packages/core/src/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,27 @@ import platform from "@rcompat/platform";
import app from "./app.js";
import { build, init } from "./hook/exports.js";

const empty_config = config => config === undefined || empty(config);

const get_config = async project_root => {
const local_config = project_root.join(config_filename);
return await local_config.exists()
? tryreturn(async _ => {
const exists = await local_config.exists()
if (exists) {
try {
const imported = await local_config.import("default");

empty(imported) && empty_config_file(local_config);
empty_config(imported) && empty_config_file(local_config);

return imported;
}).orelse(({ message }) =>
error_in_config_file(message, `${platform} ${local_config}`))
: config;
} catch (error) {
if (error.level === undefined) {
error_in_config_file(error.message, `${platform} ${local_config}`);
} else {
throw error;
}
}
}
return config;
};

export default async (mode, target) => tryreturn(async _ => {
Expand Down

0 comments on commit c3c6533

Please sign in to comment.