Skip to content

Commit d3c2998

Browse files
authored
feat: base CLI project setup (#1)
* feat: base CLI project setup * fix: add sample files for successful test
1 parent b092812 commit d3c2998

21 files changed

+10403
-0
lines changed

.babelrc.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict'
2+
3+
module.exports = function (api) {
4+
const targets = 'node >=10'
5+
api.cache(true)
6+
api.cacheDirectory = true
7+
8+
return {
9+
presets: [
10+
'@babel/preset-typescript',
11+
[
12+
'@babel/preset-env',
13+
{
14+
corejs: 3,
15+
useBuiltIns: 'entry',
16+
modules: 'commonjs',
17+
bugfixes: true,
18+
targets
19+
}
20+
]
21+
],
22+
plugins: [
23+
['@babel/plugin-proposal-decorators', { legacy: true }],
24+
'@babel/plugin-proposal-class-properties',
25+
[
26+
'@babel/plugin-transform-runtime',
27+
{
28+
helpers: false,
29+
regenerator: true
30+
}
31+
]
32+
]
33+
}
34+
}

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[*]
2+
indent_style = space
3+
indent_size = 2
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true
6+
end_of_line = lf

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/**

.eslintrc.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
module.exports = {
2+
extends: ['plugin:@typescript-eslint/recommended'],
3+
parserOptions: {
4+
sourceType: 'module',
5+
ecmaVersion: 2018,
6+
},
7+
env: {
8+
jest: true,
9+
},
10+
globals: {
11+
browser: true,
12+
page: true,
13+
},
14+
plugins: ['jest'],
15+
rules: {
16+
'array-bracket-newline': ['error', { multiline: true }],
17+
strict: ['error', 'safe'],
18+
curly: 'error',
19+
'block-scoped-var': 'error',
20+
complexity: 'warn',
21+
'default-case': 'error',
22+
'dot-notation': 'warn',
23+
eqeqeq: 'error',
24+
'guard-for-in': 'warn',
25+
'linebreak-style': ['warn', 'unix'],
26+
'no-alert': 'error',
27+
'no-case-declarations': 'error',
28+
'no-constant-condition': 'error',
29+
'no-div-regex': 'error',
30+
'no-empty': 'warn',
31+
'no-empty-pattern': 'error',
32+
'no-implicit-coercion': 'error',
33+
'prefer-arrow-callback': 'warn',
34+
'no-labels': 'error',
35+
'no-loop-func': 'error',
36+
'no-nested-ternary': 'warn',
37+
'no-script-url': 'error',
38+
'no-warning-comments': 'warn',
39+
'quote-props': ['error', 'as-needed'],
40+
'require-yield': 'error',
41+
'max-nested-callbacks': ['error', 4],
42+
'max-depth': ['error', 4],
43+
'require-await': 'error',
44+
'space-before-function-paren': [
45+
'error', {
46+
anonymous: 'never',
47+
named: 'never',
48+
asyncArrow: 'always',
49+
},
50+
],
51+
'padding-line-between-statements': [
52+
'error',
53+
{ blankLine: 'always', prev: '*', next: 'if' },
54+
{ blankLine: 'always', prev: '*', next: 'function' },
55+
{ blankLine: 'always', prev: '*', next: 'return' },
56+
],
57+
'no-useless-constructor': 'off',
58+
'no-dupe-class-members': 'off',
59+
'no-unused-expressions': 'off',
60+
curly: ['error', 'multi-line'],
61+
'object-curly-spacing': ['error', 'always'],
62+
'comma-dangle': ['error', 'always-multiline'],
63+
'@typescript-eslint/no-useless-constructor': 'error',
64+
'@typescript-eslint/no-unused-expressions': 'error',
65+
'@typescript-eslint/member-delimiter-style': [
66+
'error', {
67+
multiline: {
68+
delimiter: 'none',
69+
requireLast: true,
70+
},
71+
singleline: {
72+
delimiter: 'comma',
73+
requireLast: false,
74+
},
75+
},
76+
],
77+
},
78+
overrides: [
79+
{
80+
files: ['*.spec.ts'],
81+
rules: {
82+
// '@typescript-eslint/ban-ts-ignore': 'off',
83+
'max-nested-callbacks': ['error', 10], // allow describe/it nesting
84+
},
85+
},
86+
],
87+
}

.github/workflows/check.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Check
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
node-version: [14.x]
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
with:
22+
fetch-depth: 0
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v1
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
28+
## Try getting the node modules from cache, if failed npm ci
29+
- uses: actions/cache@v2
30+
id: cache-npm
31+
with:
32+
path: node_modules
33+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
34+
restore-keys: |
35+
${{ runner.OS }}-node-${{ env.cache-name }}-
36+
${{ runner.OS }}-node-
37+
${{ runner.OS }}-
38+
- name: Install npm deps
39+
if: steps.cache-npm.outputs.cache-hit != 'true'
40+
run: npm ci
41+
42+
- name: Commit linting
43+
uses: wagoid/commitlint-github-action@v2
44+
45+
- name: Code linting
46+
run: npm run lint:check
47+
env:
48+
CI: true
49+
50+
- name: Build nodejs code
51+
run: npm run compile

.github/workflows/ci.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Node.js tests
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
pull_request:
8+
branches:
9+
- "**"
10+
11+
jobs:
12+
node-tests:
13+
env:
14+
REPLICA: 5
15+
BEE_URL: "http://bee-0.localhost"
16+
17+
runs-on: ubuntu-latest
18+
19+
strategy:
20+
matrix:
21+
node-version: [10.x, 12.x, 14.x]
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v2
26+
with:
27+
fetch-depth: 1
28+
29+
# Setup Bee environment
30+
- name: Install bee-local
31+
run: |
32+
sudo mv $(command -v brew){,_disable}
33+
export URL=$(curl -s https://api.github.com/repos/ethersphere/bee-local/releases/latest | jq -r .tarball_url)
34+
curl -Ls ${URL} -o bee-local.tar.gz
35+
tar --strip-components=1 --wildcards -xzf bee-local.tar.gz ethersphere-bee-local-*/{beeinfra.sh,helm-values,hack}
36+
sed -i 's/IMAGE_TAG="latest"/IMAGE_TAG="0.4.1"/' beeinfra.sh
37+
- name: Install latest beekeeper
38+
run: |
39+
export TAG=$(curl -s https://api.github.com/repos/ethersphere/beekeeper/releases/latest | jq -r .tag_name)
40+
curl -Ls https://github.com/ethersphere/beekeeper/releases/download/${TAG}/beekeeper-linux-amd64 -o beekeeper
41+
chmod +x beekeeper
42+
- name: Prepare testing cluster
43+
run: ./beeinfra.sh prepare --geth
44+
- name: Set kube config
45+
run: |
46+
mkdir -p ~/.kube
47+
cp $(k3d get-kubeconfig --name='k3s-default') ~/.kube/config
48+
- name: Set testing cluster
49+
run: |
50+
echo -e "127.0.0.10\tregistry.localhost" | sudo tee -a /etc/hosts
51+
for ((i=0; i<REPLICA; i++)); do echo -e "127.0.1.$((i+1))\tbee-${i}.localhost bee-${i}-debug.localhost"; done | sudo tee -a /etc/hosts
52+
./beeinfra.sh install -r "${REPLICA}" --geth
53+
54+
## Try getting the node modules from cache, if failed npm ci
55+
- uses: actions/cache@v2
56+
id: cache-npm
57+
with:
58+
path: node_modules
59+
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
60+
restore-keys: |
61+
${{ runner.OS }}-node-${{ matrix.node }}-${{ env.cache-name }}-
62+
${{ runner.OS }}-node-${{ matrix.node }}-
63+
- name: Install npm deps
64+
if: steps.cache-npm.outputs.cache-hit != 'true'
65+
run: npm ci
66+
- name: Run node tests
67+
run: npm run test
68+
69+
- name: Debug workflow if failed
70+
if: failure()
71+
run: |
72+
KEYS=$(curl -sSf -X POST https://relay.tunshell.com/api/sessions)
73+
curl -sSf -X POST -H "Content-Type: application/json" -d "{\"text\": \"**Bee JS**\nDebug -> \`sh <(curl -sSf https://lets.tunshell.com/init.sh) L $(echo $KEYS | jq -r .peer2_key) \${TUNSHELL_SECRET} relay.tunshell.com\`\"}" https://beehive.ethswarm.org/hooks/${{ secrets.WEBHOOK_KEY }}
74+
echo "Connect to github actions node using"
75+
echo "sh <(curl -sSf https://lets.tunshell.com/init.sh) L $(echo $KEYS | jq -r .peer2_key) \${TUNSHELL_SECRET} relay.tunshell.com"
76+
curl -sSf https://lets.tunshell.com/init.sh | sh /dev/stdin T $(echo $KEYS | jq -r .peer1_key) ${{ secrets.TUNSHELL_SECRET }} relay.tunshell.com

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
lib
2+
3+
# Logs
4+
logs
5+
*.log
6+
7+
# Runtime data
8+
pids
9+
*.pid
10+
*.seed
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
.nyc_output
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
build
23+
dist
24+
25+
# Dependency directory
26+
node_modules

.huskyrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hooks": {
3+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
4+
}
5+
}

.prettierrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"printWidth": 120,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"bracketSpacing": true,
6+
"quoteProps": "consistent",
7+
"semi": false,
8+
"singleQuote": true,
9+
"trailingComma": "all",
10+
"endOfLine": "lf",
11+
"arrowParens": "avoid"
12+
}

