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: {
|
2015-12-15 15:14:10 -05:00
|
|
|
from: /\s*System.config\(\{[\s\S]*\}\);/m,
|
2015-11-22 23:56:28 -05:00
|
|
|
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',
|
2016-02-25 16:20:11 -05:00
|
|
|
//to: ['https://code.angularjs.org/tools/system.js', 'https://code.angularjs.org/tools/typescript.js']
|
|
|
|
to: ['https://code.angularjs.org/tools/system.js', 'https://npmcdn.com/typescript@1.8.2/lib/typescript.js']
|
2015-11-22 23:56:28 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/angular2/bundles/angular2.dev.js',
|
2016-03-09 20:44:47 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-beta.9/angular2.dev.js'
|
2015-11-22 23:56:28 -05:00
|
|
|
},
|
2015-12-15 06:38:42 -05:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
2015-12-15 15:59:56 -05:00
|
|
|
from: 'node_modules/angular2/bundles/angular2-all.umd.js',
|
2016-03-09 20:44:47 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-beta.9/angular2-all.umd.dev.js'
|
2015-12-15 06:38:42 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/angular2/bundles/angular2-polyfills.js',
|
2016-03-09 20:44:47 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-beta.9/angular2-polyfills.js'
|
2015-12-15 06:38:42 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/rxjs/bundles/Rx.js',
|
2016-03-09 20:44:47 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-beta.9/Rx.js'
|
2015-12-15 06:38:42 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
2015-12-15 15:59:56 -05:00
|
|
|
from: 'node_modules/rxjs/bundles/Rx.umd.js',
|
2016-03-09 20:44:47 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-beta.9/Rx.umd.js'
|
2015-12-15 06:38:42 -05:00
|
|
|
},
|
2015-11-22 23:56:28 -05:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/angular2/bundles/router.dev.js',
|
2016-03-09 20:44:47 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-beta.9/router.dev.js'
|
2015-11-22 23:56:28 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/angular2/bundles/http.dev.js',
|
2016-03-09 20:44:47 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-beta.9/http.dev.js'
|
2015-11-22 23:56:28 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
2015-12-15 06:38:42 -05:00
|
|
|
from: 'node_modules/angular2/bundles/testing.dev.js',
|
2016-03-09 20:44:47 -05:00
|
|
|
to: 'https://code.angularjs.org/2.0.0-beta.9/testing.dev.js'
|
2015-11-22 23:56:28 -05:00
|
|
|
},
|
2016-02-18 01:20:03 -05:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
|
2016-03-09 20:44:47 -05:00
|
|
|
to: 'https://npmcdn.com/angular2@2.0.0-beta.9/es6/dev/src/testing/shims_for_IE.js'
|
2016-02-18 01:20:03 -05:00
|
|
|
},
|
2016-01-17 18:02:15 -05:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/es6-shim/es6-shim.min.js',
|
|
|
|
to: 'https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.min.js'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: 'script',
|
2016-01-17 22:59:34 -05:00
|
|
|
from: 'node_modules/systemjs/dist/system-polyfills.js',
|
2016-02-11 18:08:06 -05:00
|
|
|
to: 'https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.20/system-polyfills.js'
|
2016-01-17 18:02:15 -05:00
|
|
|
},
|
2015-12-01 06:15:14 -05:00
|
|
|
{
|
|
|
|
pattern: 'script',
|
|
|
|
from: 'node_modules/a2-in-memory-web-api/web-api.js',
|
|
|
|
to: 'https://npmcdn.com/a2-in-memory-web-api/web-api.js'
|
|
|
|
},
|
2015-11-22 23:56:28 -05:00
|
|
|
{
|
|
|
|
pattern: 'link',
|
|
|
|
from: 'node_modules/bootstrap/dist/css/bootstrap.min.css',
|
2016-01-22 05:40:37 -05:00
|
|
|
to: 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css'
|
2015-11-22 23:56:28 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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]);
|
|
|
|
}
|