@output.ai/cli 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/services/env_configurator.d.ts +6 -2
- package/dist/services/env_configurator.js +11 -4
- package/dist/services/env_configurator.spec.js +89 -16
- package/dist/services/messages.js +4 -4
- package/dist/services/workflow_generator.spec.js +0 -1
- package/dist/templates/agent_instructions/skills/output-error-zod-import/SKILL.md.template +1 -1
- package/dist/templates/agent_instructions/skills/output-workflow-list/SKILL.md.template +1 -1
- package/package.json +2 -2
- package/dist/templates/workflow/.env.template +0 -7
- /package/dist/templates/project/{.env.template → .env.example.template} +0 -0
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
* Interactively configures environment variables for a project by prompting the user
|
|
3
3
|
* to provide values for empty variables or variables marked as secrets.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* This function reads from .env.example and, when the user confirms configuration,
|
|
6
|
+
* copies it to .env before prompting for values. The .env.example file remains
|
|
7
|
+
* unchanged as a template for other developers.
|
|
8
|
+
*
|
|
9
|
+
* @param projectPath - The absolute path to the project directory containing the .env.example file
|
|
6
10
|
* @param skipPrompt - If true, skips the configuration prompt and returns false immediately
|
|
7
11
|
* @returns A promise that resolves to true if environment variables were successfully configured,
|
|
8
|
-
* false if configuration was skipped (no .env file, user declined, no variables to configure,
|
|
12
|
+
* false if configuration was skipped (no .env.example file, user declined, no variables to configure,
|
|
9
13
|
* or an error occurred)
|
|
10
14
|
*/
|
|
11
15
|
export declare function configureEnvironmentVariables(projectPath: string, skipPrompt?: boolean): Promise<boolean>;
|
|
@@ -115,10 +115,14 @@ async function writeEnvFile(filePath, variables) {
|
|
|
115
115
|
* Interactively configures environment variables for a project by prompting the user
|
|
116
116
|
* to provide values for empty variables or variables marked as secrets.
|
|
117
117
|
*
|
|
118
|
-
*
|
|
118
|
+
* This function reads from .env.example and, when the user confirms configuration,
|
|
119
|
+
* copies it to .env before prompting for values. The .env.example file remains
|
|
120
|
+
* unchanged as a template for other developers.
|
|
121
|
+
*
|
|
122
|
+
* @param projectPath - The absolute path to the project directory containing the .env.example file
|
|
119
123
|
* @param skipPrompt - If true, skips the configuration prompt and returns false immediately
|
|
120
124
|
* @returns A promise that resolves to true if environment variables were successfully configured,
|
|
121
|
-
* false if configuration was skipped (no .env file, user declined, no variables to configure,
|
|
125
|
+
* false if configuration was skipped (no .env.example file, user declined, no variables to configure,
|
|
122
126
|
* or an error occurred)
|
|
123
127
|
*/
|
|
124
128
|
export async function configureEnvironmentVariables(projectPath, skipPrompt = false) {
|
|
@@ -126,12 +130,13 @@ export async function configureEnvironmentVariables(projectPath, skipPrompt = fa
|
|
|
126
130
|
return false;
|
|
127
131
|
}
|
|
128
132
|
ux.stdout('configuring environment variables...');
|
|
133
|
+
const envExamplePath = path.join(projectPath, '.env.example');
|
|
129
134
|
const envPath = path.join(projectPath, '.env');
|
|
130
135
|
try {
|
|
131
|
-
await fs.access(
|
|
136
|
+
await fs.access(envExamplePath);
|
|
132
137
|
}
|
|
133
138
|
catch {
|
|
134
|
-
ux.stdout(ux.colorize('red', '
|
|
139
|
+
ux.stdout(ux.colorize('red', '.env.example file does not exist, nothing to configure'));
|
|
135
140
|
return false;
|
|
136
141
|
}
|
|
137
142
|
const shouldConfigure = await confirm({
|
|
@@ -142,6 +147,8 @@ export async function configureEnvironmentVariables(projectPath, skipPrompt = fa
|
|
|
142
147
|
return false;
|
|
143
148
|
}
|
|
144
149
|
try {
|
|
150
|
+
// Copy .env.example to .env before configuring
|
|
151
|
+
await fs.copyFile(envExamplePath, envPath);
|
|
145
152
|
const variables = await parseEnvFile(envPath);
|
|
146
153
|
const variablesToConfigure = variables.filter(v => isEmpty(v.value) || v.isSecret);
|
|
147
154
|
if (variablesToConfigure.length === 0) {
|
|
@@ -5,16 +5,18 @@ import { configureEnvironmentVariables } from './env_configurator.js';
|
|
|
5
5
|
// Mock inquirer prompts
|
|
6
6
|
vi.mock('@inquirer/prompts', () => ({
|
|
7
7
|
input: vi.fn(),
|
|
8
|
-
confirm: vi.fn()
|
|
8
|
+
confirm: vi.fn(),
|
|
9
|
+
password: vi.fn()
|
|
9
10
|
}));
|
|
10
11
|
describe('configureEnvironmentVariables', () => {
|
|
11
|
-
const testState = { tempDir: '', envPath: '' };
|
|
12
|
+
const testState = { tempDir: '', envExamplePath: '', envPath: '' };
|
|
12
13
|
beforeEach(async () => {
|
|
13
14
|
// Clear all mocks before each test
|
|
14
15
|
vi.clearAllMocks();
|
|
15
16
|
// Create temporary directory for test files
|
|
16
17
|
testState.tempDir = path.join('/tmp', `test-env-${Date.now()}`);
|
|
17
18
|
await fs.mkdir(testState.tempDir, { recursive: true });
|
|
19
|
+
testState.envExamplePath = path.join(testState.tempDir, '.env.example');
|
|
18
20
|
testState.envPath = path.join(testState.tempDir, '.env');
|
|
19
21
|
});
|
|
20
22
|
afterEach(async () => {
|
|
@@ -27,36 +29,74 @@ describe('configureEnvironmentVariables', () => {
|
|
|
27
29
|
}
|
|
28
30
|
});
|
|
29
31
|
it('should return false if skipPrompt is true', async () => {
|
|
30
|
-
// Create a minimal .env file
|
|
31
|
-
await fs.writeFile(testState.
|
|
32
|
+
// Create a minimal .env.example file
|
|
33
|
+
await fs.writeFile(testState.envExamplePath, 'KEY=value');
|
|
32
34
|
const result = await configureEnvironmentVariables(testState.tempDir, true);
|
|
33
35
|
expect(result).toBe(false);
|
|
34
36
|
});
|
|
35
|
-
it('should return false if .env file does not exist', async () => {
|
|
37
|
+
it('should return false if .env.example file does not exist', async () => {
|
|
36
38
|
const result = await configureEnvironmentVariables(testState.tempDir, false);
|
|
37
39
|
expect(result).toBe(false);
|
|
38
40
|
});
|
|
39
41
|
it('should return false if user declines configuration', async () => {
|
|
40
42
|
const { confirm } = await import('@inquirer/prompts');
|
|
41
43
|
vi.mocked(confirm).mockResolvedValue(false);
|
|
42
|
-
await fs.writeFile(testState.
|
|
44
|
+
await fs.writeFile(testState.envExamplePath, '# API key\nAPIKEY=');
|
|
43
45
|
const result = await configureEnvironmentVariables(testState.tempDir, false);
|
|
44
46
|
expect(result).toBe(false);
|
|
45
47
|
expect(vi.mocked(confirm)).toHaveBeenCalled();
|
|
46
48
|
});
|
|
49
|
+
it('should NOT create .env when user declines configuration', async () => {
|
|
50
|
+
const { confirm } = await import('@inquirer/prompts');
|
|
51
|
+
vi.mocked(confirm).mockResolvedValue(false);
|
|
52
|
+
await fs.writeFile(testState.envExamplePath, '# API key\nAPIKEY=');
|
|
53
|
+
await configureEnvironmentVariables(testState.tempDir, false);
|
|
54
|
+
// .env should NOT exist when user declines
|
|
55
|
+
await expect(fs.access(testState.envPath)).rejects.toThrow();
|
|
56
|
+
// .env.example should still exist
|
|
57
|
+
await expect(fs.access(testState.envExamplePath)).resolves.toBeUndefined();
|
|
58
|
+
});
|
|
47
59
|
it('should return false if no empty variables exist', async () => {
|
|
48
60
|
const { confirm } = await import('@inquirer/prompts');
|
|
49
61
|
vi.mocked(confirm).mockResolvedValue(true);
|
|
50
|
-
await fs.writeFile(testState.
|
|
62
|
+
await fs.writeFile(testState.envExamplePath, 'APIKEY=my-secret-key');
|
|
51
63
|
const result = await configureEnvironmentVariables(testState.tempDir, false);
|
|
52
64
|
expect(result).toBe(false);
|
|
53
65
|
});
|
|
66
|
+
it('should copy .env.example to .env when user confirms configuration', async () => {
|
|
67
|
+
const { input, confirm } = await import('@inquirer/prompts');
|
|
68
|
+
vi.mocked(confirm).mockResolvedValue(true);
|
|
69
|
+
vi.mocked(input).mockResolvedValueOnce('sk-proj-123');
|
|
70
|
+
const originalContent = `# API key
|
|
71
|
+
APIKEY=`;
|
|
72
|
+
await fs.writeFile(testState.envExamplePath, originalContent);
|
|
73
|
+
await configureEnvironmentVariables(testState.tempDir, false);
|
|
74
|
+
// Both files should exist
|
|
75
|
+
await expect(fs.access(testState.envExamplePath)).resolves.toBeUndefined();
|
|
76
|
+
await expect(fs.access(testState.envPath)).resolves.toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
it('should write configured values to .env while leaving .env.example unchanged', async () => {
|
|
79
|
+
const { input, confirm } = await import('@inquirer/prompts');
|
|
80
|
+
vi.mocked(confirm).mockResolvedValue(true);
|
|
81
|
+
vi.mocked(input).mockResolvedValueOnce('sk-proj-123');
|
|
82
|
+
const originalContent = `# API key
|
|
83
|
+
APIKEY=`;
|
|
84
|
+
await fs.writeFile(testState.envExamplePath, originalContent);
|
|
85
|
+
const result = await configureEnvironmentVariables(testState.tempDir, false);
|
|
86
|
+
expect(result).toBe(true);
|
|
87
|
+
// .env should have the configured value
|
|
88
|
+
const envContent = await fs.readFile(testState.envPath, 'utf-8');
|
|
89
|
+
expect(envContent).toContain('APIKEY=sk-proj-123');
|
|
90
|
+
// .env.example should remain unchanged
|
|
91
|
+
const envExampleContent = await fs.readFile(testState.envExamplePath, 'utf-8');
|
|
92
|
+
expect(envExampleContent).toBe(originalContent);
|
|
93
|
+
});
|
|
54
94
|
it('should prompt for empty variables and update .env', async () => {
|
|
55
95
|
const { input, confirm } = await import('@inquirer/prompts');
|
|
56
96
|
vi.mocked(confirm).mockResolvedValue(true);
|
|
57
97
|
vi.mocked(input).mockResolvedValueOnce('sk-proj-123');
|
|
58
98
|
vi.mocked(input).mockResolvedValueOnce('');
|
|
59
|
-
await fs.writeFile(testState.
|
|
99
|
+
await fs.writeFile(testState.envExamplePath, `# API key for Anthropic
|
|
60
100
|
ANTHROPIC_API_KEY=
|
|
61
101
|
|
|
62
102
|
# API key for OpenAI
|
|
@@ -78,7 +118,7 @@ APIKEY=
|
|
|
78
118
|
|
|
79
119
|
# Another comment
|
|
80
120
|
OTHER=value`;
|
|
81
|
-
await fs.writeFile(testState.
|
|
121
|
+
await fs.writeFile(testState.envExamplePath, originalContent);
|
|
82
122
|
await configureEnvironmentVariables(testState.tempDir, false);
|
|
83
123
|
const content = await fs.readFile(testState.envPath, 'utf-8');
|
|
84
124
|
expect(content).toContain('# This is a comment');
|
|
@@ -90,7 +130,7 @@ OTHER=value`;
|
|
|
90
130
|
const { input, confirm } = await import('@inquirer/prompts');
|
|
91
131
|
vi.mocked(confirm).mockResolvedValue(true);
|
|
92
132
|
vi.mocked(input).mockResolvedValueOnce('new-key');
|
|
93
|
-
await fs.writeFile(testState.
|
|
133
|
+
await fs.writeFile(testState.envExamplePath, `APIKEY=your_api_key_here
|
|
94
134
|
EMPTY_KEY=`);
|
|
95
135
|
const result = await configureEnvironmentVariables(testState.tempDir, false);
|
|
96
136
|
expect(result).toBe(true);
|
|
@@ -103,21 +143,54 @@ EMPTY_KEY=`);
|
|
|
103
143
|
const { input, confirm } = await import('@inquirer/prompts');
|
|
104
144
|
vi.mocked(confirm).mockResolvedValue(true);
|
|
105
145
|
vi.mocked(input).mockResolvedValueOnce('new-key');
|
|
106
|
-
await fs.writeFile(testState.
|
|
146
|
+
await fs.writeFile(testState.envExamplePath, `EXISTING_KEY=existing-value
|
|
107
147
|
|
|
108
148
|
EMPTY_KEY=`);
|
|
109
149
|
await configureEnvironmentVariables(testState.tempDir, false);
|
|
110
150
|
// Should only prompt for EMPTY_KEY, not EXISTING_KEY
|
|
111
151
|
expect(vi.mocked(input)).toHaveBeenCalledTimes(1);
|
|
112
152
|
});
|
|
153
|
+
it('should handle case where .env already exists (overwrite with copy)', async () => {
|
|
154
|
+
const { input, confirm } = await import('@inquirer/prompts');
|
|
155
|
+
vi.mocked(confirm).mockResolvedValue(true);
|
|
156
|
+
vi.mocked(input).mockResolvedValueOnce('new-configured-value');
|
|
157
|
+
// Create existing .env with old content
|
|
158
|
+
await fs.writeFile(testState.envPath, 'OLD_KEY=old-value');
|
|
159
|
+
// Create .env.example with new content
|
|
160
|
+
await fs.writeFile(testState.envExamplePath, 'NEW_KEY=');
|
|
161
|
+
const result = await configureEnvironmentVariables(testState.tempDir, false);
|
|
162
|
+
expect(result).toBe(true);
|
|
163
|
+
// .env should be overwritten with .env.example content and configured values
|
|
164
|
+
const envContent = await fs.readFile(testState.envPath, 'utf-8');
|
|
165
|
+
expect(envContent).toContain('NEW_KEY=new-configured-value');
|
|
166
|
+
expect(envContent).not.toContain('OLD_KEY');
|
|
167
|
+
});
|
|
113
168
|
it('should return false if an error occurs during parsing', async () => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
await fs.writeFile(testState.
|
|
117
|
-
// Delete the file
|
|
118
|
-
|
|
169
|
+
const { confirm } = await import('@inquirer/prompts');
|
|
170
|
+
vi.mocked(confirm).mockResolvedValue(true);
|
|
171
|
+
await fs.writeFile(testState.envExamplePath, 'KEY=');
|
|
172
|
+
// Delete the .env.example file after access check but before parsing would happen
|
|
173
|
+
// We simulate this by deleting during the copy operation
|
|
174
|
+
const originalCopyFile = fs.copyFile;
|
|
175
|
+
vi.spyOn(fs, 'copyFile').mockImplementation(async () => {
|
|
176
|
+
throw new Error('Copy failed');
|
|
177
|
+
});
|
|
119
178
|
const result = await configureEnvironmentVariables(testState.tempDir, false);
|
|
120
179
|
// Should return false when error occurs
|
|
121
180
|
expect(result).toBe(false);
|
|
181
|
+
// Restore original function
|
|
182
|
+
vi.mocked(fs.copyFile).mockImplementation(originalCopyFile);
|
|
183
|
+
});
|
|
184
|
+
it('should prompt for SECRET marker values with password input', async () => {
|
|
185
|
+
const { password, confirm } = await import('@inquirer/prompts');
|
|
186
|
+
vi.mocked(confirm).mockResolvedValue(true);
|
|
187
|
+
vi.mocked(password).mockResolvedValueOnce('my-secret-api-key');
|
|
188
|
+
await fs.writeFile(testState.envExamplePath, `# API Key
|
|
189
|
+
ANTHROPIC_API_KEY=<SECRET>`);
|
|
190
|
+
const result = await configureEnvironmentVariables(testState.tempDir, false);
|
|
191
|
+
expect(result).toBe(true);
|
|
192
|
+
expect(vi.mocked(password)).toHaveBeenCalledTimes(1);
|
|
193
|
+
const envContent = await fs.readFile(testState.envPath, 'utf-8');
|
|
194
|
+
expect(envContent).toContain('ANTHROPIC_API_KEY=my-secret-api-key');
|
|
122
195
|
});
|
|
123
196
|
});
|
|
@@ -166,8 +166,8 @@ export const getProjectSuccessMessage = (folderName, installSuccess, envConfigur
|
|
|
166
166
|
if (!envConfigured) {
|
|
167
167
|
steps.push({
|
|
168
168
|
step: 'Configure environment variables',
|
|
169
|
-
command: '
|
|
170
|
-
note: '
|
|
169
|
+
command: 'cp .env.example .env',
|
|
170
|
+
note: 'Copy .env.example to .env and add your API keys'
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
steps.push({
|
|
@@ -248,8 +248,8 @@ export const getWorkflowGenerateSuccessMessage = (workflowName, targetDir, files
|
|
|
248
248
|
},
|
|
249
249
|
{
|
|
250
250
|
step: 'Configure environment',
|
|
251
|
-
command: '
|
|
252
|
-
note: '
|
|
251
|
+
command: 'cp .env.example .env',
|
|
252
|
+
note: 'Copy .env.example to .env and add your LLM provider credentials'
|
|
253
253
|
},
|
|
254
254
|
{
|
|
255
255
|
step: 'Test with example scenario',
|
|
@@ -108,7 +108,7 @@ cat src/workflows/simple/workflow.ts
|
|
|
108
108
|
### Workflow not showing
|
|
109
109
|
- Check the file exports a valid workflow definition
|
|
110
110
|
- Ensure the workflow file compiles without errors
|
|
111
|
-
- Run `npm run build` to check for TypeScript errors
|
|
111
|
+
- Run `npm run output:workflow:build` to check for TypeScript errors
|
|
112
112
|
|
|
113
113
|
## Related Commands
|
|
114
114
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@output.ai/cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "CLI for Output.ai workflow generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"handlebars": "4.7.8",
|
|
36
36
|
"json-schema-library": "10.3.0",
|
|
37
37
|
"ky": "1.12.0",
|
|
38
|
-
"validator": "13.15.
|
|
38
|
+
"validator": "13.15.22"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/cli-progress": "3.11.6",
|
|
File without changes
|