refactgor bootstrap-amd
This commit is contained in:
parent
cf1e93a5f4
commit
cf6884c01e
49
src/bootstrap-amd.js
vendored
49
src/bootstrap-amd.js
vendored
|
@ -4,51 +4,10 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var app = require('electron').app;
|
||||
var loader = require('./vs/loader');
|
||||
|
||||
// Duplicated in ../index.html for the renderes.
|
||||
function getNLSConfiguration() {
|
||||
if (process.env['VSCODE_NLS_CONFIG']) {
|
||||
return JSON.parse(process.env['VSCODE_NLS_CONFIG']);
|
||||
}
|
||||
|
||||
var locale = undefined;
|
||||
var localeOpts = '--locale';
|
||||
for (var i = 0; i < process.argv.length; i++) {
|
||||
var arg = process.argv[i];
|
||||
if (arg.slice(0, localeOpts.length) == localeOpts) {
|
||||
var segments = arg.split('=');
|
||||
locale = segments[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (locale === 'pseudo') {
|
||||
return { availableLanguages: {}, pseudo: true }
|
||||
}
|
||||
if (process.env.VSCODE_DEV) {
|
||||
return { availableLanguages: {} };
|
||||
}
|
||||
// We have a built version so we have extracted nls file. Try to find
|
||||
// the right file to use.
|
||||
locale = locale || app.getLocale();
|
||||
while (locale) {
|
||||
var candidate = path.join(__dirname, 'main.nls.') + locale + '.js';
|
||||
if (fs.existsSync(candidate)) {
|
||||
return { availableLanguages: { '*': locale } };
|
||||
} else {
|
||||
var index = locale.lastIndexOf('-');
|
||||
if (index > 0) {
|
||||
locale = locale.substring(0, index);
|
||||
} else {
|
||||
locale = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { availableLanguages: {} };
|
||||
}
|
||||
|
||||
function uriFromPath(_path) {
|
||||
var pathName = path.resolve(_path).replace(/\\/g, '/');
|
||||
|
||||
|
@ -59,8 +18,8 @@ function uriFromPath(_path) {
|
|||
return encodeURI('file://' + pathName);
|
||||
}
|
||||
|
||||
var nlsConfig = getNLSConfiguration();
|
||||
process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfig);
|
||||
var rawNlsConfig = process.env['VSCODE_NLS_CONFIG'];
|
||||
var nlsConfig = rawNlsConfig ? JSON.parse(rawNlsConfig) : { availableLanguages:{} };
|
||||
|
||||
loader.config({
|
||||
baseUrl: uriFromPath(path.join(__dirname)),
|
||||
|
|
43
src/main.js
43
src/main.js
|
@ -7,8 +7,48 @@
|
|||
global.vscodeStart = Date.now();
|
||||
|
||||
var app = require('electron').app;
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
// Duplicated in ../index.html for the renderes.
|
||||
function getNLSConfiguration() {
|
||||
var locale = undefined;
|
||||
var localeOpts = '--locale';
|
||||
for (var i = 0; i < process.argv.length; i++) {
|
||||
var arg = process.argv[i];
|
||||
if (arg.slice(0, localeOpts.length) == localeOpts) {
|
||||
var segments = arg.split('=');
|
||||
locale = segments[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (locale === 'pseudo') {
|
||||
return { availableLanguages: {}, pseudo: true }
|
||||
}
|
||||
if (process.env.VSCODE_DEV) {
|
||||
return { availableLanguages: {} };
|
||||
}
|
||||
// We have a built version so we have extracted nls file. Try to find
|
||||
// the right file to use.
|
||||
locale = locale || app.getLocale();
|
||||
while (locale) {
|
||||
var candidate = path.join(__dirname, 'main.nls.') + locale + '.js';
|
||||
if (fs.existsSync(candidate)) {
|
||||
return { availableLanguages: { '*': locale } };
|
||||
} else {
|
||||
var index = locale.lastIndexOf('-');
|
||||
if (index > 0) {
|
||||
locale = locale.substring(0, index);
|
||||
} else {
|
||||
locale = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { availableLanguages: {} };
|
||||
}
|
||||
|
||||
// Change cwd if given via env variable
|
||||
try {
|
||||
if (process.env.VSCODE_CWD) {
|
||||
|
@ -31,6 +71,9 @@ app.on('open-file', function(event, path) {
|
|||
global.macOpenFiles.push(path);
|
||||
});
|
||||
|
||||
var nlsConfig = getNLSConfiguration();
|
||||
process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfig);
|
||||
|
||||
// Load our code once ready
|
||||
app.once('ready', function() {
|
||||
process.env['AMD_ENTRYPOINT'] = 'vs/workbench/electron-main/main';
|
||||
|
|
Loading…
Reference in a new issue