Skip to content

Commit

Permalink
Implement base for non interactive cli.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Apr 12, 2024
1 parent 679a399 commit 7d61cd9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ jobs:
touch .env
echo 'METACALL_AUTH_EMAIL="${{ secrets.METACALL_AUTH_EMAIL }}"' >> .env
echo 'METACALL_AUTH_PASSWORD="${{ secrets.METACALL_AUTH_PASSWORD }}"' >> .env
npm run test
echo 'NODE_ENV=testing' >> .env
npm run coverage
- name: Publish
uses: JS-DevTools/npm-publish@v1
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
},
"editor.rulers": [80],
"editor.quickSuggestions": {
Expand Down
1 change: 1 addition & 0 deletions src/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import args from './cli/args';
import { info, warn } from './cli/messages';
import { planSelection } from './cli/selection';
import { ErrorCode } from './deploy';

// TODO: We should cache the plan and ask for it only once

export const planFetch = async (
Expand Down
4 changes: 4 additions & 0 deletions src/test/cli.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import {

dotenv.config();

// Define tty as interactive in order to test properly the CLI
process.env.NODE_ENV = 'testing';
process.env.METACALL_DEPLOY_INTERACTIVE = 'true';

const runCLI = (args: string[], inputs: string[]) => {
return runWithInput('dist/index.js', args, inputs);
};
Expand Down
12 changes: 12 additions & 0 deletions src/tty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const isInteractive = () => {
// Define this environment variable to allow tests to be interactive
// even if they run inside a non interactive tty
if (process.env.NODE_ENV === 'testing') {
return (
process.env.METACALL_DEPLOY_INTERACTIVE === 'true' ||
process.env.METACALL_DEPLOY_INTERACTIVE === '1'
);
}

return process.stdin.isTTY === true;
};
9 changes: 9 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { platform } from 'os';
import { basename, join, relative } from 'path';
import { error, printLanguage } from './cli/messages';
import { consentSelection, fileSelection } from './cli/selection';
import { isInteractive } from './tty';

const missing = (name: string): string =>
`Missing ${name} environment variable! Unable to load config`;
Expand Down Expand Up @@ -114,6 +115,14 @@ export const zip = async (
// TODO Look for the .env file in user's code and fetch it so that user don't have to write all the vars again in the CLI

export const getEnv = async (): Promise<{ name: string; value: string }[]> => {
// TODO: Implement .env loading, if .env file is found, load it and skip the rest of the function

// If the input is not interactive skip asking the end user
if (!isInteractive()) {
// TODO: We should implement support for all the inputs and prompts for non-interactive terminal
return [];
}

const enableEnv = await consentSelection(
'Do you want to add environment variables?'
);
Expand Down

0 comments on commit 7d61cd9

Please sign in to comment.