Skip to content
Permalink
Browse files

createMap.for(Source)Member overhaul

Overhauling the implementation for createMap.for(Source)Member to get more clean code and predicable results, including a lot of Jasmine tests. [conclusion ;)]
  • Loading branch information...
loedeman committed Nov 10, 2016
1 parent 75dd74a commit 69776c835794879b5e2d2ca308663892818e42ba
Showing with 1,324 additions and 1,279 deletions.
  1. +7 −1 .vscode/settings.json
  2. +65 −64 GulpFile.js
  3. +1 −1 bower.json
  4. +1 −1 dist/automapper-classes.d.ts
  5. +1 −1 dist/automapper-declaration.d.ts
  6. +6 −4 dist/automapper-interfaces.d.ts
  7. +6 −4 dist/automapper.d.ts
  8. +175 −67 dist/automapper.js
  9. +1 −0 dist/automapper.js.map
  10. +4 −12 dist/automapper.min.js
  11. +1 −0 dist/automapper.min.js.map
  12. +6 −8 gulp.config.js
  13. +1 −1 package.json
  14. +1 −1 src/js/AsyncAutoMapper.js
  15. +1 −1 src/js/AsyncAutoMapper.js.map
  16. +116 −44 src/js/AutoMapper.js
  17. +1 −1 src/js/AutoMapper.js.map
  18. +4 −2 src/js/AutoMapperEnumerations.js
  19. +1 −1 src/js/AutoMapperEnumerations.js.map
  20. +48 −16 src/js/AutoMapperHelper.js
  21. +1 −1 src/js/AutoMapperHelper.js.map
  22. +2 −2 src/js/AutoMapperValidator.js
  23. +1 −1 src/js/AutoMapperValidator.js.map
  24. +1 −1 src/ts/AsyncAutoMapper.ts
  25. +135 −43 src/ts/AutoMapper.ts
  26. +4 −2 src/ts/AutoMapperEnumerations.ts
  27. +51 −21 src/ts/AutoMapperHelper.ts
  28. +2 −2 src/ts/AutoMapperValidator.ts
  29. +0 −515 test/src/AutoMapper.js
  30. +0 −26 test/src/TypeConverter.js
  31. +0 −30 test/src/naming-conventions/CamelCaseNamingConvention.js
  32. +0 −24 test/src/naming-conventions/PascalCaseNamingConvention.js
  33. +228 −182 test/tests/js/automapper-createmap-formember-specs.js
  34. +28 −6 test/tests/js/automapper-createmap-forsourcemember-specs.js
  35. +346 −184 test/tests/ts/automapper-createmap-formember-specs.ts
  36. +32 −6 test/tests/ts/automapper-createmap-forsourcemember-specs.ts
  37. +2 −0 test/tests/ts/automapper-map-specs.ts
  38. +5 −3 tools/typings/automapper-interfaces.d.ts
  39. +15 −0 tsconfig.json
  40. +24 −0 wallaby.js
@@ -5,7 +5,13 @@
"**/.DS_Store": true,
"bower_modules": true,
"node_modules": true,
"**/__*": true
"**/__*": true,

"dist/": true,
"**/js*/": true,

"test/src*/": true,
"test/coverage*/": true
}
,
"typescript.check.workspaceVersion": false
@@ -16,13 +16,13 @@ var umd = require('gulp-umd');
var path = require('path');

var gulpKarma = require('./tools/gulp/gulp-karma.js');

var Config = require('./gulp.config.js');
var config = new Config();

gulp.task('default', ['compile-app']);

