ninjadev/nin

Definition of project root

Closed this issue · 2 comments

Most of the features of the nin backend depend on knowing the root directory of the current project.

Currently, two different methods for determining this are in use.

One, which is used by the serve command, the compiler etc. is to use the current working directory of the process as project root (i.e. the folder where the nin command was executed)

The other strategy, used at least by the nin generate command, is to check the current directory for the presence of a file called nin.json. If it can not be found in the current directory, the parent directory is searched. This process is repeated until the root of the file system is reached. If no nin.json is present, the nin command terminates.

We should decide on one common way of determing the project root for all parts of nin, to maintain a consistent API, with consistent behavior.

On my todolist is to change everything to use nin.json as root.
This allows us to run nin commands from all subdirectories within a project, which is occasionally quite useful!

Everything currently expects "projectDirectory" or whatever to be root.
A simple fix is to find root directory in the nin executable, and send that further in, that is changing

project = path.resolve(process.cwd(), project || '');
compile.compile(project);

to

project = path.resolve(process.cwd(), project || '');
projectRoot = utils.findRootFrom(project)
compile.compile(projectRoot);