mirror of
https://github.com/status-im/re-natal.git
synced 2025-02-18 07:26:34 +00:00
enable source maps in Debiug in Chrome mode
- use importScripts function when debugging in chrome - patch packager to serve *.map files
This commit is contained in:
parent
6c74e462d6
commit
337bd49735
@ -233,6 +233,12 @@ updateGitIgnore = () ->
|
|||||||
fs.appendFileSync(".gitignore", "\n# Generated by re-natal\n#\nenv/dev\nindex.android.js\nindex.ios.js")
|
fs.appendFileSync(".gitignore", "\n# Generated by re-natal\n#\nenv/dev\nindex.android.js\nindex.ios.js")
|
||||||
fs.appendFileSync(".gitignore", "\n# Figwheel\n#\nfigwheel_server.log")
|
fs.appendFileSync(".gitignore", "\n# Figwheel\n#\nfigwheel_server.log")
|
||||||
|
|
||||||
|
patchReactNativePackager = () ->
|
||||||
|
log "Patching react-native packager to serve *.map files"
|
||||||
|
edit "node_modules/react-native/packager/react-packager/src/Server/index.js", [
|
||||||
|
[/^(\s*requestType\s*=\s*'map'\s*;)$/m, "//$1"],
|
||||||
|
[/^(\s*}\s*else\s*if.*pathname\.match.*\.map.*\{)$/m, "//$1"]]
|
||||||
|
|
||||||
init = (projName) ->
|
init = (projName) ->
|
||||||
if projName.toLowerCase() is 'react' or !projName.match validNameRx
|
if projName.toLowerCase() is 'react' or !projName.match validNameRx
|
||||||
logErr 'Invalid project name. Use an alphanumeric CamelCase name.'
|
logErr 'Invalid project name. Use an alphanumeric CamelCase name.'
|
||||||
@ -318,6 +324,8 @@ init = (projName) ->
|
|||||||
\"require('react-native/local-cli/cli').init('.', '#{projName}')\"
|
\"require('react-native/local-cli/cli').init('.', '#{projName}')\"
|
||||||
"
|
"
|
||||||
|
|
||||||
|
patchReactNativePackager();
|
||||||
|
|
||||||
updateGitIgnore()
|
updateGitIgnore()
|
||||||
|
|
||||||
generateConfig projName
|
generateConfig projName
|
||||||
@ -458,6 +466,8 @@ doUpgrade = (config) ->
|
|||||||
projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase()
|
projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase()
|
||||||
projNameUs = toUnderscored projName
|
projNameUs = toUnderscored projName
|
||||||
|
|
||||||
|
patchReactNativePackager()
|
||||||
|
|
||||||
copyDevEnvironmentFiles(projNameHyph, projName, "localhost")
|
copyDevEnvironmentFiles(projNameHyph, projName, "localhost")
|
||||||
copyProdEnvironmentFiles(projNameHyph, projName)
|
copyProdEnvironmentFiles(projNameHyph, projName)
|
||||||
log 'upgraded files in env/'
|
log 'upgraded files in env/'
|
||||||
|
@ -8,13 +8,14 @@ var CLOSURE_UNCOMPILED_DEFINES = null;
|
|||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
basePath: "target/",
|
basePath: "target/",
|
||||||
googBasePath: 'goog/'
|
googBasePath: 'goog/',
|
||||||
|
serverPort: 8081
|
||||||
};
|
};
|
||||||
|
|
||||||
var React = require('react-native');
|
var React = require('react-native');
|
||||||
var self;
|
var self;
|
||||||
var scriptQueue = [];
|
var scriptQueue = [];
|
||||||
var server = null; // will be set dynamically
|
var serverHost = null; // will be set dynamically
|
||||||
var fileBasePath = null; // will be set dynamically
|
var fileBasePath = null; // will be set dynamically
|
||||||
var evaluate = eval; // This is needed, direct calls to eval does not work (RN packager???)
|
var evaluate = eval; // This is needed, direct calls to eval does not work (RN packager???)
|
||||||
var externalModules = {};
|
var externalModules = {};
|
||||||
@ -74,9 +75,12 @@ function customEval(url, javascript, success, error) {
|
|||||||
error()
|
error()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function asyncImportScripts(path, success, error) {
|
|
||||||
var url = server + '/' + path;
|
|
||||||
|
|
||||||
|
var isChrome = function () {
|
||||||
|
return typeof importScripts === "function"
|
||||||
|
};
|
||||||
|
|
||||||
|
function asyncImportScripts(url, success, error) {
|
||||||
console.info('(asyncImportScripts) Importing: ' + url);
|
console.info('(asyncImportScripts) Importing: ' + url);
|
||||||
scriptQueue.push(url);
|
scriptQueue.push(url);
|
||||||
fetch(url)
|
fetch(url)
|
||||||
@ -93,7 +97,20 @@ function asyncImportScripts(path, success, error) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Async load of javascript files
|
function syncImportScripts(url, success, error) {
|
||||||
|
try {
|
||||||
|
importScripts(url);
|
||||||
|
console.info('Evaluated: ' + url);
|
||||||
|
evalListeners.forEach(function (listener) {
|
||||||
|
listener(url)
|
||||||
|
});
|
||||||
|
success();
|
||||||
|
} catch (e) {
|
||||||
|
error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loads js file sync if possible or async.
|
||||||
function importJs(src, success, error) {
|
function importJs(src, success, error) {
|
||||||
if (typeof success !== 'function') {
|
if (typeof success !== 'function') {
|
||||||
success = function () {
|
success = function () {
|
||||||
@ -104,10 +121,14 @@ function importJs(src, success, error) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var filePath = fileBasePath + '/' + src;
|
var file = fileBasePath + '/' + src;
|
||||||
|
|
||||||
console.info('(importJs) Importing: ' + filePath);
|
console.info('(importJs) Importing: ' + file);
|
||||||
asyncImportScripts(filePath, success, error);
|
if (isChrome()) {
|
||||||
|
syncImportScripts(serverBaseUrl("localhost") + '/' + file, success, error);
|
||||||
|
} else {
|
||||||
|
asyncImportScripts(serverBaseUrl(serverHost) + '/' + file, success, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function interceptRequire() {
|
function interceptRequire() {
|
||||||
@ -127,8 +148,12 @@ function debugToLog() {
|
|||||||
console.debug = console.log;
|
console.debug = console.log;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function serverBaseUrl(host) {
|
||||||
|
return "http://" + host + ":" + config.serverPort
|
||||||
|
}
|
||||||
|
|
||||||
function loadApp(platform, devHost, onLoadCb) {
|
function loadApp(platform, devHost, onLoadCb) {
|
||||||
server = "http://" + devHost + ":8081";
|
serverHost = devHost;
|
||||||
fileBasePath = config.basePath + platform;
|
fileBasePath = config.basePath + platform;
|
||||||
|
|
||||||
evalListeners.push(function (url) {
|
evalListeners.push(function (url) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user