@@ -33,7 +33,7 @@ var runSpawn = function(done, task, opt_arg, opt_io) {
33
33
} ;
34
34
35
35
gulp . task ( 'built:copy' , function ( ) {
36
- return gulp . src ( [ 'lib/**/*' , '! lib/**/* .ts' ] )
36
+ return gulp . src ( [ 'lib/**/*.js ' , 'lib/globals.d .ts' ] )
37
37
. pipe ( gulp . dest ( 'built/' ) ) ;
38
38
} ) ;
39
39
@@ -72,91 +72,28 @@ gulp.task('tsc:globals', function(done) {
72
72
73
73
gulp . task ( 'prepublish' , function ( done ) {
74
74
runSequence ( [ 'jshint' , 'format' ] , 'tsc' , 'tsc:globals' , 'types' ,
75
- 'ambient' , ' built:copy', done ) ;
75
+ 'built:copy' , done ) ;
76
76
} ) ;
77
77
78
78
gulp . task ( 'pretest' , function ( done ) {
79
79
runSequence (
80
80
[ 'webdriver:update' , 'jshint' , 'format' ] , 'tsc' , 'tsc:globals' ,
81
- 'types' , 'ambient' , ' built:copy', done ) ;
81
+ 'types' , 'built:copy' , done ) ;
82
82
} ) ;
83
83
84
84
gulp . task ( 'default' , [ 'prepublish' ] ) ;
85
85
86
86
gulp . task ( 'types' , function ( done ) {
87
- var folder = 'built' ;
88
- var files = [ 'browser' , 'element' , 'locators' , 'expectedConditions' ,
89
- 'config' , 'plugins' , 'ptor' ] ;
90
- var outputFile = path . resolve ( folder , 'index.d.ts' ) ;
87
+ var outputFile = path . resolve ( 'built' , 'index.d.ts' ) ;
91
88
var contents = '' ;
92
- contents += '/// <reference path="../../@types/node/index.d.ts" />\n' ;
93
- contents += '/// <reference path="../../@types/jasmine/index.d.ts" />\n' ;
94
89
contents += '/// <reference path="../typings/index.d.ts" />\n' ;
95
- contents += 'import {ActionSequence, By, WebDriver, WebElement, WebElementPromise, promise, promise as wdpromise, until} from \'selenium-webdriver\';\n' ;
96
- files . forEach ( file => {
97
- contents += parseTypingsFile ( folder , file ) ;
98
- } ) ;
99
-
100
- // remove files with d.ts
101
- glob . sync ( folder + '/**/*.d.ts' ) . forEach ( file => {
102
- fs . unlinkSync ( path . resolve ( file ) ) ;
103
- } ) ;
104
-
105
- // write contents to 'built/index.d.ts'
90
+ contents += '/// <reference path="./globals.d.ts" />\n' ;
91
+ contents += 'export { ElementHelper, ProtractorBrowser } from \'./browser\';\n' ;
92
+ contents += 'export { ElementArrayFinder, ElementFinder } from \'./element\';\n' ;
93
+ contents += 'export { ProtractorExpectedConditions } from \'./expectedConditions\';\n' ;
94
+ contents += 'export { ProtractorBy } from \'./locators\';\n' ;
95
+ contents += 'export { Config } from \'./config\';\n' ;
96
+ contents += 'export { Ptor } from \'./ptor\';\n' ;
106
97
fs . writeFileSync ( outputFile , contents ) ;
107
98
done ( ) ;
108
99
} ) ;
109
-
110
- var parseTypingsFile = function ( folder , file ) {
111
- var fileContents = fs . readFileSync ( path . resolve ( folder , file + '.d.ts' ) ) . toString ( ) ;
112
- // Remove new lines inside types
113
- fileContents = fileContents . replace (
114
- / w e b d r i v e r .p r o m i s e .P r o m i s e < \{ [ a - z A - Z : , ; \n ] + \} > / g, ( type ) => {
115
- return type . replace ( / \n / g, '' ) ;
116
- }
117
- ) ;
118
- var lines = fileContents . split ( '\n' ) ;
119
- var contents = '' ;
120
- for ( var linePos in lines ) {
121
- var line = lines [ linePos ] ;
122
- if ( ! line . startsWith ( 'import' ) ) {
123
- if ( line . indexOf ( 'declare' ) !== - 1 ) {
124
- line = line . replace ( 'declare' , '' ) . trim ( ) ;
125
- }
126
-
127
- // Remove webdriver types, q, http proxy agent
128
- line = removeTypes ( line , 'webdriver.ActionSequence' ) ;
129
- line = removeTypes ( line , 'webdriver.promise.Promise<[a-zA-Z{},:; ]+>' ) ;
130
- line = removeTypes ( line , 'webdriver.util.Condition' ) ;
131
- line = removeTypes ( line , 'webdriver.WebDriver' ) ;
132
- line = removeTypes ( line , 'webdriver.Locator' ) ;
133
- line = removeTypes ( line , 'webdriver.WebElement' ) ;
134
- line = removeTypes ( line , 'HttpProxyAgent' ) ;
135
- line = removeTypes ( line , 'Q.Promise<[a-zA-Z{},:; ]+>' ) ;
136
- contents += line + '\n' ;
137
- }
138
- }
139
- return contents ;
140
- }
141
-
142
- var removeTypes = function ( line , webdriverType ) {
143
- var tempLine = line . trim ( ) ;
144
- if ( tempLine . startsWith ( '/**' ) || tempLine . startsWith ( '*' ) ) {
145
- return line ;
146
- }
147
- return line . replace ( new RegExp ( webdriverType , 'g' ) , 'any' ) ;
148
- }
149
-
150
- gulp . task ( 'ambient' , function ( done ) {
151
- var fileContents = fs . readFileSync ( path . resolve ( 'built/index.d.ts' ) ) . toString ( ) ;
152
- var contents = '' ;
153
- contents += 'declare namespace protractor {\n' ;
154
- contents += fileContents + '\n' ;
155
- contents += '}\n' ;
156
- contents += 'declare module "protractor" {\n' ;
157
-
158
- contents += ' export = protractor; \n' ;
159
- contents += '}\n' ;
160
- fs . writeFileSync ( path . resolve ( 'built/ambient.d.ts' ) , contents ) ;
161
- done ( ) ;
162
- } ) ;
0 commit comments