GithubHelp home page GithubHelp logo

saleor / cli Goto Github PK

View Code? Open in Web Editor NEW
69.0 15.0 23.0 3.63 MB

Command-line interface allowing interaction with Saleor Cloud environments.

License: Other

JavaScript 3.04% TypeScript 96.64% Shell 0.05% Just 0.27%
saleor saleor-cli cli saleor-cloud

cli's Introduction

saleor-cli

Saleor CLI

Command-Line Interface for Saleor

Saleor CLI is designed to boost your productivity and improve development experience with Saleor and Saleor Cloud. It will take the burden of spawning new storefronts and apps locally, managing and connecting them with Saleor instances, or establishing tunnels for local development in seconds.

To install the latest version of Saleor CLI, run the following command:

npm i -g @saleor/cli

You can also use npx to execute the Saleor CLI commands on the spot without installing the package.

npx saleor env list

If you're using nvm, make sure that the NVM_BIN path is added to PATH

Getting Started with CLI

A quick demo

If you're new to Saleor you might want to start by bootstrapping an end-to-end local storefront development environment (and Saleor Cloud sandbox API instance). Since it requires Cloud access, you will be asked to register to a free Saleor Cloud developer account or log in. Then the command will automatically create your new local storefront environment and connect it to a newly created Saleor API instance/sandbox:

saleor storefront create --demo

Register

If you don't have a (free developer) Saleor Cloud account yet, create one with the following command:

saleor register

Login

The saleor binary requires the Cloud API token that can be obtained via OAuth by running the login command:

saleor login

This command will open a browser and ask for your Saleor Cloud credentials. Once logged in, it will store your Cloud API token locally for the CLI to use.

You can now start executing any of the available commands.

Note: in order to log out you can use saleor logout.

Create a storefront

The following command will take you through the process of creating a new react-storefront and configuring it with a chosen Saleor Cloud API instance:

saleor store create my-new-storefront

Create an API sanbox

You can create new API endpoints by running:

saleor env create

Saleor Apps management πŸ¦„

Please check out the Saleor App Template docs for the latest documentation.

Webhooks management

Coming soon πŸ”Œ

Usage

Usage: saleor <command> [options]

Commands:
  saleor info                    Hello from Saleor
  saleor status                  Show the login status for the systems that CLI depends on
  saleor login                   Log in to the Saleor Cloud
  saleor logout                  Log out from the Saleor Cloud
  saleor configure [token]       Configure Saleor CLI
  saleor register                Create a Saleor Cloud account  [aliases: signup]
  saleor trigger [event]         This triggers a Saleor event
  saleor organization [command]  [aliases: org]
  saleor environment [command]  [aliases: env]
  saleor backup [command]
  saleor job [command]
  saleor project [command]
  saleor storefront [command]  [aliases: store]
  saleor telemetry [command]  [aliases: tele]
  saleor webhook [command]  [aliases: hook]
  saleor app [command]
  saleor vercel [command]
  saleor github [command]
  saleor checkout [command]

Options:
      --json             Output the data as JSON  [boolean]
      --short            Output data as text  [boolean] [default: false]
  -u, --instance, --url  [string]
  -V, --version          Show version number  [boolean]
  -h, --help             Show help  [boolean]

for more information, find the documentation at https://saleor.io

Development

Install dependencies

This project uses pnpm for managing dependencies

pnpm install

Run Watch Mode

pnpm watch

Run CLI

node build/cli.js ...

Environment variables

RUN_FUNCTIONAL_TESTS

Set to true to enable functional tests

DEBUG

Use it for debugging. Set to saleor-cli:* to show debug output for the Saleor CLI only. Set to * to show all debug output.

Releasing CLI

Commands should be executed locally.

Pre-Release

  • pull latest changes from main, e.g.
git pull origin main
  • check for the type errors with pnpm tsc
  • check if the bundling finishes pnpm bundle
  • publishing step involves uploading source maps to Sentry, log in with sentry-cli login if you intend to upload source maps

Release

  • change to the selected release-* branch; all release-* branches are protected
git checkout release/X.Y

where X and Y is the selected version

  • compare the commits between latest release on that branch and the current main
git log --no-merges --cherry-pick --right-only release/X.Y...main
git cherry-pick SHA1 SHA2 SHA3

where SHA1, SHA2, SHA3 are SHAs selected to be included in the upcoming version

  • mark the new version in the package.json
  • commit the new release + add the tag
git commit -m 'Release X.Y.0'
git tag X.Y.Z
  • push the updated release branch to the origin
git push origin release/X.Y
  • push the new tag to the origin
git push origin --tags
  • publish from the release branch; use the next tag for the RC version
