universal-dev-standards 3.0.0

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.
@@ -0,0 +1,221 @@
1
+ import chalk from 'chalk';
2
+ import ora from 'ora';
3
+ import {
4
+ getOptionSource,
5
+ findOption,
6
+ getAllStandards
7
+ } from '../utils/registry.js';
8
+ import {
9
+ copyStandard,
10
+ readManifest,
11
+ writeManifest,
12
+ isInitialized
13
+ } from '../utils/copier.js';
14
+ import {
15
+ promptFormat,
16
+ promptGitWorkflow,
17
+ promptMergeStrategy,
18
+ promptCommitLanguage,
19
+ promptTestLevels,
20
+ promptConfirm
21
+ } from '../prompts/init.js';
22
+
23
+ /**
24
+ * Configure command - modify options for initialized project
25
+ * @param {Object} options - Command options
26
+ */
27
+ export async function configureCommand(options) {
28
+ const projectPath = process.cwd();
29
+
30
+ console.log();
31
+ console.log(chalk.bold('Universal Development Standards - Configure'));
32
+ console.log(chalk.gray('─'.repeat(50)));
33
+
34
+ // Check if initialized
35
+ if (!isInitialized(projectPath)) {
36
+ console.log(chalk.red('✗ Standards not initialized in this project.'));
37
+ console.log(chalk.gray(' Run `uds init` first to initialize standards.'));
38
+ return;
39
+ }
40
+
41
+ // Read current manifest
42
+ const manifest = readManifest(projectPath);
43
+ if (!manifest) {
44
+ console.log(chalk.red('✗ Could not read manifest file.'));
45
+ return;
46
+ }
47
+
48
+ console.log();
49
+ console.log(chalk.cyan('Current Configuration:'));
50
+ console.log(chalk.gray(` Format: ${manifest.format || 'human'}`));
51
+ if (manifest.options) {
52
+ if (manifest.options.workflow) {
53
+ console.log(chalk.gray(` Git Workflow: ${manifest.options.workflow}`));
54
+ }
55
+ if (manifest.options.merge_strategy) {
56
+ console.log(chalk.gray(` Merge Strategy: ${manifest.options.merge_strategy}`));
57
+ }
58
+ if (manifest.options.commit_language) {
59
+ console.log(chalk.gray(` Commit Language: ${manifest.options.commit_language}`));
60
+ }
61
+ if (manifest.options.test_levels && manifest.options.test_levels.length > 0) {
62
+ console.log(chalk.gray(` Test Levels: ${manifest.options.test_levels.join(', ')}`));
63
+ }
64
+ }
65
+ console.log();
66
+
67
+ // Determine what to configure based on options or interactive mode
68
+ let configType = options.type || null;
69
+
70
+ if (!configType) {
71
+ const inquirer = await import('inquirer');
72
+ const { type } = await inquirer.default.prompt([
73
+ {
74
+ type: 'list',
75
+ name: 'type',
76
+ message: 'What would you like to configure?',
77
+ choices: [
78
+ { name: 'Format (AI/Human)', value: 'format' },
79
+ { name: 'Git Workflow Strategy', value: 'workflow' },
80
+ { name: 'Merge Strategy', value: 'merge_strategy' },
81
+ { name: 'Commit Message Language', value: 'commit_language' },
82
+ { name: 'Test Levels', value: 'test_levels' },
83
+ { name: 'All Options', value: 'all' }
84
+ ]
85
+ }
86
+ ]);
87
+ configType = type;
88
+ }
89
+
90
+ // Collect new options
91
+ const newOptions = { ...manifest.options };
92
+ let newFormat = manifest.format;
93
+
94
+ if (configType === 'all' || configType === 'format') {
95
+ newFormat = await promptFormat();
96
+ }
97
+
98
+ if (configType === 'all' || configType === 'workflow') {
99
+ newOptions.workflow = await promptGitWorkflow();
100
+ }
101
+
102
+ if (configType === 'all' || configType === 'merge_strategy') {
103
+ newOptions.merge_strategy = await promptMergeStrategy();
104
+ }
105
+
106
+ if (configType === 'all' || configType === 'commit_language') {
107
+ newOptions.commit_language = await promptCommitLanguage();
108
+ }
109
+
110
+ if (configType === 'all' || configType === 'test_levels') {
111
+ newOptions.test_levels = await promptTestLevels();
112
+ }
113
+
114
+ // Show changes
115
+ console.log();
116
+ console.log(chalk.cyan('New Configuration:'));
117
+ console.log(chalk.gray(` Format: ${newFormat}`));
118
+ if (newOptions.workflow) {
119
+ console.log(chalk.gray(` Git Workflow: ${newOptions.workflow}`));
120
+ }
121
+ if (newOptions.merge_strategy) {
122
+ console.log(chalk.gray(` Merge Strategy: ${newOptions.merge_strategy}`));
123
+ }
124
+ if (newOptions.commit_language) {
125
+ console.log(chalk.gray(` Commit Language: ${newOptions.commit_language}`));
126
+ }
127
+ if (newOptions.test_levels && newOptions.test_levels.length > 0) {
128
+ console.log(chalk.gray(` Test Levels: ${newOptions.test_levels.join(', ')}`));
129
+ }
130
+ console.log();
131
+
132
+ // Confirm
133
+ const confirmed = await promptConfirm('Apply these changes?');
134
+ if (!confirmed) {
135
+ console.log(chalk.yellow('Configuration cancelled.'));
136
+ return;
137
+ }
138
+
139
+ // Apply changes
140
+ const spinner = ora('Updating configuration...').start();
141
+
142
+ const results = {
143
+ copied: [],
144
+ errors: []
145
+ };
146
+
147
+ const standards = getAllStandards();
148
+ const formatsToUse = newFormat === 'both' ? ['ai', 'human'] : [newFormat];
149
+
150
+ // Helper to copy option files
151
+ const copyOptionFile = async (std, optionCategory, optionId, targetFormat) => {
152
+ const option = findOption(std, optionCategory, optionId);
153
+ if (option) {
154
+ const sourcePath = getOptionSource(option, targetFormat);
155
+ const result = await copyStandard(sourcePath, '.standards/options', projectPath);
156
+ if (result.success) {
157
+ results.copied.push(sourcePath);
158
+ } else {
159
+ results.errors.push(`${sourcePath}: ${result.error}`);
160
+ }
161
+ }
162
+ };
163
+
164
+ // Copy new option files
165
+ for (const std of standards) {
166
+ if (!std.options) continue;
167
+
168
+ for (const targetFormat of formatsToUse) {
169
+ // Git workflow
170
+ if (std.id === 'git-workflow') {
171
+ if (newOptions.workflow && newOptions.workflow !== manifest.options?.workflow) {
172
+ await copyOptionFile(std, 'workflow', newOptions.workflow, targetFormat);
173
+ }
174
+ if (newOptions.merge_strategy && newOptions.merge_strategy !== manifest.options?.merge_strategy) {
175
+ await copyOptionFile(std, 'merge_strategy', newOptions.merge_strategy, targetFormat);
176
+ }
177
+ }
178
+
179
+ // Commit message
180
+ if (std.id === 'commit-message') {
181
+ if (newOptions.commit_language && newOptions.commit_language !== manifest.options?.commit_language) {
182
+ await copyOptionFile(std, 'commit_language', newOptions.commit_language, targetFormat);
183
+ }
184
+ }
185
+
186
+ // Testing
187
+ if (std.id === 'testing' && newOptions.test_levels) {
188
+ for (const level of newOptions.test_levels) {
189
+ if (!manifest.options?.test_levels?.includes(level)) {
190
+ await copyOptionFile(std, 'test_level', level, targetFormat);
191
+ }
192
+ }
193
+ }
194
+ }
195
+ }
196
+
197
+ // Update manifest
198
+ manifest.format = newFormat;
199
+ manifest.options = newOptions;
200
+ manifest.version = '2.0.0';
201
+ writeManifest(manifest, projectPath);
202
+
203
+ spinner.succeed('Configuration updated');
204
+
205
+ // Summary
206
+ console.log();
207
+ console.log(chalk.green('✓ Configuration updated successfully!'));
208
+ if (results.copied.length > 0) {
209
+ console.log(chalk.gray(` ${results.copied.length} new option files copied`));
210
+ }
211
+
212
+ if (results.errors.length > 0) {
213
+ console.log();
214
+ console.log(chalk.yellow(`⚠ ${results.errors.length} error(s) occurred:`));
215
+ for (const err of results.errors) {
216
+ console.log(chalk.gray(` ${err}`));
217
+ }
218
+ }
219
+
220
+ console.log();
221
+ }