-
Notifications
You must be signed in to change notification settings - Fork 1
/
GenCode_TS.ts
29 lines (25 loc) · 983 Bytes
/
GenCode_TS.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { FairyEditor } from 'csharp';
import CodeWriter from './CodeWriter';
import { PackageCodeGen } from './PackageCodeGen';
export const genCode = (handler: FairyEditor.PublishHandler) => {
// convert chinese to pinyin, remove special chars etc.
const codePkgName = handler.ToFilename(handler.pkg.name);
const exportCodePath = `${handler.exportCodePath}`;
const writer = new CodeWriter({ blockFromNewLine: false, usingTabs: true });
writer.reset();
const rawPackageCodes = new PackageCodeGen(handler).gen();
if (!rawPackageCodes.length) return;
const pkgCodes = rawPackageCodes.map((item) => {
return `\t${item}`;
});
const codes: string[] = [];
codes.push('/* eslint-disable */');
codes.push(`declare namespace c`);
codes.push(`{`);
codes.push(...pkgCodes);
codes.push(`}`);
while (codes.length) {
writer.writeln(codes.shift());
}
writer.save(`${exportCodePath}/${codePkgName}.ts`);
};