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

Commit 9592945

Browse files
committed
Return early if the directory exists.
1 parent cb19361 commit 9592945

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

src/create-twilio-function.js

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,44 @@ const ora = require('ora');
1313

1414
async function createTwilioFunction(config) {
1515
const projectDir = `${config.path}/${config.name}`;
16+
1617
try {
1718
await createDirectory(config.path, config.name);
18-
// Get account sid and auth token
19-
accountDetails = await promptForAccountDetails(config);
20-
config = { ...accountDetails, ...config };
21-
22-
// Scaffold project
23-
const spinner = ora();
24-
spinner.start('Creating project directories and files');
25-
await createDirectory(projectDir, 'functions');
26-
await createDirectory(projectDir, 'assets');
27-
await createEnvFile(projectDir, {
28-
accountSid: config.accountSid,
29-
authToken: config.authToken
30-
});
31-
await createExampleFunction(`${projectDir}/functions`);
32-
await createPackageJSON(projectDir, config.name);
33-
spinner.succeed();
34-
35-
// Download .gitignore file from https://github.com/github/gitignore/
36-
spinner.start('Downloading .gitignore file');
37-
await createGitignore(projectDir);
38-
spinner.succeed();
39-
40-
// Install dependencies with npm
41-
spinner.start('Installing dependencies');
42-
await installDependencies(projectDir);
43-
spinner.succeed();
4419
} catch (e) {
4520
console.log(
4621
`A directory called '${
4722
config.name
4823
}' already exists. Please create your function in a new directory.`
4924
);
25+
return;
5026
}
27+
28+
// Get account sid and auth token
29+
accountDetails = await promptForAccountDetails(config);
30+
config = { ...accountDetails, ...config };
31+
32+
// Scaffold project
33+
const spinner = ora();
34+
spinner.start('Creating project directories and files');
35+
await createDirectory(projectDir, 'functions');
36+
await createDirectory(projectDir, 'assets');
37+
await createEnvFile(projectDir, {
38+
accountSid: config.accountSid,
39+
authToken: config.authToken
40+
});
41+
await createExampleFunction(`${projectDir}/functions`);
42+
await createPackageJSON(projectDir, config.name);
43+
spinner.succeed();
44+
45+
// Download .gitignore file from https://github.com/github/gitignore/
46+
spinner.start('Downloading .gitignore file');
47+
await createGitignore(projectDir);
48+
spinner.succeed();
49+
50+
// Install dependencies with npm
51+
spinner.start('Installing dependencies');
52+
await installDependencies(projectDir);
53+
spinner.succeed();
5154
}
5255

5356
module.exports = createTwilioFunction;

0 commit comments

Comments
 (0)