Skip to content

Commit 5ca27b6

Browse files
philnashdkundel
andauthored
feat(create-twilio-function): add deployinfo file to gitignore (#320)
Co-authored-by: Dominik Kundel <[email protected]>
1 parent 47051de commit 5ca27b6

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

packages/create-twilio-function/src/create-twilio-function/create-gitignore.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
const fs = require('fs');
2-
const path = require('path');
3-
const { promisify } = require('util');
1+
const { createWriteStream } = require('fs');
2+
const { join } = require('path');
3+
const gitignore = require('gitignore');
44

5-
const writeGitignore = promisify(require('gitignore').writeFile);
6-
7-
const open = promisify(fs.open);
5+
const ADDITIONAL_CONTENT = '# Twilio Serverless\n.twiliodeployinfo\n\n';
86

97
function createGitignore(dirPath) {
10-
const fullPath = path.join(dirPath, '.gitignore');
11-
return open(fullPath, 'wx').then((fd) => {
12-
const stream = fs.createWriteStream(null, { fd });
13-
return writeGitignore({
14-
type: 'Node',
15-
file: stream,
8+
return new Promise((resolve, reject) => {
9+
const fullPath = join(dirPath, '.gitignore');
10+
const stream = createWriteStream(fullPath, { flags: 'wx' });
11+
stream.on('error', reject);
12+
stream.write(ADDITIONAL_CONTENT, 'utf-8', (error) => {
13+
if (error) {
14+
reject(error);
15+
}
16+
gitignore.writeFile(
17+
{
18+
type: 'Node',
19+
file: stream,
20+
},
21+
(error) => {
22+
if (error) {
23+
reject(error);
24+
}
25+
resolve();
26+
}
27+
);
1628
});
1729
});
1830
}

packages/create-twilio-function/tests/create-gitignore.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe('create-gitignore', () => {
5757
});
5858
expect(contents).toMatch('*.log');
5959
expect(contents).toMatch('.env');
60+
expect(contents).toMatch('.twiliodeployinfo');
6061
cleanUp();
6162
});
6263

0 commit comments

Comments
 (0)