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

Add --exit flag to build command #325

Merged
merged 2 commits into from
Jan 26, 2022
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
4 changes: 4 additions & 0 deletions packages/gasket-plugin-start/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ This is a default plugin in the Gasket CLI and is always available for use.
Executes the `build` lifecycle. Use this to prepare your app for running, such
as bundling files, minifying code, processing assets, etc.

If you need to force the process to exit once the build lifecycle completes,
you can pass the `--exit` flag. This should be used sparingly. Prefer to find
and fix lingering open handle issues which may be keeping the process running.

### start command

Executes the `preboot` and `start` lifecycles. Upon building your app, use this
Expand Down
12 changes: 12 additions & 0 deletions packages/gasket-plugin-start/lib/get-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@ module.exports = function getCommands(gasket, { GasketCommand, flags }) {
class BuildCommand extends GasketCommand {
async gasketRun() {
await this.gasket.exec('build');

if (this.gasket.command.flags.exit) {
this.gasket.logger.debug('force exit');
// eslint-disable-next-line no-process-exit
process.exit(0);
}
}
}
BuildCommand.id = 'build';
BuildCommand.description = 'Prepare your app';
BuildCommand.flags = {
exit: flags.boolean({
default: false,
description: 'Exit process immediately after command completes'
})
};


class StartCommand extends GasketCommand {
Expand Down
38 changes: 36 additions & 2 deletions packages/gasket-plugin-start/test/get-commands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const sinon = require('sinon');
const getCommands = require('../lib/get-commands');

const mockGasket = {
exec: sinon.stub()
exec: sinon.stub(),
logger: {
debug: sinon.stub()
}
};

class MockGasketCommand {
Expand All @@ -12,7 +15,10 @@ class MockGasketCommand {
}
}

const mockFlags = { string: sinon.stub() };
const mockFlags = {
string: sinon.stub(),
boolean: sinon.stub()
};

const mockData = { GasketCommand: MockGasketCommand, flags: mockFlags };

Expand Down Expand Up @@ -43,9 +49,15 @@ const testCommand = async (Command, name, lifecycles) => {
};

describe('getCommands', () => {
let exitStub;

beforeEach(() => {
exitStub = sinon.stub(process, 'exit');
});

afterEach(function () {
sinon.resetHistory();
exitStub.restore();
});

it('returns commands', () => {
Expand All @@ -59,6 +71,28 @@ describe('getCommands', () => {
describe('BuildCommand', () => {
const BuildCommand = getCommands(mockGasket, mockData)[0];
testCommand(BuildCommand, 'build', ['build']);

it('calls process.exit', async function () {
const instance = new BuildCommand();
instance.gasket.command = {
flags: { exit: true }
};
await instance.gasketRun();

assume(exitStub).called();
assume(mockGasket.logger.debug).calledWith('force exit');
});

it('does not force exit without flag', async function () {
const instance = new BuildCommand();
instance.gasket.command = {
flags: {}
};
await instance.gasketRun();

assume(exitStub).not.called();
assume(mockGasket.logger.debug).not.calledWith('force exit');
});
});

describe('StartCommand', () => {
Expand Down