configforge 1.0.0-beta.10 → 1.0.0-beta.11
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.
- package/README.md +56 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/scripts/CLIGenerator.d.ts +109 -0
- package/dist/scripts/CLIGenerator.d.ts.map +1 -0
- package/dist/scripts/CLIGenerator.js +440 -0
- package/dist/scripts/CLIGenerator.js.map +1 -0
- package/dist/scripts/CLIUtils.d.ts +136 -0
- package/dist/scripts/CLIUtils.d.ts.map +1 -0
- package/dist/scripts/CLIUtils.js +361 -0
- package/dist/scripts/CLIUtils.js.map +1 -0
- package/dist/scripts/CommandBuilder.d.ts +72 -0
- package/dist/scripts/CommandBuilder.d.ts.map +1 -0
- package/dist/scripts/CommandBuilder.js +280 -0
- package/dist/scripts/CommandBuilder.js.map +1 -0
- package/dist/scripts/index.d.ts +23 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/index.js +43 -0
- package/dist/scripts/index.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -781,6 +781,57 @@ const result = await converter.convert('./config.yml');
|
|
|
781
781
|
await result.save('./config.json');
|
|
782
782
|
```
|
|
783
783
|
|
|
784
|
+
### Example 9: CLI Generation System
|
|
785
|
+
|
|
786
|
+
```javascript
|
|
787
|
+
const { forge, CLIGenerator } = require('configforge');
|
|
788
|
+
|
|
789
|
+
// Create your converter
|
|
790
|
+
const converter = forge()
|
|
791
|
+
.from('legacy')
|
|
792
|
+
.to('modern')
|
|
793
|
+
.map('app_name', 'name')
|
|
794
|
+
.map('app_version', 'version')
|
|
795
|
+
.map('database.host', 'db.hostname')
|
|
796
|
+
.map('database.port', 'db.port')
|
|
797
|
+
.defaults({
|
|
798
|
+
environment: 'production',
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
// Generate CLI for your converter
|
|
802
|
+
const cli = CLIGenerator.forConverter(converter, {
|
|
803
|
+
name: 'config-converter',
|
|
804
|
+
version: '1.0.0',
|
|
805
|
+
description: 'Convert legacy config to modern format',
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
// Add custom commands
|
|
809
|
+
cli.addCommand({
|
|
810
|
+
name: 'migrate',
|
|
811
|
+
description: 'Migrate all configs in a directory',
|
|
812
|
+
options: [
|
|
813
|
+
{
|
|
814
|
+
flags: '-d, --directory <dir>',
|
|
815
|
+
description: 'Directory containing config files',
|
|
816
|
+
},
|
|
817
|
+
],
|
|
818
|
+
action: async options => {
|
|
819
|
+
// Custom migration logic
|
|
820
|
+
console.log(`Migrating configs in ${options.directory}`);
|
|
821
|
+
},
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
// Parse command line arguments
|
|
825
|
+
cli.parse();
|
|
826
|
+
|
|
827
|
+
// Now you can use your CLI:
|
|
828
|
+
// $ config-converter convert input.yml output.json
|
|
829
|
+
// $ config-converter validate config.yml
|
|
830
|
+
// $ config-converter profile save my-config
|
|
831
|
+
// $ config-converter profile list
|
|
832
|
+
// $ config-converter migrate -d ./configs
|
|
833
|
+
```
|
|
834
|
+
|
|
784
835
|
## 🎯 Key Features
|
|
785
836
|
|
|
786
837
|
- ✅ **Simple API**: Just map fields and convert
|
|
@@ -793,6 +844,7 @@ await result.save('./config.json');
|
|
|
793
844
|
- ✅ **Multi-field merging**: Use `merge()` to combine multiple sources into one target
|
|
794
845
|
- ✅ **Default values**: Set fallback values
|
|
795
846
|
- ✅ **Comprehensive Error Handling**: Advanced error reporting with context and suggestions ⭐ NEW!
|
|
847
|
+
- ✅ **CLI Generation System**: Create command-line interfaces for converters ⭐ NEW!
|
|
796
848
|
- ✅ **File support**: Convert YAML, JSON files directly
|
|
797
849
|
- ✅ **Statistics**: Get detailed conversion reports
|
|
798
850
|
- ✅ **TypeScript**: Full type safety
|
|
@@ -811,13 +863,13 @@ await result.save('./config.json');
|
|
|
811
863
|
- **Field validation with `validate()`**
|
|
812
864
|
- **Lifecycle hooks with `before()` and `after()`** ⭐ NEW!
|
|
813
865
|
- **Advanced error handling and reporting system** ⭐ NEW!
|
|
866
|
+
- **CLI generation system with command-line interfaces** ⭐ ENHANCED!
|
|
814
867
|
- File parsing (YAML, JSON)
|
|
815
868
|
- Conversion statistics and reporting
|
|
816
869
|
- Async and sync conversion support
|
|
817
870
|
|
|
818
871
|
**🚧 Coming Soon:**
|
|
819
872
|
|
|
820
|
-
- CLI generation
|
|
821
873
|
- Plugin system
|
|
822
874
|
|
|
823
875
|
## 💡 Tips
|
|
@@ -843,6 +895,9 @@ await result.save('./config.json');
|
|
|
843
895
|
19. **Error handling provides helpful suggestions** - when field mapping fails, you'll get suggestions for similar field names
|
|
844
896
|
20. **Errors include rich context** - see exactly where and why conversions failed with detailed error information
|
|
845
897
|
21. **Use error categories** to filter and handle different types of errors (validation, mapping, parsing, etc.)
|
|
898
|
+
22. **Create CLIs for converters** - use `CLIGenerator.forConverter(converter)` to generate command-line interfaces
|
|
899
|
+
23. **Use CLI profiles** - save converter configurations as profiles for reuse: `cli profile save my-converter`
|
|
900
|
+
24. **CLI supports batch processing** - convert multiple files at once with pattern matching and parallel processing
|
|
846
901
|
|
|
847
902
|
---
|
|
848
903
|
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export * as validators from './validators/built-in';
|
|
|
6
6
|
export { ValidatorRegistry, validatorRegistry, } from './validators/ValidatorRegistry';
|
|
7
7
|
export * from './types';
|
|
8
8
|
export * from './errors';
|
|
9
|
+
export { CLIGenerator, CLIUtils, CommandBuilder, createCLI, createCommand, quickCLI, } from './scripts';
|
|
9
10
|
export { parsePath, setPath, mergePaths, detectFormat } from './utils';
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,UAAU,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,gCAAgC,CAAC;AACxC,cAAc,SAAS,CAAC;AAGxB,cAAc,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,UAAU,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,gCAAgC,CAAC;AACxC,cAAc,SAAS,CAAC;AAGxB,cAAc,UAAU,CAAC;AAGzB,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,SAAS,EACT,aAAa,EACb,QAAQ,GACT,MAAM,WAAW,CAAC;AAMnB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
36
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.detectFormat = exports.mergePaths = exports.setPath = exports.parsePath = exports.validatorRegistry = exports.ValidatorRegistry = exports.validators = exports.transforms = exports.Mapper = exports.Converter = exports.forge = void 0;
|
|
39
|
+
exports.detectFormat = exports.mergePaths = exports.setPath = exports.parsePath = exports.quickCLI = exports.createCommand = exports.createCLI = exports.CommandBuilder = exports.CLIUtils = exports.CLIGenerator = exports.validatorRegistry = exports.ValidatorRegistry = exports.validators = exports.transforms = exports.Mapper = exports.Converter = exports.forge = void 0;
|
|
40
40
|
// Main exports
|
|
41
41
|
var Forge_1 = require("./core/Forge");
|
|
42
42
|
Object.defineProperty(exports, "forge", { enumerable: true, get: function () { return Forge_1.forge; } });
|
|
@@ -52,6 +52,14 @@ Object.defineProperty(exports, "validatorRegistry", { enumerable: true, get: fun
|
|
|
52
52
|
__exportStar(require("./types"), exports);
|
|
53
53
|
// Error handling exports
|
|
54
54
|
__exportStar(require("./errors"), exports);
|
|
55
|
+
// CLI exports
|
|
56
|
+
var scripts_1 = require("./scripts");
|
|
57
|
+
Object.defineProperty(exports, "CLIGenerator", { enumerable: true, get: function () { return scripts_1.CLIGenerator; } });
|
|
58
|
+
Object.defineProperty(exports, "CLIUtils", { enumerable: true, get: function () { return scripts_1.CLIUtils; } });
|
|
59
|
+
Object.defineProperty(exports, "CommandBuilder", { enumerable: true, get: function () { return scripts_1.CommandBuilder; } });
|
|
60
|
+
Object.defineProperty(exports, "createCLI", { enumerable: true, get: function () { return scripts_1.createCLI; } });
|
|
61
|
+
Object.defineProperty(exports, "createCommand", { enumerable: true, get: function () { return scripts_1.createCommand; } });
|
|
62
|
+
Object.defineProperty(exports, "quickCLI", { enumerable: true, get: function () { return scripts_1.quickCLI; } });
|
|
55
63
|
// Plugin exports
|
|
56
64
|
// export { Plugin, PluginContext } from './plugins/Plugin'; // TODO: Implement plugin system
|
|
57
65
|
// Utility exports
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":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109 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* CLI command configuration
|
|
4
|
+
*/
|
|
5
|
+
export interface CLICommand {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
options?: CLIOption[];
|
|
9
|
+
action: (args: any, options: any) => Promise<void> | void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* CLI option configuration
|
|
13
|
+
*/
|
|
14
|
+
export interface CLIOption {
|
|
15
|
+
flags: string;
|
|
16
|
+
description: string;
|
|
17
|
+
defaultValue?: any;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* CLI generation options
|
|
21
|
+
*/
|
|
22
|
+
export interface CLIGeneratorOptions {
|
|
23
|
+
name?: string;
|
|
24
|
+
version?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
commands?: CLICommand[];
|
|
27
|
+
globalOptions?: CLIOption[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Profile configuration for saving converter setups
|
|
31
|
+
*/
|
|
32
|
+
export interface ConverterProfile {
|
|
33
|
+
name: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
converter: any;
|
|
36
|
+
createdAt: string;
|
|
37
|
+
updatedAt: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* CLI Generator for creating command-line interfaces for ConfigForge converters
|
|
41
|
+
*/
|
|
42
|
+
export declare class CLIGenerator {
|
|
43
|
+
private program;
|
|
44
|
+
private options;
|
|
45
|
+
private profiles;
|
|
46
|
+
private profilesPath;
|
|
47
|
+
constructor(options?: CLIGeneratorOptions);
|
|
48
|
+
/**
|
|
49
|
+
* Set up the main program configuration
|
|
50
|
+
*/
|
|
51
|
+
private setupProgram;
|
|
52
|
+
/**
|
|
53
|
+
* Add built-in commands for common operations
|
|
54
|
+
*/
|
|
55
|
+
private addBuiltInCommands;
|
|
56
|
+
/**
|
|
57
|
+
* Add a custom command to the CLI
|
|
58
|
+
*/
|
|
59
|
+
addCommand(command: CLICommand): void;
|
|
60
|
+
/**
|
|
61
|
+
* Handle the convert command
|
|
62
|
+
*/
|
|
63
|
+
private handleConvertCommand;
|
|
64
|
+
/**
|
|
65
|
+
* Handle the validate command
|
|
66
|
+
*/
|
|
67
|
+
private handleValidateCommand;
|
|
68
|
+
/**
|
|
69
|
+
* Handle profile list command
|
|
70
|
+
*/
|
|
71
|
+
private handleProfileListCommand;
|
|
72
|
+
/**
|
|
73
|
+
* Handle profile save command
|
|
74
|
+
*/
|
|
75
|
+
private handleProfileSaveCommand;
|
|
76
|
+
/**
|
|
77
|
+
* Handle profile delete command
|
|
78
|
+
*/
|
|
79
|
+
private handleProfileDeleteCommand;
|
|
80
|
+
/**
|
|
81
|
+
* Handle profile show command
|
|
82
|
+
*/
|
|
83
|
+
private handleProfileShowCommand;
|
|
84
|
+
/**
|
|
85
|
+
* Load profiles from disk
|
|
86
|
+
*/
|
|
87
|
+
private loadProfiles;
|
|
88
|
+
/**
|
|
89
|
+
* Save profiles to disk
|
|
90
|
+
*/
|
|
91
|
+
private saveProfiles;
|
|
92
|
+
/**
|
|
93
|
+
* Deserialize a converter from configuration
|
|
94
|
+
*/
|
|
95
|
+
private deserializeConverter;
|
|
96
|
+
/**
|
|
97
|
+
* Parse command line arguments and execute
|
|
98
|
+
*/
|
|
99
|
+
parse(argv?: string[]): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Get the commander program instance
|
|
102
|
+
*/
|
|
103
|
+
getProgram(): Command;
|
|
104
|
+
/**
|
|
105
|
+
* Create a CLI for a specific converter
|
|
106
|
+
*/
|
|
107
|
+
static forConverter(_converter: any, options?: Partial<CLIGeneratorOptions>): CLIGenerator;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=CLIGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CLIGenerator.d.ts","sourceRoot":"","sources":["../../src/scripts/CLIGenerator.ts"],"names":[],"mappings":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