Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: env first argument #57

Merged
merged 1 commit into from
Mar 7, 2022
Merged
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ module.exports = {
```
npm start
```
## Kopytko cli package
It is recommended to use [kopytko-cli](https://github.com/getndazn/kopytko-cli) package and add it to package.json scripts:

```
npm install @dazn/kopytko-packager --save-dev
```

```json
"scripts": {
"start": "kopytko start",
"build": "kopytko build",
"test": "kopytko test"
}
```

## Configuration
The main configuration file `.kopytkorc` should be placed in the root folder of the project. The example file looks like this:
Expand Down
30 changes: 27 additions & 3 deletions src/env/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,27 @@ require('dotenv').config();

const minimist = require('minimist');

const args = minimist(process.argv.slice(2), {
// runner parameter is calculated based on script execution context
// kopytko start --env=production
// '.../bin/node',
// '.../bin/kopytko',
// 'start',
// '--env=production'

// npm start -- --env=production
// '.../bin/node',
// '.../@dazn/kopytko-packager/scripts/start.js',
// '--env=production'
const runner = process.argv[1].split('/').slice(-1)[0];

// we have to slice additional args if we execute script via kopytko cli
const args = runner === 'kopytko' ? process.argv.slice(3) : process.argv.slice(2);
tbazelczuk marked this conversation as resolved.
Show resolved Hide resolved

const firstArgument = args[0] || '';
const anonymousArgument = !firstArgument.includes('--') ? firstArgument : '';
const env = process.env.ENV !== 'test' ? anonymousArgument : '';

const parsedArgs = minimist(args, {
boolean: true,
default: {
/**
Expand All @@ -11,8 +31,12 @@ const args = minimist(process.argv.slice(2), {
*
* ENV=production npm start
* npm start -- --env=production
* npm start -- production
* ENV=production kopytko start
* kopytko start --env=production
* kopytko start production
*/
env: process.env.ENV || 'dev',
env: env || process.env.ENV || 'dev',

/**
* @type {string} Roku Developer password.
Expand Down Expand Up @@ -100,4 +124,4 @@ const args = minimist(process.argv.slice(2), {
},
});

module.exports = args;
module.exports = parsedArgs;