2021-03-15 17:22:05 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
import { join as pathJoin, resolve as pathResolve } from 'path';
|
|
|
|
|
|
|
|
import generate from './lib/generate.js';
|
|
|
|
import devServer from './lib/dev.js';
|
|
|
|
|
|
|
|
const root = pathResolve(process.argv[2]);
|
|
|
|
|
|
|
|
if(!root) {
|
|
|
|
console.error('Must provide a project root');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const fileProtocolRoot = `file://${root}/`;
|
|
|
|
|
|
|
|
async function run() {
|
2021-03-15 18:18:39 +00:00
|
|
|
const astroConfig = (await import(pathJoin(root, 'astro.config.mjs'))).default;
|
|
|
|
astroConfig.projectRoot = new URL(astroConfig.projectRoot + '/', fileProtocolRoot);
|
|
|
|
astroConfig.hmxRoot = new URL(astroConfig.hmxRoot + '/', fileProtocolRoot);
|
2021-03-15 17:22:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Should use an args parser eventually
|
|
|
|
if(process.argv.includes('--generate')) {
|
2021-03-15 18:18:39 +00:00
|
|
|
return generate(astroConfig);
|
2021-03-15 17:22:05 +00:00
|
|
|
} else {
|
2021-03-15 18:18:39 +00:00
|
|
|
return devServer(astroConfig);
|
2021-03-15 17:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
run().catch(err => setTimeout(() => {throw err}));
|