Skip to content

Commit

Permalink
Merge pull request #24 from gandalf-network/staging
Browse files Browse the repository at this point in the history
Staging -> Prod [ Interactive CLI + ESM Support ]
  • Loading branch information
timigod authored Mar 24, 2024
2 parents f437a8b + a264634 commit ad47d5d
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 79 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ eyeofsauron generate

- -f, --folder [folder]: Set the destination folder for the generated files

- -j, --javascript : Specify if the generated files should be compiled to Javascript.
- -esm, --esModules : Generate JavaScript files as ESModules, utilizing `import` statements for module imports.

- -c, --commonJS : Generate JavaScript files as CommonJS modules, using `require` statements for module imports.

- -ts, --typescript : Generate TypeScript files.

### Using the Generated Files

Expand All @@ -42,7 +46,7 @@ Once you have successfully generated the necessary files and installed the requi
#### Initialization

```typescript
// index.ts
// Typescript

// Change eyeofsauron to whatever name you specified for the file generation
import Eye, { Source } from './eyeofsauron';
Expand All @@ -51,6 +55,27 @@ const privateKey = process.env.PRIVATE_KEY
const eye = new Eye({ privateKey })
```

```javascript
// ESModules

// Change eyeofsauron to whatever name you specified for the file generation
import Eye, { Source } from './eyeofsauron/index.js'

const privateKey = process.env.PRIVATE_KEY
const eye = new Eye({ privateKey })
```

```javascript
// CommonJS

// Change eyeofsauron to whatever name you specified for the file generation
const Eye = require('./eyeofsauron').default
const { Source } = require('./eyeofsauron')

const privateKey = process.env.PRIVATE_KEY
const eye = new Eye({ privateKey })
```

#### Get Activity

```typescript
Expand Down
122 changes: 91 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gandalf-network/eyeofsauron",
"version": "1.0.6",
"version": "1.0.7",
"description": "",
"main": "dist/index.js",
"bin": {
Expand Down Expand Up @@ -30,9 +30,11 @@
"@graphql-codegen/cli": "^5.0.2",
"axios": "^1.6.7",
"commander": "^12.0.0",
"inquirer": "^8.0.0",
"rimraf": "^5.0.5"
},
"devDependencies": {
"@types/inquirer": "^8.0.0",
"@types/jest": "^29.5.12",
"copyfiles": "^2.4.1",
"dotenv": "^16.4.5",
Expand Down
52 changes: 44 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@
#!/usr/bin/env node

import { Command } from 'commander';
import inquirer from 'inquirer';
import generate from './scripts/generate';

const program = new Command();

program
.name("Eye Of Sauron")
.version("1.0.0")
.description('A CLI tool for generating prebuilt functions to access the Gandalf Network')
.description('A CLI tool for generating prebuilt functions to access the Gandalf Network');

program
.command('generate')
.alias('g')
.description('Generate the prebuilt funtions')
.description('Generate the prebuilt functions')
.option('-f, --folder <folder>', 'Set the destination folder for the generated files')
.option('-j, --javascript', 'Use when generating Javascript files')
.action(async (options) => {
const folder = options.folder ? options.folder: 'eyeofsauron'
const generateJSFiles = options.javascript
await generate(folder, generateJSFiles);
.option('-ts, --typescript', 'Initialize as a TypeScript project.')
.option('-esm, --esModules', 'Initialize as an ESModules JavaScript project. i.e [ import Eye, { Source } from "./eyeofsauron/index.js" ]')
.option('-c, --commonJS', 'Initialize as a CommonJS JavaScript project. i.e [ const Eye = require("./eyeofsauron").default ]')
.allowUnknownOption()
.action(async (cliFlags) => {
let { folder, typescript, commonJS } = cliFlags;
let generateJSFiles = !typescript
let generateESMFiles = generateJSFiles && !commonJS

if (!folder) {
const answers = await inquirer.prompt([
{
type: 'input',
name: 'folder',
message: 'Set the destination folder for the generated files:',
default: 'eyeofsauron',
},
{
type: 'list',
name: 'language',
message: 'Select the language for generating the files:',
choices: ['javascript', 'typescript'],
default: 'javascript',
},
{
type: 'list',
name: 'moduleSystem',
message: 'Select the Javascript Module system for generating the JS files:',
choices: ['ESModules', 'CommonJS'],
default: 'ESModules',
when: (answers) => answers.language === 'javascript',
},
]);

folder = answers.folder;
generateJSFiles = answers.language === 'javascript'
generateESMFiles = generateJSFiles && answers.moduleSystem === 'ESModules';
}

await generate(folder, generateJSFiles, generateESMFiles);
});

program.parse(process.argv);
program.parse(process.argv);
2 changes: 1 addition & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const WATSON_URL = process.env.WATSON_URL as string;
export const WATSON_URL = "http://localhost:8080/public/gql" as string;
1 change: 1 addition & 0 deletions src/lib/plugins/custom-plugin/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ export interface RawGraphQLRequestPluginConfig extends RawClientSideBasePluginCo
* ```
*/
extensionsType?: string;
esModules?: boolean;
}
Loading

0 comments on commit ad47d5d

Please sign in to comment.