-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ecc45ef
Showing
51 changed files
with
10,487 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`) | ||
} | ||
} | ||
} |
Oops, something went wrong.