@memberjunction/metadata-sync 2.55.0 → 2.57.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.
Files changed (67) hide show
  1. package/README.md +92 -51
  2. package/dist/index.d.ts +21 -1
  3. package/dist/index.js +43 -3
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/file-backup-manager.js +2 -2
  6. package/dist/lib/file-backup-manager.js.map +1 -1
  7. package/dist/lib/provider-utils.d.ts +2 -2
  8. package/dist/lib/provider-utils.js.map +1 -1
  9. package/dist/lib/sql-logger.d.ts +44 -0
  10. package/dist/lib/sql-logger.js +140 -0
  11. package/dist/lib/sql-logger.js.map +1 -0
  12. package/dist/lib/sync-engine.d.ts +25 -0
  13. package/dist/lib/sync-engine.js +72 -2
  14. package/dist/lib/sync-engine.js.map +1 -1
  15. package/dist/lib/transaction-manager.d.ts +35 -0
  16. package/dist/lib/transaction-manager.js +100 -0
  17. package/dist/lib/transaction-manager.js.map +1 -0
  18. package/dist/services/FileResetService.d.ts +30 -0
  19. package/dist/services/FileResetService.js +183 -0
  20. package/dist/services/FileResetService.js.map +1 -0
  21. package/dist/services/InitService.d.ts +17 -0
  22. package/dist/services/InitService.js +118 -0
  23. package/dist/services/InitService.js.map +1 -0
  24. package/dist/services/PullService.d.ts +45 -0
  25. package/dist/services/PullService.js +564 -0
  26. package/dist/services/PullService.js.map +1 -0
  27. package/dist/services/PushService.d.ts +47 -0
  28. package/dist/services/PushService.js +558 -0
  29. package/dist/services/PushService.js.map +1 -0
  30. package/dist/services/StatusService.d.ts +32 -0
  31. package/dist/services/StatusService.js +138 -0
  32. package/dist/services/StatusService.js.map +1 -0
  33. package/dist/services/WatchService.d.ts +34 -0
  34. package/dist/services/WatchService.js +296 -0
  35. package/dist/services/WatchService.js.map +1 -0
  36. package/dist/services/index.d.ts +16 -0
  37. package/dist/services/index.js +28 -0
  38. package/dist/services/index.js.map +1 -0
  39. package/package.json +14 -45
  40. package/bin/debug.js +0 -7
  41. package/bin/run +0 -17
  42. package/bin/run.js +0 -6
  43. package/dist/commands/file-reset/index.d.ts +0 -15
  44. package/dist/commands/file-reset/index.js +0 -221
  45. package/dist/commands/file-reset/index.js.map +0 -1
  46. package/dist/commands/init/index.d.ts +0 -7
  47. package/dist/commands/init/index.js +0 -155
  48. package/dist/commands/init/index.js.map +0 -1
  49. package/dist/commands/pull/index.d.ts +0 -246
  50. package/dist/commands/pull/index.js +0 -1448
  51. package/dist/commands/pull/index.js.map +0 -1
  52. package/dist/commands/push/index.d.ts +0 -41
  53. package/dist/commands/push/index.js +0 -1129
  54. package/dist/commands/push/index.js.map +0 -1
  55. package/dist/commands/status/index.d.ts +0 -10
  56. package/dist/commands/status/index.js +0 -199
  57. package/dist/commands/status/index.js.map +0 -1
  58. package/dist/commands/validate/index.d.ts +0 -15
  59. package/dist/commands/validate/index.js +0 -149
  60. package/dist/commands/validate/index.js.map +0 -1
  61. package/dist/commands/watch/index.d.ts +0 -15
  62. package/dist/commands/watch/index.js +0 -300
  63. package/dist/commands/watch/index.js.map +0 -1
  64. package/dist/hooks/init.d.ts +0 -3
  65. package/dist/hooks/init.js +0 -59
  66. package/dist/hooks/init.js.map +0 -1
  67. package/oclif.manifest.json +0 -376
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@memberjunction/metadata-sync",
3
- "version": "2.55.0",
3
+ "version": "2.57.0",
4
4
  "description": "MemberJunction metadata synchronization CLI tool",
5
5
  "keywords": [
6
- "oclif",
7
6
  "metadata",
8
- "sync"
7
+ "sync",
8
+ "library"
9
9
  ],
10
10
  "homepage": "https://github.com/MemberJunction/MJ",
