Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
585fe94
upgrade libraries
Rusty-Beard May 2, 2023
8387d67
fix dependencies
s1owjke May 2, 2023
261fc74
fix e2e
Rusty-Beard May 2, 2023
c7bcbc6
fix e2e-scaffold
Rusty-Beard May 2, 2023
e124ade
fix fsevents error
Rusty-Beard May 3, 2023
0d1edb3
add repository field to package.json
Rusty-Beard May 3, 2023
979c1d2
update node version
Rusty-Beard May 3, 2023
cf9514a
update node version
Rusty-Beard May 3, 2023
4fdc382
replace graphql-tools with @graphql-tools/schema
Rusty-Beard May 3, 2023
1543f9a
self-review
Rusty-Beard May 3, 2023
e06d27b
fix imports, cli arguments descriptions, scaffold tests
Rusty-Beard May 3, 2023
f0c3ebb
fix project init
Rusty-Beard May 3, 2023
5729ad1
text improvements
Rusty-Beard May 3, 2023
dc335ec
add correct args for command handlers
Rusty-Beard May 3, 2023
0232d74
update test snapshot
Rusty-Beard May 3, 2023
345cd2c
ask for branching in case of softLimitError
Rusty-Beard May 3, 2023
2d73cd3
fix snapshot
Rusty-Beard May 3, 2023
eb65820
fix logic
Rusty-Beard May 3, 2023
02321d2
remove unused memfs lib
Rusty-Beard May 3, 2023
14e9d9e
remove workspace create ability
Rusty-Beard May 3, 2023
889affe
remove workspace create ability
Rusty-Beard May 3, 2023
82e4174
fixes
Rusty-Beard May 4, 2023
2a29adf
bump lib versions
Rusty-Beard May 5, 2023
bc70dce
improve logs
Rusty-Beard May 10, 2023
cd02db3
bump versions
Rusty-Beard May 10, 2023
c9a374f
Merge branch 'PRODUCT-1749' into PRODUCT-1003
Rusty-Beard May 10, 2023
102dfc9
fix test
Rusty-Beard May 10, 2023
08ef4e1
Merge branch 'master' into PRODUCT-1749
Rusty-Beard May 12, 2023
ec1f7e0
fix: usage of setTimeout
Rusty-Beard May 12, 2023
4869c16
fix: usage of setTimeout
Rusty-Beard May 12, 2023
29cd5c1
Merge branch 'PRODUCT-1749' into PRODUCT-1003
Rusty-Beard May 12, 2023
35d1b81
fix: add requiresArg
Rusty-Beard May 12, 2023
53bb7ce
Merge branch 'PRODUCT-1749' into PRODUCT-1003
Rusty-Beard May 12, 2023
ad76a47
feat: refactor templates, triggers
Rusty-Beard May 12, 2023
5844c8f
fix snapshot
Rusty-Beard May 12, 2023
28d4d39
fix: review
Rusty-Beard May 13, 2023
4d9602f
fix: gql query for logs
Rusty-Beard May 13, 2023
9eea8b7
Merge branch 'PRODUCT-1749' into PRODUCT-1003
Rusty-Beard May 13, 2023
8394e3d
Merge branch 'PRODUCT-1749' into PRODUCT-1928
Rusty-Beard May 13, 2023
7043f3f
feat: HttpError
Rusty-Beard May 13, 2023
bfed114
fix: proxy more errors
Rusty-Beard May 22, 2023
ed98cd0
update packages
Rusty-Beard May 22, 2023
2a08ee8
fix translations
Rusty-Beard May 22, 2023
d42cc01
update types
Rusty-Beard May 22, 2023
a8e85f1
fix name concat
Rusty-Beard May 22, 2023
1264a72
Merge branch 'PRODUCT-1749' into PRODUCT-1003
Rusty-Beard May 22, 2023
c230b94
Merge branch 'PRODUCT-1749' into PRODUCT-1928
Rusty-Beard May 22, 2023
3425d80
update packages
Rusty-Beard Jun 6, 2023
468fc9f
Merge branch 'PRODUCT-1749' into PRODUCT-1003
Rusty-Beard Jun 6, 2023
9d701d9
Merge branch 'PRODUCT-1749' into PRODUCT-1928
Rusty-Beard Jun 6, 2023
198d2fe
update packages
Rusty-Beard Jun 7, 2023
cc49303
update pkgs
Rusty-Beard Jun 20, 2023
1415c1e
Merge branch 'PRODUCT-1749' into PRODUCT-1928
Rusty-Beard Jun 20, 2023
b9c1e26
Merge branch 'PRODUCT-1749' into PRODUCT-1003
Rusty-Beard Jun 20, 2023
ba2c08f
update doc links, use function-types 2.0.0, without triggers.
Rusty-Beard Jun 21, 2023
2359cef
update trigger templates
Rusty-Beard Jun 21, 2023
8e4c2f4
update function-types
Rusty-Beard Jun 22, 2023
a540ba6
fix mocks generating
Rusty-Beard Jun 22, 2023
752e169
fix getMock
Rusty-Beard Jun 22, 2023
bcec60c
fix mock dir
Rusty-Beard Jun 22, 2023
785ec4a
generate mock based on function type
Rusty-Beard Jun 22, 2023
9d3d826
fix generated mock name during project init
Rusty-Beard Jun 22, 2023
9ac7eed
fix templates to match function-types lib 2.0.0
Rusty-Beard Jun 22, 2023
aaa5c9d
fix template package.json
Rusty-Beard Jun 22, 2023
1593144
remove destroy trigger, fix mocks
Rusty-Beard Jun 22, 2023
79ecc32
fix resolver template
Rusty-Beard Jun 22, 2023
7e25e0f
update links and readme
Rusty-Beard Jun 22, 2023
0ba0861
update readme
Rusty-Beard Jun 22, 2023
74e07d9
update readme
Rusty-Beard Jun 22, 2023
a330af6
remove .vscode
Rusty-Beard Jun 22, 2023
fba9f0b
Merge branch 'PRODUCT-1749' into PRODUCT-1003
Rusty-Beard Jun 22, 2023
f6f80c4
Merge branch 'PRODUCT-1749' into PRODUCT-1928
Rusty-Beard Jun 22, 2023
2434914
update strings
Rusty-Beard Jun 22, 2023
ce6af8c
Merge branch 'PRODUCT-1749' into PRODUCT-1928
Rusty-Beard Jun 22, 2023
9dcdfcf
Merge branch 'PRODUCT-1749' into PRODUCT-1003
Rusty-Beard Jun 22, 2023
27602bc
update logs description
Rusty-Beard Jun 22, 2023
0472e19
update pkgs
Rusty-Beard Jun 22, 2023
7e6541d
remove express
Rusty-Beard Jun 22, 2023
e788b63
update help
Rusty-Beard Jun 22, 2023
a5467bf
remove deploy functions
Rusty-Beard Jun 22, 2023
ec70508
fix snapshot
Rusty-Beard Jun 23, 2023
2987bf3
Merge branch 'PRODUCT-1749' into PRODUCT-1928
Rusty-Beard Jun 23, 2023
0b2ab32
Merge branch 'PRODUCT-1749' into PRODUCT-1003
Rusty-Beard Jun 23, 2023
1846ea0
Merge branch 'PRODUCT-1749' into PRODUCT-1928
Rusty-Beard Jun 26, 2023
54959dd
fix readme
Rusty-Beard Jun 26, 2023
02605e9
Merge remote-tracking branch '8base/feat-cli-upgrade' into PRODUCT-1928
Rusty-Beard Jun 26, 2023
c1541f7
update snapshot and readme
Rusty-Beard Jun 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 8base CLI [![Build Status](https://travis-ci.org/8base/cli.svg?branch=master)](https://travis-ci.org/8base/cli)

[**Sign Up for 8Base**](https://app.8base.com) 🤘 [**Documentation Home**](https://docs.8base.com) 📑 [**Getting Started**](https://docs.8base.com/getting-started/quick-start) 🚀 [**8base Plans**](https://www.8base.com/pricing)
[**Sign Up for 8Base**](https://app.8base.com) 🤘 [**Documentation Home**](https://docs.8base.com) 📑 [**Getting Started**](https://docs.8base.com/projects/backend/getting-started) 🚀 [**8base Plans**](https://www.8base.com/pricing)

The 8base Command Line Interface (CLI) makes it easy to generate custom functions and manage workspaces straight from the terminal.

Expand Down Expand Up @@ -37,27 +37,33 @@ $ 8base login --email="my@email.com" --password="myP@ssw0rd"
Once successfully authenticated, a file will be updated at `~/.8baserc` with a JSON payload for the authenticated session.

## Further Information
For more information about commands and configuration options, please refer the [8base CLI documentation](https://docs.8base.com/development-tools/cli). You can also learn about the different commands from the CLI by running `--help` with the package itself, or a given command.
For more information about commands and configuration options, please refer the [8base CLI documentation](https://docs.8base.com/projects/backend/development-tools/cli). You can also learn about the different commands from the CLI by running `--help` with the package itself, or a given command.

```
DESCRIPTION
The 8base Command Line Interface is a unified tool to manage your 8base workspaces services.
The 8base Command Line Interface is a unified tool to manage your 8base workspaces services.

USAGE
8base <command> [OPTIONS]
8base <command> [OPTIONS]

Use 8base command \`--help\` for information on a specific command. Use 8base help topics to view a list of available help topics. The synopsis for each command shows its parameters and their usage. Optional options are shown in square brackets.
Use 8base command `--help` for information on a specific command. Use 8base help topics to view a list of
available help topics. The synopsis for each command shows its parameters and their usage. Optional options
are shown in square brackets.

COMMANDS
8base backup <command> Backup commands.
8base configure Allows you to select a default workspace and retrieve the API endpoint URL.
8base deploy Deploys project described in 8base.yml config file from your current local directory to 8base server. You must be in the root directory of your local 8base project to use this command.
8base describe [name] Describes your 8base project’s functions and their types through 8base.yml file.
8base deploy Deploys project described in 8base.yml config file from your current local
directory to 8base server. You must be in the root directory of your local
8base project to use this command.
8base describe [name] Describes your 8base project’s functions and their types through 8base.yml
file.
8base environment <command> Environment commands.
8base export Exports current workspace data schema
8base generate <command> Generator for server and client side resources [aliases: g]
8base generate <command> Generator for server and client side resources [aliases: g]
8base import Imports 8base schema file and data to the current - or specified - workspace.
8base init [name] Initializes a new project with example directory structure and custom functions.
8base init [name] Initializes a new project with example directory structure and custom
functions.
8base invoke <name> Invokes a custom function in the production workspace.
8base invoke-local <name> Invokes the custom function in the local development workspace.
8base login Authenticates the command line user by letting them log into an 8base account.
Expand All @@ -69,9 +75,9 @@ COMMANDS
8base whoami Displays the current authenticated user.

OPTIONS
-v, --version Show version number [boolean]
-d, --debug Turn on debug logs [boolean]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
-d, --debug Turn on debug logs [boolean]
-h, --help Show help [boolean]
```

## Contributing
Expand Down
14 changes: 7 additions & 7 deletions e2e/tests/__snapshots__/help.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ COMMANDS
8base generate resolver <name> Generator for a custom resolver function.
8base generate scaffold <tableName> Generates CRUD screens for a table in a specific framework (framework availability: react)
8base generate task <name> Generator for a custom task function.
8base generate trigger <name> Generator for a custom trigger function.
8base generate trigger <tableName> Generator for a custom trigger function.
8base generate webhook <name> Generator for a custom webhook function.

OPTIONS
Expand Down Expand Up @@ -292,16 +292,16 @@ OPTIONS
`;

exports[`As a user, I can use help flag for see help information about \`[ 'generate', 'trigger' ]\`. 1`] = `
"8base generate trigger <name> [OPTIONS]
"8base generate trigger <tableName> [OPTIONS]

POSITIONALS
name The name of the trigger [string] [required]
tableName The name of table to make trigger for [string] [required]

OPTIONS
-d, --debug Turn on debug logs [boolean]
-h, --help Show help [boolean]
-t, --type The trigger type [string] [choices: "before", "after"]
-o, --operation Operation that invokes the trigger [string]
-t, --type The trigger type [string] [choices: "before", "after"] [default: "before"]
-o, --operation Operation that invokes the trigger [string] [choices: "create", "update", "delete"] [default: "create"]
-x, --mocks Included mocks dir and files [boolean] [default: true]
-s, --syntax Syntax for the generated file [string] [choices: "js", "ts"] [default: "ts"]
--silent Disable printing extra info to the console [boolean] [default: false]"
Expand All @@ -317,7 +317,7 @@ OPTIONS
-d, --debug Turn on debug logs [boolean]
-h, --help Show help [boolean]
-p, --path Path for the url (https:<endpoint>/<path>) [string]
-m, --method HTTP verb to invoke the function [string] [choices: "POST", "GET", "DELETE", "PUT"]
-m, --method HTTP verb to invoke the function [string] [choices: "POST", "GET", "DELETE", "PUT"] [default: "POST"]
-x, --mocks Included mocks dir and files [boolean] [default: true]
-s, --syntax Syntax for the generated file [string] [choices: "js", "ts"] [default: "ts"]
--silent Disable printing extra info to the console [boolean] [default: false]"
Expand Down Expand Up @@ -352,7 +352,7 @@ POSITIONALS
OPTIONS
-d, --debug Turn on debug logs [boolean]
-h, --help Show help [boolean]
-f, --functions List of functions [array] [default: ["resolver:resolver","task:task","webhook:webhook","trigger:trigger"]]
-f, --functions List of functions [array] [default: ["resolver:resolver","task:task","webhook:webhook","trigger:Users:create:before"]]
-e, --empty Skip examples [boolean] [default: false]
-x, --mocks Included mocks dir and files [boolean] [default: true]
-s, --syntax Syntax for the generated file [string] [choices: "js", "ts"] [default: "ts"]
Expand Down
9 changes: 5 additions & 4 deletions e2e/tests/__snapshots__/init.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ testdir_init
│ └── mocks
│ └── request.json
├── triggers
│ └── trigger
│ ├── handler.ts
│ └── mocks
│ └── request.json
│ └── Users
│ └── create
│ ├── before.ts
│ └── mocks
│ └── request.json
└── webhooks
└── webhook
├── handler.ts
Expand Down
3 changes: 2 additions & 1 deletion e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as cuid from '@paralleldrive/cuid2';
import * as yaml from 'js-yaml';
import stripAnsi from 'strip-ansi';
import { CLI_BIN } from './consts';
import { ProjectConfig } from '../src/common/context';

export const prepareTestEnvironment = async (
repName: string = cuid.createId(),
Expand Down Expand Up @@ -36,7 +37,7 @@ export const addResolverToProject = async (
await fs.writeFile(path.join(projectPath, subDir, funcName).concat(ext), code);
await fs.writeFile(path.join(projectPath, subDir, funcName).concat('.graphql'), graphQLData);
const yamlFilePath = path.join(projectPath, '8base.yml');
const yamlData: { functions: { [key: string]: any } } = <any>yaml.load(await fs.readFile(yamlFilePath, 'utf8'));
const yamlData = <ProjectConfig>yaml.load(await fs.readFile(yamlFilePath, 'utf8'));

yamlData.functions[funcName] = {
handler: {
Expand Down
4 changes: 2 additions & 2 deletions src/common/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export type WorkspaceConfig = {
readonly apiHost: string;
};

type Plugin = { name: string; path: string };
export type Plugin = { name: string; path: string };

export type ProjectConfig = {
functions: Object;
functions: Record<string, any>;
plugins?: Plugin[];
};

Expand Down
4 changes: 0 additions & 4 deletions src/config/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export class StaticConfig {
return this.staticData.pluginTemplatePath;
}

static get mockTemplatePath(): string {
return this.staticData.mockTemplatePath;
}

static get rootProjectDir(): string {
return this.staticData.projectDir;
}
Expand Down
4 changes: 2 additions & 2 deletions src/engine/commands/generate/commands/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ export default {

context.spinner.stop();

let eightBaseConfig: EightBaseConfig;
let eightBaseConfig;
try {
eightBaseConfig = <any>yaml.load(await fs.readFile('.8base.yml', 'utf8'));
eightBaseConfig = <EightBaseConfig>yaml.load(await fs.readFile('.8base.yml', 'utf8'));
} catch (err) {
if (err.code === 'ENOENT') {
throw new Error(translations.i18n.t('generate_scaffold_project_file_error', { projectFileName: '.8base.yml' }));
Expand Down
25 changes: 12 additions & 13 deletions src/engine/commands/generate/commands/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,29 @@ import yargs from 'yargs';

import { Context } from '../../../../common/context';
import { translations } from '../../../../common/translations';
import { ExtensionType, SyntaxType, TriggerType } from '../../../../interfaces/Extensions';
import { ExtensionType, SyntaxType, TriggerOperation, TriggerType } from '../../../../interfaces/Extensions';
import { ProjectController } from '../../../controllers/projectController';

type TriggerGenerateParams = {
name: string;
type?: string;
operation?: string;
tableName: string;
type: TriggerType;
operation: TriggerOperation;
mocks: boolean;
syntax: SyntaxType;
silent: boolean;
};

export default {
command: 'trigger <name>',
command: 'trigger <tableName>',

handler: async (params: TriggerGenerateParams, context: Context) => {
let { name, type, operation, mocks, syntax, silent } = params;

if (operation && !/[\w\d]+\.(create|update|delete)/.test(operation)) {
throw new Error(translations.i18n.t('generate_trigger_invalid_operation'));
}
const { tableName, type, operation, mocks, syntax, silent } = params;

await ProjectController.generateFunction(
context,
{
type: ExtensionType.trigger,
name,
name: tableName,
mocks,
syntax,
silent,
Expand All @@ -45,8 +41,8 @@ export default {
builder: (args: yargs.Argv): yargs.Argv =>
args
.usage(translations.i18n.t('generate_trigger_usage'))
.positional('name', {
describe: translations.i18n.t('generate_trigger_name'),
.positional('tableName', {
describe: translations.i18n.t('generate_trigger_table_name'),
type: 'string',
})
.option('type', {
Expand All @@ -55,11 +51,14 @@ export default {
type: 'string',
choices: Object.values(TriggerType),
requiresArg: true,
default: TriggerType.before,
})
.option('operation', {
alias: 'o',
describe: translations.i18n.t('generate_trigger_operation_describe'),
type: 'string',
choices: Object.values(TriggerOperation),
default: TriggerOperation.create,
requiresArg: true,
})
.option('mocks', {
Expand Down
11 changes: 6 additions & 5 deletions src/engine/commands/generate/commands/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import yargs from 'yargs';

import { Context } from '../../../../common/context';
import { translations } from '../../../../common/translations';
import { ExtensionType, SyntaxType } from '../../../../interfaces/Extensions';
import { ExtensionType, SyntaxType, WebhookMethod } from '../../../../interfaces/Extensions';
import { ProjectController } from '../../../controllers/projectController';

type WebhookGenerateParams = {
name: string;
path?: string;
method?: string;
path: string;
method: WebhookMethod;
mocks: boolean;
syntax: SyntaxType;
silent: boolean;
Expand All @@ -18,7 +18,7 @@ export default {
command: 'webhook <name>',

handler: async (params: WebhookGenerateParams, context: Context) => {
let { name, path, method, mocks, syntax, silent } = params;
const { name, path, method, mocks, syntax, silent } = params;

await ProjectController.generateFunction(
context,
Expand Down Expand Up @@ -55,7 +55,8 @@ export default {
alias: 'm',
describe: translations.i18n.t('generate_webhook_method_describe'),
type: 'string',
choices: ['POST', 'GET', 'DELETE', 'PUT'],
choices: Object.values(WebhookMethod),
default: WebhookMethod.post,
requiresArg: true,
})
.option('mocks', {
Expand Down
38 changes: 23 additions & 15 deletions src/engine/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Context } from '../../../common/context';
import { translations } from '../../../common/translations';
import { Colors } from '../../../consts/Colors';
import { ProjectController } from '../../controllers/projectController';
import { ExtensionType, SyntaxType } from '../../../interfaces/Extensions';
import { ExtensionType, SyntaxType, TriggerOperation, TriggerType } from '../../../interfaces/Extensions';
import { Interactive } from '../../../common/interactive';
import { DEFAULT_ENVIRONMENT_NAME } from '../../../consts/Environment';
import { StaticConfig } from '../../../config';
Expand Down Expand Up @@ -76,7 +76,7 @@ export default {

if (!empty && Array.isArray(functions)) {
functions.forEach(declaration => {
const [type, name] = declaration.split(':');
const [type, name, triggerOperation, triggerType] = declaration.split(':');

if (!(type in ExtensionType)) {
throw new Error(translations.i18n.t('init_invalid_function_type', { type }));
Expand All @@ -85,6 +85,10 @@ export default {
if (!name) {
throw new Error(translations.i18n.t('init_undefined_function_name'));
}

if (type === ExtensionType.trigger && !(triggerOperation in TriggerOperation && triggerType in TriggerType)) {
throw new Error(translations.i18n.t('init_incorrect_trigger'));
}
});
}

Expand Down Expand Up @@ -140,19 +144,23 @@ export default {
}

/* Generate project files before printing tree */
if (!empty && Array.isArray(params.functions)) {
if (!empty && Array.isArray(functions)) {
await Promise.all(
params.functions.map(async (declaration: string) => {
const [type, functionName] = declaration.split(':');

await ProjectController.generateFunction(context, {
type: <ExtensionType>type,
name: functionName,
mocks,
syntax,
projectPath: name,
silent: true,
});
functions.map(async (declaration: string) => {
const [type, functionName, triggerOperation, triggerType] = declaration.split(':');

await ProjectController.generateFunction(
context,
{
type: <ExtensionType>type,
name: functionName,
mocks,
syntax,
projectPath: name,
silent: true,
},
{ type: <TriggerType>triggerType, operation: <TriggerOperation>triggerOperation },
);
}),
);
}
Expand Down Expand Up @@ -192,7 +200,7 @@ export default {
alias: 'f',
describe: translations.i18n.t('init_functions_describe'),
type: 'array',
default: ['resolver:resolver', 'task:task', 'webhook:webhook', 'trigger:trigger'],
default: ['resolver:resolver', 'task:task', 'webhook:webhook', 'trigger:Users:create:before'],
})
.option('empty', {
alias: 'e',
Expand Down
2 changes: 1 addition & 1 deletion src/engine/commands/login/webLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'isomorphic-fetch';
import { SessionInfo } from '../../../interfaces/Common';
import { Utils } from '../../../common/utils';

export const webLogin = async (params: any, context: Context): Promise<SessionInfo> => {
export const webLogin = async (params: { w: string }, context: Context): Promise<SessionInfo> => {
context.spinner.start(context.i18n.t('login_in_progress'));
const session = cuid.createId();

Expand Down
Loading