moon-cli
moon-cli copied to clipboard
moon init err
Error: ENOENT: no such file or directory, open '/usr/local/lib/node_modules/moon-cli/template/config.json'
Huh, it seems to have not downloaded the template correctly. Can you check and see what the contents of /usr/local/lib/node_modules/moon-cli/template/ are?
ls: /usr/local/lib/node_modules/moon-cli/template/: No such file or directory
Odd, it looks like the template didn't download at all.
- Have you tried running it again?
- Make sure you are using the latest version of
moon-cli.
I have tried npm install moon-cli@latest -g again.
Now, moon -v is 0.1.1, but run ls /usr/local/lib/node_modules/moon-cli/ , there is not template folder.
That's odd. Moon reinstalls the latest moon-template whenever you run moon init. Have you tried that again?
Also, what platform are you on?
I have too this problem. I am was trying on ubuntu, version of cli is 0.11.0
A little late...but was also having this issue on Linux. Turns out was because the global install of moon-cli was with sudo, moon init also requires sudo to be able to save the latest template. There must be a better way to do this.
Not sure why this issue was closed - could it be reopened?
I had the same problem on MacOS.
The cause is the template path using __dirname, which resolves to /usr/local/lib/node_modules/moon-cli/bin/moon. Then deleting from within that protected dir fails.
// Download Template
const templatePath = path.join(__dirname, "/../template");
if(fs.existsSync(templatePath)) {
del(templatePath);
}
Could you use the cwd for the template dir? Since you're installing the template anew with each new project, does that template need to be installed in the global moon-cli dir rather than in the new project dir?
@ElliotPsyIT I can reopen it, but I guess you're going to need the correct permissions to run it. The problem with downloading it into the new project, is that a new project will come with a template directory that is literally a clone of itself.
I guess I can change how this works though. Instead of caching it, I can just reinstall each time.
So, if I understand the issue - moon-cli gets the source repo's template and replaces any existing one. This fails on MacOS if there is an existing template while deleting the old one, that is unless you use elevated permissions (sudo) when running the cli which permits the directory replacement.
My question is, do you need to actually write out a replacement template with each moon-cli run? Why not allow moon-cli to simply pull and use the repo's template with each run as it generates the new local project? This retains the repo template as the single source of truth for each cli run and avoids the write permission problems.
Apologies if I'm missing something ...
In exploring, I see that I can simply remove this code in bin/moon to avoid deleting a protected directory. In doing so, moon init works on MacOS without elevated privileges (sudo):
if(fs.existsSync(templatePath)) {
del(templatePath);
}
Wondering if you would you consider a pull request for this?
@ElliotPsyIT The reason I cannot download the template directly to the new location is that it also uses a templating engine format.
Each file is a template that moon-cli compiles, which is why the title and descriptions are added to the packages as needed. The reason that it is deleted before it is downloaded is to ensure that you are getting the latest version of the template.
A PR would break this and you would be stuck with an outdated template. I think a fix would be to download the template to a new location.
Possibly ~/.moon-template?
@kbrsh Ah, my apologies for not reading all through the download process to the compile step. I am a newbie, and obviously it shows. In any case, I like the idea of a dot file in the home dir for the template!
i really like moon, hope this will be fixed soon 👍
same here
Still having an issue with this. Seems the template downloads, but even if I create the file manually, config.json is removed upon running moon init <app-name>. Was anyone able to find a solution here? This was done with Moon CLI 0.1.1 and Moon version 0.11.0 as well as 1.0.0-beta.2.
Moon requires Moon CLI version 1.0.0-beta.2 to be compatible with Moon 1.0.0-beta.2. For v1, the new syntax is:
$ moon <app-name>
For now, I think the fix is just running it with sudo because Moon may not have permission to download the template. Alternatively, you may be using incompatible versions or invalid syntax. Let me know if these work and if not, let me know what the error is.
No dice with sudo. Seems the version of moon-cli downloaded when npm install moon-cli is run is still 0.1.1 (latest release). This still wants the syntax to be $ moon init <app-name> and I get the error Moon Err Command Not Found if I omit the init arg. Is there a new version of the CLI packaged in the 1.0.0 beta release of Moon? Else how do I download the new CLI version with the new init syntax?
@kbrsh got it working, thanks for the help!