summaryrefslogtreecommitdiff
path: root/src/dev.ts
diff options
context:
space:
mode:
authorGravatar Drew Powers <1369770+drwpow@users.noreply.github.com> 2021-03-16 12:37:45 -0600
committerGravatar GitHub <noreply@github.com> 2021-03-16 12:37:45 -0600
commit8c45c4a8567e31a10ae954fa11a0f3f1f94fd89c (patch)
treee526f67e93ed5a7fcf9237c2d30ec536a4a96d7b /src/dev.ts
parent1f5c7c791fe3595f4c775192ffc6b6a15efb71a1 (diff)
downloadastro-8c45c4a8567e31a10ae954fa11a0f3f1f94fd89c.tar.gz
astro-8c45c4a8567e31a10ae954fa11a0f3f1f94fd89c.tar.zst
astro-8c45c4a8567e31a10ae954fa11a0f3f1f94fd89c.zip
Annoying Lint PR™ (#3)
* Add Prettier + ESLint * Format files
Diffstat (limited to 'src/dev.ts')
-rw-r--r--src/dev.ts61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/dev.ts b/src/dev.ts
index d7a4ec47f..49faafd40 100644
--- a/src/dev.ts
+++ b/src/dev.ts
@@ -11,15 +11,15 @@ const require = createRequire(import.meta.url);
const hostname = '127.0.0.1';
const port = 3000;
-export default async function(astroConfig: AstroConfig) {
+export default async function (astroConfig: AstroConfig) {
const { projectRoot, hmxRoot } = astroConfig;
const internalPath = new URL('./frontend/', import.meta.url);
const snowpackConfigPath = new URL('./snowpack.config.js', projectRoot);
-
+
// Workaround for SKY-251
- const hmxPlugOptions: {resolve?: (s: string) => string } = {};
- if(existsSync(new URL('./package-lock.json', projectRoot))) {
+ const hmxPlugOptions: { resolve?: (s: string) => string } = {};
+ if (existsSync(new URL('./package-lock.json', projectRoot))) {
const pkgLockStr = await readFile(new URL('./package-lock.json', projectRoot), 'utf-8');
const pkgLock = JSON.parse(pkgLockStr);
hmxPlugOptions.resolve = (pkgName: string) => {
@@ -27,36 +27,37 @@ export default async function(astroConfig: AstroConfig) {
return `/_snowpack/pkg/${pkgName}.v${ver}.js`;
};
}
-
- const snowpackConfig = await loadConfiguration({
- root: projectRoot.pathname,
- mount: {
- [hmxRoot.pathname]: '/_hmx',
- [internalPath.pathname]: '/__hmx_internal__'
- },
- plugins: [
- ['astro/snowpack-plugin', hmxPlugOptions]
- ],
- devOptions: {
- open: 'none',
- output: 'stream',
- port: 0
+
+ const snowpackConfig = await loadConfiguration(
+ {
+ root: projectRoot.pathname,
+ mount: {
+ [hmxRoot.pathname]: '/_hmx',
+ [internalPath.pathname]: '/__hmx_internal__',
+ },
+ plugins: [['astro/snowpack-plugin', hmxPlugOptions]],
+ devOptions: {
+ open: 'none',
+ output: 'stream',
+ port: 0,
+ },
+ packageOptions: {
+ knownEntrypoints: ['preact-render-to-string'],
+ external: ['@vue/server-renderer'],
+ },
},
- packageOptions: {
- knownEntrypoints: ['preact-render-to-string'],
- external: ['@vue/server-renderer']
- }
- }, snowpackConfigPath.pathname);
+ snowpackConfigPath.pathname
+ );
const snowpack = await startSnowpackServer({
config: snowpackConfig,
- lockfile: null
+ lockfile: null,
});
const runtime = snowpack.getServerRuntime();
const server = http.createServer(async (req, res) => {
- const fullurl = new URL(req.url || '/', 'https://example.org/');
+ const fullurl = new URL(req.url || '/', 'https://example.org/');
const reqPath = decodeURI(fullurl.pathname);
- const selectedPage = (reqPath.substr(1) || 'index');
+ const selectedPage = reqPath.substr(1) || 'index';
console.log(reqPath, selectedPage);
const selectedPageLoc = new URL(`./pages/${selectedPage}.hmx`, hmxRoot);
@@ -67,12 +68,12 @@ export default async function(astroConfig: AstroConfig) {
if (!existsSync(selectedPageLoc) && !existsSync(selectedPageMdLoc)) {
try {
const result = await snowpack.loadUrl(reqPath);
- if(result.contentType) {
+ if (result.contentType) {
res.setHeader('Content-Type', result.contentType);
}
res.write(result.contents);
res.end();
- } catch(err) {
+ } catch (err) {
console.log('Not found', reqPath);
res.statusCode = 404;
res.setHeader('Content-Type', 'text/plain');
@@ -94,5 +95,5 @@ export default async function(astroConfig: AstroConfig) {
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
- });
-} \ No newline at end of file
+ });
+}