Skip to content

Commit ea71629

Browse files
author
Andrei Canta
committed
Merge branch 'develop'
2 parents 7b2932f + c909021 commit ea71629

16 files changed

+186
-88
lines changed

README.md

+21-14
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ Before going further, make sure you `cd` into the root path of your project (`cd
4747
- setup your chosen domain name in `/etc/hosts`
4848
- add the project to the projects list
4949

50-
3. Start your application
50+
3. Build and start your application
5151

5252
```bash
53-
$ stacker start
53+
$ stacker up
5454
```
5555

5656
After this you will be able to reach your application using the domain name you choose previously. (eg. `test-project.dev`)
@@ -74,43 +74,50 @@ Generates `stacker.yaml` based on your responses.
7474
- adds your chosen domain name in `/etc/hosts`
7575
- adds the project to the projects list
7676

77-
### `$ stacker link`
77+
### `$ stacker unlink`
7878

7979
Does the opposite of `stacker link`.
8080

81-
### `$ stacker build`
81+
### `$ stacker up`
8282

83-
Builds the project.
83+
Builds and starts the project.
8484

8585
| Type | Name | Description | Required |
8686
| --- | --- | --- | --- |
87-
| option | `--dir` | Build path | no |
8887
| option | `--ip` | IP address | no |
88+
| option | `--detached` (`-d`) | Detached mode | no |
8989

90-
### `$ stacker start`
90+
### `$ stacker build`
9191

92-
Builds the project and starts the application.
92+
Builds the project.
9393

9494
| Type | Name | Description | Required |
9595
| --- | --- | --- | --- |
96-
| option | `--dir` | Build path | no |
9796
| option | `--ip` | IP address | no |
9897

98+
### `$ stacker start`
99+
100+
Starts the application.
101+
99102
### `$ stacker stop`
100103

101104
Stops the application.
102105

103-
| Type | Name | Description | Required |
104-
| --- | --- | --- | --- |
105-
| option | `--dir` | Build path | no |
106-
107106
### `$ stacker restart`
108107

109108
Restarts the application.
110109

110+
### `$ stacker down`
111+
112+
Removes and stops the application.
113+
114+
### `$ stacker shell`
115+
116+
Opens an interactive shell for a given service.
117+
111118
| Type | Name | Description | Required |
112119
| --- | --- | --- | --- |
113-
| option | `--dir` | Build path | no |
120+
| argument | `[service]` | Service name | no |
114121

115122
### `$ stacker run`
116123

src/commands/build.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
import { StackConfig, StackManager } from 'stacker-core';
1+
import { getStackManager, catchErrors } from '../utils';
22

33

4-
async function handle(args, options, logger) {
5-
const config = await StackConfig.loadRecursive(process.cwd());
6-
const manager = new StackManager(config);
4+
async function handle(args, options) {
5+
const manager = await getStackManager();
76

8-
if (options.dir) manager.setBuildPath(options.dir);
97
if (options.ip) manager.setIpAddress(options.ip);
108

11-
await manager.build();
12-
13-
logger.info('Project was built.');
9+
return manager.build();
1410
}
1511

1612
function register(program) {
1713
program
1814
.command('build', 'Build project')
19-
.option('--dir', 'Build path', program.STRING)
2015
.option('--ip', 'IP address', program.STRING)
21-
.action(handle);
16+
.action(catchErrors(handle));
2217
}
2318

2419
export default { register };

src/commands/down.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { getStackManager, catchErrors } from '../utils';
2+
3+
4+
async function handle() {
5+
const manager = await getStackManager();
6+
7+
return manager.down();
8+
}
9+
10+
function register(program) {
11+
program
12+
.command('down', 'Stop & remove project')
13+
.action(catchErrors(handle));
14+
}
15+
16+
export default { register };

src/commands/eject.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import inquirer from 'inquirer';
2-
import { StackConfig, StackManager } from 'stacker-core';
2+
3+
import { getStackManager, catchErrors } from '../utils';
34

45

56
async function getEjectableName(stack) {
67
const choices = stack.ejectables.entries().map(([name, ejectable]) => {
78
return { value: name, name: ejectable.label };
89
});
10+
11+
if (!choices.length) throw new Error('This project has no ejectables.');
12+
913
const answers = await inquirer.prompt({
1014
type: 'list',
1115
name: 'path',
1216
message: 'Select file',
1317
choices,
1418
});
19+
1520
return answers.path;
1621
}
1722

1823
async function handle(args, options, logger) {
19-
const config = await StackConfig.loadRecursive(process.cwd());
20-
const manager = new StackManager(config);
24+
const manager = await getStackManager();
2125
const file = args.file || await getEjectableName(manager.stack);
2226

2327
await manager.eject(file);
@@ -29,7 +33,7 @@ function register(program) {
2933
program
3034
.command('eject', 'Eject file')
3135
.argument('[file]', 'Ejectable name')
32-
.action(handle);
36+
.action(catchErrors(handle));
3337
}
3438

3539
export default { register };

src/commands/init.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import inquirer from 'inquirer';
22
import { StackConfig, LaravelWizard } from 'stacker-core';
33

4+
import { getStackConfig, catchErrors } from '../utils';
5+
46

57
async function getStackName() {
68
const answers = await inquirer.prompt({
@@ -20,24 +22,25 @@ function getWizard(stack) {
2022
if (stack === 'laravel') return LaravelWizard;
2123
}
2224

23-
async function getOptions(wizard) {
25+
async function getOptions(stack) {
26+
const wizard = getWizard(stack);
27+
28+
if (!wizard) return {};
29+
2430
const questions = wizard.getQuestions();
2531
const answers = await inquirer.prompt(questions);
32+
2633
return wizard.makeOptions(answers);
2734
}
2835

2936
async function handle(args, options, logger) {
30-
if (await StackConfig.load(process.cwd())) {
31-
logger.info('This project is already initialized.');
32-
return;
33-
}
37+
if (await getStackConfig()) throw new Error('The project is already initialized');
3438

3539
const config = new StackConfig();
3640
const stack = options.stack || await getStackName();
37-
const wizard = getWizard(stack);
3841

3942
config.stack = stack;
40-
config.options = await getOptions(wizard);
43+
config.options = options.defaults ? null : await getOptions(stack);
4144

4245
await config.save(process.cwd());
4346

@@ -49,7 +52,7 @@ function register(program) {
4952
.command('init', 'Init project')
5053
.argument('[stack]', 'Stack type', ['laravel'])
5154
.option('-y, --defaults', 'Use default options', program.BOOL, false)
52-
.action(handle);
55+
.action(catchErrors(handle));
5356
}
5457

5558
export default { register };

src/commands/link.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import path from 'path';
22
import inquirer from 'inquirer';
33
import { Links, titleCase } from 'stacker-core';
44

5+
import { catchErrors } from '../utils';
6+
57

68
function promptProjectName() {
79
return inquirer.prompt([
@@ -21,16 +23,17 @@ function promptProjectName() {
2123
}
2224

2325
async function handle(args, options, logger) {
24-
const link = await Links.find({ path: process.cwd() });
26+
const projectPath = process.cwd();
27+
const link = await Links.find({ projectPath });
2528

2629
if (link !== null) {
2730
logger.info('This project is already linked.');
2831
} else {
2932
const answers = await promptProjectName();
3033
const data = {
3134
name: answers.name,
32-
projectPath: process.cwd(),
3335
host: answers.host,
36+
projectPath,
3437
};
3538
const link = await Links.create(data);
3639

@@ -41,7 +44,7 @@ async function handle(args, options, logger) {
4144
function register(program) {
4245
program
4346
.command('link', 'Link project')
44-
.action(handle);
47+
.action(catchErrors(handle));
4548
}
4649

4750
export default { register };

src/commands/links.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Links } from 'stacker-core';
22

3+
import { catchErrors } from '../utils';
4+
35

46
async function handle(args, options, logger) {
57
const links = await Links.all();
@@ -17,7 +19,7 @@ async function handle(args, options, logger) {
1719
function register(program) {
1820
program
1921
.command('links', 'List linked projects')
20-
.action(handle);
22+
.action(catchErrors(handle));
2123
}
2224

2325
export default { register };

src/commands/restart.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
import { StackConfig, StackManager } from 'stacker-core';
1+
import { getStackManager, catchErrors } from '../utils';
22

33

4-
async function handle(args, options, logger) {
5-
const config = await StackConfig.loadRecursive(process.cwd());
6-
const manager = new StackManager(config);
4+
async function handle(args) {
5+
const manager = await getStackManager();
76

8-
if (options.dir) manager.setBuildPath(options.dir);
9-
10-
await manager.restart();
11-
12-
logger.info('Done.');
7+
return manager.restart(args.service);
138
}
149

1510
function register(program) {
1611
program
1712
.command('restart', 'Restart project')
18-
.option('--dir', 'Build path', program.STRING)
19-
.action(handle);
13+
.argument('[service]', 'Service name')
14+
.action(catchErrors(handle));
2015
}
2116

2217
export default { register };

src/commands/run.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
import inquirer from 'inquirer';
2-
import { StackConfig, StackManager } from 'stacker-core';
2+
3+
import { getStackManager, catchErrors } from '../utils';
34

45

56
async function getRunnableName(stack) {
67
const choices = stack.runnables.entries().map(([name, ejectable]) => {
78
return { value: name, name: ejectable.label };
89
});
10+
11+
if (!choices.length) throw new Error('This project has no runnables.');
12+
913
const answers = await inquirer.prompt({
1014
type: 'list',
1115
name: 'command',
1216
message: 'Select command',
1317
choices,
1418
});
19+
1520
return answers.command;
1621
}
1722

18-
async function handle(args, options, logger) {
19-
const config = await StackConfig.loadRecursive(process.cwd());
20-
const manager = new StackManager(config);
23+
async function handle(args) {
24+
const manager = await getStackManager();
2125
const command = args.command || await getRunnableName(manager.stack);
2226

23-
await manager.run(command);
24-
25-
logger.info('Done.');
27+
return manager.run(command);
2628
}
2729

2830
function register(program) {
2931
program
3032
.command('run', 'Run command')
3133
.argument('[command]', 'Runnable name')
32-
.action(handle);
34+
.action(catchErrors(handle));
3335
}
3436

3537
export default { register };

src/commands/shell.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import inquirer from 'inquirer';
2+
3+
import { getStackManager, catchErrors } from '../utils';
4+
5+
6+
async function getServiceName(stack) {
7+
const choices = stack.services.values()
8+
.filter(service => service.shell)
9+
.map(service => service.name);
10+
const answers = await inquirer.prompt({
11+
type: 'list',
12+
name: 'service',
13+
message: 'Select service',
14+
choices,
15+
});
16+
17+
return answers.service;
18+
}
19+
20+
async function handle(args) {
21+
const manager = await getStackManager();
22+
const service = args.service || await getServiceName(manager.stack);
23+
24+
return manager.shell(service);
25+
}
26+
27+
function register(program) {
28+
program
29+
.command('shell', 'Open shell')
30+
.alias('sh')
31+
.argument('[service]', 'Service name')
32+
.action(catchErrors(handle));
33+
}
34+
35+
export default { register };

0 commit comments

Comments
 (0)