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

Commit 8db50ad

Browse files
committed
Merges latest from next into templates branch
1 parent 10875a3 commit 8db50ad

File tree

7 files changed

+44
-33
lines changed

7 files changed

+44
-33
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-twilio-function",
3-
"version": "2.0.0-alpha.4",
3+
"version": "2.0.0-alpha.5",
44
"description": "A CLI tool to generate a new Twilio Function using that can be run locally with twilio-run.",
55
"bin": "./bin/create-twilio-function",
66
"main": "./src/create-twilio-function.js",
@@ -34,8 +34,10 @@
3434
"ora": "^3.2.0",
3535
"pkg-install": "^1.0.0",
3636
"twilio-run": "^2.0.0-beta.12",
37-
"yargs": "^12.0.5",
38-
"rimraf": "^2.6.3"
37+
"rimraf": "^2.6.3",
38+
"window-size": "^1.1.1",
39+
"wrap-ansi": "^6.0.0",
40+
"yargs": "^12.0.5"
3941
},
4042
"engines": {
4143
"node": ">=8.0.0"

src/cli.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const yargs = require('yargs');
2-
const { handler, describe, cliInfo } = require('./command');
32
const listTemplates = require('./commands/list-templates');
3+
const DefaultCommand = require('./command');
44

55
function cli(cwd) {
66
yargs.help();
@@ -9,20 +9,8 @@ function cli(cwd) {
99
yargs.alias('v', 'version');
1010

1111
yargs.default('path', cwd);
12-
13-
yargs.usage(describe);
14-
yargs.command(
15-
'$0 <name>',
16-
describe,
17-
command => {
18-
command.positional('name', {
19-
describe: 'Name of your project.',
20-
type: 'string'
21-
});
22-
command.options(cliInfo.options);
23-
},
24-
argv => handler(argv)
25-
);
12+
yargs.usage(DefaultCommand.describe);
13+
yargs.command(DefaultCommand);
2614
yargs.command({
2715
command: 'list-templates',
2816
desc: 'List the available templates you can create a project with.',

src/command.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const createTwilioFunction = require('./create-twilio-function');
1+
const handler = require('./create-twilio-function');
2+
3+
const command = '$0 <name>';
4+
const describe = 'Creates a new Twilio Function project';
25

36
const cliInfo = {
47
options: {
@@ -32,8 +35,18 @@ const cliInfo = {
3235
}
3336
};
3437

38+
const builder = command => {
39+
command.positional('name', {
40+
describe: 'Name of your project.',
41+
type: 'string'
42+
});
43+
command.options(cliInfo.options);
44+
};
45+
3546
module.exports = {
36-
describe: 'Creates a new Twilio Function project',
37-
handler: createTwilioFunction,
38-
cliInfo: cliInfo
47+
command,
48+
describe,
49+
handler,
50+
cliInfo,
51+
builder
3952
};
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
const { getPackageManager } = require('pkg-install');
22
const chalk = require('chalk');
3+
const windowSize = require('window-size');
4+
const wrap = require('wrap-ansi');
35

46
async function successMessage(config) {
57
const packageManager = await getPackageManager({ cwd: process.cwd() });
6-
return chalk`{green Success!}
8+
return wrap(
9+
chalk`{green Success!}
710
8-
Created {bold ${config.name}} at ${config.path}
11+
Created {bold ${config.name}} at {bold ${config.path}}
912
10-
Inside that directory, you can run the following command:
13+
Inside that directory, you can run the following command:
1114
12-
{blue ${packageManager} start}
13-
Serves all functions in the ./functions subdirectory and assets in the
14-
./assets directory
15+
{blue ${packageManager} start}
16+
Serves all functions in the ./functions subdirectory and assets in the
17+
./assets directory
1518
16-
Get started by running:
19+
Get started by running:
1720
18-
{blue cd ${config.name}}
19-
{blue ${packageManager} start}`;
21+
{blue cd ${config.name}}
22+
{blue ${packageManager} start}`,
23+
windowSize.get().width - 8,
24+
{ trim: false, hard: true }
25+
);
2026
}
2127

2228
module.exports = successMessage;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
twilioRun: '^2.0.0-beta.11',
2+
twilioRun: '2.* || >2.0.0-rc',
33
node: '8.10.0'
44
};

tests/create-twilio-function.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const mkdir = promisify(fs.mkdir);
1212
const stat = promisify(fs.stat);
1313
const readdir = promisify(fs.readdir);
1414

15+
jest.mock('window-size', () => ({ get: () => ({ width: 80 }) }));
1516
jest.mock('inquirer');
1617
jest.mock('ora');
1718
jest.mock('boxen', () => {

tests/success-message.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const chalk = require('chalk');
33
const successMessage = require('../src/create-twilio-function/success-message');
44

55
jest.mock('pkg-install');
6+
jest.mock('window-size', () => ({ get: () => ({ width: 80 }) }));
67

78
describe('successMessage', () => {
89
test('creates a success message based on the package manager', async () => {
@@ -15,7 +16,7 @@ describe('successMessage', () => {
1516
expect(message).toEqual(expect.stringContaining('yarn start'));
1617
expect(message).toEqual(
1718
expect.stringContaining(
18-
chalk`Created {bold ${config.name}} at ${config.path}`
19+
chalk`Created {bold ${config.name}} at {bold ${config.path}}`
1920
)
2021
);
2122
});

0 commit comments

Comments
 (0)