Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow no config #61

Merged
merged 2 commits into from
Apr 5, 2021
Merged

Allow no config #61

merged 2 commits into from
Apr 5, 2021

Conversation

drwpow
Copy link
Member

@drwpow drwpow commented Apr 5, 2021

Changes

I wanted to set up more Astro projects without needing a astro.config.mjs, so I added basic defaults and very simple config validation.

Testing

  • Tests are passing
  • Tests updated where necessary

Docs

  • Docs / READMEs updated
  • Code comments added where helpful

No docs changes (I think)

@drwpow drwpow requested a review from matthewp April 5, 2021 21:07
if (!config.projectRoot) config.projectRoot = '.';
if (!config.astroRoot) config.astroRoot = './astro';
if (!config.dist) config.dist = './_site';
if (!config.public) config.public = './public';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kinda dumb; can be improved. I just didn‘t want to add deepmerge just yet as that can blow away user settings if not configured properly

projectRoot: '.',
astroRoot: './astro',
dist: './_site',
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only deleted tests that had stock configurations; left other tests‘ configs that expanded on these

'.jsx': 'react'
}
};
```
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added first pass at config docs

@@ -50,7 +72,7 @@ If you‘ve used [Svelte][svelte]’s styles before, Astro works almost the same
<div class="scoped">I’m a scoped style</div>
```

#### Sass
#### 👓 Sass
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m 13 and need emojis on things apparently

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ✨ LOVE IT ✨

const astroConfig = await loadConfig(rawRoot);
return cmd(astroConfig);
} catch (err) {
console.error(colors.red(err.toString() || err));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err.toString() || err might be a crutch; I just do this out of habit whenever a stack trace is 100% not helpful and I want to hide it. Config validation is one such case

const type = (thing: any): string => (Array.isArray(thing) ? 'Array' : typeof thing);

/** Throws error if a user provided an invalid config. Manually-implemented to avoid a heavy validation library. */
function validateConfig(config: any): void {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsonschema is nice but I only just now realized how heavy it is 🙃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our jsonschema object always gets out of date in Snowpack, I wish TS had a better idea of runtime type checking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran across Runtypes not too long ago. It‘s trying to be essentially a runtime for TS types. Could be something we look into, but it‘s about the same weight as jsonschema/probably has the same issues of keeping it updated.

Copy link
Contributor

@matthewp matthewp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@drwpow drwpow merged commit 1acd5ee into main Apr 5, 2021
@drwpow drwpow deleted the no-config branch April 5, 2021 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants