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

Commit af3031d

Browse files
committed
Fixes templates path.
Uses path.join instead of naiive string concatenation and __dirname to get the templates directory correct when run as a module.
1 parent 2b3f682 commit af3031d

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ const readdir = promisify(fs.readdir);
88
const copyFile = promisify(fs.copyFile);
99
const { COPYFILE_EXCL } = fs.constants;
1010
const stat = promisify(fs.stat);
11+
const path = require('path');
1112

12-
function createDirectory(path, dirName) {
13-
return mkdir(path + '/' + dirName);
13+
function createDirectory(pathName, dirName) {
14+
return mkdir(path.join(pathName, dirName));
1415
}
1516

1617
function createFile(fullPath, content) {
@@ -19,8 +20,8 @@ function createFile(fullPath, content) {
1920
});
2021
}
2122

22-
function createPackageJSON(path, name) {
23-
const fullPath = `${path}/package.json`;
23+
function createPackageJSON(pathName, name) {
24+
const fullPath = path.join(pathName, 'package.json');
2425
const packageJSON = JSON.stringify(
2526
{
2627
name: name,
@@ -45,37 +46,40 @@ function copyRecursively(src, dest) {
4546
return readdir(src).then(children => {
4647
return Promise.all(
4748
children.map(child =>
48-
stat(`${src}/${child}`).then(stat => {
49+
stat(path.join(src, child)).then(stat => {
4950
if (stat.isDirectory()) {
50-
return mkdir(`${dest}/${child}`).then(() =>
51-
copyRecursively(`${src}/${child}`, `${dest}/${child}`)
51+
return mkdir(path.join(dest, child)).then(() =>
52+
copyRecursively(path.join(src, child), path.join(dest, child))
5253
);
5354
} else {
5455
return copyFile(
55-
`./${src}/${child}`,
56-
`${dest}/${child}`,
56+
path.join(src, child),
57+
path.join(dest, child),
5758
COPYFILE_EXCL
58-
);
59+
).catch(console.error);
5960
}
6061
})
6162
)
6263
);
6364
});
6465
}
6566

66-
function createExampleFromTemplates(path) {
67-
return copyRecursively('./templates', path);
67+
function createExampleFromTemplates(pathName) {
68+
return copyRecursively(
69+
path.join(__dirname, '..', '..', 'templates'),
70+
pathName
71+
);
6872
}
6973

70-
function createEnvFile(path, { accountSid, authToken }) {
71-
const fullPath = `${path}/.env`;
74+
function createEnvFile(pathName, { accountSid, authToken }) {
75+
const fullPath = path.join(pathName, '.env');
7276
const content = `ACCOUNT_SID=${accountSid}
7377
AUTH_TOKEN=${authToken}`;
7478
return createFile(fullPath, content);
7579
}
7680

77-
function createNvmrcFile(path) {
78-
const fullPath = `${path}/.nvmrc`;
81+
function createNvmrcFile(pathName) {
82+
const fullPath = path.join(pathName, '.nvmrc');
7983
const content = versions.node;
8084
return createFile(fullPath, content);
8185
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ const fs = require('fs');
22
const { promisify } = require('util');
33
const writeGitignore = promisify(require('gitignore').writeFile);
44
const open = promisify(fs.open);
5+
const path = require('path');
56

67
function createGitignore(dirPath) {
7-
const fullPath = `${dirPath}/.gitignore`;
8+
const fullPath = path.join(dirPath, '.gitignore');
89
return open(fullPath, 'wx').then(fd => {
910
const stream = fs.createWriteStream(null, { fd: fd });
1011
return writeGitignore({ type: 'Node', file: stream });

0 commit comments

Comments
 (0)