.vscode/launch.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Run Jest tests",
6+
"command": "npm run test",
7+
"type": "node-terminal",
8+
"request": "launch",
9+
"env": {
10+
"NODE_ENV": "development",
11+
"BEE_URL": "http://localhost:1633"
12+
}
13+
},
14+
15+
{
16+
"name": "vscode-jest-tests",
17+
"program": "${workspaceFolder}/node_modules/.bin/jest",
18+
"type": "node",
19+
"request": "launch",
20+
"env": {
21+
"NODE_ENV": "development",
22+
"BEE_URL": "http://localhost:1633"
23+
},
24+
"args": [
25+
"--runInBand",
26+
"--config",
27+
"jest.config.ts"
28+
],
29+
"console": "integratedTerminal",
30+
"disableOptimisticBPs": true,
31+
"windows": {
32+
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
33+
}
34+
}
35+
]
36+
}

.vscode/settings.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"editor.codeActionsOnSave": {
3+
// For ESLint
4+
"source.fixAll.eslint": true,
5+
// For TSLint
6+
"source.fixAll.tslint": true,
7+
// For Stylelint
8+
"source.fixAll.stylelint": true
9+
},
10+
"eslint.validate": ["javascript", "typescript"],
11+
"editor.formatOnSave": true,
12+
"[javascript]": {
13+
"editor.formatOnSave": false
14+
},
15+
"[typescript]": {
16+
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
17+
"editor.codeActionsOnSave": {
18+
"source.fixAll.eslint": true
19+
},
20+
"editor.formatOnSave": true
21+
},
22+
"[json]": {
23+
"editor.defaultFormatter": "esbenp.prettier-vscode",
24+
"editor.codeActionsOnSave": {
25+
"source.fixAll.eslint": true
26+
},
27+
"editor.formatOnSave": true
28+
},
29+
"[markdown]": {
30+
"editor.formatOnSave": false
31+
},
32+
"search.exclude": {
33+
"**/node_modules": true,
34+
"**/dist": true,
35+
"**/coverage": true
36+
},
37+
"typescript.referencesCodeLens.enabled": true,
38+
"jest.runAllTestsFirst": false
39+
}

0 commit comments

Comments
 (0)