@aiot-toolkit/generator 2.0.1-alpha.0
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/README.md +11 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/typescript/TypescriptGenerator.d.ts +14 -0
- package/lib/typescript/TypescriptGenerator.js +31 -0
- package/lib/typescript/TypescriptGenerator.js.map +1 -0
- package/package.json +31 -0
package/README.md
ADDED
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TypescriptGenerator = void 0;
|
|
7
|
+
const TypescriptGenerator_1 = __importDefault(require("./typescript/TypescriptGenerator"));
|
|
8
|
+
exports.TypescriptGenerator = TypescriptGenerator_1.default;
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,2FAAkE;AAEzD,8BAFF,6BAAmB,CAEE","file":"index.js","sourcesContent":["import TypescriptGenerator from './typescript/TypescriptGenerator'\n\nexport { TypescriptGenerator }\n"],"sourceRoot":"../src"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MapData } from '@aiot-toolkit/shared-utils';
|
|
2
|
+
import { SourceFile } from 'ts-morph';
|
|
3
|
+
declare class TypescriptGenerator {
|
|
4
|
+
generate(params: {
|
|
5
|
+
sourceFilePath: string;
|
|
6
|
+
targetFilePath: string;
|
|
7
|
+
ast: SourceFile;
|
|
8
|
+
mapList: MapData[];
|
|
9
|
+
}): {
|
|
10
|
+
code: string;
|
|
11
|
+
sourcemap: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export default TypescriptGenerator;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const source_map_1 = require("source-map");
|
|
4
|
+
class TypescriptGenerator {
|
|
5
|
+
generate(params) {
|
|
6
|
+
const { sourceFilePath, ast, targetFilePath, mapList } = params;
|
|
7
|
+
// 生成写入源码
|
|
8
|
+
const code = ast.getFullText();
|
|
9
|
+
// 构建 sourcemap 数据生成 sourcemap
|
|
10
|
+
const generator = new source_map_1.SourceMapGenerator({ file: targetFilePath });
|
|
11
|
+
mapList.forEach((item) => {
|
|
12
|
+
generator.addMapping({
|
|
13
|
+
source: sourceFilePath,
|
|
14
|
+
name: item.name,
|
|
15
|
+
original: {
|
|
16
|
+
line: item.source.startLine,
|
|
17
|
+
column: item.source.startColumn
|
|
18
|
+
},
|
|
19
|
+
generated: {
|
|
20
|
+
line: item.target.startLine,
|
|
21
|
+
column: item.target.startColumn
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
const sourcemap = generator.toString();
|
|
26
|
+
return { code, sourcemap };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.default = TypescriptGenerator;
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=TypescriptGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["typescript/TypescriptGenerator.ts"],"names":[],"mappings":";;AACA,2CAA+C;AAG/C,MAAM,mBAAmB;IACvB,QAAQ,CAAC,MAKR;QACC,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;QAC/D,SAAS;QACT,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;QAC9B,8BAA8B;QAC9B,MAAM,SAAS,GAAG,IAAI,+BAAkB,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAA;QAElE,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACvB,SAAS,CAAC,UAAU,CAAC;gBACnB,MAAM,EAAE,cAAc;gBACtB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,QAAQ,EAAE;oBACR,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;oBAC3B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;iBAChC;gBACD,SAAS,EAAE;oBACT,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;oBAC3B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;iBAChC;aACF,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAA;QACtC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;IAC5B,CAAC;CACF;AAED,kBAAe,mBAAmB,CAAA","file":"TypescriptGenerator.js","sourcesContent":["import { MapData } from '@aiot-toolkit/shared-utils'\nimport { SourceMapGenerator } from 'source-map'\nimport { SourceFile } from 'ts-morph'\n\nclass TypescriptGenerator {\n generate(params: {\n sourceFilePath: string\n targetFilePath: string\n ast: SourceFile\n mapList: MapData[]\n }): { code: string; sourcemap: string } {\n const { sourceFilePath, ast, targetFilePath, mapList } = params\n // 生成写入源码\n const code = ast.getFullText()\n // 构建 sourcemap 数据生成 sourcemap\n const generator = new SourceMapGenerator({ file: targetFilePath })\n\n mapList.forEach((item) => {\n generator.addMapping({\n source: sourceFilePath,\n name: item.name,\n original: {\n line: item.source.startLine,\n column: item.source.startColumn\n },\n generated: {\n line: item.target.startLine,\n column: item.target.startColumn\n }\n })\n })\n\n const sourcemap = generator.toString()\n return { code, sourcemap }\n }\n}\n\nexport default TypescriptGenerator\n"],"sourceRoot":"../../src"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aiot-toolkit/generator",
|
|
3
|
+
"version": "2.0.1-alpha.0",
|
|
4
|
+
"description": "Generate source code and sourcemap from the AST ",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"aiot",
|
|
7
|
+
"vela",
|
|
8
|
+
"generater"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"main": "lib/index.js",
|
|
13
|
+
"directories": {
|
|
14
|
+
"lib": "lib",
|
|
15
|
+
"test": "__tests__"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "ssh://xujunjie1@git.mioffice.cn:29418/vela/aiot-toolkit"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "node ./__tests__/generator.test.js"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@aiot-toolkit/shared-utils": "2.0.1-alpha.0"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "cde5c75fa09622188ee4f1322ff9d53faf4d8520"
|
|
31
|
+
}
|