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

Commit cfab82c

Browse files
committed
Uses gitignore package to get gitignore file from GitHub.
1 parent d9be9b3 commit cfab82c

File tree

5 files changed

+18
-88
lines changed

5 files changed

+18
-88
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
"license": "MIT",
2525
"devDependencies": {
2626
"jest": "^24.5.0",
27+
"nock": "^10.0.6",
2728
"rimraf": "^2.6.3"
2829
},
2930
"dependencies": {
31+
"gitignore": "^0.6.0",
3032
"inquirer": "^6.2.2",
3133
"ora": "^3.2.0",
3234
"pkg-install": "^1.0.0",

src/create-twilio-function.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,23 @@ async function createTwilioFunction(config) {
2020
config = { ...accountDetails, ...config };
2121

2222
// Scaffold project
23-
const spinner = ora('Creating project directories and files').start();
23+
const spinner = ora();
24+
spinner.start('Creating project directories and files');
2425
await createDirectory(projectDir, 'functions');
2526
await createDirectory(projectDir, 'assets');
2627
await createEnvFile(projectDir, {
2728
accountSid: config.accountSid,
2829
authToken: config.authToken
2930
});
30-
await createGitignore(projectDir);
3131
await createExampleFunction(`${projectDir}/functions`);
3232
await createPackageJSON(projectDir, config.name);
3333
spinner.succeed();
3434

35+
// Download .gitignore file from https://github.com/github/gitignore/
36+
spinner.start('Downloading .gitignore file');
37+
await createGitignore(projectDir);
38+
spinner.succeed();
39+
3540
// Install dependencies with npm
3641
spinner.start('Installing dependencies');
3742
await installDependencies(projectDir);

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
const fs = require('fs');
22
const { promisify } = require('util');
3-
const readFile = promisify(fs.readFile);
3+
const writeGitignore = promisify(require('gitignore').writeFile);
44
const open = promisify(fs.open);
5-
const write = promisify(fs.write);
65

7-
async function createGitignore(dirPath) {
6+
function createGitignore(dirPath) {
87
const fullPath = `${dirPath}/.gitignore`;
9-
const content = await readFile(`${__dirname}/../../templates/.gitignore`);
108
return open(fullPath, 'wx').then(fd => {
11-
return write(fd, content);
9+
const stream = fs.createWriteStream(null, { fd: fd });
10+
return writeGitignore({ type: 'Node', file: stream });
1211
});
1312
}
1413

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// const nock = require('nock');
1+
const nock = require('nock');
22
const createGitignore = require('./create-gitignore');
33
const { promisify } = require('util');
44
const rimraf = promisify(require('rimraf'));
@@ -13,6 +13,9 @@ beforeAll(async () => {
1313

1414
beforeEach(async () => {
1515
await mkdir('./scratch');
16+
nock('https://raw.githubusercontent.com')
17+
.get('/github/gitignore/master/Node.gitignore')
18+
.reply(200, '*.log\n.env');
1619
});
1720

1821
afterEach(async () => {
@@ -28,6 +31,7 @@ describe('createGitignore', () => {
2831
encoding: 'utf-8'
2932
});
3033
expect(contents).toMatch('*.log');
34+
expect(contents).toMatch('.env');
3135
});
3236

3337
test('it rejects if there is already a .gitignore file', async () => {

templates/.gitignore

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)