Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ env:
# - MODE=saucelabs DART_CHANNEL=dev
- MODE=dart_experimental DART_CHANNEL=dev
- MODE=js DART_CHANNEL=dev
- MODE=router DART_CHANNEL=dev
- MODE=lint DART_CHANNEL=dev

matrix:
Expand Down
35 changes: 35 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var util = require('./tools/build/util');
var bundler = require('./tools/build/bundle');
var replace = require('gulp-replace');
var insert = require('gulp-insert');
var buildRouter = require('./modules/angular1_router/build');
var uglify = require('gulp-uglify');
var shouldLog = require('./tools/build/logging');
var tslint = require('gulp-tslint');
Expand Down Expand Up @@ -604,6 +605,34 @@ gulp.task('!test.unit.js/karma-run', function(done) {
runKarma('karma-js.conf.js', done);
});

gulp.task('test.unit.router', function (done) {
runSequence(
'!test.unit.router/karma-server',
function() {
watch('modules/**', [
'buildRouter.dev',
'!test.unit.router/karma-run'
]);
}
);
});

gulp.task('!test.unit.router/karma-server', function() {
karma.server.start({configFile: __dirname + '/modules/angular1_router/karma-router.conf.js'});
});


gulp.task('!test.unit.router/karma-run', function(done) {
karma.runner.run({configFile: __dirname + '/modules/angular1_router/karma-router.conf.js'}, function(exitCode) {
// ignore exitCode, we don't want to fail the build in the interactive (non-ci) mode
// karma will print all test failures
done();
});
});

gulp.task('buildRouter.dev', function () {
buildRouter();
});

