Skip to content

Commit 4db1d7e

Browse files
authored
Merge pull request #11 from cdsiats/feature/07
added feature to use json files in cli #7 4d
2 parents b4160dd + acc2792 commit 4db1d7e

3 files changed

Lines changed: 914 additions & 1 deletion

File tree

packages/idea-transformer/src/Transformer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ export default class Transformer<T extends Record<string, unknown>> {
2525
if (!fs.existsSync(this.input)) {
2626
throw Exception.for('Input file %s does not exist', this.input);
2727
}
28+
//read input file
29+
const content = fs.readFileSync(this.input, 'utf8');
2830
//parse schema
29-
const schema = parse(fs.readFileSync(this.input, 'utf8'));
31+
const schema: SchemaConfig = path.extname(this.input) === '.json'
32+
//parse directly
33+
? JSON.parse(content)
34+
//parse as normal
35+
: parse(content);
3036
//look for use
3137
if (Array.isArray(schema.use)) {
3238
schema.use.forEach((file: string) => {

packages/idea-transformer/tests/Terminal.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ describe('Terminal Tests', () => {
2121
}
2222
}).timeout(20000);
2323

24+
it('Should run cli using json file', async () => {
25+
const terminal = new Terminal(['transform', '-i', './schema.json'], { cwd });
26+
expect(terminal.cwd).to.equal(cwd);
27+
await terminal.run();
28+
const out = path.join(cwd, 'out/enums.ts');
29+
const exists = fs.existsSync(out);
30+
expect(exists).to.be.true;
31+
if (exists) {
32+
fs.unlinkSync(out);
33+
}
34+
}).timeout(20000);
2435
/*
2536
* UNIT TEST TO COVER THE UNCOVERED LINES
2637
*/

0 commit comments

Comments
 (0)