Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions builders/spa.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = async function spa({ output, cache }) {
module.exports = async function spa({ output, cache, environment }) {
const folder = output || 'spa';
process.env.NULLSTACK_ENVIRONMENT_MODE = 'spa';

const dir = process.cwd();
const application = require(`${dir}/.production/server`).default
const application = require(`${dir}/.${environment}/server`).default
const { existsSync, mkdirSync, writeFileSync, copySync, removeSync } = require('fs-extra');
const path = `${dir}/${folder}`;

Expand All @@ -26,8 +26,8 @@ module.exports = async function spa({ output, cache }) {
console.log(` ⚙️ /public/`)
copySync(`${dir}/public`, path);
await copy('/', '/index.html')
console.log(` ⚙️ /.production/`)
copySync(`${dir}/.production`, path, { filter })
console.log(` ⚙️ /.${environment}/`)
copySync(`${dir}/.${environment}`, path, { filter })
await copy(`/manifest.webmanifest`)
await copy(`/service-worker.js`)
await copy('/robots.txt')
Expand All @@ -37,7 +37,7 @@ module.exports = async function spa({ output, cache }) {

if (cache) {
console.log('Storing cache...');
} else {
} else if (environment === 'production') {
process.exit();
}
}
8 changes: 4 additions & 4 deletions builders/ssg.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = async function ssg({ output, cache }) {
module.exports = async function ssg({ output, cache, environment }) {
const folder = output || 'ssg';
process.env.NULLSTACK_ENVIRONMENT_MODE = 'ssg';

const dir = process.cwd();
const application = require(`${dir}/.production/server`).default;
const application = require(`${dir}/.${environment}/server`).default;
const { resolve } = require('path')
const { existsSync, mkdirSync, writeFileSync, copySync, removeSync } = require('fs-extra');

Expand Down Expand Up @@ -90,8 +90,8 @@ module.exports = async function ssg({ output, cache }) {
mkdirSync(path())
console.log(` ⚙️ /public/`)
copySync(path(`../public`), path());
console.log(` ⚙️ /.production/`)
copySync(path(`../.production`), path(), { filter });
console.log(` ⚙️ /.${environment}/`)
copySync(path(`../.${environment}`), path(), { filter });
await copyRoute()
await copyRoute(`/nullstack/${application.environment.key}/offline`);
await copyRoute(`/404`);
Expand Down
5 changes: 4 additions & 1 deletion client/liveReload.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import worker from './worker'

let shouldReloadNext = false;
let timer = null;

Expand All @@ -13,7 +15,8 @@ function reload() {
}

function liveReload() {
const socket = new WebSocket(`${location.protocol.replace('http', 'ws')}//${location.host}`);
const url = worker.api ? `${worker.api.replace('http', 'ws')}` : `${location.protocol.replace('http', 'ws')}//${location.host}`
const socket = new WebSocket(url);
socket.addEventListener('open', reload);
socket.addEventListener('close', liveReload);
}
Expand Down
13 changes: 10 additions & 3 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function logTrace(stats, showCompiling) {
lastTrace = '';
}

function start({ input, port, env }) {
function start({ input, port, env, output, mode = 'ssr' }) {
const environment = 'development';
const compiler = getCompiler({ environment, input });
if (port) {
Expand All @@ -61,7 +61,12 @@ function start({ input, port, env }) {
}
console.log(` 🚀️ Starting your application in ${environment} mode...`);
console.log();
compiler.watch({}, (error, stats) => logTrace(stats, true));
compiler.watch({}, (error, stats) => {
logTrace(stats, true)
if (!stats.hasErrors() && mode !== 'ssr') {
require(`../builders/${mode}`)({ output, environment });
};
});
}

function build({ input, output, cache, env, mode = 'ssr' }) {
Expand All @@ -74,16 +79,18 @@ function build({ input, output, cache, env, mode = 'ssr' }) {
compiler.run((error, stats) => {
logTrace(stats, false);
if (stats.hasErrors()) process.exit(1);
require(`../builders/${mode}`)({ output, cache });
require(`../builders/${mode}`)({ output, cache, environment });
});
}

program
.command('start')
.alias('s')
.description('Start application in development environment')
.addOption(new program.Option('-m, --mode <mode>', 'Build production bundles').choices(buildModes))
.option('-p, --port <port>', 'Port number to run the server')
.option('-i, --input <input>', 'Path to project that will be started')
.option('-o, --output <output>', 'Path to build output folder')
.option('-e, --env <name>', 'Name of the environment file that should be loaded')
.helpOption('-h, --help', 'Learn more about this command')
.action(start)
Expand Down