Skip to content
This repository was archived by the owner on Feb 3, 2022. It is now read-only.

Commit 139a581

Browse files
committed
Adds success message to the end of the process with next steps.
1 parent be48350 commit 139a581

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"rimraf": "^2.6.3"
2929
},
3030
"dependencies": {
31+
"boxen": "^3.0.0",
32+
"chalk": "^2.4.2",
3133
"gitignore": "^0.6.0",
3234
"inquirer": "^6.2.2",
3335
"ora": "^3.2.0",

src/create-twilio-function.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const importCredentials = require('./create-twilio-function/import-credentials')
1010
const {
1111
installDependencies
1212
} = require('./create-twilio-function/install-dependencies');
13+
const successMessage = require('./create-twilio-function/success-message');
1314
const ora = require('ora');
15+
const boxen = require('boxen');
1416

1517
async function createTwilioFunction(config) {
1618
const projectDir = `${config.path}/${config.name}`;
@@ -55,6 +57,12 @@ async function createTwilioFunction(config) {
5557
spinner.start('Installing dependencies');
5658
await installDependencies(projectDir);
5759
spinner.succeed();
60+
61+
// Success message
62+
63+
console.log(
64+
boxen(await successMessage(config), { padding: 1, borderStyle: 'round' })
65+
);
5866
}
5967

6068
module.exports = createTwilioFunction;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { getPackageManager } = require('pkg-install');
2+
const chalk = require('chalk');
3+
4+
async function successMessage(config) {
5+
const packageManager = await getPackageManager({ cwd: process.cwd() });
6+
return chalk`{green Success!}
7+
8+
Created {bold ${config.name}} at ${config.path}
9+
10+
Inside that directory, you can run the following command:
11+
12+
{blue ${packageManager} start}
13+
Serves all functions in the ./functions subdirectory
14+
15+
Get started by running:
16+
17+
{blue cd ${config.name}}
18+
{blue ${packageManager} start}`;
19+
}
20+
21+
module.exports = successMessage;

tests/create-twilio-function.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
} = require('../src/create-twilio-function/install-dependencies');
55
const inquirer = require('inquirer');
66
const ora = require('ora');
7+
const boxen = require('boxen');
78
const fs = require('fs');
89
const { promisify } = require('util');
910
const rimraf = promisify(require('rimraf'));
@@ -12,17 +13,20 @@ const stat = promisify(fs.stat);
1213

1314
jest.mock('inquirer');
1415
jest.mock('ora');
16+
jest.mock('boxen', () => {
17+
return () => 'success message';
18+
});
1519
ora.mockImplementation(() => {
1620
const spinner = {
1721
start: () => spinner,
1822
succeed: () => spinner
1923
};
2024
return spinner;
2125
});
22-
2326
jest.mock('../src/create-twilio-function/install-dependencies.js', () => {
2427
return { installDependencies: jest.fn() };
2528
});
29+
console.log = jest.fn();
2630

2731
beforeAll(async () => {
2832
await rimraf('./scratch');
@@ -46,6 +50,7 @@ describe('createTwilioFunction', () => {
4650
authToken: 'test-auth-token'
4751
})
4852
);
53+
4954
const name = 'test-function';
5055
await createTwilioFunction({ name, path: './scratch' });
5156

@@ -70,6 +75,8 @@ describe('createTwilioFunction', () => {
7075
expect(example.isFile());
7176

7277
expect(installDependencies).toHaveBeenCalledWith(`./scratch/${name}`);
78+
79+
expect(console.log).toHaveBeenCalledWith('success message');
7380
});
7481

7582
it("doesn't scaffold if the target folder name already exists", async () => {
@@ -79,9 +86,10 @@ describe('createTwilioFunction', () => {
7986

8087
await createTwilioFunction({ name, path: './scratch' });
8188

82-
expect.assertions(2);
89+
expect.assertions(3);
8390

8491
expect(console.error).toHaveBeenCalledTimes(1);
92+
expect(console.log).not.toHaveBeenCalled();
8593

8694
try {
8795
await stat(`./scratch/${name}/package.json`);

tests/success-message.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const pkgInstall = require('pkg-install');
2+
const chalk = require('chalk');
3+
const successMessage = require('../src/create-twilio-function/success-message');
4+
5+
jest.mock('pkg-install');
6+
7+
describe('successMessage', () => {
8+
test('creates a success message based on the package manager', async () => {
9+
pkgInstall.getPackageManager.mockResolvedValue('yarn');
10+
const config = {
11+
name: 'test-function',
12+
path: './test-path'
13+
};
14+
const message = await successMessage(config);
15+
expect(message).toEqual(expect.stringContaining('yarn start'));
16+
expect(message).toEqual(
17+
expect.stringContaining(
18+
chalk`Created {bold ${config.name}} at ${config.path}`
19+
)
20+
);
21+
});
22+
});

0 commit comments

Comments
 (0)