Skip to content

Commit

Permalink
initialize repo
Browse files Browse the repository at this point in the history
  • Loading branch information
haseebrabbani committed Jul 23, 2021
0 parents commit ecc45ef
Show file tree
Hide file tree
Showing 51 changed files with 10,487 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/dist
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Forta Agent CLI

## Installation

To install locally, run `npm install`, `npm run build` and then `npm run publish:local` (which just runs `npm link`). This will create a symlink to the local `dist` folder. You should only need to symlink once, and then any changes you make to the `dist` folder should be in effect

## Commands

After installing, you should have the `forta-agent` tool available. To see the possible commands, run `forta-agent help`. You can also see options for specific commands (e.g. `forta-agent test help`)
46 changes: 46 additions & 0 deletions cli/commands/init/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { join } from 'path'
import { AwilixContainer } from 'awilix'
import shelljs from 'shelljs'
import prompts from 'prompts'
import { assertExists, assertShellResult } from '../../utils'
import { CreateNewKeyfile } from '../../utils/create.new.keyfile'

export default function provideInit(
container: AwilixContainer
) {
assertExists(container, 'container')

return async function init(cliArgs: any) {

try {
// we manually inject dependencies here (instead of through the provide function above) so that
// we get RUNTIME errors if certain configuration is missing
const shell = container.resolve<typeof shelljs>("shell")
const createNewKeyfile = container.resolve<CreateNewKeyfile>("createNewKeyfile")

const isTypescript = !!cliArgs.typescript
console.log(`initializing ${isTypescript ? "Typescript" : "Javascript"} Forta Agent...`)
const starterProjectPath = `${join(__dirname, '..', '..', '..', 'starter-project')}`
// copy files from starter-project to current directory
const copyProjectResult = shell.cp('-r', [`${starterProjectPath}/*`, `${starterProjectPath}/.*`], '.')
assertShellResult(copyProjectResult, 'error copying starter-project folder')
// copy files out from js/ts folder
const copyJsTsResult = shell.cp('-r', isTypescript ? './ts/*' : './js/*', '.')
assertShellResult(copyJsTsResult, `error unpacking ${isTypescript ? 'ts' : 'js'} folder`)
// remove unused files/folders
const rmResult = shell.rm('-rf', 'js', 'ts', 'node_modules', '.git')
assertShellResult(rmResult, 'error cleaning up files')

// initialize keystore
console.log('creating new keyfile...')
const { password } = await prompts({
type: 'password',
name: 'password',
message: `Enter password to encrypt new keyfile`
})
await createNewKeyfile(password)
} catch (e) {
console.error(`ERROR: ${e.message}`)
}
}
}
Loading

0 comments on commit ecc45ef

Please # to comment.