I have the following, standard folder structure within my generator. The task I am current struggling with is I currently have a templated _package.json that I write to disk for the main generation. There is one variable in the written package.json I would like to hydrate which is the actual version of the generator project. Basically, I want to be able to determine via the new generated api project's package.json which version of the generator was used to construct the project, so that I can target older versions and mark them for updates.
I have tried to accomplish this in both various generator steps like prompting.js and writing.js and via the following code:
var fs = require('fs');
let pkgGeneratorAPIVersion = JSON.parse(fs.readFileSync('../../package.json', 'utf8'));
but it isn't working. I keep getting the following error:
Error: ENOENT: no such file or directory, open 'package.json'
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at module.exports.prompt.answers
I've tried various relative paths to no avail. Is there a better way to parse the json file? Is my relative path off? Any help is greatly appreciated.