pnpm publish

or

pnpm publish --tag next

Important

CLI is currently published in an identical form to three packages in npmjs.com:

When releasing a new version, modify name in package.json to saleor-cli and saleor respectively and repeat pnpm publish step. Do not commit these package.json changes.

cli's People

Contributors

2can avatar cloud11pl avatar cmiacz avatar dependabot[bot] avatar karola312 avatar lkostrowski avatar magul avatar michalina-graczyk avatar mirekm avatar pawelpikus avatar timuric avatar wcislo-saleor avatar witoszekdev avatar zaiste avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cli's Issues

Prepare Github Action to release new version of CLI

Proposal

Create github action, can be "prepare release" or something like this

This can open a draft release with autogenerate changelogs for commit

Maintainers can prepare release message

After draft release is "released", npm publish should happen.

[CLI] it should be impossible to deploy an app without an env.

Steps to reproduce:

  1. Create some environment
  2. Create an app in that env.
  3. Remove created env.
  4. Do saleor app deploy on created app from step 2
  5. Use an URL which is provided

Current result:
I am getting an 404, but when I use login to saleor button then I am correctly logged in.
As a User I shouldn't get a possibility to deploy an app when environment doesn't exist anymore.

Expected result:
User is getting a warning message or user is not allowed to do this scenario.

Image

https://watch.screencastify.com/v/ZArinO9z2ux6dvdY2eJp

Lack of variables in the .env file results in tunnel error

Steps to reproduce:

  • clone app-template repo
  • start dev server
  • in the second terminal run saleor app tunnel
  • cli returns error ERROR 'app tunnel' must be run from the directory of your Saleor app
  • create an empty .env file - touch .env
  • now tunnel starts flawlessly

Verify the environment presence

Validate environment URL read from the .env file. If the environment is not present or accessible show an error.

The '.env' file with 'VARIABLE_NAME' not found.

to create env, run saleor app attach

Task linked
#211

cli dependencies

Discussed in https://github.com/saleor/saleor-cli/discussions/244

Originally posted by arshamkhodajoo August 4, 2022
Hi, hope you have great time
I followed https://learn.saleor.io/setup/prerequisites/ and tried to make storefront with saleor storefront create shop
after few minutes guessing some dependency conflicts (with [email protected] throws error required explicit @7.5.0)
now the command thows this error:
 ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  not found: next

  1. why there is no pre-requirement installation guide on website ?
  2. how to fix this error

[CLI] app deploy command improvement

Context

app deploy command needs time that app is deployed on vercel.

We can make this explicit for users

Proposed improvements

  • By default, CLI will hang and show loading/progress bar, when app is deploying
  • Manifest URL should be printed near deployment URL
  • Install link and command can be highlighted after deployment succeeded
  • For programmatic use, CLI should have flag or env variable (like CI=true) that will disable loading -> this is breaking change, so we can consider old behavior as default, and change it in v2

Prepare Github issue template

We want external contributors (and ourselves!) to provide best possible content opening issues.

Let's introduce issue templates!

Improve `app install`

  • skip name input when manifestURL is provided (use the name taken from manifest by default)
  • allow --name= option to overwrite manifestURL
  • add manifest-url to options

Submitting apps for review to marketplace

@lkostrowski Here's the requirement set from @mirekm

The flow is mostly implemented (roughly ~80%)

cc @magul


For the complete experience, we would like developers to be able to publish apps in the marketplace once they are done with coding and ready.

Something like:

saleor app publish <version> 

General assumptions:

  • MVP of publishing command would open PR for review in our marketplace repository
  • Let's wrap it up analogously to how npm publishing works (let's investigate in more details how does it work )
  • We would need apps versioning
  • We would need apps required Saleor's API
  • App versions would be the releases/tags in the app's repository
  • We would need some manifest with the general app's name/description/etc

Warn user about not supported Node version

Context

CLI doesn't work on Node <16 and we decided not to support lower versions. We must be sure our users are aware of it and CLI handles gracefully not supported environment

Proposed solution

  1. Check the existing node version (node -v) and compare it to engines field in package.json
  2. Print (on red!) there is a version mismatch each time CLI is spawned

Test CLI on Windows

There is the unresolved issue (Clickup 7534) that seems to be reproducible on Windows (only)

image

We should run the testing process on CLI on Windows.
Probably most of the developers in Saleor are developing on Mac/Unix - it's likely that we will not spot errors on Windows. We should consider running this test periodically

RequestError: Timeout awaiting 'request' for 2000ms

I just installed saleor-cli and tried saleor info, it threw below error after 3-5 tries and finally worked. It looks like timeout error is not handled properly.

Output (truncated) with a long TimeoutError exception object:

