Skip to content

Commit

Permalink
fix: env first argument
Browse files Browse the repository at this point in the history
  • Loading branch information
tbazelczuk committed Mar 7, 2022
1 parent c84dbd2 commit ca19852
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
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);

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;

0 comments on commit ca19852

Please sign in to comment.