|
1 | 1 | import type {Command, CommandContext, CommandResult} from './Command' |
2 | | -import * as os from 'node:os' |
3 | | -import * as path from 'node:path' |
4 | | -import process from 'node:process' |
5 | | -import {generateAindex} from '@/Aindex' |
6 | | -import {DEFAULT_CONFIG_FILE_NAME, ensureConfigLink, getGlobalConfigPath} from '@/ConfigLoader' |
7 | 2 |
|
8 | | -function resolveWorkspacePath(workspaceDir: string): string { |
9 | | - if (workspaceDir === '~') return os.homedir() |
10 | | - if (workspaceDir.startsWith('~/') || workspaceDir.startsWith('~\\')) return path.join(os.homedir(), workspaceDir.slice(2)) |
11 | | - return path.normalize(workspaceDir) |
12 | | -} |
13 | | - |
14 | | -function linkCwdConfig(logger: CommandContext['logger']): void { |
15 | | - const globalConfigPath = getGlobalConfigPath() |
16 | | - const cwdConfigPath = path.join(process.cwd(), DEFAULT_CONFIG_FILE_NAME) |
17 | | - ensureConfigLink(cwdConfigPath, globalConfigPath, logger) |
18 | | -} |
| 3 | +const INIT_DEPRECATION_MESSAGE = '`tnmsc init` is deprecated and no longer initializes aindex. Maintain the public target-relative definitions manually under `~/workspace/aindex/public/`.' |
19 | 4 |
|
20 | 5 | export class InitCommand implements Command { |
21 | 6 | readonly name = 'init' |
22 | 7 |
|
23 | 8 | async execute(ctx: CommandContext): Promise<CommandResult> { |
24 | | - const {logger, userConfigOptions} = ctx |
25 | | - |
26 | | - logger.info('initializing aindex structure', {command: 'init'}) |
27 | | - |
28 | | - const workspaceDir = resolveWorkspacePath(userConfigOptions.workspaceDir) |
29 | | - const aindexDir = path.join(workspaceDir, userConfigOptions.aindex.dir) |
30 | | - |
31 | | - const result = generateAindex(aindexDir, {logger, config: userConfigOptions.aindex}) |
32 | | - try { |
33 | | - linkCwdConfig(logger) |
34 | | - } |
35 | | - catch (error) { |
36 | | - const errorMessage = error instanceof Error ? error.message : String(error) |
37 | | - return { |
38 | | - success: false, |
39 | | - filesAffected: result.createdFiles.length, |
40 | | - dirsAffected: result.createdDirs.length, |
41 | | - message: errorMessage |
42 | | - } |
43 | | - } |
44 | | - |
45 | | - const message = result.createdDirs.length === 0 && result.createdFiles.length === 0 |
46 | | - ? `All ${result.existedDirs.length} directories and ${result.existedFiles.length} files already exist` |
47 | | - : `Created ${result.createdDirs.length} directories and ${result.createdFiles.length} files (${result.existedDirs.length} dirs, ${result.existedFiles.length} files already existed)` |
| 9 | + const {logger} = ctx |
48 | 10 |
|
49 | | - logger.info('initialization complete', { |
50 | | - dirsCreated: result.createdDirs.length, |
51 | | - filesCreated: result.createdFiles.length, |
52 | | - dirsExisted: result.existedDirs.length, |
53 | | - filesExisted: result.existedFiles.length |
54 | | - }) |
| 11 | + logger.warn('deprecated init command invoked', {command: 'init'}) |
55 | 12 |
|
56 | 13 | return { |
57 | | - success: result.success, |
58 | | - filesAffected: result.createdFiles.length, |
59 | | - dirsAffected: result.createdDirs.length, |
60 | | - message |
| 14 | + success: false, |
| 15 | + filesAffected: 0, |
| 16 | + dirsAffected: 0, |
| 17 | + message: INIT_DEPRECATION_MESSAGE |
61 | 18 | } |
62 | 19 | } |
63 | 20 | } |
0 commit comments