Testers wanted for boilerplate to create CLI apps (Mac, Windows, Linux)

cli
testers

#1

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.

UPDATE:
Announced on the main forum:


SAFE FUSE - mount your SAFE storage as virtual drive
#2

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.


#3

Um, might be I incorrectly removed the backslash escapes for the @ symbol (as in \@ or \\@). Can’t test atm though, am sitting by the canal in the :sun_with_face:

Are you on Windows? That might be a reason it works for me (on Linux).


#4

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:

image


#5

Ah, how to handle that. :thinking: 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.


#6

@happybeing check out fs-extra for this sort of thing. It’s got a few more features than the baked in fs module in node.


#7

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:

$ ./dist/prod/safecmd.exe
.git - 0 B
.gitignore - 998 B
dist - 0 B
LICENSE - 34.32 KB
node_modules - 0 B
package-lock.json - 57.46 KB
package.json - 1.8 KB
README.md - 4.86 KB
safe-app-cli.js - 3.61 KB
safecmd.js - 3.04 KB

Safe.bootstrap() with appInfo: {"id":"example","name":"example","vendor":"example"}
getLibPath() returning:  C:\Users\benno\Documents\src\safe-cli-boilerplate\dist\prod\node_modules\@maidsafe\safe-node-app\src\native
ipcReceive(13488)
on(auth-uri) handling data.message: safe-zxhhbxbszq:AQAAAGmfrS0AAAAAAAAAACAAAAAAAAAAGW0xrwF64M-KNSNNDVNj9Xyl43dUmZpbRAi8cLKNjRMgAAAAAAAAAFwWRmh-TPNFCVflZY5MZxATm4XyK6PGJXZse8EeywEXIAAAAAAAAAD6DpJ4mXTIy68xPbwpq2CX8Y8TDQFTC0p_Nx-HivX6mEAAAAAAAAAATECF6rgAmH6S58YImJeYK-Q4z1c51hz21ATAL3JkDOX6DpJ4mXTIy68xPbwpq2CX8Y8TDQFTC0p_Nx-HivX6mCAAAAAAAAAAX90MVn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I68pg6AAAAAAAAGAAAAAAAAAADQ6aRvJ1eda-I-zx2D8iqfBRThG8d_koAAAAAAAAAAA

Similar when running the mock version (with Peruse Mock) — except it shows the Quick Setup Completed:

$ ./dist/mock/safecmd.exe
.git - 0 B
.gitignore - 998 B
dist - 0 B
LICENSE - 34.32 KB
node_modules - 0 B
package-lock.json - 57.46 KB
package.json - 1.8 KB
README.md - 4.86 KB
safe-app-cli.js - 3.61 KB
safecmd.js - 3.04 KB

Safe.bootstrap() with appInfo: {"id":"example","name":"example","vendor":"example"}
getLibPath() returning:  C:\Users\benno\Documents\src\safe-cli-boilerplate\dist\mock\node_modules\@maidsafe\safe-node-app\src\native
ipcReceive(10292)
on(auth-uri) handling data.message: safe-zxhhbxbszq:AQAAAGRionsAAAAAAAAAACAAAAAAAAAAy8nRObr0cyi6pqiRXU55ey45U3UQRi5Mr173_5CPHV8gAAAAAAAAANmDASgIJz_VRudCVnKt2ti_dOIu4ID2jK0u8H-aw0k7IAAAAAAAAAAK-G8WE1jWpr1IY-nHSWauu-0eLCS0ki0z-rMrvCI0PUAAAAAAAAAAZrWcs0CH_QgJi92WGbbU16DuybhQPgnUmgI9WqQNjf8K-G8WE1jWpr1IY-nHSWauu-0eLCS0ki0z-rMrvCI0PSAAAAAAAAAAgsUTD-p-x7JfA3pOaLoupjOS9t8vP8YCrzShCRWiUAMgAAAAAAAAAJ-VZa1v20lOXtfBrswyCwTEnL9u4wRnLk5PTHfMTohvAAAAAAAAAAAAAAAAAAAAAJ0dV9feQqfJe1kHAJfzX6AW8dDwNaAFoZs4h3f98u1bmDoAAAAAAAAYAAAAAAAAAHGxX0pZV4FVDiFSltAD9B_bqufrQ6AREQAAAAAAAAAA
Quick Setup Completed

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!


#8

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.


#9

Using the SAFE Browser I’m getting further:

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.)


#10

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.


#11

Yes, that’s what I tried to show — that the error message comes from mkdir.


