UNPKG

1.26 kBPlain TextView Raw
1import fileUtil = require("./tool/FileUtil");
2import fs = require("fs");
3import path = require("path");
4class AddNS {
5 private _url: string;
6 constructor(url: string) {
7 var self = this;
8 if(!url)
9 {
10 console.log('------------请输入路径------------');
11 return;
12 }
13 self._url = url;
14 self.trans();
15 }
16
17 private trans():void
18 {
19 let self = this;
20 fileUtil.FileUtil.walkDir(path.join(this._url),self.onFile,null,self);
21 }
22
23 private onFile(url:string):void
24 {
25 let type = path.basename(url).split('.')[0];
26 var tsStr = fs.readFileSync(url, 'utf-8');
27 tsStr = tsStr.replace(/(\r\n)/mg, "\r");
28 tsStr = tsStr.replace(/^/mg, " ");
29 tsStr = tsStr.replace(/(class\s+)/g, "export $1");
30 tsStr = tsStr.replace(/(interface\s+)/g, "export $1");
31 tsStr = tsStr.replace(/(const\s+enum\s+)/g, "export $1");
32 tsStr = tsStr.replace(/(enum\s+)/g, "export $1");
33
34 tsStr = "namespace byh {\r" + tsStr + "\r}";
35 tsStr = tsStr.replace(/\r/mg, "\r\n");
36 fs.writeFileSync(url, tsStr);
37 }
38}
39
40export function run(url: string): void {
41 new AddNS(url);
42}
\No newline at end of file