Skip to content

Commit eb04332

Browse files
committed
Fix template path for the npm package to make it relative!
1 parent 1372039 commit eb04332

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-nodejs-project",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "An npm initializer to scaffold a node project and include basic tools like lint, testing, etc.",
55
"main": "src/index.js",
66
"bin": "src/index.js",

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ async function myPackage() {
1414
// First arg = path
1515
const destPath = path.resolve(process.argv[2]);
1616
const projectFolder = utils.normalizeName(destPath);
17+
const templatePath = path.join(__dirname, '..', 'template');
1718

1819
// TODO Include here a way to get "options" for the other args
1920

@@ -70,15 +71,15 @@ async function myPackage() {
7071
}
7172

7273
// Copy template files
73-
utils.copyDirRecursive('template', destPath);
74+
utils.copyDirRecursive(templatePath, destPath);
7475

7576
// TODO Copy license and update with project data
7677

7778

7879
// Update readme with project data
7980
let originalReadmeFile;
8081
try {
81-
originalReadmeFile = fs.readFileSync('./template/README.md', 'utf8');
82+
originalReadmeFile = fs.readFileSync(path.join(templatePath, 'README.md'), 'utf8');
8283
} catch (error) {
8384
throw error;
8485
}
@@ -94,7 +95,7 @@ async function myPackage() {
9495
// Update package.json with project data
9596
let originalPackageFile;
9697
try {
97-
originalPackageFile = fs.readFileSync('./template/package.json', 'utf8');
98+
originalPackageFile = fs.readFileSync(path.join(templatePath, 'package.json'), 'utf8');
9899
} catch (error) {
99100
throw error;
100101
}

src/utils/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function normalizeName(filepath) {
3232
*/
3333
function copyDirRecursive(currentPath = './', destPath = '../new') {
3434
let dest = path.resolve(destPath);
35+
let current = path.resolve(currentPath);
3536

3637
// Create the dest folder
3738
if (!fs.existsSync(dest)) {
@@ -40,9 +41,9 @@ function copyDirRecursive(currentPath = './', destPath = '../new') {
4041
}
4142

4243
// Read files in folder
43-
let files = fs.readdirSync(currentPath);
44+
let files = fs.readdirSync(current);
4445
for(file of files) {
45-
src = path.resolve(path.join(currentPath, file));
46+
src = path.resolve(path.join(current, file));
4647
dest = path.resolve(path.join(destPath, file));
4748

4849
if (fs.lstatSync(src).isDirectory()) {

0 commit comments

Comments
 (0)