@git.zone/cli 1.15.5 → 1.16.1

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.
Files changed (81) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/gitzone.cli.js +26 -2
  3. package/dist_ts/gitzone.logging.d.ts +3 -0
  4. package/dist_ts/gitzone.logging.js +20 -2
  5. package/dist_ts/mod_format/classes.baseformatter.d.ts +21 -0
  6. package/dist_ts/mod_format/classes.baseformatter.js +73 -0
  7. package/dist_ts/mod_format/classes.changecache.d.ts +25 -0
  8. package/dist_ts/mod_format/classes.changecache.js +105 -0
  9. package/dist_ts/mod_format/classes.dependency-analyzer.d.ts +13 -0
  10. package/dist_ts/mod_format/classes.dependency-analyzer.js +87 -0
  11. package/dist_ts/mod_format/classes.diffreporter.d.ts +13 -0
  12. package/dist_ts/mod_format/classes.diffreporter.js +94 -0
  13. package/dist_ts/mod_format/classes.formatcontext.d.ts +19 -0
  14. package/dist_ts/mod_format/classes.formatcontext.js +51 -0
  15. package/dist_ts/mod_format/classes.formatplanner.d.ts +13 -0
  16. package/dist_ts/mod_format/classes.formatplanner.js +164 -0
  17. package/dist_ts/mod_format/classes.formatstats.d.ts +40 -0
  18. package/dist_ts/mod_format/classes.formatstats.js +161 -0
  19. package/dist_ts/mod_format/classes.rollbackmanager.d.ts +21 -0
  20. package/dist_ts/mod_format/classes.rollbackmanager.js +170 -0
  21. package/dist_ts/mod_format/format.copy.d.ts +22 -0
  22. package/dist_ts/mod_format/format.copy.js +66 -2
  23. package/dist_ts/mod_format/format.packagejson.js +48 -2
  24. package/dist_ts/mod_format/formatters/cleanup.formatter.d.ts +7 -0
  25. package/dist_ts/mod_format/formatters/cleanup.formatter.js +33 -0
  26. package/dist_ts/mod_format/formatters/copy.formatter.d.ts +4 -0
  27. package/dist_ts/mod_format/formatters/copy.formatter.js +8 -0
  28. package/dist_ts/mod_format/formatters/gitignore.formatter.d.ts +4 -0
  29. package/dist_ts/mod_format/formatters/gitignore.formatter.js +8 -0
  30. package/dist_ts/mod_format/formatters/legacy.formatter.d.ts +11 -0
  31. package/dist_ts/mod_format/formatters/legacy.formatter.js +29 -0
  32. package/dist_ts/mod_format/formatters/license.formatter.d.ts +4 -0
  33. package/dist_ts/mod_format/formatters/license.formatter.js +8 -0
  34. package/dist_ts/mod_format/formatters/npmextra.formatter.d.ts +4 -0
  35. package/dist_ts/mod_format/formatters/npmextra.formatter.js +8 -0
  36. package/dist_ts/mod_format/formatters/packagejson.formatter.d.ts +4 -0
  37. package/dist_ts/mod_format/formatters/packagejson.formatter.js +8 -0
  38. package/dist_ts/mod_format/formatters/prettier.formatter.d.ts +9 -0
  39. package/dist_ts/mod_format/formatters/prettier.formatter.js +111 -0
  40. package/dist_ts/mod_format/formatters/readme.formatter.d.ts +7 -0
  41. package/dist_ts/mod_format/formatters/readme.formatter.js +19 -0
  42. package/dist_ts/mod_format/formatters/templates.formatter.d.ts +4 -0
  43. package/dist_ts/mod_format/formatters/templates.formatter.js +8 -0
  44. package/dist_ts/mod_format/formatters/tsconfig.formatter.d.ts +4 -0
  45. package/dist_ts/mod_format/formatters/tsconfig.formatter.js +8 -0
  46. package/dist_ts/mod_format/index.d.ts +14 -1
  47. package/dist_ts/mod_format/index.js +202 -28
  48. package/dist_ts/mod_format/interfaces.format.d.ts +43 -0
  49. package/dist_ts/mod_format/interfaces.format.js +2 -0
  50. package/dist_ts/mod_format/mod.plugins.d.ts +5 -1
  51. package/dist_ts/mod_format/mod.plugins.js +6 -2
  52. package/package.json +2 -1
  53. package/readme.hints.md +187 -0
  54. package/readme.plan.md +170 -0
  55. package/ts/00_commitinfo_data.ts +1 -1
  56. package/ts/gitzone.cli.ts +29 -1
  57. package/ts/gitzone.logging.ts +23 -1
  58. package/ts/mod_format/classes.baseformatter.ts +93 -0
  59. package/ts/mod_format/classes.changecache.ts +144 -0
  60. package/ts/mod_format/classes.dependency-analyzer.ts +107 -0
  61. package/ts/mod_format/classes.diffreporter.ts +108 -0
  62. package/ts/mod_format/classes.formatcontext.ts +65 -0
  63. package/ts/mod_format/classes.formatplanner.ts +184 -0
  64. package/ts/mod_format/classes.formatstats.ts +209 -0
  65. package/ts/mod_format/classes.rollbackmanager.ts +218 -0
  66. package/ts/mod_format/format.copy.ts +77 -1
  67. package/ts/mod_format/format.packagejson.ts +50 -1
  68. package/ts/mod_format/formatters/cleanup.formatter.ts +39 -0
  69. package/ts/mod_format/formatters/copy.formatter.ts +8 -0
  70. package/ts/mod_format/formatters/gitignore.formatter.ts +8 -0
  71. package/ts/mod_format/formatters/legacy.formatter.ts +36 -0
  72. package/ts/mod_format/formatters/license.formatter.ts +8 -0
  73. package/ts/mod_format/formatters/npmextra.formatter.ts +8 -0
  74. package/ts/mod_format/formatters/packagejson.formatter.ts +8 -0
  75. package/ts/mod_format/formatters/prettier.formatter.ts +125 -0
  76. package/ts/mod_format/formatters/readme.formatter.ts +22 -0
  77. package/ts/mod_format/formatters/templates.formatter.ts +8 -0
  78. package/ts/mod_format/formatters/tsconfig.formatter.ts +8 -0
  79. package/ts/mod_format/index.ts +241 -33
  80. package/ts/mod_format/interfaces.format.ts +45 -0
  81. package/ts/mod_format/mod.plugins.ts +8 -0
