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

Implemented a new build system #6

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.next
out
tmp
ffconf2018-out
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

37 changes: 37 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const shell = require('shelljs');

const { config, version } = require('./package.json');
const { outputFolder } = config;

const build = ({ outputFolder, version }) => {
shell.echo('building static files:');

shell.echo('removing build directory');
shell.rm('-rf', outputFolder);

shell.echo('running next build');
shell.exec(`${__dirname}/node_modules/.bin/next build`);

shell.echo('running next export');
shell.exec(`${__dirname}/node_modules/.bin/next export -o ${outputFolder}`);

shell.echo('copying sw.js file');
shell.cp('static/js/sw.js', outputFolder);

shell.echo('replacing version in sw.js file');
shell.sed('-i', '@VERSION@', version, `${outputFolder}/sw.js`);

shell.echo('copying style.css file');
shell.cp(`${outputFolder}/_next/static/style.css`, `${outputFolder}/static`);

shell.echo('removing _next directory');
shell.rm('-rf', `${outputFolder}/_next`);

shell.echo('done building static files');
};

if (module.parent) {
module.exports = build;
} else {
build({ outputFolder, version });
}
20 changes: 17 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
/* eslint no-console: off */
const express = require('express');
const app = express();

app.use('/static', express.static(__dirname + '/static'));
app.use('/', express.static(__dirname + '/static'));
const build = require('./build');

const port = process.env.PORT || 9000;

const { config, version } = require('./package.json');
const { outputFolder } = config;

app.use('/', express.static(`${__dirname}/${outputFolder}`));

build({ outputFolder, version });

if (module.parent) {
module.exports = app;
} else {
app.listen(process.env.PORT);
app.listen(port, err => {
if (err) {
throw err;
}
console.log(`Ready on http://localhost:${port}`);
});
}
Loading