11
11
  "bugs": {
@@ -19,63 +19,32 @@
19
19
  "author": "MemberJunction",
20
20
  "main": "dist/index.js",
21
21
  "types": "dist/index.d.ts",
22
- "bin": {
23
- "mj-sync": "bin/run.js"
24
- },
25
22
  "files": [
26
- "/bin",
27
- "/dist",
28
- "/oclif.manifest.json"
23
+ "/dist"
29
24
  ],
30
25
  "scripts": {
31
- "build": "tsc -b",
32
- "prepack": "npm run build && oclif manifest && oclif readme",
33
- "postpack": "rimraf oclif.manifest.json",
34
- "version": "oclif readme && git add README.md"
35
- },
36
- "oclif": {
37
- "bin": "mj-sync",
38
- "commands": "./dist/commands",
39
- "hooks": {
40
- "init": "./dist/hooks/init"
41
- },
42
- "dirname": "mj-sync",
43
- "plugins": [
44
- "@oclif/plugin-help",
45
- "@oclif/plugin-warn-if-update-available",
46
- "@oclif/plugin-version"
47
- ],
48
- "warn-if-update-available": {
49
- "timeoutInDays": 1
50
- }
26
+ "build": "tsc -b"
51
27
  },
52
28
  "dependencies": {
53
- "@inquirer/prompts": "^5.0.1",
54
- "@memberjunction/core": "2.55.0",
55
- "@memberjunction/core-entities": "2.55.0",
56
- "@memberjunction/core-entities-server": "2.55.0",
57
- "@memberjunction/global": "2.55.0",
58
- "@memberjunction/sqlserver-dataprovider": "2.55.0",
59
- "@memberjunction/graphql-dataprovider": "2.55.0",
60
- "@oclif/core": "^3",
61
- "@oclif/plugin-help": "^6",
62
- "@oclif/plugin-version": "^2.0.17",
63
- "@oclif/plugin-warn-if-update-available": "^3.0.16",
29
+ "@memberjunction/core": "2.57.0",
30
+ "@memberjunction/core-entities": "2.57.0",
31
+ "@memberjunction/core-entities-server": "2.57.0",
32
+ "@memberjunction/global": "2.57.0",
33
+ "@memberjunction/sqlserver-dataprovider": "2.57.0",
34
+ "@memberjunction/graphql-dataprovider": "2.57.0",
64
35
  "chokidar": "^3.6.0",
65
36
  "cosmiconfig": "9.0.0",
66
37
  "dotenv": "16.4.5",
67
38
  "fast-glob": "^3.3.2",
68
39
  "fs-extra": "^11.2.0",
69
- "ora-classic": "^5.4.2",
70
40
  "zod": "^3.23.4",
71
41
  "crypto": "^1.0.1",
72
42
  "axios": "^1.6.8",
73
- "mssql": "^11.0.1"
43
+ "mssql": "^11.0.1",
44
+ "uuid": "^10.0.0"
74
45
  },
75
46
  "devDependencies": {
76
- "@oclif/prettier-config": "^0.2.1",
77
47
  "@types/fs-extra": "^11.0.4",
78
- "oclif": "^4",
79
48
  "rimraf": "5.0.7",
80
49
  "ts-node": "^10.9.2",
81
50
  "typescript": "^5.4.5"
@@ -83,4 +52,4 @@
83
52
  "engines": {
84
53
  "node": ">=20.0.0"
85
54
  }
86
- }
55
+ }
package/bin/debug.js DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // Debug wrapper for VS Code that properly handles arguments
4
- const args = process.argv.slice(2).join(' ').split(' ').filter(arg => arg.length > 0);
5
- process.argv = [process.argv[0], process.argv[1], ...args];
6
-
7
- require('./run');
package/bin/run DELETED
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const oclif = require('@oclif/core')
4
-
5
- const path = require('path')
6
- const project = path.join(__dirname, '..', 'tsconfig.json')
7
-
8
- // In dev mode -> use ts-node and dev plugins
9
- process.env.NODE_ENV = 'development'
10
-
11
- require('ts-node').register({project})
12
-
13
- // In dev mode, always show stack traces
14
- oclif.settings.debug = true;
15
-
16
- // Start the CLI
17
- oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
package/bin/run.js DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- require('dotenv').config()
3
- ;(async () => {
4
- const oclif = await import('@oclif/core')
5
- await oclif.execute({development: false, dir: __dirname})
6
- })()
@@ -1,15 +0,0 @@
1
- import { Command } from '@oclif/core';
2
- export default class FileReset extends Command {
3
- static description: string;
4
- static examples: string[];
5
- static flags: {
6
- sections: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
7
- 'dry-run': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
- 'no-backup': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
- yes: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
- verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
- };
12
- run(): Promise<void>;
13
- private countSections;
14
- private removeSections;
15
- }
@@ -1,221 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const core_1 = require("@oclif/core");
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const path_1 = __importDefault(require("path"));
9
- const prompts_1 = require("@inquirer/prompts");
10
- const ora_classic_1 = __importDefault(require("ora-classic"));
11
- const fast_glob_1 = __importDefault(require("fast-glob"));
12
- const chalk_1 = __importDefault(require("chalk"));
13
- const config_1 = require("../../config");
14
- const config_manager_1 = require("../../lib/config-manager");
15
- class FileReset extends core_1.Command {
16
- static description = 'Remove primaryKey and sync sections from metadata JSON files';
17
- static examples = [
18
- `<%= config.bin %> <%= command.id %>`,
19
- `<%= config.bin %> <%= command.id %> --sections=primaryKey`,
20
- `<%= config.bin %> <%= command.id %> --sections=sync`,
21
- `<%= config.bin %> <%= command.id %> --dry-run`,
22
- `<%= config.bin %> <%= command.id %> --no-backup`,
23
- `<%= config.bin %> <%= command.id %> --yes`,
24
- ];
25
- static flags = {
26
- sections: core_1.Flags.string({
27
- description: 'Which sections to remove',
28
- options: ['both', 'primaryKey', 'sync'],
29
- default: 'both',
30
- }),
31
- 'dry-run': core_1.Flags.boolean({
32
- description: 'Show what would be removed without actually removing'
33
- }),
34
- 'no-backup': core_1.Flags.boolean({
35
- description: 'Skip creating backup files'
36
- }),
37
- yes: core_1.Flags.boolean({
38
- char: 'y',
39
- description: 'Skip confirmation prompt'
40
- }),
41
- verbose: core_1.Flags.boolean({
42
- char: 'v',
43
- description: 'Show detailed output'
44
- }),
45
- };
46
- async run() {
47
- const { flags } = await this.parse(FileReset);
48
- const spinner = (0, ora_classic_1.default)();
49
- try {
50
- // Load sync config
51
- const syncConfig = await (0, config_1.loadSyncConfig)(config_manager_1.configManager.getOriginalCwd());
52
- if (!syncConfig) {
53
- this.error('No .mj-sync.json found in current directory');
54
- }
55
- // Find all metadata JSON files
56
- spinner.start('Finding metadata files');
57
- const pattern = syncConfig.filePattern || '.*.json';
58
- const files = await (0, fast_glob_1.default)(pattern, {
59
- cwd: config_manager_1.configManager.getOriginalCwd(),
60
- absolute: true,
61
- ignore: ['.mj-sync.json', '.mj-folder.json'],
62
- });
63
- spinner.stop();
64
- if (files.length === 0) {
65
- this.log('No metadata files found');
66
- return;
67
- }
68
- this.log(`Found ${files.length} metadata file${files.length === 1 ? '' : 's'}`);
69
- // Count what will be removed
70
- let filesWithPrimaryKey = 0;
71
- let filesWithSync = 0;
72
- let totalPrimaryKeys = 0;
73
- let totalSyncs = 0;
74
- for (const file of files) {
75
- const content = await fs_extra_1.default.readJson(file);
76
- const stats = this.countSections(content);
77
- if (stats.primaryKeyCount > 0) {
78
- filesWithPrimaryKey++;
79
- totalPrimaryKeys += stats.primaryKeyCount;
80
- }
81
- if (stats.syncCount > 0) {
82
- filesWithSync++;
83
- totalSyncs += stats.syncCount;
84
- }
85
- }
86
- // Show what will be removed
87
- this.log('');
88
- if (flags.sections === 'both' || flags.sections === 'primaryKey') {
89
- this.log(`Will remove ${chalk_1.default.yellow(totalPrimaryKeys)} primaryKey section${totalPrimaryKeys === 1 ? '' : 's'} from ${chalk_1.default.yellow(filesWithPrimaryKey)} file${filesWithPrimaryKey === 1 ? '' : 's'}`);
90
- }
91
- if (flags.sections === 'both' || flags.sections === 'sync') {
92
- this.log(`Will remove ${chalk_1.default.yellow(totalSyncs)} sync section${totalSyncs === 1 ? '' : 's'} from ${chalk_1.default.yellow(filesWithSync)} file${filesWithSync === 1 ? '' : 's'}`);
93
- }
94
- if (flags['dry-run']) {
95
- this.log('');
96
- this.log(chalk_1.default.cyan('Dry run mode - no files will be modified'));
97
- if (flags.verbose) {
98
- this.log('');
99
- for (const file of files) {
100
- const content = await fs_extra_1.default.readJson(file);
101
- const stats = this.countSections(content);
102
- if (stats.primaryKeyCount > 0 || stats.syncCount > 0) {
103
- this.log(`${path_1.default.relative(config_manager_1.configManager.getOriginalCwd(), file)}:`);
104
- if (stats.primaryKeyCount > 0) {
105
- this.log(` - ${stats.primaryKeyCount} primaryKey section${stats.primaryKeyCount === 1 ? '' : 's'}`);
106
- }
107
- if (stats.syncCount > 0) {
108
- this.log(` - ${stats.syncCount} sync section${stats.syncCount === 1 ? '' : 's'}`);
109
- }
110
- }
111
- }
112
- }
113
- return;
114
- }
115
- // Confirm before proceeding
116
- if (!flags.yes) {
117
- const confirmed = await (0, prompts_1.confirm)({
118
- message: 'Do you want to proceed?',
119
- default: false,
120
- });
121
- if (!confirmed) {
122
- this.log('Operation cancelled');
123
- return;
124
- }
125
- }
126
- // Process files
127
- spinner.start('Processing files');
128
- let processedFiles = 0;
129
- let modifiedFiles = 0;
130
- for (const file of files) {
131
- processedFiles++;
132
- const content = await fs_extra_1.default.readJson(file);
133
- const originalContent = JSON.stringify(content);
134
- // Remove sections
135
- const cleanedContent = this.removeSections(content, flags.sections);
136
- // Only write if content changed
137
- if (JSON.stringify(cleanedContent) !== originalContent) {
138
- // Create backup if requested
139
- if (!flags['no-backup']) {
140
- const backupPath = `${file}.backup`;
141
- await fs_extra_1.default.writeJson(backupPath, content, { spaces: 2 });
142
- }
143
- // Write cleaned content
144
- await fs_extra_1.default.writeJson(file, cleanedContent, { spaces: 2 });
145
- modifiedFiles++;
146
- if (flags.verbose) {
147
- spinner.stop();
148
- this.log(`✓ ${path_1.default.relative(config_manager_1.configManager.getOriginalCwd(), file)}`);
149
- spinner.start('Processing files');
150
- }
151
- }
152
- }
153
- spinner.stop();
154
- // Show summary
155
- this.log('');
156
- this.log(chalk_1.default.green(`✓ Reset complete`));
157
- this.log(` Processed: ${processedFiles} file${processedFiles === 1 ? '' : 's'}`);
158
- this.log(` Modified: ${modifiedFiles} file${modifiedFiles === 1 ? '' : 's'}`);
159
- if (!flags['no-backup'] && modifiedFiles > 0) {
160
- this.log(` Backups created: ${modifiedFiles}`);
161
- }
162
- }
163
- catch (error) {
164
- spinner.stop();
165
- this.error(error instanceof Error ? error.message : String(error));
166
- }
167
- }
168
- countSections(data) {
169
- let primaryKeyCount = 0;
170
- let syncCount = 0;
171
- if (Array.isArray(data)) {
172
- for (const item of data) {
173
- const stats = this.countSections(item);
174
- primaryKeyCount += stats.primaryKeyCount;
175
- syncCount += stats.syncCount;
176
- }
177
- }
178
- else if (data && typeof data === 'object') {
179
- if ('primaryKey' in data)
180
- primaryKeyCount++;
181
- if ('sync' in data)
182
- syncCount++;
183
- // Check related entities
184
- if (data.relatedEntities) {
185
- for (const entityData of Object.values(data.relatedEntities)) {
186
- const stats = this.countSections(entityData);
187
- primaryKeyCount += stats.primaryKeyCount;
188
- syncCount += stats.syncCount;
189
- }
190
- }
191
- }
192
- return { primaryKeyCount, syncCount };
193
- }
194
- removeSections(data, sections) {
195
- if (Array.isArray(data)) {
196
- return data.map(item => this.removeSections(item, sections));
197
- }
198
- else if (data && typeof data === 'object') {
199
- const cleaned = { ...data };
200
- // Remove specified sections
201
- if (sections === 'both' || sections === 'primaryKey') {
202
- delete cleaned.primaryKey;
203
- }
204
- if (sections === 'both' || sections === 'sync') {
205
- delete cleaned.sync;
206
- }
207
- // Process related entities
208
- if (cleaned.relatedEntities) {
209
- const cleanedRelated = {};
210
- for (const [entityName, entityData] of Object.entries(cleaned.relatedEntities)) {
211
- cleanedRelated[entityName] = this.removeSections(entityData, sections);
212
- }
213
- cleaned.relatedEntities = cleanedRelated;
214
- }
215
- return cleaned;
216
- }
217
- return data;
218
- }
219
- }
220
- exports.default = FileReset;
221
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/file-reset/index.ts"],"names":[],"mappings":";;;;;AAAA,sCAA6C;AAC7C,wDAA0B;AAC1B,gDAAwB;AACxB,+CAA4C;AAC5C,8DAA8B;AAC9B,0DAAiC;AACjC,kDAA0B;AAC1B,yCAA8C;AAC9C,6DAAyD;AAEzD,MAAqB,SAAU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EAAE,CAAC;oBAC/E,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;gBACzE,CAAC;gBACD,OAAO,CAAC,eAAe,GAAG,cAAc,CAAC;YAC3C,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;;AAvOH,4BAwOC","sourcesContent":["import { Command, Flags } from '@oclif/core';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport { confirm } from '@inquirer/prompts';\nimport ora from 'ora-classic';\nimport fastGlob from 'fast-glob';\nimport chalk from 'chalk';\nimport { loadSyncConfig } from '../../config';\nimport { configManager } from '../../lib/config-manager';\n\nexport default class FileReset extends Command {\n static description = 'Remove primaryKey and sync sections from metadata JSON files';\n \n static examples = [\n `<%= config.bin %> <%= command.id %>`,\n `<%= config.bin %> <%= command.id %> --sections=primaryKey`,\n `<%= config.bin %> <%= command.id %> --sections=sync`,\n `<%= config.bin %> <%= command.id %> --dry-run`,\n `<%= config.bin %> <%= command.id %> --no-backup`,\n `<%= config.bin %> <%= command.id %> --yes`,\n ];\n \n static flags = {\n sections: Flags.string({\n description: 'Which sections to remove',\n options: ['both', 'primaryKey', 'sync'],\n default: 'both',\n }),\n 'dry-run': Flags.boolean({ \n description: 'Show what would be removed without actually removing' \n }),\n 'no-backup': Flags.boolean({ \n description: 'Skip creating backup files' \n }),\n yes: Flags.boolean({ \n char: 'y', \n description: 'Skip confirmation prompt' \n }),\n verbose: Flags.boolean({ \n char: 'v', \n description: 'Show detailed output' \n }),\n };\n \n async run(): Promise<void> {\n const { flags } = await this.parse(FileReset);\n const spinner = ora();\n \n try {\n // Load sync config\n const syncConfig = await loadSyncConfig(configManager.getOriginalCwd());\n if (!syncConfig) {\n this.error('No .mj-sync.json found in current directory');\n }\n \n // Find all metadata JSON files\n spinner.start('Finding metadata files');\n const pattern = syncConfig.filePattern || '.*.json';\n const files = await fastGlob(pattern, {\n cwd: configManager.getOriginalCwd(),\n absolute: true,\n ignore: ['.mj-sync.json', '.mj-folder.json'],\n });\n \n spinner.stop();\n \n if (files.length === 0) {\n this.log('No metadata files found');\n return;\n }\n \n this.log(`Found ${files.length} metadata file${files.length === 1 ? '' : 's'}`);\n \n // Count what will be removed\n let filesWithPrimaryKey = 0;\n let filesWithSync = 0;\n let totalPrimaryKeys = 0;\n let totalSyncs = 0;\n \n for (const file of files) {\n const content = await fs.readJson(file);\n const stats = this.countSections(content);\n if (stats.primaryKeyCount > 0) {\n filesWithPrimaryKey++;\n totalPrimaryKeys += stats.primaryKeyCount;\n }\n if (stats.syncCount > 0) {\n filesWithSync++;\n totalSyncs += stats.syncCount;\n }\n }\n \n // Show what will be removed\n this.log('');\n if (flags.sections === 'both' || flags.sections === 'primaryKey') {\n this.log(`Will remove ${chalk.yellow(totalPrimaryKeys)} primaryKey section${totalPrimaryKeys === 1 ? '' : 's'} from ${chalk.yellow(filesWithPrimaryKey)} file${filesWithPrimaryKey === 1 ? '' : 's'}`);\n }\n if (flags.sections === 'both' || flags.sections === 'sync') {\n this.log(`Will remove ${chalk.yellow(totalSyncs)} sync section${totalSyncs === 1 ? '' : 's'} from ${chalk.yellow(filesWithSync)} file${filesWithSync === 1 ? '' : 's'}`);\n }\n \n if (flags['dry-run']) {\n this.log('');\n this.log(chalk.cyan('Dry run mode - no files will be modified'));\n \n if (flags.verbose) {\n this.log('');\n for (const file of files) {\n const content = await fs.readJson(file);\n const stats = this.countSections(content);\n if (stats.primaryKeyCount > 0 || stats.syncCount > 0) {\n this.log(`${path.relative(configManager.getOriginalCwd(), file)}:`);\n if (stats.primaryKeyCount > 0) {\n this.log(` - ${stats.primaryKeyCount} primaryKey section${stats.primaryKeyCount === 1 ? '' : 's'}`);\n }\n if (stats.syncCount > 0) {\n this.log(` - ${stats.syncCount} sync section${stats.syncCount === 1 ? '' : 's'}`);\n }\n }\n }\n }\n return;\n }\n \n // Confirm before proceeding\n if (!flags.yes) {\n const confirmed = await confirm({\n message: 'Do you want to proceed?',\n default: false,\n });\n \n if (!confirmed) {\n this.log('Operation cancelled');\n return;\n }\n }\n \n // Process files\n spinner.start('Processing files');\n let processedFiles = 0;\n let modifiedFiles = 0;\n \n for (const file of files) {\n processedFiles++;\n const content = await fs.readJson(file);\n const originalContent = JSON.stringify(content);\n \n // Remove sections\n const cleanedContent = this.removeSections(content, flags.sections);\n \n // Only write if content changed\n if (JSON.stringify(cleanedContent) !== originalContent) {\n // Create backup if requested\n if (!flags['no-backup']) {\n const backupPath = `${file}.backup`;\n await fs.writeJson(backupPath, content, { spaces: 2 });\n }\n \n // Write cleaned content\n await fs.writeJson(file, cleanedContent, { spaces: 2 });\n modifiedFiles++;\n \n if (flags.verbose) {\n spinner.stop();\n this.log(`✓ ${path.relative(configManager.getOriginalCwd(), file)}`);\n spinner.start('Processing files');\n }\n }\n }\n \n spinner.stop();\n \n // Show summary\n this.log('');\n this.log(chalk.green(`✓ Reset complete`));\n this.log(` Processed: ${processedFiles} file${processedFiles === 1 ? '' : 's'}`);\n this.log(` Modified: ${modifiedFiles} file${modifiedFiles === 1 ? '' : 's'}`);\n if (!flags['no-backup'] && modifiedFiles > 0) {\n this.log(` Backups created: ${modifiedFiles}`);\n }\n \n } catch (error) {\n spinner.stop();\n this.error(error instanceof Error ? error.message : String(error));\n }\n }\n \n private countSections(data: any): { primaryKeyCount: number; syncCount: number } {\n let primaryKeyCount = 0;\n let syncCount = 0;\n \n if (Array.isArray(data)) {\n for (const item of data) {\n const stats = this.countSections(item);\n primaryKeyCount += stats.primaryKeyCount;\n syncCount += stats.syncCount;\n }\n } else if (data && typeof data === 'object') {\n if ('primaryKey' in data) primaryKeyCount++;\n if ('sync' in data) syncCount++;\n \n // Check related entities\n if (data.relatedEntities) {\n for (const entityData of Object.values(data.relatedEntities)) {\n const stats = this.countSections(entityData);\n primaryKeyCount += stats.primaryKeyCount;\n syncCount += stats.syncCount;\n }\n }\n }\n \n return { primaryKeyCount, syncCount };\n }\n \n private removeSections(data: any, sections: string): any {\n if (Array.isArray(data)) {\n return data.map(item => this.removeSections(item, sections));\n } else if (data && typeof data === 'object') {\n const cleaned = { ...data };\n \n // Remove specified sections\n if (sections === 'both' || sections === 'primaryKey') {\n delete cleaned.primaryKey;\n }\n if (sections === 'both' || sections === 'sync') {\n delete cleaned.sync;\n }\n \n // Process related entities\n if (cleaned.relatedEntities) {\n const cleanedRelated: any = {};\n for (const [entityName, entityData] of Object.entries(cleaned.relatedEntities)) {\n cleanedRelated[entityName] = this.removeSections(entityData, sections);\n }\n cleaned.relatedEntities = cleanedRelated;\n }\n \n return cleaned;\n }\n \n return data;\n }\n}"]}
@@ -1,7 +0,0 @@
1
- import { Command } from '@oclif/core';
2
- export default class Init extends Command {
3
- static description: string;
4
- static examples: string[];
5
- run(): Promise<void>;
6
- private createAIPromptsExample;
7
- }
@@ -1,155 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const core_1 = require("@oclif/core");
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const path_1 = __importDefault(require("path"));
9
- const prompts_1 = require("@inquirer/prompts");
10
- const ora_classic_1 = __importDefault(require("ora-classic"));
11
- class Init extends core_1.Command {
12
- static description = 'Initialize a directory for metadata synchronization';
13
- static examples = [
14
- `<%= config.bin %> <%= command.id %>`,
15
- ];
16
- async run() {
17
- const spinner = (0, ora_classic_1.default)();
18
- try {
19
- // Check if already initialized
20
- if (await fs_extra_1.default.pathExists('.mj-sync.json')) {
21
- const overwrite = await (0, prompts_1.select)({
22
- message: 'Directory already initialized. Overwrite configuration?',
23
- choices: [
24
- { name: 'Yes', value: true },
25
- { name: 'No', value: false }
26
- ]
27
- });
28
- if (!overwrite) {
29
- this.log('Initialization cancelled');
30
- return;
31
- }
32
- }
33
- // Create root configuration
34
- const rootConfig = {
35
- version: '1.0.0',
36
- push: {
37
- validateBeforePush: true,
38
- requireConfirmation: true
39
- },
40
- watch: {
41
- debounceMs: 1000,
42
- ignorePatterns: ['*.tmp', '*.bak', '.DS_Store']
43
- }
44
- };
45
- spinner.start('Creating root configuration');
46
- await fs_extra_1.default.writeJson('.mj-sync.json', rootConfig, { spaces: 2 });
47
- spinner.succeed('Created .mj-sync.json');
48
- // Ask if they want to set up an entity directory
49
- const setupEntity = await (0, prompts_1.select)({
50
- message: 'Would you like to set up an entity directory now?',
51
- choices: [
52
- { name: 'Yes - AI Prompts', value: 'ai-prompts' },
53
- { name: 'Yes - Other entity', value: 'other' },
54
- { name: 'No - I\'ll set up later', value: 'no' }
55
- ]
56
- });
57
- if (setupEntity !== 'no') {
58
- const entityName = setupEntity === 'ai-prompts'
59
- ? 'AI Prompts'
60
- : await (0, prompts_1.input)({
61
- message: 'Enter the entity name (e.g., "Templates", "AI Models"):',
62
- });
63
- const dirName = setupEntity === 'ai-prompts'
64
- ? 'ai-prompts'
65
- : await (0, prompts_1.input)({
66
- message: 'Enter the directory name:',
67
- default: entityName.toLowerCase().replace(/\s+/g, '-')
68
- });
69
- // Create entity directory
70
- spinner.start(`Creating ${dirName} directory`);
71
- await fs_extra_1.default.ensureDir(dirName);
72
- // Create entity configuration
73
- const entityConfig = {
74
- entity: entityName,
75
- filePattern: '*.json',
76
- defaults: {}
77
- };
78
- await fs_extra_1.default.writeJson(path_1.default.join(dirName, '.mj-sync.json'), entityConfig, { spaces: 2 });
79
- spinner.succeed(`Created ${dirName} directory with entity configuration`);
80
- // Create example structure
81
- if (setupEntity === 'ai-prompts') {
82
- await this.createAIPromptsExample(dirName);
83
- }
84
- }
85
- this.log('\n✅ Initialization complete!');
86
- this.log('\nNext steps:');
87
- this.log('1. Run "mj-sync pull --entity=\'AI Prompts\'" to pull existing data');
88
- this.log('2. Edit files locally');
89
- this.log('3. Run "mj-sync push" to sync changes back to the database');
90
- }
91
- catch (error) {
92
- spinner.fail('Initialization failed');
93
- // Enhanced error logging for debugging
94
- this.log('\n=== Initialization Error Details ===');
95
- this.log(`Error type: ${error?.constructor?.name || 'Unknown'}`);
96
- this.log(`Error message: ${error instanceof Error ? error.message : String(error)}`);
97
- if (error instanceof Error && error.stack) {
98
- this.log(`\nStack trace:`);
99
- this.log(error.stack);
100
- }
101
- // Log context information
102
- this.log(`\nContext:`);
103
- this.log(`- Working directory: ${process.cwd()}`);
104
- // Check if error is related to common issues
105
- const errorMessage = error instanceof Error ? error.message : String(error);
106
- if (errorMessage.includes('permission') || errorMessage.includes('EACCES')) {
107
- this.log(`\nHint: This appears to be a file permission issue.`);
108
- this.log(`Make sure you have write permissions in the current directory.`);
109
- }
110
- else if (errorMessage.includes('ENOENT') || errorMessage.includes('no such file')) {
111
- this.log(`\nHint: This appears to be a file or directory access issue.`);
112
- this.log(`Make sure the current directory exists and is accessible.`);
113
- }
114
- else if (errorMessage.includes('already exists') || errorMessage.includes('EEXIST')) {
115
- this.log(`\nHint: Files or directories already exist.`);
116
- this.log(`Try using the overwrite option or manually remove existing files.`);
117
- }
118
- this.error(error);
119
- }
120
- }
121
- async createAIPromptsExample(dirName) {
122
- const exampleDir = path_1.default.join(dirName, 'examples');
123
- await fs_extra_1.default.ensureDir(exampleDir);
124
- // Create folder config
125
- const folderConfig = {
126
- defaults: {
127
- CategoryID: '@lookup:AI Prompt Categories.Name=Examples',
128
- Temperature: 0.7
129
- }
130
- };
131
- await fs_extra_1.default.writeJson(path_1.default.join(exampleDir, '.mj-folder.json'), folderConfig, { spaces: 2 });
132
- // Create example prompt
133
- const examplePrompt = {
134
- _primaryKey: {
135
- ID: 'example-001'
136
- },
137
- _fields: {
138
- Name: 'Example Greeting Prompt',
139
- Description: 'A simple example prompt to demonstrate the sync tool',
140
- PromptTypeID: '@lookup:AI Prompt Types.Name=Chat',
141
- Temperature: 0.8,
142
- MaxTokens: 150,
143
- Prompt: '@file:greeting.prompt.md'
144
- }
145
- };
146
- await fs_extra_1.default.writeJson(path_1.default.join(exampleDir, 'greeting.json'), examplePrompt, { spaces: 2 });
147
- // Create the markdown file
148
- const promptContent = `You are a friendly assistant. Please greet the user warmly and ask how you can help them today.
149
-
150
- Be conversational and welcoming in your tone.`;
151
- await fs_extra_1.default.writeFile(path_1.default.join(exampleDir, 'greeting.prompt.md'), promptContent);
152
- }
153
- }
154
- exports.default = Init;
155
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/init/index.ts"],"names":[],"mappings":";;;;;AAAA,sCAAsC;AACtC,wDAA0B;AAC1B,gDAAwB;AACxB,+CAAkD;AAClD,8DAA8B;AAE9B,MAAqB,IAAK,SAAQ,cAAO;IACvC,MAAM,CAAC,WAAW,GAAG,qDAAqD,CAAC;IAE3E,MAAM,CAAC,QAAQ,GAAG;QAChB,qCAAqC;KACtC,CAAC;IAEF,KAAK,CAAC,GAAG;QACP,MAAM,OAAO,GAAG,IAAA,qBAAG,GAAE,CAAC;QAEtB,IAAI,CAAC;YACH,+BAA+B;YAC/B,IAAI,MAAM,kBAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;gBACzC,MAAM,SAAS,GAAG,MAAM,IAAA,gBAAM,EAAC;oBAC7B,OAAO,EAAE,yDAAyD;oBAClE,OAAO,EAAE;wBACP,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE;wBAC5B,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;qBAC7B;iBACF,CAAC,CAAC;gBAEH,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,IAAI,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;oBACrC,OAAO;gBACT,CAAC;YACH,CAAC;YAED,4BAA4B;YAC5B,MAAM,UAAU,GAAG;gBACjB,OAAO,EAAE,OAAO;gBAChB,IAAI,EAAE;oBACJ,kBAAkB,EAAE,IAAI;oBACxB,mBAAmB,EAAE,IAAI;iBAC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OAAO,EAAE,UAAU,CAAC,CAAC;QAClD,MAAM,kBAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAE/B,uBAAuB;QACvB,MAAM,YAAY,GAAG;YACnB,QAAQ,EAAE;gBACR,UAAU,EAAE,4CAA4C;gBACxD,WAAW,EAAE,GAAG;aACjB;SACF,CAAC;QAEF,MAAM,kBAAE,CAAC,SAAS,CAAC,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;QAE1F,wBAAwB;QACxB,MAAM,aAAa,GAAG;YACpB,WAAW,EAAE;gBACX,EAAE,EAAE,aAAa;aAClB;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,yBAAyB;gBAC/B,WAAW,EAAE,sDAAsD;gBACnE,YAAY,EAAE,mCAAmC;gBACjD,WAAW,EAAE,GAAG;gBAChB,SAAS,EAAE,GAAG;gBACd,MAAM,EAAE,0BAA0B;aACnC;SACF,CAAC;QAEF,MAAM,kBAAE,CAAC,SAAS,CAChB,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,EACtC,aAAa,EACb,EAAE,MAAM,EAAE,CAAC,EAAE,CACd,CAAC;QAEF,2BAA2B;QAC3B,MAAM,aAAa,GAAG;;8CAEoB,CAAC;QAE3C,MAAM,kBAAE,CAAC,SAAS,CAChB,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,oBAAoB,CAAC,EAC3C,aAAa,CACd,CAAC;IACJ,CAAC;;AA5KH,uBA6KC","sourcesContent":["import { Command } from '@oclif/core';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport { input, select } from '@inquirer/prompts';\nimport ora from 'ora-classic';\n\nexport default class Init extends Command {\n static description = 'Initialize a directory for metadata synchronization';\n \n static examples = [\n `<%= config.bin %> <%= command.id %>`,\n ];\n \n async run(): Promise<void> {\n const spinner = ora();\n \n try {\n // Check if already initialized\n if (await fs.pathExists('.mj-sync.json')) {\n const overwrite = await select({\n message: 'Directory already initialized. Overwrite configuration?',\n choices: [\n { name: 'Yes', value: true },\n { name: 'No', value: false }\n ]\n });\n \n if (!overwrite) {\n this.log('Initialization cancelled');\n return;\n }\n }\n \n // Create root configuration\n const rootConfig = {\n version: '1.0.0',\n push: {\n validateBeforePush: true,\n requireConfirmation: true\n },\n watch: {\n debounceMs: 1000,\n ignorePatterns: ['*.tmp', '*.bak', '.DS_Store']\n }\n };\n \n spinner.start('Creating root configuration');\n await fs.writeJson('.mj-sync.json', rootConfig, { spaces: 2 });\n spinner.succeed('Created .mj-sync.json');\n \n // Ask if they want to set up an entity directory\n const setupEntity = await select({\n message: 'Would you like to set up an entity directory now?',\n choices: [\n { name: 'Yes - AI Prompts', value: 'ai-prompts' },\n { name: 'Yes - Other entity', value: 'other' },\n { name: 'No - I\\'ll set up later', value: 'no' }\n ]\n });\n \n if (setupEntity !== 'no') {\n const entityName = setupEntity === 'ai-prompts' \n ? 'AI Prompts'\n : await input({\n message: 'Enter the entity name (e.g., \"Templates\", \"AI Models\"):',\n });\n \n const dirName = setupEntity === 'ai-prompts'\n ? 'ai-prompts'\n : await input({\n message: 'Enter the directory name:',\n default: entityName.toLowerCase().replace(/\\s+/g, '-')\n });\n \n // Create entity directory\n spinner.start(`Creating ${dirName} directory`);\n await fs.ensureDir(dirName);\n \n // Create entity configuration\n const entityConfig = {\n entity: entityName,\n filePattern: '*.json',\n defaults: {}\n };\n \n await fs.writeJson(path.join(dirName, '.mj-sync.json'), entityConfig, { spaces: 2 });\n spinner.succeed(`Created ${dirName} directory with entity configuration`);\n \n // Create example structure\n if (setupEntity === 'ai-prompts') {\n await this.createAIPromptsExample(dirName);\n }\n }\n \n this.log('\\n✅ Initialization complete!');\n this.log('\\nNext steps:');\n this.log('1. Run \"mj-sync pull --entity=\\'AI Prompts\\'\" to pull existing data');\n this.log('2. Edit files locally');\n this.log('3. Run \"mj-sync push\" to sync changes back to the database');\n \n } catch (error) {\n spinner.fail('Initialization failed');\n \n // Enhanced error logging for debugging\n this.log('\\n=== Initialization Error Details ===');\n this.log(`Error type: ${error?.constructor?.name || 'Unknown'}`);\n this.log(`Error message: ${error instanceof Error ? error.message : String(error)}`);\n \n if (error instanceof Error && error.stack) {\n this.log(`\\nStack trace:`);\n this.log(error.stack);\n }\n \n // Log context information\n this.log(`\\nContext:`);\n this.log(`- Working directory: ${process.cwd()}`);\n \n // Check if error is related to common issues\n const errorMessage = error instanceof Error ? error.message : String(error);\n if (errorMessage.includes('permission') || errorMessage.includes('EACCES')) {\n this.log(`\\nHint: This appears to be a file permission issue.`);\n this.log(`Make sure you have write permissions in the current directory.`);\n } else if (errorMessage.includes('ENOENT') || errorMessage.includes('no such file')) {\n this.log(`\\nHint: This appears to be a file or directory access issue.`);\n this.log(`Make sure the current directory exists and is accessible.`);\n } else if (errorMessage.includes('already exists') || errorMessage.includes('EEXIST')) {\n this.log(`\\nHint: Files or directories already exist.`);\n this.log(`Try using the overwrite option or manually remove existing files.`);\n }\n \n this.error(error as Error);\n }\n }\n \n private async createAIPromptsExample(dirName: string): Promise<void> {\n const exampleDir = path.join(dirName, 'examples');\n await fs.ensureDir(exampleDir);\n \n // Create folder config\n const folderConfig = {\n defaults: {\n CategoryID: '@lookup:AI Prompt Categories.Name=Examples',\n Temperature: 0.7\n }\n };\n \n await fs.writeJson(path.join(exampleDir, '.mj-folder.json'), folderConfig, { spaces: 2 });\n \n // Create example prompt\n const examplePrompt = {\n _primaryKey: {\n ID: 'example-001'\n },\n _fields: {\n Name: 'Example Greeting Prompt',\n Description: 'A simple example prompt to demonstrate the sync tool',\n PromptTypeID: '@lookup:AI Prompt Types.Name=Chat',\n Temperature: 0.8,\n MaxTokens: 150,\n Prompt: '@file:greeting.prompt.md'\n }\n };\n \n await fs.writeJson(\n path.join(exampleDir, 'greeting.json'), \n examplePrompt, \n { spaces: 2 }\n );\n \n // Create the markdown file\n const promptContent = `You are a friendly assistant. Please greet the user warmly and ask how you can help them today.\n\nBe conversational and welcoming in your tone.`;\n \n await fs.writeFile(\n path.join(exampleDir, 'greeting.prompt.md'),\n promptContent\n );\n }\n}"]}