Skip to content

Commit

Permalink
Merge branch 'feature/cli_06' of github.com:nevermined-io/cli into fe…
Browse files Browse the repository at this point in the history
…ature/cli_06
  • Loading branch information
aaitor committed Oct 14, 2022
2 parents b3cef7b + f37ae27 commit 9beafd5
Show file tree
Hide file tree
Showing 52 changed files with 92 additions and 199 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
70 changes: 3 additions & 67 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,72 +1,8 @@
{
"env": {
"browser": true,
"es6": true,
"mocha": true
},
"extends": [
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": false
},
"project": "tsconfig.json",
"tsconfigRootDir": "."
},
"plugins": [
"@typescript-eslint",
"prettier"
"nevermined"
],
"rules": {
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/indent": "off",
"@typescript-eslint/member-delimiter-style": [
"warn",
{
"multiline": {
"delimiter": "none",
"requireLast": true
}
}
],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-useless-constructor": "warn",
"no-dupe-class-members": [
"warn"
],
"no-empty": [
"error",
{
"allowEmptyCatch": true
}
],
"no-restricted-properties": [
2,
{
"object": "describe",
"property": "only"
},
{
"object": "it",
"property": "only"
}
],
"no-useless-constructor": [
"off"
],
"prefer-destructuring": [
"warn"
],
"prettier/prettier": "warn"
"@next/next/no-html-link-for-pages": "off"
}
}
}
6 changes: 3 additions & 3 deletions .github/workflows/release-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '12.x'
node-version: '16'
registry-url: https://registry.npmjs.org/
- run: yarn install --frozen-lockfile
- run: yarn build
Expand Down
5 changes: 0 additions & 5 deletions .prettierrc

This file was deleted.

