make the script works from any folder

This commit is contained in:
Frédéric Harper
2022-04-22 11:01:11 -04:00
parent 65cef03328
commit 3e9435f5cf
3 changed files with 41 additions and 3 deletions

29
scripts/package-lock.json generated Normal file
View File

@@ -0,0 +1,29 @@
{
"name": "scripts",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"devDependencies": {
"app-root-path": "^3.0.0"
}
},
"node_modules/app-root-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/app-root-path/-/app-root-path-3.0.0.tgz",
"integrity": "sha512-qMcx+Gy2UZynHjOHOIXPNvpf+9cjvk3cWrBBK7zg4gH9+clobJRb9NGzcT7mQTcV/6Gm/1WelUtqxVXnNlrwcw==",
"dev": true,
"engines": {
"node": ">= 6.0.0"
}
}
},
"dependencies": {
"app-root-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/app-root-path/-/app-root-path-3.0.0.tgz",
"integrity": "sha512-qMcx+Gy2UZynHjOHOIXPNvpf+9cjvk3cWrBBK7zg4gH9+clobJRb9NGzcT7mQTcV/6Gm/1WelUtqxVXnNlrwcw==",
"dev": true
}
}
}

5
scripts/package.json Normal file
View File

@@ -0,0 +1,5 @@
{
"devDependencies": {
"app-root-path": "^3.0.0"
}
}

View File

@@ -1,8 +1,12 @@
'use strict;'
const fs = require('fs');
const appRoot = require('app-root-path');
let path = require('path');
//Get the data
const data = fs.readFileSync('../people.json');
path = path.parse(appRoot.path);
parentFolderPath = path.dir.split(path.sep).pop();
const data = fs.readFileSync(`${parentFolderPath}/people.json`);
const json = JSON.parse(data);
//Order by name
@@ -16,5 +20,5 @@ const peopleList = json.people.map(people =>
).join('\r\n');
//Write README.md
const template = fs.readFileSync('README-TEMPLATE.md', 'utf8');
fs.writeFileSync('../README.md', template.replace('PLACEHOLDER', peopleList));
const template = fs.readFileSync(`${appRoot}/README-TEMPLATE.md`, 'utf8');
fs.writeFileSync(`${parentFolderPath}/README.md`, template.replace('PLACEHOLDER', peopleList));