-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f7d5b0
commit 26c7664
Showing
42 changed files
with
373 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
|
||
import { rollup } from 'rollup'; | ||
import { readdirSync ,writeFileSync } from 'fs'; | ||
import { readdirSync, writeFileSync } from 'fs'; | ||
|
||
import dts from "rollup-plugin-dts"; | ||
|
||
async function build_dts_file(lang){ | ||
async function build_dts_file(lang) { | ||
console.log(`正在编译${lang}语言的.d.ts文件`); | ||
const path=`./src/.decls/${lang}`; | ||
const rollup_config={ | ||
input: path+'/jsstp.d.ts', | ||
const path = `./src/.decls/${lang}`; | ||
const rollup_config = { | ||
input: path + '/jsstp.d.ts', | ||
output: [ | ||
{ | ||
format: 'esm' | ||
} | ||
], | ||
plugins: [dts()] | ||
} | ||
var bundle=await rollup(rollup_config) | ||
var dts_code= (await bundle.generate(rollup_config.output[0])).output[0].code; | ||
var bundle = await rollup(rollup_config) | ||
var dts_code = (await bundle.generate(rollup_config.output[0])).output[0].code; | ||
|
||
//修补d.ts | ||
//`info_object$1`=>`info_object` | ||
dts_code=dts_code.replace(/info_object\$1/g,'info_object'); | ||
dts_code = dts_code.replace(/info_object\$1/g, 'info_object'); | ||
// `some ${string}` => string | ||
dts_code=dts_code.replace(/`some \${string}`/g,'string'); | ||
dts_code = dts_code.replace(/`some \${string}`/g, 'string'); | ||
|
||
{ | ||
var dts_code_array=dts_code.split("\n"); | ||
var dts_code_array = dts_code.split("\n"); | ||
//remove all single line comments | ||
dts_code_array=dts_code_array.filter(line=>!/^[ \t]*\/\//.test(line)); | ||
dts_code_array = dts_code_array.filter(line => !/^[ \t]*\/\//.test(line)); | ||
//remove all multi line comments | ||
var in_comment=false; | ||
dts_code_array=dts_code_array.filter(line=>{ | ||
if(/[ \t]*\/\*(?![\*@])/.test(line)) | ||
in_comment=true; | ||
if(in_comment && /\*\/$/.test(line)){ | ||
in_comment=false; | ||
var in_comment = false; | ||
dts_code_array = dts_code_array.filter(line => { | ||
if (/[ \t]*\/\*(?![\*@])/.test(line)) | ||
in_comment = true; | ||
if (in_comment && /\*\/$/.test(line)) { | ||
in_comment = false; | ||
return false; | ||
} | ||
if(!in_comment) | ||
if (!in_comment) | ||
return true; | ||
return false; | ||
}); | ||
//remove all multi empty lines to single empty line | ||
var last_line_is_empty=false; | ||
dts_code_array=dts_code_array.filter(line=>{ | ||
if(line.length==0){ | ||
if(last_line_is_empty) | ||
var last_line_is_empty = false; | ||
dts_code_array = dts_code_array.filter(line => { | ||
if (line.length == 0) { | ||
if (last_line_is_empty) | ||
return false; | ||
else | ||
last_line_is_empty=true; | ||
}else | ||
last_line_is_empty=false; | ||
last_line_is_empty = true; | ||
} else | ||
last_line_is_empty = false; | ||
return true; | ||
}); | ||
dts_code=dts_code_array.join("\n"); | ||
dts_code = dts_code_array.join("\n"); | ||
} | ||
|
||
writeFileSync(`dist/${lang}/jsstp.d.ts`,dts_code); | ||
writeFileSync(`dist/${lang}/jsstp.d.ts`, dts_code); | ||
} | ||
//对于每个在src/.decls/中的文件夹,我们都需要调用一次build_dts_file | ||
for(const lang of readdirSync("./src/.decls")) | ||
for (const lang of readdirSync("./src/.decls")) | ||
build_dts_file(lang); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.