-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathnew-change.ts
More file actions
61 lines (49 loc) · 1.98 KB
/
new-change.ts
File metadata and controls
61 lines (49 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* New Change Command
*
* Creates a new change directory with optional description and schema.
*/
import ora from 'ora';
import path from 'path';
import { createChange, validateChangeName } from '../../utils/change-utils.js';
import { validateSchemaExists } from './shared.js';
// -----------------------------------------------------------------------------
// Types
// -----------------------------------------------------------------------------
export interface NewChangeOptions {
description?: string;
schema?: string;
}
// -----------------------------------------------------------------------------
// Command Implementation
// -----------------------------------------------------------------------------
export async function newChangeCommand(name: string | undefined, options: NewChangeOptions): Promise<void> {
if (!name) {
throw new Error('Missing required argument <name>');
}
const validation = validateChangeName(name);
if (!validation.valid) {
throw new Error(validation.error);
}
const projectRoot = process.cwd();
// Validate schema if provided
if (options.schema) {
validateSchemaExists(options.schema, projectRoot);
}
const schemaDisplay = options.schema ? ` with schema '${options.schema}'` : '';
const spinner = ora(`Creating change '${name}'${schemaDisplay}...`).start();
try {
const result = await createChange(projectRoot, name, { schema: options.schema });
// If description provided, create README.md with description
if (options.description) {
const { promises: fs } = await import('fs');
const changeDir = path.join(projectRoot, 'openspec', 'changes', name);
const readmePath = path.join(changeDir, 'README.md');
await fs.writeFile(readmePath, `# ${name}\n\n${options.description}\n`, 'utf-8');
}
spinner.succeed(`Created change '${name}' at openspec/changes/${name}/ (schema: ${result.schema})`);
} catch (error) {
spinner.fail(`Failed to create change '${name}'`);
throw error;
}
}