2015-11-22 23:56:28 -05:00
|
|
|
module.exports = {
|
|
|
|
translate: translate
|
|
|
|
};
|
|
|
|
|
|
|
|
var _rxRules = {
|
2015-12-10 12:40:54 -05:00
|
|
|
basehref: {
|
2015-12-10 14:49:25 -05:00
|
|
|
from: /<base href=".*"[/]?>/,
|
2015-12-10 12:40:54 -05:00
|
|
|
to: '<script>document.write(\'<base href="\' + document.location + \'" />\');</script>'
|
|
|
|
},
|
2016-04-27 14:28:22 -04:00
|
|
|
angular_pkg: {
|
|
|
|
from: /src=".?node_modules\/@angular/g,
|
2016-08-31 01:21:47 -04:00
|
|
|
to: 'src="https://unpkg.com/@angular'
|
2016-04-27 14:28:22 -04:00
|
|
|
},
|
2015-11-22 23:56:28 -05:00
|
|
|
script: {
|
|
|
|
from: /<script.*".*%tag%".*>.*<\/script>/,
|
2016-09-01 02:56:12 -04:00
|
|
|
to: '<script src="%tag%"></script>'
|
2015-11-22 23:56:28 -05:00
|
|
|
},
|
|
|
|
link: {
|
|
|
|
from: '/<link rel="stylesheet" href=".*%tag%".*>/',
|
2016-09-01 02:56:12 -04:00
|
|
|
to: '<link rel="stylesheet" href="%tag%">'
|
2016-05-19 15:45:15 -04:00
|
|
|
},
|
2016-11-05 15:53:47 -04:00
|
|
|
systemjs: {
|
|
|
|
from: /<script src="systemjs.config.js"><\/script>/,
|
2016-11-21 20:13:21 -05:00
|
|
|
to: '<script src="https://cdn.rawgit.com/angular/angular.io/b3c65a9/public/docs/_examples/_boilerplate/systemjs.config.web.js"></script>'
|
2016-11-05 15:53:47 -04:00
|
|
|
},
|
|
|
|
// Clear script like this:
|
|
|
|
// <script>
|
|
|
|
// System.import('app').catch(function(err){ console.error(err); });
|
|
|
|
// </script>
|
|
|
|
system_strip_import_app: {
|
2016-11-10 17:44:51 -05:00
|
|
|
from: /<script>[^]?\s*System.import\('app'\)[^]*\/script>/,
|
2016-11-05 15:53:47 -04:00
|
|
|
to: ''
|
|
|
|
},
|
2016-05-19 15:45:15 -04:00
|
|
|
system_extra_main: {
|
|
|
|
from: /main:\s*[\'|\"]index.js[\'|\"]/,
|
2016-09-01 02:56:12 -04:00
|
|
|
to: 'main: "index.ts"'
|
2016-05-19 15:45:15 -04:00
|
|
|
},
|
|
|
|
system_extra_defaultExtension: {
|
|
|
|
from: /defaultExtension:\s*[\'|\"]js[\'|\"]/,
|
2016-09-01 02:56:12 -04:00
|
|
|
to: 'defaultExtension: "ts"'
|
|
|
|
},
|
|
|
|
zone_pkg: {
|
|
|
|
from: /src=".?node_modules\/zone.js\/dist\/(.*)"/g,
|
|
|
|
to: 'src="https://unpkg.com/zone.js/dist/$1?main=browser"'
|
|
|
|
},
|
2015-11-22 23:56:28 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
var _rxData = [
|
2015-12-10 12:40:54 -05:00
|
|
|
{
|
|
|
|
pattern: 'basehref',
|
|
|
|
},
|
2016-05-19 19:37:54 -04:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/core-js/client/shim.min.js',
|
2016-08-31 01:21:47 -04:00
|
|
|
to: 'https://unpkg.com/core-js/client/shim.min.js'
|
2016-05-19 19:37:54 -04:00
|
|
|
},
|
2015-12-15 06:38:42 -05:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
2016-04-27 14:28:22 -04:00
|
|
|
from: 'node_modules/zone.js/dist/zone.js',
|
2016-09-21 08:19:22 -04:00
|
|
|
to: 'https://unpkg.com/zone.js@0.6.25?main=browser'
|
2015-12-15 06:38:42 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
2016-04-27 14:28:22 -04:00
|
|
|
from: 'node_modules/reflect-metadata/Reflect.js',
|
2016-10-21 17:31:09 -04:00
|
|
|
to: 'https://unpkg.com/reflect-metadata@0.1.8'
|
2016-04-07 16:31:40 -04:00
|
|
|
},
|
2015-12-15 06:38:42 -05:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
2016-09-13 05:34:44 -04:00
|
|
|
from: 'node_modules/rxjs/bundles/Rx.js',
|
|
|
|
to: 'https://unpkg.com/rxjs@5.0.0-beta.12/bundles/Rx.js'
|
2016-04-07 16:31:40 -04:00
|
|
|
},
|
2015-11-22 23:56:28 -05:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
2016-04-27 14:28:22 -04:00
|
|
|
from: 'node_modules/systemjs/dist/system.src.js',
|
2016-10-21 17:31:09 -04:00
|
|
|
to: 'https://unpkg.com/systemjs@0.19.39/dist/system.src.js'
|
2016-01-17 18:02:15 -05:00
|
|
|
},
|
2015-12-01 06:15:14 -05:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
2016-04-27 14:28:22 -04:00
|
|
|
from: 'node_modules/angular/in-memory-web-api/web-api.js',
|
2016-08-31 01:21:47 -04:00
|
|
|
to: 'https://unpkg.com/angular/in-memory-web-api/web-api.js'
|
2015-12-01 06:15:14 -05:00
|
|
|
},
|
2016-09-01 02:56:12 -04:00
|
|
|
|
|
|
|
// Test libraries
|
|
|
|
|
|
|
|
// Plunker recommends getting jasmine from cloudfare
|
2016-10-30 02:53:21 -04:00
|
|
|
// Don't upgrade to 2.5.x until following issue resolved
|
|
|
|
// https://github.com/jasmine/jasmine/issues/1231
|
2016-09-01 02:56:12 -04:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/jasmine-core/lib/jasmine-core/jasmine.js',
|
|
|
|
to: 'https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js',
|
|
|
|
to: 'https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine-html.js'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/jasmine-core/lib/jasmine-core/boot.js',
|
|
|
|
to: 'https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/boot.js'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'link',
|
|
|
|
from: 'node_modules/jasmine-core/lib/jasmine-core/jasmine.css',
|
|
|
|
to: 'https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.css'
|
|
|
|
},
|
2016-04-27 14:28:22 -04:00
|
|
|
{
|
|
|
|
pattern: 'angular_pkg',
|
2016-05-19 15:45:15 -04:00
|
|
|
},
|
2016-09-01 02:56:12 -04:00
|
|
|
{
|
|
|
|
pattern: 'zone_pkg',
|
|
|
|
},
|
2016-11-05 15:53:47 -04:00
|
|
|
{
|
|
|
|
pattern: 'systemjs',
|
|
|
|
},
|
2016-11-21 02:25:09 -05:00
|
|
|
// {
|
|
|
|
// pattern: 'system_strip_import_app',
|
|
|
|
// },
|
2016-05-19 15:45:15 -04:00
|
|
|
{
|
|
|
|
pattern: 'system_extra_main'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'system_extra_defaultExtension'
|
2015-11-22 23:56:28 -05:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
|
2016-09-01 02:56:12 -04:00
|
|
|
// var first_time = true; // DIAGNOSTIC
|
2015-11-22 23:56:28 -05:00
|
|
|
|
|
|
|
function translate(html) {
|
|
|
|
_rxData.forEach(function(rxDatum) {
|
|
|
|
var rxRule = _rxRules[rxDatum.pattern];
|
|
|
|
// rxFrom is a rexexp
|
|
|
|
var rxFrom = rxRule.from;
|
|
|
|
if (rxDatum.from) {
|
|
|
|
var from = rxDatum.from.replace('/', '\/');
|
|
|
|
var rxTemp = rxFrom.toString();
|
|
|
|
rxTemp = rxTemp.replace('%tag%', from);
|
|
|
|
rxFrom = rxFromString(rxTemp);
|
|
|
|
}
|
|
|
|
// rxTo is a string
|
|
|
|
var rxTo = rxRule.to;
|
|
|
|
if (rxDatum.to) {
|
|
|
|
var to = rxDatum.to;
|
|
|
|
to = Array.isArray(to) ? to : [to];
|
|
|
|
to = to.map(function (toItem) {
|
|
|
|
return rxTo.replace("%tag%", toItem);
|
|
|
|
});
|
|
|
|
rxTo = to.join("\n ");
|
|
|
|
}
|
2016-09-01 02:56:12 -04:00
|
|
|
|
|
|
|
/* DIAGNOSTIC
|
|
|
|
if (first_time && rxDatum.pattern === 'zone_pkg') {
|
|
|
|
first_time = false;
|
|
|
|
|
|
|
|
console.log('zone_pkg');
|
|
|
|
console.log(' rxFrom: '+rxFrom);
|
|
|
|
console.log(' rxTo: '+rxTo);
|
|
|
|
console.log(' replace: ' + html.replace(rxFrom, rxTo ));
|
|
|
|
}
|
|
|
|
*/
|
2015-11-22 23:56:28 -05:00
|
|
|
html = html.replace(rxFrom, rxTo );
|
|
|
|
});
|
|
|
|
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function rxFromString(rxString) {
|
|
|
|
var rx = /^\/(.*)\/(.*)/;
|
|
|
|
var pieces = rx.exec(rxString);
|
|
|
|
return RegExp(pieces[1], pieces[2]);
|
|
|
|
}
|