forge-type 1.0.3 → 1.0.4
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/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +40 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const index_1 = require("./index");
|
|
11
|
+
const program = new commander_1.Command();
|
|
12
|
+
program
|
|
13
|
+
.name('forge-type-cli')
|
|
14
|
+
.description('CLI for generating TypeScript types from JSON data')
|
|
15
|
+
.version('1.0.0');
|
|
16
|
+
program
|
|
17
|
+
.command('generate')
|
|
18
|
+
.description('Generate TypeScript type/interface for a model')
|
|
19
|
+
.requiredOption('-m, --model <name>', 'Model name')
|
|
20
|
+
.requiredOption('-d, --data <file>', 'Path to JSON file with model data')
|
|
21
|
+
.option('-o, --output <dir>', 'Output directory', './types')
|
|
22
|
+
.option('--modify', 'Modify existing type if exists', false)
|
|
23
|
+
.action((options) => {
|
|
24
|
+
const dataPath = path_1.default.resolve(process.cwd(), options.data);
|
|
25
|
+
if (!fs_1.default.existsSync(dataPath)) {
|
|
26
|
+
console.error('Data file not found:', dataPath);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
const jsonData = JSON.parse(fs_1.default.readFileSync(dataPath, 'utf-8'));
|
|
30
|
+
const result = (0, index_1.createTypeFromData)(options.model, jsonData, { modify: options.modify });
|
|
31
|
+
// Save to output directory
|
|
32
|
+
const outputDir = path_1.default.resolve(process.cwd(), options.output);
|
|
33
|
+
if (!fs_1.default.existsSync(outputDir))
|
|
34
|
+
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
35
|
+
const outputPath = path_1.default.join(outputDir, `${options.model}.ts`);
|
|
36
|
+
fs_1.default.writeFileSync(outputPath, result.type, 'utf-8');
|
|
37
|
+
console.log('Type generated at:', outputPath);
|
|
38
|
+
});
|
|
39
|
+
program.parse(process.argv);
|
|
40
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AACA,yCAAmC;AACnC,4CAAmB;AACnB,gDAAuB;AACvB,mCAA4C;AAE5C,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAA;AAE7B,OAAO;KACJ,IAAI,CAAC,gBAAgB,CAAC;KACtB,WAAW,CAAC,oDAAoD,CAAC;KACjE,OAAO,CAAC,OAAO,CAAC,CAAA;AAEnB,OAAO;KACJ,OAAO,CAAC,UAAU,CAAC;KACnB,WAAW,CAAC,gDAAgD,CAAC;KAC7D,cAAc,CAAC,oBAAoB,EAAE,YAAY,CAAC;KAClD,cAAc,CAAC,mBAAmB,EAAE,mCAAmC,CAAC;KACxE,MAAM,CAAC,oBAAoB,EAAE,kBAAkB,EAAE,SAAS,CAAC;KAC3D,MAAM,CAAC,UAAU,EAAE,gCAAgC,EAAE,KAAK,CAAC;KAC3D,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;IAClB,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version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE;;;EAoBzF"}
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTypeFromData = createTypeFromData;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
4
5
|
const interfaceGenerator_1 = require("./generator/interfaceGenerator");
|
|
5
|
-
|
|
6
|
-
function createTypeFromData(name, data, options // pass { modify: true } to update existing interface
|
|
7
|
-
) {
|
|
6
|
+
function createTypeFromData(name, data, options) {
|
|
8
7
|
const typeString = (0, interfaceGenerator_1.generateInterface)(name, data, options);
|
|
9
|
-
|
|
8
|
+
// Trigger CLI to write file
|
|
9
|
+
const args = [
|
|
10
|
+
'generate',
|
|
11
|
+
'--model', name,
|
|
12
|
+
'--data', JSON.stringify(data), // or path to a temp file
|
|
13
|
+
'--output', './types',
|
|
14
|
+
];
|
|
15
|
+
const cli = (0, child_process_1.spawn)('npx', ['forge-type-cli', ...args], { stdio: 'inherit' });
|
|
16
|
+
cli.on('close', (code) => {
|
|
17
|
+
if (code === 0)
|
|
18
|
+
console.log('File created successfully via CLI');
|
|
19
|
+
else
|
|
20
|
+
console.error('CLI process failed');
|
|
21
|
+
});
|
|
10
22
|
return {
|
|
11
23
|
name,
|
|
12
|
-
filePath,
|
|
13
24
|
type: typeString,
|
|
14
25
|
};
|
|
15
26
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAGA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAGA,gDAoBC;AAvBD,iDAAqC;AACrC,uEAAkE;AAElE,SAAgB,kBAAkB,CAAC,IAAY,EAAE,IAAS,EAAE,OAA8B;IACxF,MAAM,UAAU,GAAG,IAAA,sCAAiB,EAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAEzD,4BAA4B;IAC5B,MAAM,IAAI,GAAG;QACX,UAAU;QACV,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,yBAAyB;QACzD,UAAU,EAAE,SAAS;KACtB,CAAA;IACD,MAAM,GAAG,GAAG,IAAA,qBAAK,EAAC,KAAK,EAAE,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAA;IAC3E,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;QACvB,IAAI,IAAI,KAAK,CAAC;YAAE,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAA;;YAC3D,OAAO,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,IAAI;QACJ,IAAI,EAAE,UAAU;KACjB,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "forge-type",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Automatically generates TypeScript interfaces and types from JSON data, with enum detection.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
],
|
|
24
24
|
"author": "Your Name",
|
|
25
25
|
"license": "MIT",
|
|
26
|
-
"dependencies": {
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"commander": "^14.0.2"
|
|
28
|
+
},
|
|
27
29
|
"devDependencies": {
|
|
28
30
|
"@types/node": "^25.0.3",
|
|
29
31
|
"ts-node": "^10.9.2",
|