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>'
|
|
|
|
},
|
2015-11-22 23:56:28 -05:00
|
|
|
script: {
|
|
|
|
from: /<script.*".*%tag%".*>.*<\/script>/,
|
|
|
|
to: '<script src="%tag%"></script>'
|
|
|
|
},
|
|
|
|
link: {
|
|
|
|
from: '/<link rel="stylesheet" href=".*%tag%".*>/',
|
|
|
|
to: '<link rel="stylesheet" href="%tag%">'
|
|
|
|
},
|
|
|
|
config: {
|
|
|
|
from: /\s*System.config\(\{\s*packages:[\s\S]*\}\}\s*\}\);/m,
|
|
|
|
to: "\n" +
|
|
|
|
" System.config({\n" +
|
|
|
|
" transpiler: 'typescript', \n" +
|
|
|
|
" typescriptOptions: { emitDecoratorMetadata: true }, \n" +
|
|
|
|
" packages: {'app': {defaultExtension: 'ts'}} \n" +
|
|
|
|
" });"
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var _rxData = [
|
2015-12-10 12:40:54 -05:00
|
|
|
{
|
|
|
|
pattern: 'basehref',
|
|
|
|
},
|
2015-11-22 23:56:28 -05:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/systemjs/dist/system.src.js',
|
|
|
|
to: ['https://rawgithub.com/systemjs/systemjs/0.19.6/dist/system.js', 'https://code.angularjs.org/tools/typescript.js']
|
|
|
|
// to: ['https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.18.4/system.js', 'https://code.angularjs.org/tools/typescript.js' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/angular2/bundles/angular2.dev.js',
|
2015-12-14 18:44:50 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-alpha.53/angular2.dev.js'
|
2015-11-22 23:56:28 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/angular2/bundles/router.dev.js',
|
2015-12-14 18:44:50 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-alpha.53/router.dev.js'
|
2015-11-22 23:56:28 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/angular2/bundles/http.dev.js',
|
2015-12-14 18:44:50 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-alpha.53/http.dev.js'
|
2015-11-22 23:56:28 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/angular2/bundles/testing.js',
|
2015-12-14 18:44:50 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-alpha.53/testing.js'
|
2015-11-22 23:56:28 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'link',
|
|
|
|
from: 'node_modules/bootstrap/dist/css/bootstrap.min.css',
|
2015-11-30 20:24:16 -05:00
|
|
|
to: 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap-theme.min.css'
|
2015-11-22 23:56:28 -05:00
|
|
|
// to: 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'config',
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 ");
|
|
|
|
}
|
|
|
|
html = html.replace(rxFrom, rxTo );
|
|
|
|
});
|
|
|
|
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function rxFromString(rxString) {
|
|
|
|
var rx = /^\/(.*)\/(.*)/;
|
|
|
|
var pieces = rx.exec(rxString);
|
|
|
|
return RegExp(pieces[1], pieces[2]);
|
|
|
|
}
|