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

Commit dfee78f

Browse files
committed
Merge version 2 into master
2 parents 08c619a + 7eeac27 commit dfee78f

23 files changed

+752
-130
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Changelog for `create-twilio-function`
22

3-
## Ongoing [](https://github.com/twilio-labs/create-twilio-function/compare/v1.0.1...master)
3+
## Ongoing [](https://github.com/twilio-labs/create-twilio-function/compare/v1.0.2...next)
44

5-
...
5+
- Exports details about the cli command so that other projects can consume it. Fixes #12
6+
- Generates new project from the ./templates directory in this project
7+
- Can generate projects based on a template from twilio-labs/function-templates
68

79
## 1.0.2 (July 10, 2019) [](https://github.com/twilio-labs/create-twilio-function/compare/v1.0.1...v1.0.2)
810

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,28 @@ create-twilio-function <name>
3838
3939
Creates a new Twilio Function project
4040
41+
Commands:
42+
create-twilio-function <name> Creates a new Twilio Function
43+
project [default]
44+
create-twilio-function list-templates List the available templates you can
45+
create a project with.
46+
4147
Positionals:
42-
name Name of your project. [string]
48+
name Name of your project. [string]
4349
4450
Options:
45-
--account-sid, -a The Account SID for your Twilio account [string]
46-
--auth-token, -t Your Twilio account Auth Token [string]
47-
--skip-credentials Don't ask for Twilio account credentials or import them
48-
from the environment [boolean] [default: false]
51+
--account-sid, -a The Account SID for your Twilio account [string]
52+
--auth-token, -t Your Twilio account Auth Token [string]
53+
--skip-credentials Don't ask for Twilio account credentials or import
54+
them from the environment [boolean] [default: false]
4955
--import-credentials Import credentials from the environment variables
5056
TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN
51-
[boolean] [default: false]
52-
-h, --help Show help [boolean]
53-
-v, --version Show version number [boolean]
54-
--path [default: (cwd)]
57+
[boolean] [default: false]
58+
--template Initialize your new project with a template from
59+
github.com/twilio-labs/function-templates [string]
60+
-h, --help Show help [boolean]
61+
-v, --version Show version number [boolean]
62+
--path [default: (cwd)]
5563
```
5664

5765
## Contributing

jest.config.js

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://jestjs.io/docs/en/configuration.html
3+
4+
module.exports = {
5+
// All imported modules in your tests should be mocked automatically
6+
// automock: false,
7+
8+
// Stop running tests after `n` failures
9+
// bail: 0,
10+
11+
// Respect "browser" field in package.json when resolving modules
12+
// browser: false,
13+
14+
// The directory where Jest should store its cached dependency information
15+
// cacheDirectory: "/private/var/folders/zj/m36rb_wx6ddb953lr4qlg0b9y6hcv1/T/jest_yio0o1",
16+
17+
// Automatically clear mock calls and instances between every test
18+
clearMocks: true,
19+
20+
// Indicates whether the coverage information should be collected while executing the test
21+
collectCoverage: true,
22+
23+
// An array of glob patterns indicating a set of files for which coverage information should be collected
24+
collectCoverageFrom: [
25+
'src/**/*.js',
26+
'!**/node_modules/**',
27+
'!templates/**/*.{js,html,css}'
28+
],
29+
30+
// The directory where Jest should output its coverage files
31+
coverageDirectory: 'coverage',
32+
33+
// An array of regexp pattern strings used to skip coverage collection
34+
// coveragePathIgnorePatterns: [
35+
// "/node_modules/"
36+
// ],
37+
38+
// A list of reporter names that Jest uses when writing coverage reports
39+
// coverageReporters: [
40+
// "json",
41+
// "text",
42+
// "lcov",
43+
// "clover"
44+
// ],
45+
46+
// An object that configures minimum threshold enforcement for coverage results
47+
// coverageThreshold: null,
48+
49+
// A path to a custom dependency extractor
50+
// dependencyExtractor: null,
51+
52+
// Make calling deprecated APIs throw helpful error messages
53+
// errorOnDeprecated: false,
54+
55+
// Force coverage collection from ignored files using an array of glob patterns
56+
// forceCoverageMatch: [],
57+
58+
// A path to a module which exports an async function that is triggered once before all test suites
59+
// globalSetup: null,
60+
61+
// A path to a module which exports an async function that is triggered once after all test suites
62+
// globalTeardown: null,
63+
64+
// A set of global variables that need to be available in all test environments
65+
// globals: {},
66+
67+
// An array of directory names to be searched recursively up from the requiring module's location
68+
// moduleDirectories: [
69+
// "node_modules"
70+
// ],
71+
72+
// An array of file extensions your modules use
73+
// moduleFileExtensions: [
74+
// "js",
75+
// "json",
76+
// "jsx",
77+
// "ts",
78+
// "tsx",
79+
// "node"
80+
// ],
81+
82+
// A map from regular expressions to module names that allow to stub out resources with a single module
83+
// moduleNameMapper: {},
84+
85+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
86+
// modulePathIgnorePatterns: [],
87+
88+
// Activates notifications for test results
89+
// notify: false,
90+
91+
// An enum that specifies notification mode. Requires { notify: true }
92+
// notifyMode: "failure-change",
93+
94+
// A preset that is used as a base for Jest's configuration
95+
// preset: null,
96+
97+
// Run tests from one or more projects
98+
// projects: null,
99+
100+
// Use this configuration option to add custom reporters to Jest
101+
// reporters: undefined,
102+
103+
// Automatically reset mock state between every test
104+
// resetMocks: false,
105+
106+
// Reset the module registry before running each individual test
107+
// resetModules: false,
108+
109+
// A path to a custom resolver
110+
// resolver: null,
111+
112+
// Automatically restore mock state between every test
113+
// restoreMocks: false,
114+
115+
// The root directory that Jest should scan for tests and modules within
116+
// rootDir: null,
117+
118+
// A list of paths to directories that Jest should use to search for files in
119+
// roots: [
120+
// "<rootDir>"
121+
// ],
122+
123+
// Allows you to use a custom runner instead of Jest's default test runner
124+
// runner: "jest-runner",
125+
126+
// The paths to modules that run some code to configure or set up the testing environment before each test
127+
// setupFiles: [],
128+
129+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
130+
// setupFilesAfterEnv: [],
131+
132+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
133+
// snapshotSerializers: [],
134+
135+
// The test environment that will be used for testing
136+
testEnvironment: 'node'
137+
138+
// Options that will be passed to the testEnvironment
139+
// testEnvironmentOptions: {},
140+
141+
// Adds a location field to test results
142+
// testLocationInResults: false,
143+
144+
// The glob patterns Jest uses to detect test files
145+
// testMatch: [
146+
// "**/__tests__/**/*.[jt]s?(x)",
147+
// "**/?(*.)+(spec|test).[tj]s?(x)"
148+
// ],
149+
150+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
151+
// testPathIgnorePatterns: [
152+
// "/node_modules/"
153+
// ],
154+
155+
// The regexp pattern or array of patterns that Jest uses to detect test files
156+
// testRegex: [],
157+
158+
// This option allows the use of a custom results processor
159+
// testResultsProcessor: null,
160+
161+
// This option allows use of a custom test runner
162+
// testRunner: "jasmine2",
163+
164+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
165+
// testURL: "http://localhost",
166+
167+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
168+
// timers: "real",
169+
170+
// A map from regular expressions to paths to transformers
171+
// transform: null,
172+
173+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
174+
// transformIgnorePatterns: [
175+
// "/node_modules/"
176+
// ],
177+
178+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
179+
// unmockedModulePathPatterns: undefined,
180+
181+
// Indicates whether each individual test should be reported during the run
182+
// verbose: null,
183+
184+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
185+
// watchPathIgnorePatterns: [],
186+
187+
// Whether to use watchman for file crawling
188+
// watchman: true,
189+
};

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-twilio-function",
3-
"version": "1.0.3",
3+
"version": "2.0.0-rc.1",
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",
@@ -24,8 +24,7 @@
2424
"license": "MIT",
2525
"devDependencies": {
2626
"jest": "^24.5.0",
27-
"nock": "^10.0.6",
28-
"rimraf": "^2.6.3"
27+
"nock": "^10.0.6"
2928
},
3029
"dependencies": {
3130
"boxen": "^3.0.0",
@@ -34,13 +33,18 @@
3433
"inquirer": "^6.2.2",
3534
"ora": "^3.2.0",
3635
"pkg-install": "^1.0.0",
36+
"rimraf": "^2.6.3",
37+
"twilio-run": "^2.0.0-rc.4",
38+
"window-size": "^1.1.1",
39+
"wrap-ansi": "^6.0.0",
3740
"yargs": "^12.0.5"
3841
},
3942
"engines": {
4043
"node": ">=8.0.0"
4144
},
4245
"files": [
4346
"bin/",
44-
"src/"
47+
"src/",
48+
"templates/"
4549
]
4650
}

src/cli.js

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,16 @@
11
const yargs = require('yargs');
2-
const createTwilioFunction = require('./create-twilio-function');
2+
const DefaultCommand = require('./command');
3+
const ListTemplateCommand = require('twilio-run/dist/commands/list-templates');
34

45
function cli(cwd) {
56
yargs.help();
67
yargs.alias('h', 'help');
78
yargs.version();
89
yargs.alias('v', 'version');
9-
1010
yargs.default('path', cwd);
11-
12-
yargs.usage('Creates a new Twilio Function project');
13-
yargs.command(
14-
'$0 <name>',
15-
'Creates a new Twilio Function project',
16-
command => {
17-
command.positional('name', {
18-
describe: 'Name of your project.',
19-
type: 'string'
20-
});
21-
command.options({
22-
'account-sid': {
23-
alias: 'a',
24-
describe: 'The Account SID for your Twilio account',
25-
type: 'string'
26-
},
27-
'auth-token': {
28-
alias: 't',
29-
describe: 'Your Twilio account Auth Token',
30-
type: 'string'
31-
},
32-
'skip-credentials': {
33-
describe:
34-
"Don't ask for Twilio account credentials or import them from the environment",
35-
type: 'boolean',
36-
default: false
37-
},
38-
'import-credentials': {
39-
describe:
40-
'Import credentials from the environment variables TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN',
41-
type: 'boolean',
42-
default: false
43-
}
44-
});
45-
},
46-
argv => createTwilioFunction(argv)
47-
);
48-
11+
yargs.usage(DefaultCommand.describe);
12+
yargs.command(DefaultCommand);
13+
yargs.command(ListTemplateCommand);
4914
return yargs;
5015
}
5116

src/command.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const handler = require('./create-twilio-function');
2+
3+
const command = '$0 <name>';
4+
const describe = 'Creates a new Twilio Function project';
5+
6+
const cliInfo = {
7+
options: {
8+
'account-sid': {
9+
alias: 'a',
10+
describe: 'The Account SID for your Twilio account',
11+
type: 'string'
12+
},
13+
'auth-token': {
14+
alias: 't',
15+
describe: 'Your Twilio account Auth Token',
16+
type: 'string'
17+
},
18+
'skip-credentials': {
19+
describe:
20+
"Don't ask for Twilio account credentials or import them from the environment",
21+
type: 'boolean',
22+
default: false
23+
},
24+
'import-credentials': {
25+
describe:
26+
'Import credentials from the environment variables TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN',
27+
type: 'boolean',
28+
default: false
29+
},
30+
template: {
31+
describe:
32+
'Initialize your new project with a template from github.com/twilio-labs/function-templates',
33+
type: 'string'
34+
}
35+
}
36+
};
37+
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+
46+
module.exports = {
47+
command,
48+
describe,
49+
handler,
50+
cliInfo,
51+
builder
52+
};

0 commit comments

Comments
 (0)