7
7
* 6. Convert them to await expressions
8
8
*/
9
9
10
- import fs from "fs" ;
11
-
12
10
import {
13
11
FileInfo ,
14
12
API ,
15
13
Options ,
16
- ASTPath ,
17
- CallExpression ,
18
14
ExportDefaultDeclaration ,
19
15
ExportNamedDeclaration ,
20
- AwaitExpression ,
21
- Collection ,
22
16
} from "jscodeshift" ;
17
+ import CONSTANTS from "./constants" ;
23
18
24
19
const tsParser = require ( "jscodeshift/parser/ts" ) ;
25
20
26
21
const debug = require ( "debug" ) ( "transform:export-async-script" ) ;
27
22
const debug2 = require ( "debug" ) ( "transform:print:export-async-script" ) ;
28
23
29
- import {
30
- addAwaitKeyword ,
31
- convertAllCallExpressionToAsync ,
32
- findParentFunction ,
33
- setFunctionAsync ,
34
- } from "./utils" ;
35
-
36
- const METEOR_ROOT_DIRECTORY = "/home/minhna/WORKS/Mike/settler/se2-admin" ;
24
+ import { convertAllCallExpressionToAsync , getFileContent } from "./utils" ;
37
25
38
26
module . exports = function ( fileInfo : FileInfo , { j } : API , options : Options ) {
39
27
debug (
@@ -52,45 +40,11 @@ module.exports = function (fileInfo: FileInfo, { j }: API, options: Options) {
52
40
53
41
const getRealImportSource = ( source : string ) : string => {
54
42
if ( / ^ \/ / . test ( source ) ) {
55
- return METEOR_ROOT_DIRECTORY + source ;
43
+ return CONSTANTS . METEOR_ROOT_DIRECTORY + source ;
56
44
}
57
45
return getPathFromSource ( fileInfo . path ) + "/" + source . replace ( / ^ \. \/ / , "" ) ;
58
46
} ;
59
47
60
- const getFileContent = ( path : string ) : string | undefined => {
61
- let fileContent : Buffer | null = null ;
62
-
63
- if ( / ( \. j s | \. t s ) $ / . test ( path ) ) {
64
- try {
65
- fileContent = fs . readFileSync ( path ) ;
66
- } catch ( e ) {
67
- debug ( "File was not found:" , path ) ;
68
- }
69
- } else {
70
- try {
71
- fileContent = fs . readFileSync ( path + ".js" ) ;
72
- } catch ( e ) {
73
- try {
74
- fileContent = fs . readFileSync ( path + ".ts" ) ;
75
- } catch ( e2 ) {
76
- // check for index file
77
- try {
78
- fileContent = fs . readFileSync ( path + "/index.js" ) ;
79
- } catch ( e3 ) {
80
- try {
81
- fileContent = fs . readFileSync ( path + "/index.ts" ) ;
82
- } catch ( e4 ) {
83
- debug ( "File was not found" ) ;
84
- }
85
- }
86
- }
87
- }
88
- }
89
-
90
- // debug("content", fileContent.toString());
91
- return fileContent ?. toString ( ) ;
92
- } ;
93
-
94
48
// function to read the export source file, then check for exported async function
95
49
interface AnalyzeSourceParams {
96
50
exportedFunction : string ;
0 commit comments