Skip to content

Commit

Permalink
Merge pull request #77 from izelnakri/fastboot-enchancements
Browse files Browse the repository at this point in the history
fastboot enchancements
  • Loading branch information
izelnakri authored Feb 17, 2020
2 parents 45c8ed9 + 9587e07 commit 1184092
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
DOCKER_TAG=$(echo mber:${CIRCLE_BRANCH} | tr '/' '_')
docker pull ${HUB_USERNAME}/${DOCKER_TAG}
docker run -t -d --name="mber" ${HUB_USERNAME}/${DOCKER_TAG} /bin/bash
- run: docker exec -it -e NODE_OPTIONS=--experimental-modules mber npm test
- run: docker exec -it mber npm test

workflows:
version: 2
Expand Down
61 changes: 29 additions & 32 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,55 @@
#! /usr/bin/env node

import chalk from 'ansi-colors';
import Console from './lib/utils/console.js';
import printCommand from './lib/commands/index.js';
import compileCommand from './lib/commands/compile.js';
import serveCommand from './lib/commands/serve.js';
import testCommand from './lib/commands/test.js';
import buildCommand from './lib/commands/build.js';
import consoleCommand from './lib/commands/console.js';
import newCommand from './lib/commands/new.js';
import generateCommand from './lib/commands/generate.js';
import deleteCommand from './lib/commands/delete.js';

process.title = 'mber';
global.mainContext = global; // NOTE: needed for ember-template-compiler

let shouldRunCommand = false;

const CLI = {
default(commandHandler) {
async default(commandHandler) {
if (!process.argv[2]) {
shouldRunCommand = true;

return commandHandler();
return await commandHandler();
}
},
command(commandName, commandHandler) {
async command(commandName, commandHandler) {
const commandMatchesArray = Array.isArray(commandName) && commandName.includes(process.argv[2]);

if (commandMatchesArray || commandName === process.argv[2]) {
shouldRunCommand = true;

return commandHandler();
return await commandHandler();
}
}
};

CLI.default(() => printCommand());
CLI.command(['serve', 'server', 's'], () => serveCommand()); // TODO: add proxy
CLI.command(['test', 't'], () => testCommand()); // TODO: add --proxy
CLI.command(['build', 'b'], () => buildCommand()); // TODO: add --proxy
CLI.command(['compile', 'transpile', 'c'], () => compileCommand());
CLI.command(['console'], () => consoleCommand());
CLI.command(['help', 'h', 'print', 'p'], () => printCommand());
CLI.command(['init', 'new'], () => newCommand());
CLI.command(['generate', 'g', 'create'], () => generateCommand(process.argv[3], process.argv[4]));
CLI.command(['delete', 'd', 'destroy', 'remove'], () =>
deleteCommand(process.argv[3], process.argv[4])
);

if (!shouldRunCommand) {
Console.log(chalk.red('unknown command. Available options are:'));
printCommand();
setTimeout(() => process.exit(1), 100);
}
(async () => {
CLI.default(async () => await runCommand('./lib/commands/index.js'));
CLI.command(['serve', 'server', 's'], async () => await runCommand('./lib/commands/serve.js')); // TODO: add proxy
CLI.command(['test', 't'], async () => await runCommand('./lib/commands/test.js')); // TODO: add --proxy
CLI.command(['build', 'b'], async () => await runCommand('./lib/commands/build.js')); // TODO: add --proxy
CLI.command(['compile', 'transpile', 'c'], async () => await runCommand('./lib/commands/compile.js'));
CLI.command(['console'], async () => await runCommand('./lib/commands/console.js'));
CLI.command(['help', 'h', 'print', 'p'], async () => await runCommand('./lib/commands/index.js'));
CLI.command(['init', 'new'], async () => await runCommand('./lib/commands/new.js'));
CLI.command(['generate', 'g', 'create'], async () => {
return (await import('./lib/commands/generate.js')).default(process.argv[3], process.argv[4])
});
CLI.command(['delete', 'd', 'destroy', 'remove'], async () => {
(await import('./lib/commands/delete.js')).default(process.argv[3], process.argv[4]);
});

if (!shouldRunCommand) {
Console.log(chalk.red('unknown command. Available options are:'));
await runCommand('./lib/commands/index.js');
setTimeout(() => process.exit(1), 100);
}
})();

async function runCommand(commandPath) {
return (await import(commandPath)).default();
}
// NOTE: maybe merge server and console commands in future?
5 changes: 3 additions & 2 deletions lib/builders/build-fastboot-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default async function(
const applicationName = ENV.modulePrefix || 'frontend';
const applicationPath = assetMap['assets/application.js'];
const projectRoot = buildConfig.projectRoot || (await findProjectRoot());
const packageJSON = JSON.parse(await fs.readFile(`${projectRoot}/package.json`)).toString();

return fs.writeFile(
`${projectRoot}/${distPath}/package.json`,
Expand Down Expand Up @@ -54,11 +55,11 @@ export default async function(
htmlFile: 'index.html',
vendorFiles: [assetMap['assets/vendor.js']]
},
moduleWhitelist: [
moduleWhitelist: (packageJSON.fastbootDependencies || []).concat([
'node-fetch',
'abortcontroller-polyfill',
'abortcontroller-polyfill/dist/cjs-ponyfill'
],
]),
schemaVersion: 3
}
},
Expand Down
8 changes: 4 additions & 4 deletions lib/utils/fastboot-express-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export default function(distPath, opts={}) {
let headers = result.headers;
let statusMessage = result.error ? 'NOT OK ' : 'OK ';

for (var pair of headers.entries()) {
response.set(pair[0], pair[1]);
}

if (result.error) {
console.log('RESILIENT MODE CAUGHT:', result.error.stack);
console.log(result.error);

next(result.error);
} else {
for (var pair of headers.entries()) {
response.set(pair[0], pair[1]);
}
}

// TODO: on debug, show fastboot render times
Expand Down

0 comments on commit 1184092

Please sign in to comment.