https://saleor.io/
https://cloud.saleor.io/
https://github.com/saleor/
node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

RequestError: Timeout awaiting 'request' for 2000ms
...

Saleor Commerce CLI v1.0.3
Node v16.13.1

Setup unit tests

Till now CLI was not tested

We need to introduce unit tests as a part of DoD. Before this is written we should ensure tests are set up properly.

This issue is complete, when I can

  • Add test file *.test.ts(x) or *.spec.ts(x)
  • Propose testing runner
  • Typescript loading is working properly

Additionally we can install https://github.com/jest-community/jest-extended

Include permissions descriptions to CLI listing

Context

saleor app permission listing shows only the keys

Zrzut ekranu 2022-07-27 o 15 27 28

Proposed solution

  1. Include description from API in the listings (all permission occurencies)
  2. Include docs link below Select one or more permissions. This way CLI can link do docs from existing context.

Checkout creation and deployment

  • Deployment of checkout together with Storefront is the critical path
  • We need a way to deploy checkout like storefront
  • We need to be able to create a template with storefront and checkout connected

Early validate if all envs are set (in Vercel)

Currently (tested for Klaviyo) app returns 200 and dashboard "thinks" it's installed. However not all envs were set in vercel.

app-template should validate - fail fast, return proper message

Saleor CLI + Saleor Platform integration

Context

CLI should allow to create entire Saleor stack for local development with a single command. Now, Saleor Platform must be discovered, while CLI is possibly the main developer's tool.

Solution

Introduce saleor bootstrap (or something like this) command. It will clone saleor-platform repo to selected directory and run make script to build it. Later, it will show instructions how to use it.

This command can be included in homepage of Saleor and Docs

Local CLI usage

At the moment, CLI only works for cloud and can be working with staging if env is set.

If local Docker container is running, CLI should use it as a target.

Introduce a way to alter this behavior. For example saleor.json file can be checked locally (created by CLI during bootstrap) and it can contain a localhost for container instead cloud URL. If saleor.json is not found, it can search in default location

Versioning

By default, CLI should bootstrap last stable platform project (with current submodules). However, platform should be versioned (tags), e.g v3.6, so users can go back.

This feature can be added in second iteration

Migrate saleor-cli to @saleor/cli

  • Move saleor-cli to @saleor org in NPM
  • Change implementation of saleor-cli to be proxy to @saleor-cli
  • Add deprecation message to saleor-cli executions
  • Update docs

Verify `storefront deploy` output

Verify the output of storefront deploy which should provide all necessary information for user.
Unify the output provided by storefront deploy with app deploy.

Handle gracefully limitied Vercel's access to Github

The CLI User should be notified that Vercel has no access to the Github repository the User is currently using.

To test that scenario you need to configure the Vercel application in Github Integrations:

  1. Go to https://github.com/settings/installations and click the Configure button in the row with Vercel.
  2. Authenticate yourself
  3. In the Repository access section choose at least one repository for which Vercel will have access. Use Save button to confirm.
  4. Test some Vercel command using github eg. saleor app deploy. Use repository for which the access hasn't been granted to the Vercel integration. As a result the following error message from Vercel should appear: ERROR The provided GitHub repository does not contain the requested branch or commit reference. Please ensure the repository is not empty.

Implemented in #246

Bug cannot install Cli Ubuntu 18.04 LTS

Just at the end of npm I get:

npm ERR! code 1 npm ERR! path /home/stgod/.nvm/versions/node/v16.2.0/lib/node_modules/saleor npm ERR! command failed npm ERR! command sh -c node ./build/scripts/binary.js install npm ERR! node:child_process:326 npm ERR! ex = new Error('Command failed: ' + cmd + '\n' + stderr); npm ERR! ^ npm ERR! npm ERR! Error: Command failed: ./vendor/tunnel --version npm ERR! ./vendor/tunnel: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.33' not found (required by ./vendor/tunnel)
npm ERR! ./vendor/tunnel: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.28' not found (required by ./vendor/tunnel) npm ERR! ./vendor/tunnel: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.32' not found (required by ./vendor/tunnel)
npm ERR! ./vendor/tunnel: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.34' not found (required by ./vendor/tunnel) npm ERR! npm ERR! at ChildProcess.exithandler (node:child_process:326:12) npm ERR! at ChildProcess.emit (node:events:365:28) npm ERR! at maybeClose (node:internal/child_process:1067:16) npm ERR! at Socket.<anonymous> (node:internal/child_process:453:11) npm ERR! at Socket.emit (node:events:365:28) npm ERR! at Pipe.<anonymous> (node:net:661:12) { npm ERR! killed: false, npm ERR! code: 1, npm ERR! signal: null, npm ERR! cmd: './vendor/tunnel --version', npm ERR! stdout: '', npm ERR! stderr: "./vendor/tunnel: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.33' not found (required by ./vendor/tunnel)\n" +
npm ERR! "./vendor/tunnel: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.28' not found (required by ./vendor/tunnel)\n" + npm ERR! "./vendor/tunnel: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.32' not found (required by ./vendor/tunnel)\n" +
npm ERR! "./vendor/tunnel: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./vendor/tunnel)\n"
npm ERR! }