gulp.task('watch', function() {
gulp.task('watch', function () {
gulp.watch([config.allTypeScript], ['compile-app']);
});

@@ -39,62 +39,59 @@ gulp.task('ts-lint', function () {

/** compile TypeScript and include references to library and app .d.ts files. */
gulp.task('compile-app', ['ts-lint'], function () {
var appTsFiles = [config.allAppTsFiles//, // path to typescript files
//config.libraryTypeScriptDefinitions // reference to library .d.ts files
];

var tsResult = gulp.src(appTsFiles)
.pipe(sourcemaps.init())
.pipe(tsc(config.tscOptions));

tsResult.dts.pipe(gulp.dest(config.appJsOutputFolder));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.appJsOutputFolder));
var tscProject = tsc.createProject('tsconfig.json'/*, {
outDir: config.bundleFolder,
outFile: config.appBundleName
}*/);
var tsResult = gulp.src([config.allAppTsFiles])
.pipe(sourcemaps.init())
.pipe(tscProject());

tsResult.dts.pipe(gulp.dest(config.appJsOutputFolder));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.appJsOutputFolder));
});


/** compile TypeScript sample files. */
gulp.task('compile-samples', ['distribute'], function () {
var sampleTsFiles = [
config.allSampleTsFiles//, // path to typescript files
//config.libraryTypeScriptDefinitions // reference to library .d.ts files
];
];

var tscProject = tsc.createProject('tsconfig.json');
var tsResult = gulp.src(sampleTsFiles)
.pipe(sourcemaps.init())
.pipe(tsc(config.tscOptions));
.pipe(sourcemaps.init())
.pipe(tscProject());

tsResult.dts.pipe(gulp.dest(config.samplesJsOutputFolder));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.samplesJsOutputFolder));
tsResult.dts.pipe(gulp.dest(config.samplesJsOutputFolder));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.samplesJsOutputFolder));
});

/** compile TypeScript sample files. */
gulp.task('compile-performance-tests', ['distribute'], function () {
var performanceTestTsFiles = [
config.allPerformanceTestTsFiles
];
];

var tscProject = tsc.createProject('tsconfig.json');
var tsResult = gulp.src(performanceTestTsFiles)
.pipe(sourcemaps.init())
.pipe(tsc(config.tscOptions));
.pipe(sourcemaps.init())
.pipe(tscProject());

tsResult.dts.pipe(gulp.dest(config.performanceTestsJsOutputFolder));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.performanceTestsJsOutputFolder));
tsResult.dts.pipe(gulp.dest(config.performanceTestsJsOutputFolder));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.performanceTestsJsOutputFolder));
});

/** compile TypeScript test files. */
function compileTest() {
var testTsFiles = [
config.allTestTsFiles//, // path to typescript test files
//config.libraryTypeScriptDefinitions // reference to library .d.ts files
];

var tsResult = gulp.src(testTsFiles).pipe(tsc(config.tscOptions));
var tscProject = tsc.createProject('tsconfig.json');
var tsResult = gulp.src([config.allTestTsFiles]).pipe(tscProject());
tsResult.dts.pipe(gulp.dest(config.testJsOutputFolder));
return tsResult.js.pipe(gulp.dest(config.testJsOutputFolder));
}
@@ -105,17 +102,17 @@ gulp.task('compile-test-app-dependent', ['compile-app'], compileTest);
/** compile TypeScript test files. */
gulp.task('compile-test', compileTest);

gulp.task('copy-test-output-coverage-app-dependent',
['compile-test-app-dependent'], function() {
return gulp.src(config.appJsOutputFolder + '**/*.js')
.pipe(copy(config.testCoverageOutputFolder, { prefix: 2 }));
});
gulp.task('copy-test-output-coverage-app-dependent',
['compile-test-app-dependent'], function () {
return gulp.src(config.appJsOutputFolder + '**/*.*')
.pipe(copy(config.testCoverageOutputFolder, { prefix: 2 }));
});

gulp.task('copy-test-output-coverage',
['compile-test'], function() {
return gulp.src(config.appJsOutputFolder + '**/*.js')
.pipe(copy(config.testCoverageOutputFolder, { prefix: 2 }));
});
gulp.task('copy-test-output-coverage',
['compile-test'], function () {
return gulp.src(config.appJsOutputFolder + '**/*.*')
.pipe(copy(config.testCoverageOutputFolder, { prefix: 2 }));
});

