0%

Create npm repo

I need to simulate a npm repo to test codes. The following steps are how to create a npm repo.

Create a npm account

Go to npmjs.com, click “join for free”, then create your account. The weird thing is the password needs at least 10 characters!

Create a npm repo on your local terminal

1
mkdir npm_own

Copy github.com/treehouses/cli package.json url to local

Because I want to test the code on github.com/treehouses/cli and don’t want to mess up the current repo, I copy the url to my local

1
wget https://github.com/treehouses/cli/blob/master/package.json

Create your own package.json

I try to create a repo named “flyingsaucer8”.
Using vim to make my own package.json based on treehouses package.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
"name": "flyingsaucer8",
"version": "0.0.6",
"description": "flyingsaucer",
"main": "cli.sh",
"bin": {
"flyingsaucer": "cli.sh"
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/vmnet8/flyingsaucer.git"
},
"scripts": {
"postinstall": "if [ $(id -u) = 0 ]; then ln -sr _flyingsaucer /etc/bash_completion.d/_flyingsaucer; fi && exit 0",
"postuninstall": "if [ $(id -u) = 0 ]; then rm /etc/bash_completion.d/_flyingsaucer; fi && exit 0",
"test": "echo \"Error: no test specified\" && exit 0"
},
"keywords": [
"flyingsaucer"
],
"author": {
"name": "flyingsaucer team",
"email": "alien@flyingsaucer.io",
"url": "https://flyingsaucer.io"
},
"license": "AGPL-3.0",
"bugs": {
"url": "https://github.com/vmnet8/flyingsaucer/issues",
"email": "alien@flyingsaucer.io"
},
"homepage": "https://github.com/vmnet8/flyingsaucer",
"dependencies": {}
}

npm publish

1
2
3
4
5
pi@treehouses:~/git_repo/npm_own:npm login
Username:vmnet8
password:
Email:(This IS Public)vmnet8@gmail.com
Logged in as vmnet8 on https://registry.npmjs.org/.

then you can publish your repo to npm

1
pi@treehouses:~/git_repo/npm_own:npm publish --access=public

Right now, you know how to push your code to npmjs repo

copy other code from github.com/treehouses/cli

1
2
wget https://github.com/treehouses/cli/blob/master/cli.sh
wget https://github.com/treehouses/cli/blob/master/_treehouses

I need to copy globals.sh and other modules, I only copied speedtest and detectpi.

1
2
3
wget https://github.com/treehouses/cli/blob/master/modules/speedtest.sh
wget https://github.com/treehouses/cli/blob/master/modules/globals.sh
wget https:eehouses/cli/blob/master/modules/detectrpi.sh

change the cli.sh and _treehouses to fit my situation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash

SCRIPTPATH=$(realpath "$0")
SCRIPTFOLDER=$(dirname "$SCRIPTPATH")

source "$SCRIPTFOLDER/modules/globals.sh"
source "$SCRIPTFOLDER/modules/detectrpi.sh"
source "$SCRIPTFOLDER/modules/speedtest.sh"



case $1 in
detectrpi)
detectrpi
;;
speedtest)
shift
speedtest "$@"
;;
help)
help "$2"
;;
*)
help
;;
esac

Notice: I am supposed to keep globals.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash

_treehouses_complete()
{
local cur prev

# Valid top-level completions
commands="detectpi speedtest"
help_cmds="detectpi speedtest"

# services_cmds="" Think about it, a little bit complicated

# upgrade_cmds="" I am not sure whether we should put autocompletion here.



COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}

if [ $COMP_CWORD -eq 1 ]
then
COMPREPLY=( $(compgen -W "${commands}" -- $cur) )
elif [ $COMP_CWORD -eq 2 ]
then
case "$prev" in
"help")
COMPREPLY=( $(compgen -W "$help_cmds" -- $cur) )
;;
"*")
;;
esac
elif [ $COMP_CWORD -eq 3 ]
then
case "$prev" in
"console")
COMPREPLY=( $(compgen -W "$bootoption_second_cmds" -- $cur) )
;;
"desktop")
COMPREPLY=( $(compgen -W "$bootoption_second_cmds" -- $cur) )
;;
"notice")
COMPREPLY=( $(compgen -W "$notice_cmds" -- $cur) )
;;
"*")
;;
esac
fi

}
complete -F _treehouses_complete treehouses

then I need to add execute to cli.sh and _flyingsaucer

1
2
pi@treehosues:~/git_repo/npm_own/ $chmod +x cli.sh
pi@treehosues:~/git_repo/npm_own/ $chmod +x _flyingsaucer

install npm package

Go to my local terminal to install npm package

1
pi@treehosues:~/git_repo/npm_own/ $ sudo npm install -g flyingsaucer8

test

After npm installed, I can test on my local maching if the bash completion works

1
2
3
4

pi@treehouses:~/git_repo/npm_own/ $ cd /etc/bash_completion
pi@treehouses:~/etc/bash_completion $ ls -al
lrwxrwxrwx 1 root root 54 Oct 17 07:09 _treehouses -> ../../usr/lib/node_modules/@treehouses/cli/_treehouses

It shows the symbolic doesn’t work.

1
2
3
 
pi@treehouses:~/git_repo/npm_own/ $ flyingsaucer speedtest
pi@treehouses:~/git_repo/npm_own/ $ flyingsaucer detectpi

It shows speedtest works well, but detectpi doesn’t