Skip to content

Commit

Permalink
added npm ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Rostaminikoo authored and Rostaminikoo committed Aug 15, 2023
1 parent eda210a commit 3677fe4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 42 deletions.
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test
src
public

webpack.config.js
tsconfig.json
jest.config.js
13 changes: 0 additions & 13 deletions index.html

This file was deleted.

22 changes: 0 additions & 22 deletions src/api.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export * from "./parameters";
export * from "./properties";
export * from "./statements";
export * from "./types";
export * from "./api";
export * from "./writer";
24 changes: 24 additions & 0 deletions src/writer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import ts from "typescript";

export class Writer {

private _printer: ts.Printer;
private _nodes: Array<ts.Node> = [];

constructor(...nodes: Array<ts.Node>) {
this._nodes = nodes || this._nodes;
this._printer = ts.createPrinter({ newLine: ts.NewLineKind.CarriageReturnLineFeed });
}

setNodes(...nodes: Array<ts.Node>) {
this._nodes = nodes || this._nodes;
}

print(): string {
const result: Array<string> = [];
this._nodes.forEach(n =>
result.push(this._printer.printNode(ts.EmitHint.Unspecified, n, undefined))
)
return result.join("\n\n")
}
}
11 changes: 5 additions & 6 deletions test/compilerAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

// import "ts-polyfill";

import ts, { SyntaxKind, factory } from "typescript";
import { nodeText, ConstructorGenerator, IdentifierGenerator, TypeGenerator, ParameterGenerator, ClassGenerator, stringType, assignToClassProperty, expOrNull, numberType } from "../src";
import { IdentifierGenerator, TypeGenerator, ClassGenerator, stringType, assignToClassProperty, expOrNull, numberType, Writer } from "../src";

describe("test typescript compiler API directly", () => {
test("idendifier Generatore", () => {
const cg = new IdentifierGenerator("hamid");
expect(nodeText(cg.generate())).toEqual("hamid")
expect(new Writer(cg.generate()).print()).toEqual("hamid")
});

test("TypeGenerator testing", () => {
Expand All @@ -21,12 +20,12 @@ describe("test typescript compiler API directly", () => {
const cg = new TypeGenerator("MyType");
cg.setType(arrayString);

expect(nodeText(cg.generate())).toEqual("type MyType = string[];")
expect(new Writer(cg.generate()).print()).toEqual("type MyType = string[];")

const f = new TypeGenerator("IfcText");
f.Modifiers.export();
f.setType(cg.toArrayTypeNode())
expect(nodeText(f.generate())).toEqual("export type IfcText = MyType[];")
expect(new Writer(f.generate()).print()).toEqual("export type IfcText = MyType[];")
});

test("class Generator", () => {
Expand All @@ -51,7 +50,7 @@ describe("test typescript compiler API directly", () => {
.setBody()
.returnsProperty(property.Identifier);

console.log(new Writer(c.generate()).print());

console.log(nodeText(c.generate()));
})
});

0 comments on commit 3677fe4

Please sign in to comment.