Skip to content

Commit

Permalink
feat: add declare
Browse files Browse the repository at this point in the history
  • Loading branch information
daichangxin committed May 19, 2021
1 parent 97ef209 commit 3c5ffb7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
5 changes: 2 additions & 3 deletions GenCode_TS.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.genCode = void 0;
const CodeWriter_1 = require("./CodeWriter");
const PackageCodeGen_1 = require("./PackageCodeGen");
const genCode = (handler) => {
exports.genCode = (handler) => {
// convert chinese to pinyin, remove special chars etc.
const codePkgName = handler.ToFilename(handler.pkg.name);
const exportCodePath = `${handler.exportCodePath}`;
Expand All @@ -17,7 +17,7 @@ const genCode = (handler) => {
});
const codes = [];
codes.push('/* eslint-disable */');
codes.push(`namespace c`);
codes.push(`declare namespace c`);
codes.push(`{`);
codes.push(...pkgCodes);
codes.push(`}`);
Expand All @@ -26,4 +26,3 @@ const genCode = (handler) => {
}
writer.save(`${exportCodePath}/${codePkgName}.ts`);
};
exports.genCode = genCode;
2 changes: 1 addition & 1 deletion GenCode_TS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const genCode = (handler: FairyEditor.PublishHandler) => {

const codes: string[] = [];
codes.push('/* eslint-disable */');
codes.push(`namespace c`);
codes.push(`declare namespace c`);
codes.push(`{`);
codes.push(...pkgCodes);
codes.push(`}`);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ https://gist.github.com/daichangxin/dd69b8325e1bd82756432f4681a566f5
## 代码导出风格如下:
1、每个fairygui的包,导出对应一个文件,如包名为farm,则导出的文件是`${设置的导出目录}/farm.ts`

2、为了方便区分定义导出,所有文件默认添加`namespace c`作为命名空间。
2、为了方便区分定义导出,所有文件默认添加`declare namespace c`作为命名空间。

3、例子
```
Expand Down
6 changes: 2 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.onDestroy = exports.onPublish = void 0;
const GenCode_TS_1 = require("./GenCode_TS");
const onPublish = (handler) => {
exports.onPublish = (handler) => {
if (!handler.genCode)
return;
handler.genCode = false;
GenCode_TS_1.genCode(handler);
};
exports.onPublish = onPublish;
const onDestroy = () => {
exports.onDestroy = () => {
// do cleanup here
};
exports.onDestroy = onDestroy;
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "gen-package-defines-plugin",
"displayName": "导出类定义",
"description": "将设置为导出的组件定义导出",
"version": "1.0",
"version": "1.0.0",
"author": {
"name": "xin"
},
Expand Down

0 comments on commit 3c5ffb7

Please sign in to comment.