gulp.task('test.unit.dart', function (done) {
runSequence(
Expand Down Expand Up @@ -641,6 +670,12 @@ gulp.task('!test.unit.dart/karma-server', function() {
});


gulp.task('test.unit.router/ci', function (done) {
var browserConf = getBrowsersFromCLI();
karma.server.start({configFile: __dirname + '/modules/angular1_router/karma-router.conf.js',
singleRun: true, reporters: ['dots'], browsers: browserConf.browsersToRun}, done);
});

gulp.task('test.unit.js/ci', function (done) {
var browserConf = getBrowsersFromCLI();
karma.server.start({configFile: __dirname + '/karma-js.conf.js',
Expand Down
1 change: 1 addition & 0 deletions karma-dart.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = function(config) {

exclude: [
'dist/dart/**/packages/**',
'modules/angular1_router/**'
],

karmaDartImports: {
Expand Down
1 change: 1 addition & 0 deletions karma-js.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = function(config) {

exclude: [
'dist/js/dev/es5/**/e2e_test/**',
'dist/angular1_router.js'
],

customLaunchers: sauceConf.customLaunchers,
Expand Down
133 changes: 133 additions & 0 deletions modules/angular1_router/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
'use strict';

var fs = require('fs');
var ts = require('typescript');

var files = [
'lifecycle_annotations_impl.ts',
'url_parser.ts',
'path_recognizer.ts',
'route_config_impl.ts',
'async_route_handler.ts',
'sync_route_handler.ts',
'route_recognizer.ts',
'instruction.ts',
'route_config_nomalizer.ts',
'route_lifecycle_reflector.ts',
'route_registry.ts',
'router.ts'
];

var PRELUDE = '(function(){\n';
var POSTLUDE = '\n}());\n';
var FACADES = fs.readFileSync(__dirname + '/lib/facades.es5', 'utf8');
var TRACEUR_RUNTIME = fs.readFileSync(__dirname + '/../../node_modules/traceur/bin/traceur-runtime.js', 'utf8');
var DIRECTIVES = fs.readFileSync(__dirname + '/src/ng_outlet.js', 'utf8');
function main() {
var dir = __dirname + '/../angular2/src/router/';

var out = '';

var sharedCode = '';
files.forEach(function (file) {
var moduleName = 'router/' + file.replace(/\.ts$/, '');

sharedCode += transform(moduleName, fs.readFileSync(dir + file, 'utf8'));
});

out += "angular.module('ngComponentRouter')";
out += angularFactory('$router', ['$q', '$location', '$$controllerIntrospector',
'$browser', '$rootScope', '$injector'], [
FACADES,
"var exports = {Injectable: function () {}};",
"var require = function () {return exports;};",
sharedCode,
"var RouteConfig = exports.RouteConfig;",
"angular.annotations = {RouteConfig: RouteConfig, CanActivate: exports.CanActivate};",
"angular.stringifyInstruction = exports.stringifyInstruction;",
"var RouteRegistry = exports.RouteRegistry;",
"var RootRouter = exports.RootRouter;",
//TODO: move this code into a templated JS file
"var registry = new RouteRegistry();",
"var location = new Location();",

"$$controllerIntrospector(function (name, constructor) {",
"if (constructor.$canActivate) {",
"constructor.annotations = constructor.annotations || [];",
"constructor.annotations.push(new angular.annotations.CanActivate(function (instruction) {",
"return $injector.invoke(constructor.$canActivate, constructor, {",
"$routeParams: instruction.component ? instruction.component.params : instruction.params",
"});",
"}));",
"}",
"if (constructor.$routeConfig) {",
"constructor.annotations = constructor.annotations || [];",
"constructor.annotations.push(new angular.annotations.RouteConfig(constructor.$routeConfig));",
"}",
"if (constructor.annotations) {",
"constructor.annotations.forEach(function(annotation) {",
"if (annotation instanceof RouteConfig) {",
"annotation.configs.forEach(function (config) {",
"registry.config(constructor, config);",
"});",
"}",
"});",
"}",
"});",

"var router = new RootRouter(registry, undefined, location, new Object());",
"$rootScope.$watch(function () { return $location.path(); }, function (path) {",
"if (router.lastNavigationAttempt !== path) {",
"router.navigate(path);",
"}",
"});",

"return router;"
].join('\n'));

return PRELUDE + TRACEUR_RUNTIME + DIRECTIVES + out + POSTLUDE;
}


/*
* Given a directory name and a file's TypeScript content, return an object with the ES5 code,
* sourcemap, anf exported variable identifier name for the content.
*/
var IMPORT_RE = new RegExp("import \\{?([\\w\\n_, ]+)\\}? from '(.+)';?", 'g');
function transform(dir, contents) {
contents = contents.replace(IMPORT_RE, function (match, imports, includePath) {
//TODO: remove special-case
if (isFacadeModule(includePath) || includePath === './router_outlet') {
return '';
}
return match;
});
return ts.transpile(contents, {
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS,
sourceRoot: dir
});
}


function angularFactory(name, deps, body) {
return ".factory('" + name + "', [" +
deps.map(function (service) {
return "'" + service + "', ";
}).join('') +
"function (" + deps.join(', ') + ") {\n" + body + "\n}])";
}


function isFacadeModule(modulePath) {
return modulePath.indexOf('facade') > -1 ||
modulePath === 'angular2/src/reflection/reflection';
}

module.exports = function () {
var dist = __dirname + '/../../dist';
if (!fs.existsSync(dist)) {
fs.mkdirSync(dist);
}
fs.writeFileSync(dist + '/angular_1_router.js', main(files));
};
22 changes: 22 additions & 0 deletions modules/angular1_router/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div ng-app="myApp" ng-controller="MyCtrl">

</div>
<script src="../../node_modules/angular/angular.js"></script>
<script src="../../dist/angular_1_router.js"></script>
<script>
angular.module('myApp', ['ngComponentRouter'])
.controller('MyCtrl', ['$router', function ($router) {
console.log($router);
$router.navigate('/')
.then(console.log.bind(console, 'resolve'), console.log.bind(console, 'reject'));
}]);
</script>
</body>
</html>
28 changes: 28 additions & 0 deletions modules/angular1_router/karma-router.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

var sauceConf = require('../../sauce.conf');

// This runs the tests for the router in Angular 1.x

module.exports = function (config) {
var options = {
frameworks: ['jasmine'],

files: [
'../../node_modules/angular/angular.js',
'../../node_modules/angular-animate/angular-animate.js',
'../../node_modules/angular-mocks/angular-mocks.js',

'../../dist/angular_1_router.js',

'test/*.es5.js',
'test/*_spec.js'
],

customLaunchers: sauceConf.customLaunchers,

browsers: ['ChromeCanary']
};

config.set(options);
};
Loading