With help from @bzee I have created a way to build cross platform command line apps for SAFEnetwork and would like some testing and feedback.
You don’t have to be a developer to do this, but it helps! You will need access to alpha2 though.
Non devs who are familiar with the command line and installing things such as npm, building repos etc can help by trying it out as is: you will just build it and try it out, tell me what happened and offer any suggestions for improvements.
Devs can help in the same way, but also try creating your own command line utilities. It uses Nodejs so you will be creating Nodejs app, and packaging it for any of Linux, MacOS and Windows.
The CLI app authenticates via the SAFE Browser similar to desktop apps such as the Web Hosting Manager.
Let me know if you would like to help and which platform(s) you can test it on.
I get the following when building for the mock network:
$ npm run build-mock
> safecmd@0.0.2 build-mock C:\Users\benno\Documents\src\safe-cli-boilerplate
> mkdir -p ./dist/mock/node_modules/@maidsafe/safe-node-app/src/native/mock/ && cp -R node_modules/@maidsafe/safe-node-app/src/native/mock/*.* ./dist/mock/node_modules/@maidsafe/safe-node-app/src/native/mock/ && pkg -t host -o ./dist/mock/safecmd safecmd.js
The syntax of the command is incorrect.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! safecmd@0.0.2 build-mock: `mkdir -p ./dist/mock/node_modules/@maidsafe/safe-node-app/src/native/mock/ && cp -R node_modules/@maidsafe/safe-node-app/src/native/mock/*.* ./dist/mock/node_modules/@maidsafe/safe-node-app/src/native/mock/ && pkg -t host -o ./dist/mock/safecmd safecmd.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the safecmd@0.0.2 build-mock script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\benno\AppData\Roaming\npm-cache\_logs\2018-05-31T15_09_47_754Z-debug.log
Building for the live network (using npm run build) results in similar error output.
I’m assuming it’s because mkdir is not supported on Windows. The ‘The syntax of the command is incorrect.’ is the same when just executing mkdir in cmd.exe:
Ah, how to handle that. I might have seen an npm module for doing mkdir -p … not sure, but that might be handy. Let me know if you have any suggestions.
When running pkg I have had some issues in the past where it would give the following message — I just encountered it again a few times:
> pkg@4.3.1
> Error! Error: EBUSY: resource busy or locked, open 'C:\Users\benno\Documents\src\safe-cli-boilerplate\dist\prod\safecmd.exe'
Checking task manager, the program is not open or used. I can just remove the file and run pkg again. It might be worth removing a potential executable before running pkg.
When running npm install initially on a fresh repository with NODE_ENV="" will cause @maidsafe/safe-node-app to be installed without the mock libraries. So when building your CLI for the mock network, it should be npm install-ed with NODE_ENV=dev.
Running the production version (with Peruse) does not show me the expected test results:
I’ll take a look at it when I’ve got time tonight or tomorrow. The code seems to be quite okay at first glance. Great work on the readability of the README anyhow!
Thanks @bzee this is top feedback and help. BTW I didn’t test with Peruse, only SB and SB mock so please try that in case it’s a difference between them.
I ran the production version. The first time running it — when not having the app authorised yet — it will not give me the test results. The second time running, when the app is already authorised, I will get the full expected output. (This is when I have the ‘Apps can re-authenticate automatically’ enabled.)
Maybe I’m missing context, but the mkdir error in cmd.exe is normal in your example, because no (directory) argument given. The ‘-p’ option (or /p) however, isn’t supported by the mkdir of cmd.exe, if I’m not mistaken.
AFAIK you shouldn’t need sudo for this unless your system is incorrectly configured. nmp install -g <package> should work so you might want to look into that. I’m sorry but I don’t recall more about this even though I had that issue a long time ago.
Otherwise this looks petty good. It is supposed to give you a file listing [check] and then create a file on SAFE, read it back, and print some info about that [fail - but we know this doesn’t always work]
But Im failing already…
willie@sputnik:~$ cd projects/safe/
willie@sputnik:~/projects/safe$ npm install -g pkg
npm WARN deprecated simple-bufferstream@1.0.0: no longer maintained
npm WARN checkPermissions Missing write access to /usr/lib/node_modules
npm ERR! path /usr/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access ‘/usr/lib/node_modules’
npm ERR! { Error: EACCES: permission denied, access ‘/usr/lib/node_modules’
npm ERR! stack: ‘Error: EACCES: permission denied, access '/usr/lib/node_modules'’,
npm ERR! errno: -13,
npm ERR! code: ‘EACCES’,
npm ERR! syscall: ‘access’,
npm ERR! path: ‘/usr/lib/node_modules’ }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /home/willie/.npm/_logs/2018-06-01T21_11_36_135Z-debug.log
willie@sputnik:~/projects/safe$ sudo !!
sudo npm install -g pkg
[sudo] password for willie:
npm WARN deprecated simple-bufferstream@1.0.0: no longer maintained
npm ERR! code ERR_STREAM_WRITE_AFTER_END
npm ERR! write after end
npm ERR! A complete log of this run can be found in:
npm ERR! /home/willie/.npm/_logs/2018-06-01T21_12_08_372Z-debug.log
willie@sputnik:~/projects/safe$
I’m not sure Willie but thanks for trying. I think there’s a better solution (which will avoid using ‘-g’) but haven’t time to try it out for a few days but will get back to you about that.
That npm error is the same as I had. It’s the access to /usr/lib/ that’s obviously a problem but I don’t think that’s mis-configured, it’s just normal for /usr/lib/ and given it’s just the install of pkg, I’d suggest do that with > sudo npm install -g pkg
That will work then as it does here on Linux Mint 18.1… though what I see is different each time… sometimes it sees all of this result, other times part of it.
Quick Setup Completed
New file is created and saved to the network successfully
The file has been opened and read
The content of the file which has been read: Hello Safe World
These are separate issues, as you probably realise. The npm -g issue is something I no longer experience although I did in the past and fixed it. So I never need sudo for that now. I can’t recall how I fixed it, but it’s a common problem.
The second issue, sometimes getting the output you quoted, sometimes not, is known but not yet solved.
In the mean time Benno has pushed a fix which might avoid the first issue by installing pkg locally. If you want to test this:
sudo npm remove -g pkg
# cd into your CLI folder
git pull
npm install
I haven’t tested this myself so the above might be wrong, but if you want to try it…