12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"scripts": {
"build": "tsc",
"prebuild": "rm -rf ./dist && mkdir ./dist && cp -r ./resources ./dist/resources",
"lint": "eslint --ignore-path .gitignore --ext .ts,.tsx .",
"lint:fix": "eslint --fix --ignore-path .gitignore --ext .ts,.tsx .",
"lint": "eslint ./",
"lint:fix": "npm run lint -- --fix",
"format": "prettier --parser typescript --ignore-path .gitignore --write '**/*.{js,jsx,ts,tsx}'",
"clean": "rm -rf ./dist/ ./doc/ ./.nyc_output",
"build:watch": "npm build --watch",
Expand All @@ -29,7 +29,7 @@
"cross-fetch": "~3.1.5",
"dotenv": "^16.0.1",
"eta": "1.12.3",
"ipfs-http-client-lite": "~0.3.0",
"ipfs-http-client-lite": "^0.3.0",
"log4js": "^6.5.2",
"tar": "^6.1.11",
"yargs": "^17.5.1"
Expand All @@ -42,10 +42,14 @@
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"eslint-config-alloy": "^4.3.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-nevermined": "^0.1.0",
"eslint-config-next": "^12.3.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.2.5",
"prettier": "^2.4.1",
"prettier-package-json": "^2.7.0",
"rollup": "^2.58.0",
"ts-jest": "^27.0.6",
"ts-node": "^10.3.0",
Expand Down
3 changes: 3 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('eslint-config-nevermined/prettier.config'),
};
8 changes: 4 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type CliCommands = typeof CliCommands
const cmdHandler = async (
cmd: keyof CliCommands,
argv: any,
requiresAccount: boolean = true
requiresAccount = true
) => {
let { verbose, network, accountIndex } = argv

Expand All @@ -46,7 +46,7 @@ const cmdHandler = async (

if (argv.json) {
// The `--json` parameter was given so we setup logs in json format
addLayout('json', function (config) {
addLayout('json', function () {
return function (logEvent) {
// we don't need separator as we only have one line, wich represents the output of the command
return JSON.stringify(logEvent) // + config.separator
Expand Down Expand Up @@ -145,8 +145,8 @@ const y = yargs(hideBin(process.argv))
.command(
'$0',
false,
() => {},
(argv) => {
() => ({}),
() => {
yargs.showHelp()
return process.exit()
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/accounts/fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const accountsFund = async (
const { verbose, token } = argv

let errorMessage = ''
let results: string[] = []
const results: string[] = []
logger.info(
chalk.dim(`Funding account: '${chalk.whiteBright(account.getId())}'`)
)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/accounts/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const accountsList = async (
config: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network, nftTokenAddress, address } = argv
const { verbose, nftTokenAddress } = argv

const token = await loadToken(nvm, config, verbose)

Expand Down
2 changes: 1 addition & 1 deletion src/commands/agreements/listAgreements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const listAgreements = async (
config: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network, did } = argv
const { did } = argv

logger.info(
chalk.dim(`Loading agreements for DID: '${chalk.whiteBright(did)}'\n`)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/agreements/showAgreement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const showAgreement = async (
config: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network, agreementId } = argv
const { agreementId } = argv

logger.info(
chalk.dim(
Expand Down
4 changes: 2 additions & 2 deletions src/commands/assets/downloadAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Logger } from 'log4js'
import { ExecutionOutput } from '../../models/ExecutionOutput'
import { ConfigEntry } from '../../models/ConfigDefinition'

const rl = readline.createInterface({
readline.createInterface({
input: process.stdin,
output: process.stdout
})
Expand All @@ -18,7 +18,7 @@ export const downloadAsset = async (
config: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network, did } = argv
const { did } = argv

logger.info(chalk.dim(`Downloading asset: ${did}`))

Expand Down
17 changes: 5 additions & 12 deletions src/commands/assets/getAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
InstantiableConfig
} from '@nevermined-io/nevermined-sdk-js/dist/node/Instantiable.abstract'

const rl = readline.createInterface({
readline.createInterface({
input: process.stdin,
output: process.stdout
})
Expand All @@ -25,7 +25,7 @@ export const getAsset = async (
config: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network, did, password } = argv
const { did } = argv

let agreementId

Expand All @@ -38,20 +38,13 @@ export const getAsset = async (

// const keyTransfer = await makeKeyTransfer()

// if (password) {
// const key = await keyTransfer.secretToPublic(keyTransfer.makeKey(password))
// account.babyX = key.x
// account.babyY = key.y
// account.babySecret = password
// }

logger.debug(chalk.dim(`Using account: '${account.getId()}'`))

if (argv.agreementId === '') {
if (!argv.agreementId) {
logger.info(chalk.dim(`Ordering asset: ${did}`))
agreementId = await nvm.assets.order(did, 'access', account)
} else {
;({ agreementId } = argv)
agreementId = argv.agreementId
}

logger.info(
Expand All @@ -73,7 +66,7 @@ export const getAsset = async (
argv.fileIndex
)
logger.info(chalk.dim(`Files downloaded to: ${path}`))
results = path
const results = path
// }

return {
Expand Down
14 changes: 3 additions & 11 deletions src/commands/assets/orderAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Logger } from 'log4js'
import { ExecutionOutput } from '../../models/ExecutionOutput'
import { ConfigEntry } from '../../models/ConfigDefinition'

const rl = readline.createInterface({
readline.createInterface({
input: process.stdin,
output: process.stdout
})
Expand All @@ -19,7 +19,7 @@ export const orderAsset = async (
config: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network, did, password } = argv
const { did } = argv

// TODO: Enable DTP when `sdk-dtp` is ready
// const keyTransfer = await makeKeyTransfer()
Expand All @@ -28,15 +28,7 @@ export const orderAsset = async (

logger.debug(chalk.dim(`Using account: '${account.getId()}'`))

let agreementId
// if (password) {
// const key = await keyTransfer.secretToPublic(keyTransfer.makeKey(password))
// account.babyX = key.x
// account.babyY = key.y
// account.babySecret = password
// agreementId = await nvm.assets.order(did, 'access-proof', account)
// } else {
agreementId = await nvm.assets.order(did, 'access', account)
const agreementId = await nvm.assets.order(did, 'access', account)
// }

logger.info(chalk.dim(`Agreement Id: ${agreementId}`))
Expand Down
5 changes: 2 additions & 3 deletions src/commands/assets/registerAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const registerAsset = async (
config: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network, metadata, assetType, password, encrypt } = argv
const { verbose, metadata, assetType, password } = argv
const token = await loadToken(nvm, config, verbose)

// TODO: Enable DTP when `sdk-dtp` is ready
Expand Down Expand Up @@ -55,7 +55,7 @@ export const registerAsset = async (

logger.debug(`Using Price ${argv.price}`)

const providerKey = await nvm.gateway.getBabyjubPublicKey()
await nvm.gateway.getBabyjubPublicKey()

const _files: File[] = []
let _fileIndex = 0
Expand Down Expand Up @@ -133,7 +133,6 @@ export const registerAsset = async (
const ddo = await nvm.assets.create(
ddoMetadata,
account,
// @ts-ignore
assetRewards,
['access']
// undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/assets/resolveDID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const resolveDID = async (
config: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network, did } = argv
const { did } = argv

logger.info(chalk.dim(`Resolving the asset: ${chalk.green(did)}`))

Expand Down
2 changes: 1 addition & 1 deletion src/commands/assets/retireDID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const retireDID = async (
config: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network, did } = argv
const { did } = argv

logger.info(chalk.dim(`Retiring the asset: ${did}`))

Expand Down
2 changes: 1 addition & 1 deletion src/commands/assets/searchAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const searchAsset = async (
config: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network, query, json, onlyMetadata } = argv
const { query, json, onlyMetadata } = argv

logger.info(chalk.dim(`Search using query: ${chalk.green(query)}`))

Expand Down
4 changes: 1 addition & 3 deletions src/commands/network/networkGetConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
ARTIFACTS_PATH,
loadNeverminedConfigContract,
StatusCodes
} from '../../utils'
Expand All @@ -8,7 +7,6 @@ import { Account, Nevermined } from '@nevermined-io/nevermined-sdk-js'
import { ExecutionOutput } from '../../models/ExecutionOutput'
import chalk from 'chalk'
import { ConfigEntry } from '../../models/ConfigDefinition'
import { ethers } from 'ethers'

export const networkGetConfig = async (
nvm: Nevermined,
Expand All @@ -17,7 +15,7 @@ export const networkGetConfig = async (
configEntry: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network } = argv
const { network } = argv

logger.info(
chalk.dim(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/network/networkList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const networkList = async (
configEntry: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
const { verbose, network, hideInternal } = argv
const { hideInternal } = argv

logger.info(chalk.dim(`Nevermined pre-configured networks:`))

Expand Down
Loading

0 comments on commit 9beafd5

Please sign in to comment.