Skip to content

Commit c95f38a

Browse files
committed
use arg flags to change behaviour to avoid breaking change
1 parent 0aeec31 commit c95f38a

File tree

5 files changed

+28
-106
lines changed

5 files changed

+28
-106
lines changed

.env.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# required: true
3+
# format: text
4+
# description: QBO Client Id
5+
# link: https://developer.intuit.com
6+
QBO_CLIENT_ID=xyz
7+
8+
# required: true
9+
# format: text
10+
# description: QBO Client Secret
11+
# link: https://developer.intuit.com
12+
QBO_CLIENT_SECRET=123

README.md

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1 @@
1-
<h1 align="center">configure-env</h1>
2-
<p align="center">CLI tool to generate and populate <code>.env</code> files from <code>.env.example</code> templates.</p>
3-
<p align="center">
4-
<a href="https://www.npmjs.com/package/configure-env"><img alt="npm (scoped)" src="https://img.shields.io/npm/v/configure-env.svg?style=flat-square"></a> <a href="https://www.npmjs.com/package/configure-env"><img alt="npm" src="https://img.shields.io/npm/dt/configure-env.svg?style=flat-square"></a> <a href="https://github.com/twilio-labs/configure-env/blob/master/LICENSE"><img alt="GitHub" src="https://img.shields.io/github/license/twilio-labs/configure-env.svg?style=flat-square"></a><a href="https://github.com/twilio-labs/configure-env/blob/master/CODE_OF_CONDUCT.md"><img alt="Code of Conduct" src="https://img.shields.io/badge/%F0%9F%92%96-Code%20of%20Conduct-blueviolet.svg?style=flat-square"></a> <a href="https://github.com/twilio-labs/configure-env/blob/master/CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" alt="PRs Welcome" /></a>
5-
</p>
6-
<hr>
7-
8-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
9-
10-
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
11-
12-
<!-- ALL-CONTRIBUTORS-BADGE:END -->
13-
14-
## About
15-
16-
`configure-env` will read a `.env.example` or any other similar `.env` file and prompt for values for each variable that has a comment header above it. Afterwards it will generate a `.env` file out of it.
17-
18-
It works as a more user-friendly approach to:
19-
20-
```
21-
cp .env.example .env
22-
```
23-
24-
## Installation
25-
26-
You can install the CLI tool via `npm` or another package manager. Ideally install it as a dev dependency instead of global:
27-
28-
```bash
29-
# Install it as a dev dependency
30-
npm install configure-env --save-dev
31-
32-
# Afterwards you can use by using:
33-
node_modules/.bin/configure-env
34-
35-
npx configure-env
36-
37-
# Or inside your package.json scripts section as "configure-env"
38-
```
39-
40-
## Usage
41-
42-
In a project that contains a `.env.example` file, run:
43-
44-
```bash
45-
$ npx configure-env --help
46-
Prompts user for environment variables and generates .env files based on a
47-
.env.example file
48-
49-
Usage:
50-
configure-env.js -o [outputFile] -i [exampleFile]
51-
52-
Options:
53-
--help Show help [boolean]
54-
--version Show version number [boolean]
55-
--output, -o Location of the .env file that should be written
56-
[string] [default: ".env"]
57-
--input, -i Location of input .env.example file for prompts
58-
[string] [default: ".env.example"]
59-
--verbose [boolean] [default: false]
60-
61-
Examples:
62-
npx configure-env Reads a .env.example file in the current directory and
63-
creates a .env file
64-
configure-env.js | cat The output can be either written to a file or piped to
65-
another process
66-
67-
This project is part of Twilio Labs. Please file any issues
68-
github.com/twilio-labs/configure-env
69-
70-
```
71-
72-
## Contributing
73-
74-
This project welcomes contributions from the community. Please see the [`CONTRIBUTING.md`](CONTRIBUTING.md) file for more details.
75-
76-
### Code of Conduct
77-
78-
Please be aware that this project has a [Code of Conduct](CODE_OF_CONDUCT.md). The tldr; is to just be excellent to each other ❤️
79-
80-
## Contributors
81-
82-
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
83-
84-
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
85-
<!-- prettier-ignore-start -->
86-
<!-- markdownlint-disable -->
87-
<table>
88-
<tr>
89-
<td align="center"><a href="https://dkundel.com"><img src="https://avatars3.githubusercontent.com/u/1505101?v=4" width="80px;" alt="Dominik Kundel"/><br /><sub><b>Dominik Kundel</b></sub></a><br /><a href="https://github.com/twilio-labs/configure-env/commits?author=dkundel" title="Code">💻</a></td>
90-
</tr>
91-
</table>
92-
93-
<!-- markdownlint-enable -->
94-
<!-- prettier-ignore-end -->
95-
96-
<!-- ALL-CONTRIBUTORS-LIST:END -->
97-
98-
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
99-
100-
## License
101-
102-
[MIT](LICENSE)
1+
This is a Fork Of https://github.com/twilio-labs/configure-env

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "configure-env",
3-
"version": "2.0.0-1",
2+
"name": "copy-env-example",
3+
"version": "1.0.0",
44
"description": "Configures your project's environment by creating a .env file.",
55
"main": "dist/index.js",
66
"bin": {

src/cli.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface CliArguments extends Arguments {
1212
output: string;
1313
verbose: boolean;
1414
input: string;
15+
useOutputFileDefaults: boolean;
16+
promptForExistingVars: boolean;
1517
}
1618

1719
export function parseArgs(args: string[]): CliArguments {
@@ -45,6 +47,8 @@ export function parseArgs(args: string[]): CliArguments {
4547
desc: 'Location of input .env.example file for prompts',
4648
},
4749
verbose: { type: 'boolean', default: false },
50+
useOutputFileDefaults: { type: 'boolean', default: false },
51+
promptForExistingVars: { type: 'boolean', default: true },
4852
})
4953
.parse(args);
5054

@@ -76,7 +80,6 @@ export async function cli(
7680
) {
7781
const options = parseArgs(args);
7882
const exampleFileContent = await getExampleContent(options.input);
79-
const outputFileContent = await getOutputContent(options.output);
8083
const output = !ttyOutStream.isTTY
8184
? ((ttyOutStream as unknown) as fs.WriteStream)
8285
: getOutputStream(options.output);
@@ -86,6 +89,8 @@ export async function cli(
8689
exampleFileContent,
8790
output,
8891
promptStream,
92+
useOutputFileDefaults: options.useOutputFileDefaults,
93+
promptForExistingVars: options.promptForExistingVars,
8994
};
9095
return configureEnv(config);
9196
}

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export type Config = {
1212
promptStream: tty.WriteStream;
1313
exampleFileContent: string;
1414
outputFileContent?: string;
15+
useOutputFileDefaults: boolean;
16+
promptForExistingVars: boolean;
1517
};
1618

1719
export async function configureEnv(config: Config) {
@@ -24,7 +26,11 @@ export async function configureEnv(config: Config) {
2426
const parsedEnv = await parserLib.parseAsObject(config.outputFileContent);
2527
parsedExample.variables.forEach(variable => {
2628
if ( variable.configurable && parsedEnv[variable.key]) {
27-
variable.default = parsedEnv[variable.key];
29+
if(config.useOutputFileDefaults) {
30+
variable.default = parsedEnv[variable.key];
31+
}
32+
// is prompt needed if value is already set in .env
33+
variable.configurable = config.promptForExistingVars;
2834
}
2935
})
3036
}

0 commit comments

Comments
 (0)