/** distribute JS output files. */
gulp.task('distribute', ['bundle-app', 'bundle-app-uglify', 'distribute-app-definitions', 'bundle-app-definitions', 'distribute-app-sync-version']);
@@ -124,19 +121,21 @@ gulp.task('distribute', ['bundle-app', 'bundle-app-uglify', 'distribute-app-defi
gulp.task('bundle-app', ['compile-app'], function () {
// concat source scripts
gulp.src(config.allAppJsFiles)
.pipe(sourcemaps.init())
.pipe(concat(config.appBundleName))
.pipe(umd({
exports: function(file) {
exports: function (file) {
return path.basename(file.path, path.extname(file.path));
}
}))
.pipe(header(config.libraryHeaderTemplate, {
organization : config.libraryOrganization,
organization: config.libraryOrganization,
url: config.libraryUrl,
license: config.libraryLicense,
version: config.libraryVersion,
currentDate: config.currentDate.toISOString()
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.bundleFolder));
});

@@ -145,15 +144,17 @@ gulp.task('bundle-app', ['compile-app'], function () {
gulp.task('bundle-app-uglify', ['compile-app'], function () {
// concat and uglify source scripts
gulp.src(config.allAppJsFiles)
.pipe(uglify())
.pipe(sourcemaps.init())
.pipe(concat(config.appBundleNameMinified))
.pipe(header(config.libraryHeaderTemplate, {
organization : config.libraryOrganization,
.pipe(uglify())
.pipe(header(config.libraryHeaderTemplate, {
organization: config.libraryOrganization,
url: config.libraryUrl,
license: config.libraryLicense,
version: config.libraryVersion,
currentDate: config.currentDate.toISOString()
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.bundleFolder));
});

@@ -190,16 +191,16 @@ gulp.task('distribute-app-sync-version', function () {

function test() {
var karmaConfig = {
configFile: config.testFolder + 'karma.conf.js',
preprocessors: {},
singleRun: true,
autoWatch: false
};
configFile: config.testFolder + 'karma.conf.js',
preprocessors: {},
singleRun: true,
autoWatch: false
};
karmaConfig.preprocessors[config.testCoverageOutputFolder + '**/*.js'] = ['coverage'];

return gulp
.src(config.allTestFiles)
.pipe(gulpKarma(karmaConfig));
.pipe(gulpKarma(karmaConfig));
}
/** execute test files (dependency to compile-test). */
gulp.task('test', ['compile-test', 'copy-test-output-coverage'], test);
@@ -210,22 +211,22 @@ gulp.task('test-app-dependent', ['compile-test-app-dependent', 'copy-test-output
/** watch app and test test files (dependency to compile-test). */
gulp.task('test-watch', ['compile-test', 'copy-test-output-coverage'], function () {
var karmaConfig = {
configFile: config.testFolder + 'karma.conf.js',
//preprocessors: {},
singleRun: false,
autoWatch: true
};
configFile: config.testFolder + 'karma.conf.js',
//preprocessors: {},
singleRun: false,
autoWatch: true
};
//karmaConfig.preprocessors[config.testCoverageOutputFolder + '**/*.js'] = ['coverage'];

gulp.watch([config.allAppTsFiles, config.libraryTypeScriptDefinitions], ['compile-test-app-dependent']);
gulp.watch([config.allTestTsFiles], ['compile-test', 'copy-test-output-coverage']);

gulp.src(config.allTestFiles)
.pipe(gulpKarma(karmaConfig));
});

gulp.task('coveralls', function () {
return gulp
.src(config.testFolder + 'coverage/**/lcov.info')
.pipe(coveralls());
.pipe(coveralls());
});
@@ -1,6 +1,6 @@
{
"name": "automapper-ts",
"version": "1.7.3",
"version": "1.8.0",
"description": "A convention-based object-object mapper in JavaScript, written in TypeScript. Ported from the original C# AutoMapper library at https://github.com/AutoMapper/AutoMapper.",
"keywords": [
"automapper",
@@ -1,7 +1,7 @@
// [bundle remove start]
/// <reference path="automapper-interfaces.d.ts" />
// [bundle remove end]
// Type definitions for AutoMapper.js 1.7.3
// Type definitions for AutoMapper.js 1.8.0
// Project: https://github.com/loedeman/AutoMapper
// Definitions by: Bert Loedeman <https://github.com/loedeman>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -2,7 +2,7 @@

/// <reference path="automapper-classes.d.ts" />

// Type definitions for AutoMapper.js 1.7.3
// Type definitions for AutoMapper.js 1.8.0
// Project: https://github.com/loedeman/AutoMapper
// Definitions by: Bert Loedeman <https://github.com/loedeman>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -1,5 +1,5 @@
// [bundle remove start]
// Type definitions for AutoMapper.js 1.7.3
// Type definitions for AutoMapper.js 1.8.0
// Project: https://github.com/loedeman/AutoMapper
// Definitions by: Bert Loedeman <https://github.com/loedeman>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -10,12 +10,13 @@ declare module AutoMapperJs {
// [v1.8]
interface IProperty18 { // TODO Rename!
name: string;
sourcePropertyName: string;
destinationPropertyName: string;
level: number;
}

interface ISourceProperty extends IProperty18 {
children: ISourceProperty[];
destinationPropertyName: string;
destination: IDestinationProperty;
}

@@ -29,12 +30,13 @@ declare module AutoMapperJs {
transformationType: number; // Ideal: AutoMapperJs.DestinationTransformationType (but not as easy as it appears to be);
constant?: any;
memberConfigurationOptionsFunc?: (opts: IMemberConfigurationOptions) => void;
function2?: any;
asyncMemberConfigurationOptionsFunc?: (opts: IMemberConfigurationOptions, cb: IMemberCallback) => void;
sourceMemberConfigurationOptionsFunc?: (opts: ISourceMemberConfigurationOptions) => void;
asyncSourceMemberConfigurationOptionsFunc?: (opts: ISourceMemberConfigurationOptions, cb: IMemberCallback) => void;
}

interface IDestinationProperty extends IProperty18 {
child: IDestinationProperty;
sourcePropertyName: string;
transformations: IDestinationTransformation[];
ignore: boolean;
sourceMapping: boolean; // TODO is this still necessary?
@@ -1,4 +1,4 @@
// Type definitions for AutoMapper.js 1.7.3
// Type definitions for AutoMapper.js 1.8.0
// Project: https://github.com/loedeman/AutoMapper
// Definitions by: Bert Loedeman <https://github.com/loedeman>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -188,12 +188,13 @@ declare module AutoMapperJs {
// [v1.8]
interface IProperty18 { // TODO Rename!
name: string;
sourcePropertyName: string;
destinationPropertyName: string;
level: number;
}

interface ISourceProperty extends IProperty18 {
children: ISourceProperty[];
destinationPropertyName: string;
destination: IDestinationProperty;
}

@@ -207,12 +208,13 @@ declare module AutoMapperJs {
transformationType: number; // Ideal: AutoMapperJs.DestinationTransformationType (but not as easy as it appears to be);
constant?: any;
memberConfigurationOptionsFunc?: (opts: IMemberConfigurationOptions) => void;
function2?: any;
asyncMemberConfigurationOptionsFunc?: (opts: IMemberConfigurationOptions, cb: IMemberCallback) => void;
sourceMemberConfigurationOptionsFunc?: (opts: ISourceMemberConfigurationOptions) => void;
asyncSourceMemberConfigurationOptionsFunc?: (opts: ISourceMemberConfigurationOptions, cb: IMemberCallback) => void;
}

interface IDestinationProperty extends IProperty18 {
child: IDestinationProperty;
sourcePropertyName: string;
transformations: IDestinationTransformation[];
ignore: boolean;
sourceMapping: boolean; // TODO is this still necessary?

0 comments on commit 69776c8

Please sign in to comment.
You can’t perform that action at this time.