Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

* Feature: `pos-cli exec liquid` command to execute Liquid code directly on an instance (supports `-f` flag to load from file, requires confirmation on production)
* Feature: `pos-cli exec graphql` command to execute GraphQL queries directly on an instance (supports `-f` flag to load from file, requires confirmation on production)
* Feature: `pos-cli test run` command to run tests using the tests module

## 5.5.0

* Feature: (GUI) Ability to add, edit and remove users
Expand Down
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,60 @@ If you need guidance or additional information about how to use a specific gener

pos-cli generate modules/core/generators/command --generator-help

### Executing Code

#### Execute Liquid

Execute Liquid code directly on your instance:

pos-cli exec liquid [environment] [code]

Example:

pos-cli exec liquid staging "{{ 'hello' | upcase }}"

You can also execute Liquid code from a file using the `-f` flag:

pos-cli exec liquid staging -f path/to/script.liquid

#### Execute GraphQL

Execute GraphQL queries directly on your instance:

pos-cli exec graphql [environment] [query]

Example:

pos-cli exec graphql staging "{ users(per_page: 5) { results { id email } } }"

You can also execute GraphQL from a file using the `-f` flag:

pos-cli exec graphql staging -f path/to/query.graphql

**Note:** When executing on production environments (environment name contains "prod" or "production"), you will be prompted for confirmation before execution.

### Running Tests

To run tests on your instance, you need to have the [tests module](https://github.com/Platform-OS/pos-module-tests) installed.

#### Run All Tests

pos-cli test run [environment]

Example:

pos-cli test run staging

This command runs all tests and streams the results in real-time, showing individual test outcomes and a summary at the end.

#### Run a Single Test

pos-cli test run [environment] [test-name]

Example:

pos-cli test run staging my_test

## Development

The `pos-cli gui serve` command uses a distinct build process for the GraphiQL interface located in the `gui/editor/graphql` directory.
Expand Down
59 changes: 59 additions & 0 deletions bin/pos-cli-exec-graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node

const fs = require('fs');
const { program } = require('commander');
const Gateway = require('../lib/proxy');
const fetchAuthData = require('../lib/settings').fetchSettings;
const logger = require('../lib/logger');
const { isProductionEnvironment, confirmProductionExecution } = require('../lib/productionEnvironment');

program
.name('pos-cli exec graphql')
.argument('<environment>', 'name of environment. Example: staging')
.argument('[graphql]', 'graphql query to execute as string')
.option('-f, --file <path>', 'path to graphql file to execute')
.action(async (environment, graphql, options) => {
let query = graphql;

if (options.file) {
if (!fs.existsSync(options.file)) {
logger.Error(`File not found: ${options.file}`);
process.exit(1);
}
query = fs.readFileSync(options.file, 'utf8');
}

if (!query) {
logger.Error("error: missing required argument 'graphql'");
process.exit(1);
}

const authData = fetchAuthData(environment, program);
const gateway = new Gateway(authData);

if (isProductionEnvironment(environment)) {
const confirmed = await confirmProductionExecution(environment);
if (!confirmed) {
logger.Info('Execution cancelled.');
process.exit(0);
}
}

try {
const response = await gateway.graph({ query });

if (response.errors) {
logger.Error(`GraphQL execution error: ${JSON.stringify(response.errors, null, 2)}`);
process.exit(1);
}

if (response.data) {
logger.Print(JSON.stringify(response, null, 2));
}
} catch (error) {
logger.Error(`Failed to execute graphql: ${error.message}`);
process.exit(1);
}
});

program.parse(process.argv);
59 changes: 59 additions & 0 deletions bin/pos-cli-exec-liquid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node

const fs = require('fs');
const { program } = require('commander');
const Gateway = require('../lib/proxy');
const fetchAuthData = require('../lib/settings').fetchSettings;
const logger = require('../lib/logger');
const { isProductionEnvironment, confirmProductionExecution } = require('../lib/productionEnvironment');

program
.name('pos-cli exec liquid')
.argument('<environment>', 'name of environment. Example: staging')
.argument('[code]', 'liquid code to execute as string')
.option('-f, --file <path>', 'path to liquid file to execute')
.action(async (environment, code, options) => {
let liquidCode = code;

if (options.file) {
if (!fs.existsSync(options.file)) {
logger.Error(`File not found: ${options.file}`);
process.exit(1);
}
liquidCode = fs.readFileSync(options.file, 'utf8');
}

if (!liquidCode) {
logger.Error("error: missing required argument 'code'");
process.exit(1);
}

const authData = fetchAuthData(environment, program);
const gateway = new Gateway(authData);

if (isProductionEnvironment(environment)) {
const confirmed = await confirmProductionExecution(environment);
if (!confirmed) {
logger.Info('Execution cancelled.');
process.exit(0);
}
}

try {
const response = await gateway.liquid({ content: liquidCode });

if (response.error) {
logger.Error(`Liquid execution error: ${response.error}`);
process.exit(1);
}

if (response.result) {
logger.Print(response.result);
}
} catch (error) {
logger.Error(`Failed to execute liquid: ${error.message}`);
process.exit(1);
}
});

program.parse(process.argv);
9 changes: 9 additions & 0 deletions bin/pos-cli-exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

const { program } = require('commander');

program
.name('pos-cli exec')
.command('liquid <environment> <code>', 'execute liquid code on instance')
.command('graphql <environment> <graphql>', 'execute graphql query on instance')
.parse(process.argv);
Loading
Loading