@@ -1,40 +1,248 @@
1
1
  import * as plugins from './mod.plugins.js';
2
2
  import { Project } from '../classes.project.js';
3
+ import { FormatContext } from './classes.formatcontext.js';
4
+ import { FormatPlanner } from './classes.formatplanner.js';
5
+ import { logger, setVerboseMode } from '../gitzone.logging.js';
3
6
 
4
- export let run = async (writeArg: boolean = true): Promise<any> => {
5
- const project = await Project.fromCwd();
6
-
7
- // cleanup
8
- const formatCleanup = await import('./format.cleanup.js');
9
- await formatCleanup.run(project);
10
-
11
- // npmextra
12
- const formatNpmextra = await import('./format.npmextra.js');
13
- await formatNpmextra.run(project);
14
-
15
- // license
16
- const formatLicense = await import('./format.license.js');
17
- await formatLicense.run(project);
18
-
19
- // format package.json
20
- const formatPackageJson = await import('./format.packagejson.js');
21
- await formatPackageJson.run(project);
7
+ // Import wrapper classes for formatters
8
+ import { CleanupFormatter } from './formatters/cleanup.formatter.js';
9
+ import { NpmextraFormatter } from './formatters/npmextra.formatter.js';
10
+ import { LicenseFormatter } from './formatters/license.formatter.js';
11
+ import { PackageJsonFormatter } from './formatters/packagejson.formatter.js';
12
+ import { TemplatesFormatter } from './formatters/templates.formatter.js';
13
+ import { GitignoreFormatter } from './formatters/gitignore.formatter.js';
14
+ import { TsconfigFormatter } from './formatters/tsconfig.formatter.js';
15
+ import { PrettierFormatter } from './formatters/prettier.formatter.js';
16
+ import { ReadmeFormatter } from './formatters/readme.formatter.js';
17
+ import { CopyFormatter } from './formatters/copy.formatter.js';
22
18
 
23
- // format .gitlab-ci.yml
24
- const formatTemplates = await import('./format.templates.js');
25
- await formatTemplates.run(project);
26
-
27
- // format .gitignore
28
- const formatGitignore = await import('./format.gitignore.js');
29
- await formatGitignore.run(project);
19
+ export let run = async (options: {
20
+ dryRun?: boolean;
21
+ yes?: boolean;
22
+ planOnly?: boolean;
23
+ savePlan?: string;
24
+ fromPlan?: string;
25
+ detailed?: boolean;
26
+ interactive?: boolean;
27
+ parallel?: boolean;
28
+ verbose?: boolean;
29
+ } = {}): Promise<any> => {
30
+ // Set verbose mode if requested
31
+ if (options.verbose) {
32
+ setVerboseMode(true);
33
+ }
34
+
35
+ const project = await Project.fromCwd();
36
+ const context = new FormatContext();
37
+ await context.initializeCache(); // Initialize the cache system
38
+ const planner = new FormatPlanner();
39
+
40
+ // Get configuration from npmextra
41
+ const npmextraConfig = new plugins.npmextra.Npmextra();
42
+ const formatConfig = npmextraConfig.dataFor<any>('gitzone.format', {
43
+ interactive: true,
44
+ showDiffs: false,
45
+ autoApprove: false,
46
+ planTimeout: 30000,
47
+ rollback: {
48
+ enabled: true,
49
+ autoRollbackOnError: true,
50
+ backupRetentionDays: 7,
51
+ maxBackupSize: '100MB',
52
+ excludePatterns: ['node_modules/**', '.git/**']
53
+ },
54
+ modules: {
55
+ skip: [],
56
+ only: [],
57
+ order: []
58
+ },
59
+ parallel: true,
60
+ cache: {
61
+ enabled: true,
62
+ clean: true // Clean invalid entries from cache
63
+ }
64
+ });
65
+
66
+ // Clean cache if configured
67
+ if (formatConfig.cache.clean) {
68
+ await context.getChangeCache().clean();
69
+ }
70
+
71
+ // Override config with command options
72
+ const interactive = options.interactive ?? formatConfig.interactive;
73
+ const autoApprove = options.yes ?? formatConfig.autoApprove;
74
+ const parallel = options.parallel ?? formatConfig.parallel;
75
+
76
+ try {
77
+ // Initialize formatters
78
+ const formatters = [
79
+ new CleanupFormatter(context, project),
80
+ new NpmextraFormatter(context, project),
81
+ new LicenseFormatter(context, project),
82
+ new PackageJsonFormatter(context, project),
83
+ new TemplatesFormatter(context, project),
84
+ new GitignoreFormatter(context, project),
85
+ new TsconfigFormatter(context, project),
86
+ new PrettierFormatter(context, project),
87
+ new ReadmeFormatter(context, project),
88
+ new CopyFormatter(context, project),
89
+ ];
90
+
91
+ // Filter formatters based on configuration
92
+ const activeFormatters = formatters.filter(formatter => {
93
+ if (formatConfig.modules.only.length > 0) {
94
+ return formatConfig.modules.only.includes(formatter.name);
95
+ }
96
+ if (formatConfig.modules.skip.includes(formatter.name)) {
97
+ return false;
98
+ }
99
+ return true;
100
+ });
101
+
102
+ // Plan phase
103
+ logger.log('info', 'Analyzing project for format operations...');
104
+ let plan = options.fromPlan
105
+ ? JSON.parse(await plugins.smartfile.fs.toStringSync(options.fromPlan))
106
+ : await planner.planFormat(activeFormatters);
107
+
108
+ // Display plan
109
+ await planner.displayPlan(plan, options.detailed);
110
+
111
+ // Save plan if requested
112
+ if (options.savePlan) {
113
+ await plugins.smartfile.memory.toFs(JSON.stringify(plan, null, 2), options.savePlan);
114
+ logger.log('info', `Plan saved to ${options.savePlan}`);
115
+ }
116
+
117
+ // Exit if plan-only mode
118
+ if (options.planOnly) {
119
+ return;
120
+ }
121
+
122
+ // Dry-run mode
123
+ if (options.dryRun) {
124
+ logger.log('info', 'Dry-run mode - no changes will be made');
125
+ return;
126
+ }
127
+
128
+ // Interactive confirmation
129
+ if (interactive && !autoApprove) {
130
+ const interactInstance = new plugins.smartinteract.SmartInteract();
131
+ const response = await interactInstance.askQuestion({
132
+ type: 'confirm',
133
+ name: 'proceed',
134
+ message: 'Proceed with formatting?',
135
+ default: true
136
+ });
137
+
138
+ if (!(response as any).proceed) {
139
+ logger.log('info', 'Format operation cancelled by user');
140
+ return;
141
+ }
142
+ }
143
+
144
+ // Execute phase
145
+ logger.log('info', `Executing format operations${parallel ? ' in parallel' : ' sequentially'}...`);
146
+ await planner.executePlan(plan, activeFormatters, context, parallel);
147
+
148
+ // Finish statistics tracking
149
+ context.getFormatStats().finish();
150
+
151
+ // Display statistics
152
+ const showStats = npmextraConfig.dataFor('gitzone.format.showStats', true);
153
+ if (showStats) {
154
+ context.getFormatStats().displayStats();
155
+ }
156
+
157
+ // Save stats if requested
158
+ if (options.detailed) {
159
+ const statsPath = `.nogit/format-stats-${Date.now()}.json`;
160
+ await context.getFormatStats().saveReport(statsPath);
161
+ }
162
+
163
+ logger.log('success', 'Format operations completed successfully!');
164
+
165
+ } catch (error) {
166
+ logger.log('error', `Format operation failed: ${error.message}`);
167
+
168
+ // Automatic rollback if enabled
169
+ if (formatConfig.rollback.enabled && formatConfig.rollback.autoRollbackOnError) {
170
+ logger.log('info', 'Attempting automatic rollback...');
171
+ try {
172
+ await context.rollbackOperation();
173
+ logger.log('success', 'Rollback completed successfully');
174
+ } catch (rollbackError) {
175
+ logger.log('error', `Rollback failed: ${rollbackError.message}`);
176
+ }
177
+ }
178
+
179
+ throw error;
180
+ }
181
+ };
30
182
 
31
- // format TypeScript
32
- const formatTsConfig = await import('./format.tsconfig.js');
33
- await formatTsConfig.run(project);
34
- const formatPrettier = await import('./format.prettier.js');
35
- await formatPrettier.run(project);
183
+ // Export CLI command handlers
184
+ export const handleRollback = async (operationId?: string): Promise<void> => {
185
+ const context = new FormatContext();
186
+ const rollbackManager = context.getRollbackManager();
187
+
188
+ if (!operationId) {
189
+ // Rollback to last operation
190
+ const backups = await rollbackManager.listBackups();
191
+ const lastOperation = backups
192
+ .filter(op => op.status !== 'rolled-back')
193
+ .sort((a, b) => b.timestamp - a.timestamp)[0];
194
+
195
+ if (!lastOperation) {
196
+ logger.log('warn', 'No operations available for rollback');
197
+ return;
198
+ }
199
+
200
+ operationId = lastOperation.id;
201
+ }
202
+
203
+ try {
204
+ await rollbackManager.rollback(operationId);
205
+ logger.log('success', `Successfully rolled back operation ${operationId}`);
206
+ } catch (error) {
207
+ logger.log('error', `Rollback failed: ${error.message}`);
208
+ throw error;
209
+ }
210
+ };
36
211
 
37
- // format readme.md
38
- const formatReadme = await import('./format.readme.js');
39
- await formatReadme.run();
212
+ export const handleListBackups = async (): Promise<void> => {
213
+ const context = new FormatContext();
214
+ const rollbackManager = context.getRollbackManager();
215
+ const backups = await rollbackManager.listBackups();
216
+
217
+ if (backups.length === 0) {
218
+ logger.log('info', 'No backup operations found');
219
+ return;
220
+ }
221
+
222
+ console.log('\nAvailable backups:');
223
+ console.log('━'.repeat(50));
224
+
225
+ for (const backup of backups) {
226
+ const date = new Date(backup.timestamp).toLocaleString();
227
+ const status = backup.status;
228
+ const filesCount = backup.files.length;
229
+
230
+ console.log(`ID: ${backup.id}`);
231
+ console.log(`Date: ${date}`);
232
+ console.log(`Status: ${status}`);
233
+ console.log(`Files: ${filesCount}`);
234
+ console.log('─'.repeat(50));
235
+ }
40
236
  };
237
+
238
+ export const handleCleanBackups = async (): Promise<void> => {
239
+ const context = new FormatContext();
240
+ const rollbackManager = context.getRollbackManager();
241
+
242
+ // Get retention days from config
243
+ const npmextraConfig = new plugins.npmextra.Npmextra();
244
+ const retentionDays = npmextraConfig.dataFor<any>('gitzone.format.rollback.backupRetentionDays', 7);
245
+
246
+ await rollbackManager.cleanOldBackups(retentionDays);
247
+ logger.log('success', `Cleaned backups older than ${retentionDays} days`);
248
+ };
@@ -0,0 +1,45 @@
1
+ export type IFormatOperation = {
2
+ id: string;
3
+ timestamp: number;
4
+ files: Array<{
5
+ path: string;
6
+ originalContent: string;
7
+ checksum: string;
8
+ permissions: string;
9
+ }>;
10
+ status: 'pending' | 'in-progress' | 'completed' | 'failed' | 'rolled-back';
11
+ error?: Error;
12
+ }
13
+
14
+ export type IFormatPlan = {
15
+ summary: {
16
+ totalFiles: number;
17
+ filesAdded: number;
18
+ filesModified: number;
19
+ filesRemoved: number;
20
+ estimatedTime: number;
21
+ };
22
+ changes: Array<{
23
+ type: 'create' | 'modify' | 'delete';
24
+ path: string;
25
+ module: string;
26
+ description: string;
27
+ diff?: string;
28
+ size?: number;
29
+ }>;
30
+ warnings: Array<{
31
+ level: 'info' | 'warning' | 'error';
32
+ message: string;
33
+ module: string;
34
+ }>;
35
+ }
36
+
37
+ export type IPlannedChange = {
38
+ type: 'create' | 'modify' | 'delete';
39
+ path: string;
40
+ module: string;
41
+ description: string;
42
+ content?: string; // For create/modify operations
43
+ diff?: string;
44
+ size?: number;
45
+ }
@@ -1,5 +1,7 @@
1
1
  export * from '../plugins.js';
2
2
 
3
+ import * as crypto from 'crypto';
4
+ import * as path from 'path';
3
5
  import * as lik from '@push.rocks/lik';
4
6
  import * as smartfile from '@push.rocks/smartfile';
5
7
  import * as smartgulp from '@push.rocks/smartgulp';
@@ -9,8 +11,12 @@ import * as smartobject from '@push.rocks/smartobject';
9
11
  import * as smartnpm from '@push.rocks/smartnpm';
10
12
  import * as smartstream from '@push.rocks/smartstream';
11
13
  import * as through2 from 'through2';
14
+ import * as npmextra from '@push.rocks/npmextra';
15
+ import * as smartdiff from '@push.rocks/smartdiff';
12
16
 
13
17
  export {
18
+ crypto,
19
+ path,
14
20
  lik,
15
21
  smartfile,
16
22
  smartgulp,
@@ -20,4 +26,6 @@ export {
20
26
  smartnpm,
21
27
  smartstream,
22
28
  through2,
29
+ npmextra,
30
+ smartdiff,
23
31
  };