#12

:beer: + Linux =>

$ npm run build-mock

> safecmd@0.0.2 build-mock /home/safe/x/y/SAFE/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

sh: 1: pkg: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
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! spawn ENOENT
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!     /home/safe/.npm/_logs/2018-06-01T16_45_17_478Z-debug.log

btw trivial but broken link in safe-app-cli.js

github.com/project-decorum/decorum-lib/src/Safe.ts

perhaps should be

github.com/project-decorum/decorum-lib/blob/master/src/Safe.ts


#13

Thanks @davidpbrown. Very helpful. Please:

npm install -g pkg


#14

works as

sudo npm install -g pkg

Curious that it’s drawn macos and win…

$ npm run buildall-mock

> safecmd@0.0.2 buildall-mock /home/safe/x/y/SAFE/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 linux,macos,win -o ./dist/mock/safecmd safecmd.js

> pkg@4.3.1
> Fetching base Node.js binaries to PKG_CACHE_PATH
  fetched-v8.9.0-macos-x64     [====================] 100%
  fetched-v8.9.0-win-x64       [====================] 100%

Still it completed.

Environment is not quite right as then > To test with mock
fails

safe-browser: command not found

but I know enough to run yarn mock through to yarn run package from https://github.com/maidsafe/safe_browser and find that at ./safe_browser/dist/safe-browser-v0.10.2-linux-x64

then run as

./safe-browser

creating account
then

$ ./dist/mock/safecmd
.git - 4 KB
.gitignore - 998 B
LICENSE - 34.32 KB
README.md - 4.98 KB
dist - 4 KB
node_modules - 36 KB
package-lock.json - 57.46 KB
package.json - 1.8 KB
safe-app-cli.js - 3.61 KB
safecmd.js - 3.04 KB

Safe.bootstrap() with appInfo: {"id":"example","name":"example","vendor":"example"}
getLibPath() returning:  /home/safe/x/y/SAFE/safe-cli-boilerplate/dist/mock/node_modules/@maidsafe/safe-node-app/src/native
ipcReceive(18104)
on(auth-uri) handling data.message: safe-zxhhbxbszq:AQAAAF3Cs_0AAAAAAAAAACAAAAAAAAAATT1JDwMfzo2pSQd6ypHIA54OHSyGXf7Repk5E2gW8RMgAAAAAAAAAO6ffdu8lqeQbCvAKkk5Yc1vv2-HvgqiyjrGttzGQsWBIAAAAAAAAACuaTnss97oS4_Z6qFW-NW_2zTIJH0uBwHW2mpnzECiL0AAAAAAAAAA44xKlGJSxFFcckEDLsYjEPhSKaBc9alYpsBgbOT1AMCuaTnss97oS4_Z6qFW-NW_2zTIJH0uBwHW2mpnzECiLyAAAAAAAAAApVgqUEOdHX0IXkwLwfVimB9wD7sMZLw83q94k3w1KgkgAAAAAAAAAPOPz3u_ZdIaz2ziEyEfYQ9OsZdkvY3F52R341KKV3bAAAAAAAAAAAAAAAAAAAAAACDr2vxSSHmVeU0BzPgNv8ZPyW-QQYi1iIuUbgnwYfM3mDoAAAAAAAAYAAAAAAAAAEFdLql-yObxhzxBBNqzZP3sywi3EtoN9AAAAAAAAAAA

not sure what to make of that.
brain over for today… :+1:


#15

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]

If you re-run the command a few times you should see it succeed in both parts (you can see the expected out put here https://github.com/theWebalyst/safe-cli-boilerplate#to-test-with-mock).

Thanks very much for your help! :slight_smile:


#16

I can help on Ubuntu 18.04.

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$

Must have an incorrectly configured system… :frowning:


#17

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.

All these tests are helping a great deal. :slight_smile:


#18

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

#19

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… :slight_smile:


#20

@davidpbrown @southside @draw All those who have tested, please:

If you have done ‘npm install -g pkg’, this is no longer required so please:

sudo npm remove -g pkg

cd into your CLI folder

git pull
npm install

@bzee I think I’ve fixed the mkdir -p issue so please can you re-test on Windows.

We still have the intermittent error doing stuff on SAFE Network. Let me know if you still have issues with the build scripts. Thanks for testing! :slight_smile:

PS @joshuef the fix for mkdir -p in the build scripts was to switch to mkdirp. I’m not sure if fs-extra can be used in that way inside package.json?