In the previous articles, we took a little detour to understand the program
variable used in run()
function.
async function run(): Promise<void> {
console.log("program.resetPreferences:", program.resetPreferences);
// a Conf object creation with projectName.
// We do not know what Conf does yet and it is okay.
const conf = new Conf({ projectName: 'create-next-app' })
// My first thought, where did the program come from?
// Let’s find out by looking outside the run() function.
// We skipped Conf class but the program variable cannot be skipped.
// I know for a fact it is a global variable.
if (program.resetPreferences) {
conf.clear()
console.log(`Preferences reset successfully`)
return
}
if (typeof projectPath === 'string') {
projectPath = projectPath.trim()
}
Unknown here is Conf. Let’s find out what it is. You have knowns and unknowns and the goal is to make unknowns in your code to knowns as much as possible.
Conf
conf is a simple npm config handling for your app or module.
Let’s console.log this and find out what is in it.
- Prepare a build
npm run build
- Execute the command
npx create-my-app
This is what conf has
conf Conf {
_deserialize: [Function (anonymous)],
_serialize: [Function (anonymous)],
events: EventEmitter {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
[Symbol(kCapture)]: false
},
path: '/Users/ramunarasinga/Library/Preferences/create-next-app-nodejs/config.json'
}
I am thinking conf is used to persist some of your preferences chosen when you run create-next-app because the following is set just before closing the run function:
I initially made this tool to let command-line tools persist some data.
The above quote from the conf package documentation.
Conclusion
Conf is used to persist data such as preferences when you use command line tools
I am building a platform that explains best practices used in open source by elite programmers. Join the waitlist and I will send you the link to the tutorials once they are ready.
If you have any questions, feel free to reach out to me at ramu.narasinga@gmail.com
Get free courses inspired by the best practices used in open source.
About me:
Website: https://ramunarasinga.com/
Linkedin: https://www.linkedin.com/in/ramu-narasinga-189361128/
Github: https://github.com/Ramu-Narasinga
Email: ramu.narasinga@gmail.com
Top comments (0)