This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
chore(types): add function types to element and locators #3279
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -5,6 +5,9 @@ var clangFormat = require('clang-format'); | |
var gulpFormat = require('gulp-clang-format'); | ||
var runSequence = require('run-sequence'); | ||
var spawn = require('child_process').spawn; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var glob = require('glob'); | ||
|
||
var runSpawn = function(done, task, opt_arg) { | ||
opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : []; | ||
|
@@ -56,12 +59,53 @@ gulp.task('tsc', function(done) { | |
}); | ||
|
||
gulp.task('prepublish', function(done) { | ||
runSequence(['typings', 'jshint', 'clang'],'tsc', 'built:copy', done); | ||
runSequence(['typings', 'jshint', 'clang'], 'tsc', 'types', 'built:copy', done); | ||
}); | ||
|
||
gulp.task('pretest', function(done) { | ||
runSequence( | ||
['webdriver:update', 'typings', 'jshint', 'clang'], 'tsc', 'built:copy', done); | ||
['webdriver:update', 'typings', 'jshint', 'clang'], 'tsc', 'types', | ||
'built:copy', done); | ||
}); | ||
|
||
gulp.task('default',['prepublish']); | ||
|
||
gulp.task('types', function(done) { | ||
var folder = 'built'; | ||
var files = ['ptor', 'browser', 'locators']; | ||
var outputFile = path.resolve(folder, 'index.d.ts'); | ||
var contents = ''; | ||
files.forEach(file => { | ||
contents += parseTypingsFile(folder, file); | ||
}); | ||
|
||
// add module declaration | ||
contents += 'declare module "protractor" {\n'; | ||
contents += ' export = protractor\n'; | ||
contents += '}\n'; | ||
|
||
// remove files with d.ts | ||
glob.sync(folder + '/**/*.d.ts').forEach(file => { | ||
fs.unlinkSync(path.resolve(file)); | ||
}); | ||
|
||
// write contents to 'built/index.d.ts' | ||
fs.writeFileSync(outputFile, contents); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, I think it's a little cleaner to just do:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see that folder is used for more stuff. Nevermind. |
||
done(); | ||
}); | ||
|
||
var parseTypingsFile = function(folder, file) { | ||
var fileContents = fs.readFileSync(path.resolve(folder, file + '.d.ts')).toString(); | ||
var lines = fileContents.split('\n'); | ||
var contents = ''; | ||
for (var linePos in lines) { | ||
var line = lines[linePos]; | ||
if (!line.startsWith('import')) { | ||
if (line.indexOf('export') !== -1) { | ||
line = line.replace('export', '').trim(); | ||
} | ||
contents += line + '\n'; | ||
} | ||
} | ||
return contents; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this step? Do they interfere if left in?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this would be cleaner to have one d.ts file instead of many when we publish to npm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, sgtm.