I have a bunch of typescript files, and some of them export a constant called APIS
.
I'm attempting to access these exports (with the goal of combining them into one file), but for some reason it's not working. I know I must be making a mistake somewhere, but I can't pinpoint what it is.
For instance, in my "services" folder, I have two files: service1.ts and service2.ts.
service1.ts:
...
export const APIS = [ { "field1" : "blabla" } ];
service2.ts: does not have the APIS
variable.
This is my gulpfile.js:
var gulp = require('gulp');
var concat = require('gulp-concat');
var map = require('gulp-map');
gulp.task('default', function() {
return gulp.src('.../services/*.ts')
.pipe(map(function(file) {
return file.APIS;
}))
.pipe(concat('all.js'))
.pipe(gulp.dest('./test/'));
});
When I execute this task, it doesn't output anything. When I added console.log(file.APIS);
to the map function, all values returned undefined
(even though it is defined in service1.ts!).
Referencing: Extracting typescript exports to json file using gulp
EDIT: So, I attempted saving the exports in a .js file rather than a .ts file, and now I am able to access those variables using require
:
gulp.task('default', function() {
return gulp.src('./**/*.service.export.js')
.pipe(map(function(file) {
var fileObj = require(file.path);
...
}))
Now if I try console.log(fileObj.APIS);
I receive the correct values. However, I'm still unsure how to pass these values along and merge them into a single file. Is there a way to aggregate them into an array?