npm ERR! A complete log of this run can be found in:
npm ERR! /home/stgod/.npm/_logs/2022-06-28T02_56_36_060Z-debug.log
`
Im using node version:

v16.15.1

Also, my ubuntu version is:

o LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.6 LTS Release: 18.04 Codename: bionic
Dont have any Idea what could be happening here.

Someone knows something bout this?
I'm not sure about what this "vendor-tunnel" is..

Global error handler with help reference

Context

When CLI has a problem it fails with raw js error printed to the console.

We want to provide the developer support at this point, giving some resources, help, possible solutions and link do support

Proposed solution

  1. Create a global error handler that will intercept thrown errors
  2. Create the error message template, that will include:
  • Information about required environment (see #200 )
  • Link do Github Issues
  • Link to docs

[CLI] Not enough described actions for GH login

Steps to reproduce the problem:

  1. Go to your apps folder as a logged-in GH user and logout on Vercel user
  2. Use saleor app deploy command

Current result:

User doesn't get a propper message what's wrong.

⠏ Starting a deployment in Vercel...errors:
  message: This endpoint requires you to be authenticated.
  documentation_url: https://docs.github.com/graphql/guides/forming-calls-with-graphql#authenticating-with-graphql

Expected result:

User is informed that should be logged in to Vercel, right now user may get confused.

Screenshots:

Image

Proposal: move graphQL codegen to app-sdk

Context

Currently our setup of storefront, checkout, app-templates and probably any other API consumer uses graphpql codegen to generate d.ts from GQL schema

I see 2 downsides:

  1. We repeat ourselves
  2. We somehow "force" users to use all these (opinionated) packages in their apps.

Proposal

We can merge codegen scripts into small package (can be under saleor-cli or app-template, or standalone + binding to CLI etc).
This will "blackbox" codegen generator to npm script.
It can also be easily opt-out - just install your own codegen and stop using Saleor's

Boxen - problem with links

When long URL is displayed in boxen it's auto split into two lines separated by boxen border which makes the link useless

https://watch.screencastify.com/v/uxSy4cBsONJSMLGDdzgD

example below

https://saleor-demo-kt8ljdo2.saleor.cloud/dashboard/apps/install?manifestUrl=https%3A%2F%2Fmy-saleor-ah7tvw83f-michalina-gra   β”‚β”‚
czyk.vercel.app%2Fapi%2Fmanifest

A video showing the problem in action:

CleanShot.2022-08-04.at.16.15.25.mp4

Update `saleor storefront` for the new monorepo structure

Update saleor storefront command to make it work with for the new monorepo structure in saleor/react-storefront.

Currently saleor storefront is broken. It tries deploying saleor/react-storefront as if it was a single project. However, we've just recently modified its structure and it's a monorepo now. storefront is now in apps/storefront.

Document ENV variables for CLI

CLI can be configured with env variables, but it's not documented.

Add readme section for env variables and config/saleor.json

`saleor store create` does not set API URI properly

Reproduce:

  1. saleor store create storefront1
  2. It will create a new storefront with correct information from chose project on cloud
  3. Visit created store at http://localhost:3005 and got below error:

error - Error: request to https://undefined/graphql/ failed, reason: getaddrinfo ENOTFOUND undefined

  1. Look at .env file and found this line NEXT_PUBLIC_API_URI=https://undefined/graphql/
  2. Update it to correct API URI and npm run dev
  3. Visi http://localhost:3001 (NEXT_PUBLIC_VERCEL_URL variable, and why not 3005 same as creating store step?) and it works now

Refine the Vercel API integration with error handling

The Saleor App registration flow relies on the Vercel integration. The latter is not properly tested. We should improve the error handling and communicate the problems so that both the dashboard and CLI can inform about the app installation issues.

How to test

  • saleor app deploy
  • change a character in SALEOR_DEPLOYMENT_TOKEN
  • redeploy
  • re-install

Audit CLIs app deploy flow

Context

CLI is improving workflow od app deploy command.

Goal

Make app deploy & app install flow smooth for users

Let's review this work and possibly - improve copy

Here is related issue
#206

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.